mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-18 14:34:04 +09:00
more efficient particles
Former-commit-id: 56dad88ecd715ad6e357e33b903851a47a358dcd Former-commit-id: c85c0b759a447c0461563d98156f59879fa95db2
This commit is contained in:
@@ -4,7 +4,7 @@ import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
|
||||
/**
|
||||
* Created by SKYHi14 on 2017-01-21.
|
||||
* Created by minjaesong on 2017-01-21.
|
||||
*/
|
||||
abstract class ActorVisible(renderOrder: ActorOrder) : Actor(renderOrder) {
|
||||
open val hitbox = Hitbox(0.0, 0.0, 0.0, 0.0)
|
||||
|
||||
@@ -13,16 +13,14 @@ import org.newdawn.slick.Image
|
||||
/**
|
||||
* Actors with static sprites and very simple physics
|
||||
*
|
||||
* Created by SKYHi14 on 2017-01-20.
|
||||
* Created by minjaesong on 2017-01-20.
|
||||
*/
|
||||
open class ParticleBase(renderOrder: ActorOrder, maxLifeTime: Int? = null) : ActorVisible(renderOrder), Projectile {
|
||||
open class ParticleBase(renderOrder: ActorOrder, maxLifeTime: Int? = null) : Runnable {
|
||||
|
||||
override var actorValue = ActorValue()
|
||||
override @Volatile var flagDespawn = false
|
||||
/** Will NOT actually delete from the CircularArray */
|
||||
@Volatile var flagDespawn = false
|
||||
|
||||
override fun run() {
|
||||
TODO("not implemented")
|
||||
}
|
||||
override fun run() = update(Terrarum.appgc, Terrarum.ingame.UPDATE_DELTA)
|
||||
|
||||
var isNoSubjectToGrav = false
|
||||
var dragCoefficient = 3.0
|
||||
@@ -31,38 +29,47 @@ open class ParticleBase(renderOrder: ActorOrder, maxLifeTime: Int? = null) : Act
|
||||
private var lifetimeCounter = 0
|
||||
|
||||
open val velocity = Vector2(0.0, 0.0)
|
||||
open val hitbox = Hitbox(0.0, 0.0, 0.0, 0.0)
|
||||
|
||||
open lateinit var image: Image
|
||||
open lateinit var body: Image
|
||||
open var glow: Image? = null
|
||||
|
||||
init {
|
||||
|
||||
}
|
||||
|
||||
override fun update(gc: GameContainer, delta: Int) {
|
||||
lifetimeCounter += delta
|
||||
if (velocity.isZero || lifetimeCounter >= lifetimeMax ||
|
||||
// simple stuck check
|
||||
TileCodex[Terrarum.ingame.world.getTileFromTerrain(
|
||||
hitbox.pointedX.div(TILE_SIZE).floorInt(),
|
||||
hitbox.pointedY.div(TILE_SIZE).floorInt()
|
||||
) ?: Tile.STONE].isSolid) {
|
||||
flagDespawn = true
|
||||
fun update(gc: GameContainer, delta: Int) {
|
||||
if (!flagDespawn) {
|
||||
lifetimeCounter += delta
|
||||
if (velocity.isZero || lifetimeCounter >= lifetimeMax ||
|
||||
// simple stuck check
|
||||
TileCodex[Terrarum.ingame.world.getTileFromTerrain(
|
||||
hitbox.pointedX.div(TILE_SIZE).floorInt(),
|
||||
hitbox.pointedY.div(TILE_SIZE).floorInt()
|
||||
) ?: Tile.STONE].isSolid) {
|
||||
flagDespawn = true
|
||||
}
|
||||
|
||||
// gravity, winds, etc. (external forces)
|
||||
if (!isNoSubjectToGrav) {
|
||||
velocity += Terrarum.ingame.world.gravitation / dragCoefficient * SI_TO_GAME_ACC
|
||||
}
|
||||
|
||||
|
||||
// combine external forces
|
||||
hitbox.translate(velocity)
|
||||
}
|
||||
|
||||
// gravity, winds, etc. (external forces)
|
||||
if (!isNoSubjectToGrav) {
|
||||
velocity += Terrarum.ingame.world.gravitation / dragCoefficient * SI_TO_GAME_ACC
|
||||
}
|
||||
|
||||
|
||||
// combine external forces
|
||||
hitbox.translate(velocity)
|
||||
}
|
||||
|
||||
override fun drawBody(g: Graphics) {
|
||||
g.drawImage(image, hitbox.centeredX.toFloat(), hitbox.centeredY.toFloat())
|
||||
fun drawBody(g: Graphics) {
|
||||
if (!flagDespawn) {
|
||||
g.drawImage(body, hitbox.centeredX.toFloat(), hitbox.centeredY.toFloat())
|
||||
}
|
||||
}
|
||||
|
||||
override fun drawGlow(g: Graphics) {
|
||||
fun drawGlow(g: Graphics) {
|
||||
if (!flagDespawn && glow != null) {
|
||||
g.drawImage(glow, hitbox.centeredX.toFloat(), hitbox.centeredY.toFloat())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,21 +4,21 @@ import org.dyn4j.geometry.Vector2
|
||||
import org.newdawn.slick.Image
|
||||
|
||||
/**
|
||||
* Created by SKYHi14 on 2017-01-20.
|
||||
* Created by minjaesong on 2017-01-20.
|
||||
*/
|
||||
class ParticleTestRain(posX: Double, posY: Double) : ParticleBase(ActorOrder.BEHIND, 6000) {
|
||||
|
||||
init {
|
||||
image = Image("./assets/graphics/weathers/raindrop.tga")
|
||||
val w = image.width.toDouble()
|
||||
val h = image.height.toDouble()
|
||||
body = Image("./assets/graphics/weathers/raindrop.tga")
|
||||
val w = body.width.toDouble()
|
||||
val h = body.height.toDouble()
|
||||
hitbox.setFromWidthHeight(
|
||||
posX - w.times(0.5),
|
||||
posY - h.times(0.5),
|
||||
w, h
|
||||
)
|
||||
|
||||
velocity.y = 16.0
|
||||
velocity.y = 10.0
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Image
|
||||
|
||||
/**
|
||||
* Created by SKYHi14 on 2017-01-07.
|
||||
* Created by minjaesong on 2017-01-07.
|
||||
*/
|
||||
class TapestryObject(val image: Image, val artName: String, val artAuthor: String) : FixtureBase(physics = false) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user