mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-10 02:24:05 +09:00
code cleanup related to ActorWithPhysics
This commit is contained in:
@@ -458,12 +458,12 @@ class StateInGame : BasicGameState() {
|
|||||||
// velocity
|
// velocity
|
||||||
worldG.color = GameFontBase.codeToCol["g"]
|
worldG.color = GameFontBase.codeToCol["g"]
|
||||||
worldG.drawString(
|
worldG.drawString(
|
||||||
"${0x7F.toChar()}X ${actor.moveDelta.x}",
|
"${0x7F.toChar()}X ${actor.externalForce.x}",
|
||||||
actor.hitbox.posX.toFloat(),
|
actor.hitbox.posX.toFloat(),
|
||||||
actor.hitbox.pointedY.toFloat() + 4 + 8
|
actor.hitbox.pointedY.toFloat() + 4 + 8
|
||||||
)
|
)
|
||||||
worldG.drawString(
|
worldG.drawString(
|
||||||
"${0x7F.toChar()}Y ${actor.moveDelta.y}",
|
"${0x7F.toChar()}Y ${actor.externalForce.y}",
|
||||||
actor.hitbox.posX.toFloat(),
|
actor.hitbox.posX.toFloat(),
|
||||||
actor.hitbox.pointedY.toFloat() + 4 + 8 * 2
|
actor.hitbox.pointedY.toFloat() + 4 + 8 * 2
|
||||||
)
|
)
|
||||||
@@ -510,7 +510,7 @@ class StateInGame : BasicGameState() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun keyPressed(key: Int, c: Char) {
|
override fun keyPressed(key: Int, c: Char) {
|
||||||
if (key == Key.GRAVE) {
|
if (key == Key.GRAVE || key == Key.ESCAPE) {
|
||||||
consoleHandler.toggleOpening()
|
consoleHandler.toggleOpening()
|
||||||
}
|
}
|
||||||
else if (key == Key.F3) {
|
else if (key == Key.F3) {
|
||||||
|
|||||||
@@ -71,7 +71,6 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
|
|||||||
*/
|
*/
|
||||||
internal val externalForce = Vector2(0.0, 0.0)
|
internal val externalForce = Vector2(0.0, 0.0)
|
||||||
|
|
||||||
//val moveDelta = Vector2(0.0, 0.0) // moveDelta = velocity + controllerMoveDelta
|
|
||||||
@Transient private val VELO_HARD_LIMIT = 100.0
|
@Transient private val VELO_HARD_LIMIT = 100.0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ class Hitbox(x1: Double, y1: Double, width: Double, height: Double) {
|
|||||||
fun setPositionX(x: Double) = setPosition(x, posY)
|
fun setPositionX(x: Double) = setPosition(x, posY)
|
||||||
fun setPositionY(y: Double) = setPosition(posX, y)
|
fun setPositionY(y: Double) = setPosition(posX, y)
|
||||||
|
|
||||||
fun setPositionFromPoint(x1: Double, y1: Double): Hitbox {
|
fun setPositionFromPointed(x1: Double, y1: Double): Hitbox {
|
||||||
hitboxStart = Point2d(x1 - width / 2, y1 - height)
|
hitboxStart = Point2d(x1 - width / 2, y1 - height)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ open class ProjectileSimple(
|
|||||||
override fun update(gc: GameContainer, delta: Int) {
|
override fun update(gc: GameContainer, delta: Int) {
|
||||||
// hit something and despawn
|
// hit something and despawn
|
||||||
lifetimeCounter += delta
|
lifetimeCounter += delta
|
||||||
if (ccdCollided || grounded || lifetimeCounter >= lifetimeMax ||
|
if (grounded || lifetimeCounter >= lifetimeMax || // ccdCollided ||
|
||||||
// stuck check
|
// stuck check
|
||||||
BlockCodex[Terrarum.ingame!!.world.getTileFromTerrain(feetPosTile[0], feetPosTile[1]) ?: Block.STONE].isSolid
|
BlockCodex[Terrarum.ingame!!.world.getTileFromTerrain(feetPosTile[0], feetPosTile[1]) ?: Block.STONE].isSolid
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -55,13 +55,14 @@ internal class AILuaAPI(g: Globals, actor: ActorWithPhysics) {
|
|||||||
*/
|
*/
|
||||||
fun composeActorObject(actor: ActorWithPhysics): LuaTable {
|
fun composeActorObject(actor: ActorWithPhysics): LuaTable {
|
||||||
val t: LuaTable = LuaTable()
|
val t: LuaTable = LuaTable()
|
||||||
|
val moveDelta = actor.externalForce + actor.controllerMoveDelta
|
||||||
|
|
||||||
t["name"] = actor.actorValue.getAsString(AVKey.NAME).toLua()
|
t["name"] = actor.actorValue.getAsString(AVKey.NAME).toLua()
|
||||||
t["posX"] = actor.hitbox.centeredX.toLua()
|
t["posX"] = actor.hitbox.centeredX.toLua()
|
||||||
t["posY"] = actor.hitbox.centeredY.toLua()
|
t["posY"] = actor.hitbox.centeredY.toLua()
|
||||||
|
|
||||||
t["veloX"] = actor.moveDelta.x.toLua()
|
t["veloX"] = moveDelta.x.toLua()
|
||||||
t["veloY"] = actor.moveDelta.y.toLua()
|
t["veloY"] = moveDelta.y.toLua()
|
||||||
|
|
||||||
t["width"] = actor.hitbox.width.toLua()
|
t["width"] = actor.hitbox.width.toLua()
|
||||||
t["height"] = actor.hitbox.height.toLua()
|
t["height"] = actor.hitbox.height.toLua()
|
||||||
|
|||||||
@@ -150,10 +150,13 @@ object CollisionSolver {
|
|||||||
|
|
||||||
// if they actually makes collision (e.g. player vs ball), solve it
|
// if they actually makes collision (e.g. player vs ball), solve it
|
||||||
if (a makesCollisionWith b) {
|
if (a makesCollisionWith b) {
|
||||||
val ux_1 = a.moveDelta.x
|
val a_moveDelta = a.externalForce + a.controllerMoveDelta
|
||||||
val ux_2 = b.moveDelta.x
|
val b_moveDelta = b.externalForce + b.controllerMoveDelta
|
||||||
val uy_1 = a.moveDelta.y
|
|
||||||
val uy_2 = b.moveDelta.y
|
val ux_1 = a_moveDelta.x
|
||||||
|
val ux_2 = b_moveDelta.x
|
||||||
|
val uy_1 = a_moveDelta.y
|
||||||
|
val uy_2 = b_moveDelta.y
|
||||||
val m1 = a.mass
|
val m1 = a.mass
|
||||||
val m2 = b.mass
|
val m2 = b.mass
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user