mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-15 21:14:04 +09:00
tiki torch now spawns smoke particles and flames are randomly animated
This commit is contained in:
@@ -2,8 +2,10 @@ package net.torvald.terrarum.gameparticles
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.spriteanimation.SpriteAnimation
|
||||
import net.torvald.terrarum.gameactors.Actor
|
||||
import net.torvald.terrarum.imagefont.TinyAlphNum
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
|
||||
/**
|
||||
* @param tex image
|
||||
@@ -14,7 +16,7 @@ open class ParticleVanishingTexture(val tex: TextureRegion, x: Double, y: Double
|
||||
|
||||
init {
|
||||
velocity.set(0.0, -1.0)
|
||||
hitbox.setDimension(2.0, 2.0)
|
||||
hitbox.setDimension(tex.regionWidth.toDouble(), tex.regionHeight.toDouble())
|
||||
hitbox.setPositionFromPointed(x, y)
|
||||
|
||||
body = tex
|
||||
@@ -29,6 +31,11 @@ open class ParticleVanishingTexture(val tex: TextureRegion, x: Double, y: Double
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param text a text
|
||||
* @param x x-coord of the particle's initial spawn position, bottom-centre
|
||||
* @param y y-coord of the particle's initial spawn position, bottom-centre
|
||||
*/
|
||||
class ParticleVanishingText(val text: String, x: Double, y: Double) : ParticleBase(Actor.RenderOrder.OVERLAY, false, 2f) {
|
||||
|
||||
private val lines = text.split('\n')
|
||||
@@ -55,4 +62,43 @@ class ParticleVanishingText(val text: String, x: Double, y: Double) : ParticleBa
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tex image
|
||||
* @param x x-coord of the particle's initial spawn position, bottom-centre
|
||||
* @param y y-coord of the particle's initial spawn position, bottom-centre
|
||||
*/
|
||||
open class ParticleVanishingSprite(val sprite: TextureRegionPack, val delay: Float, x: Double, y: Double, val start: Int = 0) : ParticleBase(Actor.RenderOrder.OVERLAY, false, 2f) {
|
||||
|
||||
private var row = 0
|
||||
private var frame = start % sprite.horizontalCount
|
||||
private var frameAdvanceCounter = 0f
|
||||
|
||||
init {
|
||||
velocity.set(0.0, -1.0)
|
||||
hitbox.setDimension(sprite.tileW.toDouble(), sprite.tileH.toDouble())
|
||||
hitbox.setPositionFromPointed(x, y)
|
||||
|
||||
isNoSubjectToGrav = true
|
||||
}
|
||||
|
||||
override fun update(delta: Float) {
|
||||
super.update(delta)
|
||||
|
||||
drawColour.a = (lifetimeMax - lifetimeCounter) / lifetimeMax
|
||||
|
||||
if (frameAdvanceCounter >= delay) {
|
||||
frameAdvanceCounter -= delay
|
||||
frame = (frame + 1) % sprite.horizontalCount
|
||||
}
|
||||
frameAdvanceCounter += delta
|
||||
}
|
||||
|
||||
override fun drawBody(batch: SpriteBatch) {
|
||||
if (!flagDespawn) {
|
||||
batch.color = drawColour
|
||||
batch.draw(sprite.get(frame, row), hitbox.startX.toFloat(), hitbox.startY.toFloat())
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user