mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
pick and hammer spawns particles
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,10 +11,13 @@ import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
import net.torvald.terrarum.gameitems.mouseInInteractableRangeTools
|
||||
import net.torvald.terrarum.gameparticles.createRandomBlockParticle
|
||||
import net.torvald.terrarum.itemproperties.Calculate
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.DroppedItem
|
||||
import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore.BASE_MASS_AND_SIZE
|
||||
import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore.TOOL_DURABILITY_BASE
|
||||
import org.dyn4j.geometry.Vector2
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
@@ -90,6 +93,17 @@ 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 = false
|
||||
(Terrarum.ingame as TerrarumIngame).addParticle(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,10 +10,14 @@ import net.torvald.terrarum.gameactors.ActorWithBody
|
||||
import net.torvald.terrarum.gameitems.GameItem
|
||||
import net.torvald.terrarum.gameitems.ItemID
|
||||
import net.torvald.terrarum.gameitems.mouseInInteractableRangeTools
|
||||
import net.torvald.terrarum.gameparticles.createRandomBlockParticle
|
||||
import net.torvald.terrarum.itemproperties.Calculate
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.modulebasegame.gameactors.DroppedItem
|
||||
import net.torvald.terrarum.modulebasegame.gameitems.SledgehammerCore.BASE_MASS_AND_SIZE
|
||||
import net.torvald.terrarum.modulebasegame.gameitems.SledgehammerCore.TOOL_DURABILITY_BASE
|
||||
import net.torvald.terrarum.worlddrawer.CreateTileAtlas
|
||||
import org.dyn4j.geometry.Vector2
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
@@ -95,6 +99,18 @@ 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 = false
|
||||
it.drawColour.set(App.tileMaker.wallOverlayColour)
|
||||
(Terrarum.ingame as TerrarumIngame).addParticle(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user