better particle emission on block break

This commit is contained in:
minjaesong
2023-10-12 14:28:39 +09:00
parent 3a3d789777
commit 93d33b793c
5 changed files with 55 additions and 47 deletions

View File

@@ -1245,6 +1245,10 @@ public class App implements ApplicationListener {
public static String recycledPlayersDir;
/** defaultDir + "/Recycled/Worlds" */
public static String recycledWorldsDir;
/** defaultDir + "/Custom/" */
public static String customDir;
/** defaultDir + "/Custom/Music" */
public static String customMusicDir;
private static void getDefaultDirectory() {
String OS = OSName.toUpperCase();
@@ -1278,6 +1282,8 @@ public class App implements ApplicationListener {
recycledPlayersDir = defaultDir + "/Recycled/Players";
recycledWorldsDir = defaultDir + "/Recycled/Worlds";
importDir = defaultDir + "/Imports";
customDir = defaultDir + "/Custom";
customMusicDir = customDir + "/Music";
System.out.println(String.format("os.name = %s (with identifier %s)", OSName, operationSystem));
System.out.println(String.format("os.version = %s", OSVersion));
@@ -1293,7 +1299,9 @@ public class App implements ApplicationListener {
new File(worldsDir),
new File(recycledPlayersDir),
new File(recycledWorldsDir),
new File(importDir)
new File(importDir),
new File(customDir),
new File(customMusicDir)
};
for (File it : dirs) {

View File

@@ -22,7 +22,7 @@ open class ParticleBase(renderOrder: Actor.RenderOrder, var despawnUponCollision
override fun run() = update(App.UPDATE_RATE)
var isNoSubjectToGrav = false
var dragCoefficient = 36.0
var dragCoefficient = 40.0
val lifetimeMax = maxLifeTime ?: 5f
var lifetimeCounter = 0f
@@ -55,8 +55,8 @@ open class ParticleBase(renderOrder: Actor.RenderOrder, var despawnUponCollision
)].isSolid) {
if (despawnUponCollision) flagDespawn = true
if (!noCollision) velocity.y = 0.0
if (despawnUponCollision && lifetimeCounter >= 0.1f) flagDespawn = true
if (!noCollision && lifetimeCounter >= 0.1f) velocity.y = 0.0
}
if (lifetimeCounter >= lifetimeMax) {

View File

@@ -41,23 +41,12 @@ open class ParticleVanishingTexture(val tex: TextureRegion, x: Double, y: Double
}
// pickaxe sparks must use different create- function
fun createRandomBlockParticle(block: ItemID, position: Vector2, velocityMult: Double): ParticleBase {
fun createRandomBlockParticle(tileNum: Int, position: Vector2, velocityMult: Vector2, tx: Int, ty: Int, tw: Int, th: Int): ParticleBase {
val velocity = Vector2(
(Math.random() + Math.random()) * velocityMult,
0.0
(Math.random() + Math.random()) * velocityMult.x,
-velocityMult.y
) // 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
@@ -65,10 +54,8 @@ fun createRandomBlockParticle(block: ItemID, position: Vector2, velocityMult: Do
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)
val texRegionBody = TextureRegion(texBody.texture, texBody.regionX + tx, texBody.regionY + ty, tw, th)
val texRegionGlow = TextureRegion(texGlow.texture, texGlow.regionX + tx, texGlow.regionY + ty, tw, th)
return ParticleVanishingTexture(texRegionBody, position.x, position.y).also {
it.glow = texRegionGlow

View File

@@ -1,5 +1,6 @@
package net.torvald.terrarum.modulebasegame.gameitems
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.terrarum.*
import net.torvald.terrarum.App.printdbg
@@ -53,10 +54,13 @@ object PickaxeCore {
for (oy in 0 until mh) for (ox in 0 until mw) {
val x = mx + xoff + ox
val y = my + yoff + oy
val (wx, wy) = INGAME.world.coerceXY(x, y)
val mousePoint = Point2d(x.toDouble(), y.toDouble())
val actorvalue = actor.actorValue
val tile = (INGAME.world).getTileFromTerrain(x, y)
val tile = INGAME.world.getTileFromTerrain(x, y)
val tileNum = INGAME.world.layerTerrain.unsafeGetTile(wx, wy)
item?.using = true
@@ -80,7 +84,7 @@ object PickaxeCore {
val swingDmgToFrameDmg = delta.toDouble() / actorvalue.getAsDouble(AVKey.ACTION_INTERVAL)!!
val (oreOnTile, _) = INGAME.world.getTileFromOre(x, y)
(INGAME.world).inflictTerrainDamage(
INGAME.world.inflictTerrainDamage(
x, y,
Calculate.pickaxePower(actor, item?.material) * swingDmgToFrameDmg
)?.let { tileBroken ->
@@ -93,17 +97,7 @@ object PickaxeCore {
if (drop.isNotBlank()) {
INGAME.queueActorAddition(DroppedItem(drop, (x + 0.5) * TILE_SIZED, (y + 1.0) * TILE_SIZED))
}
repeat(9) {
val pos = Vector2(
x * TILE_SIZED + 2 + (4 * (it % 3)),
y * TILE_SIZED + 4 + (4 * (it / 3))
)
createRandomBlockParticle(tile, pos, 1.0 * (if (Math.random() < 0.5) -1 else 1)).let {
it.despawnUponCollision = true
(Terrarum.ingame as TerrarumIngame).addParticle(it)
}
}
makeDust(tileNum, x, y, 9)
}
}
@@ -114,6 +108,33 @@ object PickaxeCore {
usageStatus
}
private val pixelOffs = intArrayOf(2, 7, 12) // hard-coded assuming TILE_SIZE=16
fun makeDust(tileNum: Int, x: Int, y: Int, density: Int = 9, drawCol: Color = Color.WHITE) {
val pw = 3
val ph = 3
val xo = App.GLOBAL_RENDER_TIMER and 1
val yo = App.GLOBAL_RENDER_TIMER.ushr(1) and 1
val indices = (0..8).toList().shuffled().subList(0, density)
for (it in indices) {
val u = pixelOffs[it % 3]
val v = pixelOffs[it / 3]
val pos = Vector2(
TILE_SIZED * x + u + xo,
TILE_SIZED * y + v + yo - ph,
)
val veloMult = Vector2(
1.0 * (if (Math.random() < 0.5) -1 else 1),
(2.0 - (it / 3)) / 2.0 // 1, 0.5, 0
)
createRandomBlockParticle(tileNum, pos, veloMult, u, v, pw, ph).let {
it.despawnUponCollision = true
it.drawColour.set(drawCol)
(Terrarum.ingame as TerrarumIngame).addParticle(it)
}
}
}
fun endPrimaryUse(actor: ActorWithBody, delta: Float, item: GameItem): Boolean {
item.using = false

View File

@@ -56,10 +56,13 @@ object SledgehammerCore {
val x = mx + xoff + ox
val y = my + yoff + oy
val (wx, wy) = INGAME.world.coerceXY(x, y)
val mousePoint = Point2d(x.toDouble(), y.toDouble())
val actorvalue = actor.actorValue
val wall = INGAME.world.getTileFromWall(x, y)
val tileTerrain = INGAME.world.getTileFromTerrain(x, y)
val tileNum = INGAME.world.layerWall.unsafeGetTile(wx, wy)
val wallNear = listOf(
INGAME.world.getTileFromWall(x, (y - 1).coerceAtLeast(0)),
@@ -99,18 +102,7 @@ object SledgehammerCore {
if (drop.isNotBlank()) {
INGAME.queueActorAddition(DroppedItem("wall@$drop", (x + 0.5) * TILE_SIZED, (y + 1.0) * TILE_SIZED))
}
repeat(9) {
val pos = Vector2(
x * TILE_SIZED + 2 + (4 * (it % 3)),
y * TILE_SIZED + 4 + (4 * (it / 3))
)
createRandomBlockParticle(wall, pos, 1.0 * (if (Math.random() < 0.5) -1 else 1)).let {
it.despawnUponCollision = true
it.drawColour.set(App.tileMaker.wallOverlayColour)
(Terrarum.ingame as TerrarumIngame).addParticle(it)
}
}
PickaxeCore.makeDust(tileNum, x, y, 9, App.tileMaker.wallOverlayColour)
}
}