no message

This commit is contained in:
minjaesong
2017-05-25 17:43:02 +09:00
parent 5255ae60af
commit f466f6f001
2 changed files with 56 additions and 61 deletions

View File

@@ -55,8 +55,8 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
val tilewiseHitbox: Hitbox val tilewiseHitbox: Hitbox
get() = Hitbox.fromTwoPoints( get() = Hitbox.fromTwoPoints(
hitbox.posX.div(TILE_SIZE).floor(), hitbox.startX.div(TILE_SIZE).floor(),
hitbox.posY.div(TILE_SIZE).floor(), hitbox.startY.div(TILE_SIZE).floor(),
hitbox.endX.div(TILE_SIZE).floor(), hitbox.endX.div(TILE_SIZE).floor(),
hitbox.endY.div(TILE_SIZE).floor() hitbox.endY.div(TILE_SIZE).floor()
) )
@@ -157,9 +157,10 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
* Flags and Properties * Flags and Properties
*/ */
val grounded: Boolean val grounded: Boolean
get() = isPlayerNoClip || isTouchingSide(hitbox, COLLIDING_BOTTOM) get() = isPlayerNoClip ||
(world.gravitation.y > 0 && isTouchingSide(hitbox, COLLIDING_BOTTOM) ||
world.gravitation.y < 0 && isTouchingSide(hitbox, COLLIDING_TOP))
/** Default to 'true' */ /** Default to 'true' */
var isVisible = true var isVisible = true
/** Default to 'true' */ /** Default to 'true' */
@@ -716,22 +717,17 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
// apply Normal Force // apply Normal Force
// next step (resolve controllerMoveDelta) requires this to be pre-handled // next step (resolve controllerMoveDelta) requires this to be pre-handled
if (isTouchingSide(simulationHitbox, COLLIDING_BOTTOM)) { if (isTouchingSide(simulationHitbox, COLLIDING_BOTTOM)) {
//if (gravitation.y > 0.0) grounded = true
// reset walkY
walkY *= elasticity walkY *= elasticity
externalForce.y *= elasticity externalForce.y *= elasticity
debug1("!! grounded ${Random().nextInt(1000)}!!") debug1("!! grounded ${Random().nextInt(1000)}!!")
} }
else if (isTouchingSide(simulationHitbox, COLLIDING_TOP)) { else if (isTouchingSide(simulationHitbox, COLLIDING_TOP)) {
//if (gravitation.y < 0.0) grounded = true
// reset walkY
walkY *= elasticity walkY *= elasticity
externalForce.y *= elasticity externalForce.y *= elasticity
debug1("!! headbutt ${Random().nextInt(1000)}!!") debug1("!! headbutt ${Random().nextInt(1000)}!!")
} }
if (isTouchingSide(simulationHitbox, COLLIDING_LR)) { if (isTouchingSide(simulationHitbox, COLLIDING_LR)) {
// reset walkX
//walkX *= elasticity //walkX *= elasticity
externalForce.x *= elasticity externalForce.x *= elasticity
debug1("!! tackle ${Random().nextInt(1000)}!!") debug1("!! tackle ${Random().nextInt(1000)}!!")
@@ -783,8 +779,8 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
} }
if (isTouchingSide(simulationHitboxX, COLLIDING_LEFT) || isTouchingSide(simulationHitboxX, COLLIDING_RIGHT)) { if (isTouchingSide(simulationHitboxX, COLLIDING_LR)) {
controllerMoveDelta!!.x *= elasticity //controllerMoveDelta!!.x *= elasticity // FIXME commented: "brake" applied when climbing down several steps
} }
} }
@@ -811,7 +807,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
// set new mid // set new mid
// TODO UD-touching or colliding? // TODO UD-touching or colliding?
if (isTouchingSide(simulationHitboxY, COLLIDING_TOP) || isTouchingSide(simulationHitboxY, COLLIDING_BOTTOM)) { if (isTouchingSide(simulationHitboxY, COLLIDING_UD)) {
debug3("y bmid = $bmid, new endY: ${simulationHitboxY.endY}, going back") debug3("y bmid = $bmid, new endY: ${simulationHitboxY.endY}, going back")
high = bmid high = bmid
} }
@@ -828,7 +824,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
} }
simulationHitbox.setPosition(simulationHitboxX.posX, simulationHitboxY.posY) simulationHitbox.setPosition(simulationHitboxX.startX, simulationHitboxY.startY)
debug3("== END ControllerMoveDelta ==") debug3("== END ControllerMoveDelta ==")
} }
@@ -974,9 +970,9 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
if (isNoCollideWorld) return false if (isNoCollideWorld) return false
// detectors are inside of the bounding box // detectors are inside of the bounding box
val x1 = hitbox.posX val x1 = hitbox.startX
val x2 = hitbox.endX - A_PIXEL val x2 = hitbox.endX - A_PIXEL
val y1 = hitbox.posY val y1 = hitbox.startY
val y2 = hitbox.endY - A_PIXEL val y2 = hitbox.endY - A_PIXEL
@@ -1009,40 +1005,39 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
// detectors are inside of the bounding box // detectors are inside of the bounding box
if (option == COLLIDING_TOP) { if (option == COLLIDING_TOP) {
x1 = hitbox.posX x1 = hitbox.startX
x2 = hitbox.endX - A_PIXEL x2 = hitbox.endX - A_PIXEL
y1 = hitbox.posY - A_PIXEL - A_PIXEL y1 = hitbox.startY - A_PIXEL - A_PIXEL
y2 = y1 y2 = y1
} }
else if (option == COLLIDING_BOTTOM) { else if (option == COLLIDING_BOTTOM) {
x1 = hitbox.posX x1 = hitbox.startX
x2 = hitbox.endX - A_PIXEL x2 = hitbox.endX - A_PIXEL
y1 = hitbox.endY y1 = hitbox.endY
y2 = y1 y2 = y1
} }
else if (option == COLLIDING_LEFT) { else if (option == COLLIDING_LEFT) {
x1 = hitbox.posX - A_PIXEL x1 = hitbox.startX - A_PIXEL
x2 = x1 x2 = x1
y1 = hitbox.posY y1 = hitbox.startY
y2 = hitbox.endY - A_PIXEL y2 = hitbox.endY - A_PIXEL
} }
else if (option == COLLIDING_RIGHT) { else if (option == COLLIDING_RIGHT) {
x1 = hitbox.endX x1 = hitbox.endX
x2 = x1 x2 = x1
y1 = hitbox.posY y1 = hitbox.startY
y2 = hitbox.endY - A_PIXEL y2 = hitbox.endY - A_PIXEL
} }
else if (option == COLLIDING_ALLSIDE) { else if (option == COLLIDING_ALLSIDE) {
x1 = hitbox.posX - A_PIXEL return isTouchingSide(hitbox, COLLIDING_LEFT) || isTouchingSide(hitbox, COLLIDING_RIGHT) ||
x2 = hitbox.endX isTouchingSide(hitbox, COLLIDING_BOTTOM) || isTouchingSide(hitbox, COLLIDING_TOP)
y1 = hitbox.posY - A_PIXEL
y2 = hitbox.endY
} }
else if (option == COLLIDING_LR) { else if (option == COLLIDING_LR) {
x1 = hitbox.posX - A_PIXEL return isTouchingSide(hitbox, COLLIDING_LEFT) || isTouchingSide(hitbox, COLLIDING_RIGHT)
x2 = hitbox.endX }
y1 = hitbox.posY else if (option == COLLIDING_UD) {
y2 = hitbox.endY - A_PIXEL return isTouchingSide(hitbox, COLLIDING_BOTTOM) || isTouchingSide(hitbox, COLLIDING_TOP)
} }
else throw IllegalArgumentException() else throw IllegalArgumentException()
@@ -1340,23 +1335,23 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
if (WorldCamera.xCentre > leftsidePadding && centrePosPoint.x <= rightsidePadding) { if (WorldCamera.xCentre > leftsidePadding && centrePosPoint.x <= rightsidePadding) {
// camera center neg, actor center pos // camera center neg, actor center pos
spriteGlow!!.render(g, spriteGlow!!.render(g,
(hitbox.posX - offsetX).toFloat() + world.width * TILE_SIZE, (hitbox.startX - offsetX).toFloat() + world.width * TILE_SIZE,
(hitbox.posY - offsetY).toFloat(), (hitbox.startY - offsetY).toFloat(),
(scale).toFloat() (scale).toFloat()
) )
} }
else if (WorldCamera.xCentre < rightsidePadding && centrePosPoint.x >= leftsidePadding) { else if (WorldCamera.xCentre < rightsidePadding && centrePosPoint.x >= leftsidePadding) {
// camera center pos, actor center neg // camera center pos, actor center neg
spriteGlow!!.render(g, spriteGlow!!.render(g,
(hitbox.posX - offsetX).toFloat() - world.width * TILE_SIZE, (hitbox.startX - offsetX).toFloat() - world.width * TILE_SIZE,
(hitbox.posY - offsetY).toFloat(), (hitbox.startY - offsetY).toFloat(),
(scale).toFloat() (scale).toFloat()
) )
} }
else { else {
spriteGlow!!.render(g, spriteGlow!!.render(g,
(hitbox.posX - offsetX).toFloat(), (hitbox.startX - offsetX).toFloat(),
(hitbox.posY - offsetY).toFloat(), (hitbox.startY - offsetY).toFloat(),
(scale).toFloat() (scale).toFloat()
) )
} }
@@ -1381,23 +1376,23 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
if (WorldCamera.xCentre > leftsidePadding && centrePosPoint.x <= rightsidePadding) { if (WorldCamera.xCentre > leftsidePadding && centrePosPoint.x <= rightsidePadding) {
// camera center neg, actor center pos // camera center neg, actor center pos
sprite!!.render(g, sprite!!.render(g,
(hitbox.posX - offsetX).toFloat() + world.width * TILE_SIZE, (hitbox.startX - offsetX).toFloat() + world.width * TILE_SIZE,
(hitbox.posY - offsetY).toFloat(), (hitbox.startY - offsetY).toFloat(),
(scale).toFloat() (scale).toFloat()
) )
} }
else if (WorldCamera.xCentre < rightsidePadding && centrePosPoint.x >= leftsidePadding) { else if (WorldCamera.xCentre < rightsidePadding && centrePosPoint.x >= leftsidePadding) {
// camera center pos, actor center neg // camera center pos, actor center neg
sprite!!.render(g, sprite!!.render(g,
(hitbox.posX - offsetX).toFloat() - world.width * TILE_SIZE, (hitbox.startX - offsetX).toFloat() - world.width * TILE_SIZE,
(hitbox.posY - offsetY).toFloat(), (hitbox.startY - offsetY).toFloat(),
(scale).toFloat() (scale).toFloat()
) )
} }
else { else {
sprite!!.render(g, sprite!!.render(g,
(hitbox.posX - offsetX).toFloat(), (hitbox.startX - offsetX).toFloat(),
(hitbox.posY - offsetY).toFloat(), (hitbox.startY - offsetY).toFloat(),
(scale).toFloat() (scale).toFloat()
) )
} }
@@ -1467,8 +1462,8 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
private fun forEachOccupyingTileNum(consumer: (Int?) -> Unit) { private fun forEachOccupyingTileNum(consumer: (Int?) -> Unit) {
val tiles = ArrayList<Int?>() val tiles = ArrayList<Int?>()
for (y in tilewiseHitbox.posY.toInt()..tilewiseHitbox.endY.toInt()) { for (y in tilewiseHitbox.startY.toInt()..tilewiseHitbox.endY.toInt()) {
for (x in tilewiseHitbox.posX.toInt()..tilewiseHitbox.endX.toInt()) { for (x in tilewiseHitbox.startX.toInt()..tilewiseHitbox.endX.toInt()) {
tiles.add(world.getTileFromTerrain(x, y)) tiles.add(world.getTileFromTerrain(x, y))
} }
} }
@@ -1478,8 +1473,8 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
private fun forEachOccupyingTile(consumer: (BlockProp?) -> Unit) { private fun forEachOccupyingTile(consumer: (BlockProp?) -> Unit) {
val tileProps = ArrayList<BlockProp?>() val tileProps = ArrayList<BlockProp?>()
for (y in tilewiseHitbox.posY.toInt()..tilewiseHitbox.endY.toInt()) { for (y in tilewiseHitbox.startY.toInt()..tilewiseHitbox.endY.toInt()) {
for (x in tilewiseHitbox.posX.toInt()..tilewiseHitbox.endX.toInt()) { for (x in tilewiseHitbox.startX.toInt()..tilewiseHitbox.endX.toInt()) {
tileProps.add(BlockCodex[world.getTileFromTerrain(x, y)]) tileProps.add(BlockCodex[world.getTileFromTerrain(x, y)])
} }
} }
@@ -1493,7 +1488,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
// offset 1 pixel to the down so that friction would work // offset 1 pixel to the down so that friction would work
val y = hitbox.endY.plus(1.0).div(TILE_SIZE).floorInt() val y = hitbox.endY.plus(1.0).div(TILE_SIZE).floorInt()
for (x in tilewiseHitbox.posX.toInt()..tilewiseHitbox.endX.toInt()) { for (x in tilewiseHitbox.startX.toInt()..tilewiseHitbox.endX.toInt()) {
tiles.add(world.getTileFromTerrain(x, y)) tiles.add(world.getTileFromTerrain(x, y))
} }
@@ -1506,7 +1501,7 @@ open class ActorWithPhysics(renderOrder: RenderOrder, val immobileBody: Boolean
// offset 1 pixel to the down so that friction would work // offset 1 pixel to the down so that friction would work
val y = hitbox.endY.plus(1.0).div(TILE_SIZE).floorInt() val y = hitbox.endY.plus(1.0).div(TILE_SIZE).floorInt()
for (x in tilewiseHitbox.posX.toInt()..tilewiseHitbox.endX.toInt()) { for (x in tilewiseHitbox.startX.toInt()..tilewiseHitbox.endX.toInt()) {
tileProps.add(BlockCodex[world.getTileFromTerrain(x, y)]) tileProps.add(BlockCodex[world.getTileFromTerrain(x, y)])
} }

View File

@@ -64,9 +64,9 @@ class Hitbox(x1: Double, y1: Double, width: Double, height: Double) {
fun setFromTwoPoints(x1: Double, y1: Double, x2: Double, y2: Double): Hitbox { fun setFromTwoPoints(x1: Double, y1: Double, x2: Double, y2: Double): Hitbox {
return setFromWidthHeight(x1, y1, x2 - x1, y2 - y1) return setFromWidthHeight(x1, y1, x2 - x1, y2 - y1)
} }
fun reassign(other: Hitbox) = setFromTwoPoints(other.posX, other.posY, other.endX, other.endY) fun reassign(other: Hitbox) = setFromTwoPoints(other.startX, other.startY, other.endX, other.endY)
fun translate(x: Double, y: Double) = setPosition(posX + x, posY + y) fun translate(x: Double, y: Double) = setPosition(startX + x, startY + y)
fun translate(vec: Vector2?) = if (vec != null) translate(vec.x, vec.y) else this fun translate(vec: Vector2?) = if (vec != null) translate(vec.x, vec.y) else this
fun setPosition(x1: Double, y1: Double): Hitbox { fun setPosition(x1: Double, y1: Double): Hitbox {
@@ -75,8 +75,8 @@ class Hitbox(x1: Double, y1: Double, width: Double, height: Double) {
} }
fun setPosition(vector: Vector2) = setPosition(vector.x, vector.y) fun setPosition(vector: Vector2) = setPosition(vector.x, vector.y)
fun setPositionX(x: Double) = setPosition(x, posY) fun setPositionX(x: Double) = setPosition(x, startY)
fun setPositionY(y: Double) = setPosition(posX, y) fun setPositionY(y: Double) = setPosition(startX, y)
fun setPositionFromPointed(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)
@@ -84,12 +84,12 @@ class Hitbox(x1: Double, y1: Double, width: Double, height: Double) {
} }
fun translatePosX(d: Double): Hitbox { fun translatePosX(d: Double): Hitbox {
setPositionX(posX + d) setPositionX(startX + d)
return this return this
} }
fun translatePosY(d: Double): Hitbox { fun translatePosY(d: Double): Hitbox {
setPositionY(posY + d) setPositionY(startY + d)
return this return this
} }
@@ -101,16 +101,16 @@ class Hitbox(x1: Double, y1: Double, width: Double, height: Double) {
/** /**
* Returns x value of start point * Returns x value of start point
* @return top-left point posX * @return top-left point startX
*/ */
val posX: Double val startX: Double
get() = hitboxStart.x get() = hitboxStart.x
/** /**
* Returns y value of start point * Returns y value of start point
* @return top-left point posY * @return top-left point startY
*/ */
val posY: Double val startY: Double
get() = hitboxStart.y get() = hitboxStart.y
val centeredX: Double val centeredX: Double
@@ -120,12 +120,12 @@ class Hitbox(x1: Double, y1: Double, width: Double, height: Double) {
get() = (hitboxStart.y + hitboxEnd.y) * 0.5 get() = (hitboxStart.y + hitboxEnd.y) * 0.5
fun intersects(position: Point2d) = fun intersects(position: Point2d) =
(position.x >= posX && position.x <= posX + width) && (position.x >= startX && position.x <= startX + width) &&
(position.y >= posY && position.y <= posY + height) (position.y >= startY && position.y <= startY + height)
fun toVector(): Vector2 = Vector2(posX, posY) fun toVector(): Vector2 = Vector2(startX, startY)
fun clone(): Hitbox = Hitbox(posX, posY, width, height) fun clone(): Hitbox = Hitbox(startX, startY, width, height)
companion object { companion object {
fun fromTwoPoints(x1: Double, y1: Double, x2: Double, y2: Double) = fun fromTwoPoints(x1: Double, y1: Double, x2: Double, y2: Double) =