pick and hammer spawns particles

This commit is contained in:
minjaesong
2023-10-12 01:47:00 +09:00
parent 00ca1d3e1a
commit 6bf535e968
4 changed files with 78 additions and 2 deletions

View File

@@ -14,7 +14,7 @@ import org.dyn4j.geometry.Vector2
*
* Created by minjaesong on 2017-01-20.
*/
open class ParticleBase(renderOrder: Actor.RenderOrder, val despawnUponCollision: Boolean, val noCollision: Boolean = true, maxLifeTime: Second? = null) : Runnable {
open class ParticleBase(renderOrder: Actor.RenderOrder, var despawnUponCollision: Boolean, var noCollision: Boolean = true, maxLifeTime: Second? = null) : Runnable {
/** Will NOT actually delete from the CircularArray */
@Volatile var flagDespawn = false
@@ -22,7 +22,7 @@ open class ParticleBase(renderOrder: Actor.RenderOrder, val despawnUponCollision
override fun run() = update(App.UPDATE_RATE)
var isNoSubjectToGrav = false
var dragCoefficient = 3.0
var dragCoefficient = 36.0
val lifetimeMax = maxLifeTime ?: 5f
var lifetimeCounter = 0f

View File

@@ -2,12 +2,20 @@ package net.torvald.terrarum.gameparticles
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.App
import net.torvald.terrarum.TerrarumAppConfiguration.TILE_SIZE
import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.gameactors.drawBodyInGoodPosition
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.imagefont.TinyAlphNum
import net.torvald.terrarum.worlddrawer.BlocksDrawer
import net.torvald.terrarum.worlddrawer.CreateTileAtlas.RenderTag
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import org.dyn4j.geometry.Vector2
/**
* The texture must be manually discarded.
*
* @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
@@ -29,6 +37,44 @@ open class ParticleVanishingTexture(val tex: TextureRegion, x: Double, y: Double
drawColour.a = (lifetimeMax - lifetimeCounter) / lifetimeMax
}
}
// pickaxe sparks must use different create- function
fun createRandomBlockParticle(block: ItemID, position: Vector2, velocityMult: Double): ParticleBase {
val velocity = Vector2(
(Math.random() + Math.random()) * velocityMult,
0.0
) // triangular distribution with mean of 1.0 * velocityMult
val w = 3
val h = 3
val renderTag = App.tileMaker.getRenderTag(block)
val baseTilenum = renderTag.tileNumber
val representativeTilenum = when (renderTag.maskType) {
RenderTag.MASK_16 -> 15
RenderTag.MASK_47 -> 22
else -> 0
}
val tileNum = baseTilenum + representativeTilenum
val atlasX = tileNum % BlocksDrawer.weatherTerrains[1].horizontalCount
val atlasY = tileNum / BlocksDrawer.weatherTerrains[1].horizontalCount
// take base texture
val texBody = BlocksDrawer.weatherTerrains[1].get(atlasX, atlasY)
val texGlow = BlocksDrawer.tilesGlow.get(atlasX, atlasY)
// take random square part
val ox = (Math.random() * (TILE_SIZE - w + 1)).toInt()
val oy = (Math.random() * (TILE_SIZE - h + 1)).toInt()
val texRegionBody = TextureRegion(texBody.texture, texBody.regionX + ox, texBody.regionY + oy, w, h)
val texRegionGlow = TextureRegion(texGlow.texture, texGlow.regionX + ox, texGlow.regionY + oy, w, h)
return ParticleVanishingTexture(texRegionBody, position.x, position.y).also {
it.glow = texRegionGlow
it.velocity.set(velocity)
it.isNoSubjectToGrav = false
}
}
/**