bigger torch flame sprite; basic physics on particles

This commit is contained in:
minjaesong
2021-08-17 20:51:25 +09:00
parent a2b3334692
commit 9a271b1b9e
6 changed files with 24 additions and 19 deletions

View File

@@ -15,7 +15,7 @@ import org.dyn4j.geometry.Vector2
* *
* Created by minjaesong on 2017-01-20. * Created by minjaesong on 2017-01-20.
*/ */
open class ParticleBase(renderOrder: Actor.RenderOrder, val despawnUponCollision: Boolean, maxLifeTime: Second? = null) : Runnable { open class ParticleBase(renderOrder: Actor.RenderOrder, val despawnUponCollision: Boolean, val noCollision: Boolean = true, maxLifeTime: Second? = null) : Runnable {
/** Will NOT actually delete from the CircularArray */ /** Will NOT actually delete from the CircularArray */
@Volatile var flagDespawn = false @Volatile var flagDespawn = false
@@ -44,15 +44,20 @@ open class ParticleBase(renderOrder: Actor.RenderOrder, val despawnUponCollision
open fun update(delta: Float) { open fun update(delta: Float) {
if (!flagDespawn) { if (!flagDespawn) {
lifetimeCounter += delta lifetimeCounter += delta
if (despawnUponCollision) { if (velocity.isZero ||
if (velocity.isZero || // simple stuck check
// simple stuck check BlockCodex[(Terrarum.ingame!!.world).getTileFromTerrain(
BlockCodex[(Terrarum.ingame!!.world).getTileFromTerrain( hitbox.centeredX.div(TerrarumAppConfiguration.TILE_SIZE).floorInt(),
hitbox.canonicalX.div(TerrarumAppConfiguration.TILE_SIZE).floorInt(), hitbox.startY.div(TerrarumAppConfiguration.TILE_SIZE).floorInt()
hitbox.canonicalY.div(TerrarumAppConfiguration.TILE_SIZE).floorInt() )].isSolid ||
) ?: Block.STONE].isSolid) { BlockCodex[(Terrarum.ingame!!.world).getTileFromTerrain(
flagDespawn = true hitbox.centeredX.div(TerrarumAppConfiguration.TILE_SIZE).floorInt(),
} hitbox.endY.div(TerrarumAppConfiguration.TILE_SIZE).floorInt()
)].isSolid) {
if (despawnUponCollision) flagDespawn = true
if (!noCollision) velocity.y = 0.0
} }
if (lifetimeCounter >= lifetimeMax) { if (lifetimeCounter >= lifetimeMax) {

View File

@@ -12,7 +12,7 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
* @param x x-coord of the particle's initial spawn position, bottom-centre * @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 * @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) { open class ParticleVanishingTexture(val tex: TextureRegion, x: Double, y: Double, noCollision: Boolean = true) : ParticleBase(Actor.RenderOrder.OVERLAY, false, noCollision, 2f) {
init { init {
velocity.set(0.0, -1.0) velocity.set(0.0, -1.0)
@@ -36,7 +36,7 @@ open class ParticleVanishingTexture(val tex: TextureRegion, x: Double, y: Double
* @param x x-coord of the particle's initial spawn position, bottom-centre * @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 * @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) { class ParticleVanishingText(val text: String, x: Double, y: Double, noCollision: Boolean = true) : ParticleBase(Actor.RenderOrder.OVERLAY, false, noCollision, 2f) {
private val lines = text.split('\n') private val lines = text.split('\n')
@@ -69,7 +69,7 @@ class ParticleVanishingText(val text: String, x: Double, y: Double) : ParticleBa
* @param x x-coord of the particle's initial spawn position, bottom-centre * @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 * @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) { open class ParticleVanishingSprite(val sprite: TextureRegionPack, val delay: Float, x: Double, y: Double, val start: Int = 0, noCollision: Boolean = true) : ParticleBase(Actor.RenderOrder.OVERLAY, false, noCollision, 2f) {
private var row = 0 private var row = 0
private var frame = start % sprite.horizontalCount private var frame = start % sprite.horizontalCount

View File

@@ -61,7 +61,7 @@ internal class FixtureTikiTorch(nameFun: () -> String) : FixtureBase(BlockBox(Bl
} }
private var nextDelay = 0.4f private var nextDelay = 0.25f
private var spawnTimer = 0f private var spawnTimer = 0f
override fun update(delta: Float) { override fun update(delta: Float) {
@@ -70,11 +70,11 @@ internal class FixtureTikiTorch(nameFun: () -> String) : FixtureBase(BlockBox(Bl
if (spawnTimer >= nextDelay) { if (spawnTimer >= nextDelay) {
(Terrarum.ingame as TerrarumIngame).addParticle(ParticleVanishingSprite( (Terrarum.ingame as TerrarumIngame).addParticle(ParticleVanishingSprite(
CommonResourcePool.getAsTextureRegionPack("particles-tiki_smoke.tga"), CommonResourcePool.getAsTextureRegionPack("particles-tiki_smoke.tga"),
0.25f, hitbox.centeredX, hitbox.startY + 5, rng.nextInt(256) 0.25f, hitbox.centeredX, hitbox.startY + 5, rng.nextInt(256), false
)) ))
spawnTimer -= nextDelay spawnTimer -= nextDelay
nextDelay = rng.nextFloat() * 0.4f + 0.4f nextDelay = rng.nextFloat() * 0.25f + 0.25f
sprite?.delays?.set(0, rng.nextFloat() * 0.4f + 0.1f) sprite?.delays?.set(0, rng.nextFloat() * 0.4f + 0.1f)
} }

View File

@@ -12,7 +12,7 @@ import net.torvald.terrarum.gameparticles.ParticleBase
/** /**
* Created by minjaesong on 2017-12-18. * Created by minjaesong on 2017-12-18.
*/ */
class ParticleMegaRain(posX: Double, posY: Double) : ParticleBase(Actor.RenderOrder.BEHIND, true, 3.2f) { class ParticleMegaRain(posX: Double, posY: Double) : ParticleBase(Actor.RenderOrder.BEHIND, true, false, 3.2f) {
init { init {
body = MegaRainGovernor.get() body = MegaRainGovernor.get()

View File

@@ -9,7 +9,7 @@ import net.torvald.terrarum.gameparticles.ParticleBase
/** /**
* Created by minjaesong on 2017-01-20. * Created by minjaesong on 2017-01-20.
*/ */
class ParticleTestRain(posX: Double, posY: Double) : ParticleBase(Actor.RenderOrder.BEHIND, true, 6f) { class ParticleTestRain(posX: Double, posY: Double) : ParticleBase(Actor.RenderOrder.BEHIND, true, false, 6f) {
init { init {
body = TextureRegion(Texture(ModMgr.getGdxFile("basegame", "weathers/raindrop.tga"))) body = TextureRegion(Texture(ModMgr.getGdxFile("basegame", "weathers/raindrop.tga")))