vanishing particle test

This commit is contained in:
minjaesong
2021-08-17 15:31:00 +09:00
parent 74ae35e9a9
commit 42c09640d0
10 changed files with 121 additions and 15 deletions

View File

@@ -0,0 +1,58 @@
package net.torvald.terrarum.gameparticles
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.imagefont.TinyAlphNum
/**
* @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 ParticleVanishingTexture(val tex: TextureRegion, x: Double, y: Double) : ParticleBase(Actor.RenderOrder.OVERLAY, false, 2f) {
init {
velocity.set(0.0, -1.0)
hitbox.setDimension(2.0, 2.0)
hitbox.setPositionFromPointed(x, y)
body = tex
isNoSubjectToGrav = true
}
override fun update(delta: Float) {
super.update(delta)
drawColour.a = (lifetimeMax - lifetimeCounter) / lifetimeMax
}
}
class ParticleVanishingText(val text: String, x: Double, y: Double) : ParticleBase(Actor.RenderOrder.OVERLAY, false, 2f) {
private val lines = text.split('\n')
init {
velocity.set(0.0, -1.0)
hitbox.setDimension(lines.maxOf { TinyAlphNum.getWidth(it) }.toDouble(), lines.size * TinyAlphNum.H.toDouble())
hitbox.setPositionFromPointed(x, y)
isNoSubjectToGrav = true
}
override fun update(delta: Float) {
super.update(delta)
drawColour.a = (lifetimeMax - lifetimeCounter) / lifetimeMax
}
override fun drawBody(batch: SpriteBatch) {
if (!flagDespawn) {
batch.color = drawColour
lines.forEachIndexed { index, line ->
TinyAlphNum.draw(batch, line, hitbox.startX.toFloat(), hitbox.startY.toFloat() + TinyAlphNum.H * index)
}
}
}
}