mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
tiki torch now spawns smoke particles and flames are randomly animated
This commit is contained in:
BIN
assets/mods/basegame/particles/tiki_smoke.tga
LFS
Normal file
BIN
assets/mods/basegame/particles/tiki_smoke.tga
LFS
Normal file
Binary file not shown.
Binary file not shown.
@@ -43,7 +43,7 @@ class SpriteAnimation(@Transient val parentActor: ActorWithBody) {
|
||||
|
||||
private var delta = 0f
|
||||
|
||||
val looping = true
|
||||
var looping = true
|
||||
private var animationRunning = true
|
||||
var flipHorizontal = false
|
||||
var flipVertical = false
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,15 +3,14 @@ package net.torvald.terrarum.modulebasegame.gameactors
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
||||
import net.torvald.gdx.graphics.Cvec
|
||||
import net.torvald.random.HQRNG
|
||||
import net.torvald.terrarum.AppLoader
|
||||
import net.torvald.terrarum.IngameInstance
|
||||
import net.torvald.terrarum.ModMgr
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.spriteanimation.SpriteAnimation
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.blockproperties.Block
|
||||
import net.torvald.terrarum.blockproperties.BlockCodex
|
||||
import net.torvald.terrarum.gameactors.AVKey
|
||||
import net.torvald.terrarum.gameactors.Hitbox
|
||||
import net.torvald.terrarum.gameactors.Luminous
|
||||
import net.torvald.terrarum.gameparticles.ParticleVanishingSprite
|
||||
import net.torvald.terrarum.gameparticles.ParticleVanishingText
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
@@ -36,6 +35,15 @@ internal class FixtureTikiTorch(nameFun: () -> String) : FixtureBase(BlockBox(Bl
|
||||
override val lightBoxList: ArrayList<Hitbox>
|
||||
|
||||
init {
|
||||
// loading textures
|
||||
CommonResourcePool.addToLoadingList("sprites-fixtures-tiki_torch.tga") {
|
||||
TextureRegionPack(ModMgr.getGdxFile("basegame", "sprites/fixtures/tiki_torch.tga"), 16, 32)
|
||||
}
|
||||
CommonResourcePool.addToLoadingList("particles-tiki_smoke.tga") {
|
||||
TextureRegionPack(ModMgr.getGdxFile("basegame", "particles/tiki_smoke.tga"), 10, 10)
|
||||
}
|
||||
CommonResourcePool.loadAll()
|
||||
|
||||
density = 1200.0
|
||||
|
||||
setHitboxDimension(16, 32, 0, 0)
|
||||
@@ -43,13 +51,14 @@ internal class FixtureTikiTorch(nameFun: () -> String) : FixtureBase(BlockBox(Bl
|
||||
lightBoxList = ArrayList(1)
|
||||
lightBoxList.add(Hitbox(6.0, 5.0, 4.0, 3.0))
|
||||
|
||||
makeNewSprite(TextureRegionPack(ModMgr.getGdxFile("basegame", "sprites/fixtures/tiki_torch.tga"), 16, 32))
|
||||
sprite!!.setRowsAndFrames(1, 1)
|
||||
makeNewSprite(CommonResourcePool.getAsTextureRegionPack("sprites-fixtures-tiki_torch.tga"))
|
||||
sprite!!.setRowsAndFrames(1, 2)
|
||||
|
||||
actorValue[AVKey.BASEMASS] = MASS
|
||||
|
||||
rndHash1 = rng.nextInt()
|
||||
rndHash2 = rng.nextInt()
|
||||
|
||||
}
|
||||
|
||||
private var nextDelay = 0.4f
|
||||
@@ -59,11 +68,15 @@ internal class FixtureTikiTorch(nameFun: () -> String) : FixtureBase(BlockBox(Bl
|
||||
super.update(delta)
|
||||
|
||||
if (spawnTimer >= nextDelay) {
|
||||
val s = rng.nextInt(1, 1000).toString()
|
||||
(Terrarum.ingame as TerrarumIngame).addParticle(ParticleVanishingText(s, hitbox.centeredX, hitbox.startY + 10))
|
||||
(Terrarum.ingame as TerrarumIngame).addParticle(ParticleVanishingSprite(
|
||||
CommonResourcePool.getAsTextureRegionPack("particles-tiki_smoke.tga"),
|
||||
0.25f, hitbox.centeredX, hitbox.startY + 10, rng.nextInt(256)
|
||||
))
|
||||
|
||||
spawnTimer -= nextDelay
|
||||
nextDelay = rng.nextFloat() * 0.4f + 0.4f
|
||||
|
||||
sprite?.delays?.set(0, rng.nextFloat() * 0.4f + 0.1f)
|
||||
}
|
||||
|
||||
spawnTimer += delta
|
||||
|
||||
Reference in New Issue
Block a user