code cleanup related to ActorWithPhysics

This commit is contained in:
minjaesong
2017-05-10 21:02:05 +09:00
parent 57419a9a24
commit 4f52a4d09b
6 changed files with 15 additions and 12 deletions

View File

@@ -458,12 +458,12 @@ class StateInGame : BasicGameState() {
// velocity
worldG.color = GameFontBase.codeToCol["g"]
worldG.drawString(
"${0x7F.toChar()}X ${actor.moveDelta.x}",
"${0x7F.toChar()}X ${actor.externalForce.x}",
actor.hitbox.posX.toFloat(),
actor.hitbox.pointedY.toFloat() + 4 + 8
)
worldG.drawString(
"${0x7F.toChar()}Y ${actor.moveDelta.y}",
"${0x7F.toChar()}Y ${actor.externalForce.y}",
actor.hitbox.posX.toFloat(),
actor.hitbox.pointedY.toFloat() + 4 + 8 * 2
)
@@ -510,7 +510,7 @@ class StateInGame : BasicGameState() {
}
override fun keyPressed(key: Int, c: Char) {
if (key == Key.GRAVE) {
if (key == Key.GRAVE || key == Key.ESCAPE) {
consoleHandler.toggleOpening()
}
else if (key == Key.F3) {

View File

@@ -71,7 +71,6 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
*/
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
/**

View File

@@ -80,7 +80,7 @@ class Hitbox(x1: Double, y1: Double, width: Double, height: Double) {
fun setPositionX(x: Double) = setPosition(x, posY)
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)
return this
}

View File

@@ -71,7 +71,7 @@ open class ProjectileSimple(
override fun update(gc: GameContainer, delta: Int) {
// hit something and despawn
lifetimeCounter += delta
if (ccdCollided || grounded || lifetimeCounter >= lifetimeMax ||
if (grounded || lifetimeCounter >= lifetimeMax || // ccdCollided ||
// stuck check
BlockCodex[Terrarum.ingame!!.world.getTileFromTerrain(feetPosTile[0], feetPosTile[1]) ?: Block.STONE].isSolid
) {

View File

@@ -55,13 +55,14 @@ internal class AILuaAPI(g: Globals, actor: ActorWithPhysics) {
*/
fun composeActorObject(actor: ActorWithPhysics): LuaTable {
val t: LuaTable = LuaTable()
val moveDelta = actor.externalForce + actor.controllerMoveDelta
t["name"] = actor.actorValue.getAsString(AVKey.NAME).toLua()
t["posX"] = actor.hitbox.centeredX.toLua()
t["posY"] = actor.hitbox.centeredY.toLua()
t["veloX"] = actor.moveDelta.x.toLua()
t["veloY"] = actor.moveDelta.y.toLua()
t["veloX"] = moveDelta.x.toLua()
t["veloY"] = moveDelta.y.toLua()
t["width"] = actor.hitbox.width.toLua()
t["height"] = actor.hitbox.height.toLua()

View File

@@ -150,10 +150,13 @@ object CollisionSolver {
// if they actually makes collision (e.g. player vs ball), solve it
if (a makesCollisionWith b) {
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 a_moveDelta = a.externalForce + a.controllerMoveDelta
val b_moveDelta = b.externalForce + b.controllerMoveDelta
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 m2 = b.mass