mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-14 20:44:05 +09:00
actorwithbody splitted in favour of new particle type
Former-commit-id: 121bd069d0a9eeef60f5ecb085a11a93c4b4a84d Former-commit-id: 539b4b6916e808c01298190cf347e928f61fe62e
This commit is contained in:
68
src/net/torvald/terrarum/gameactors/ParticleBase.kt
Normal file
68
src/net/torvald/terrarum/gameactors/ParticleBase.kt
Normal file
@@ -0,0 +1,68 @@
|
||||
package net.torvald.terrarum.gameactors
|
||||
|
||||
import net.torvald.terrarum.Terrarum
|
||||
import net.torvald.terrarum.gameactors.ActorWithSprite.Companion.SI_TO_GAME_ACC
|
||||
import net.torvald.terrarum.mapdrawer.FeaturesDrawer.TILE_SIZE
|
||||
import net.torvald.terrarum.tileproperties.Tile
|
||||
import net.torvald.terrarum.tileproperties.TileCodex
|
||||
import org.dyn4j.geometry.Vector2
|
||||
import org.newdawn.slick.GameContainer
|
||||
import org.newdawn.slick.Graphics
|
||||
import org.newdawn.slick.Image
|
||||
|
||||
/**
|
||||
* Actors with static sprites and very simple physics
|
||||
*
|
||||
* Created by SKYHi14 on 2017-01-20.
|
||||
*/
|
||||
open class ParticleBase(renderOrder: ActorOrder, maxLifeTime: Int? = null) : ActorVisible(renderOrder), Projectile {
|
||||
|
||||
override var actorValue = ActorValue()
|
||||
override @Volatile var flagDespawn = false
|
||||
|
||||
override fun run() {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
var isNoSubjectToGrav = false
|
||||
var dragCoefficient = 3.0
|
||||
|
||||
private val lifetimeMax = maxLifeTime ?: 5000
|
||||
private var lifetimeCounter = 0
|
||||
|
||||
open val velocity = Vector2(0.0, 0.0)
|
||||
|
||||
open lateinit var image: Image
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// 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())
|
||||
}
|
||||
|
||||
override fun drawGlow(g: Graphics) {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user