more screwing around and commenting

This commit is contained in:
Minjae Song
2018-12-31 00:50:44 +09:00
parent 738d5e669a
commit 1263360d06
5 changed files with 45 additions and 53 deletions

View File

@@ -66,21 +66,32 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
*/
override val hitbox = Hitbox(0.0, 0.0, 0.0, 0.0) // Hitbox is implemented using Double;
/** half integer tilewise hitbox */ // got the idea from gl_FragCoord
/** half integer tilewise hitbox.
* May hold width/height of zero; the end point should be inclusive!
*
* e.g. USE `for (x in hitbox.startX..hitbox.endX)`, NOT `for (x in hitbox.startX until hitbox.endX)`
*/ // got the idea from gl_FragCoord
val hIntTilewiseHitbox: Hitbox
get() = Hitbox.fromTwoPoints(
hitbox.startX.plus(0.00001f).div(TILE_SIZE).floor() + 0.5f,
hitbox.startY.plus(0.00001f).div(TILE_SIZE).floor() + 0.5f,
hitbox.endX.plus(0.00001f).div(TILE_SIZE).floor() + 0.5f,
hitbox.endY.plus(0.00001f).div(TILE_SIZE).floor() + 0.5f
)
hitbox.endY.plus(0.00001f).div(TILE_SIZE).floor() + 0.5f,
true
)
/** May hold width/height of zero; the end point should be inclusive!
*
* e.g. USE `for (x in hitbox.startX..hitbox.endX)`, NOT `for (x in hitbox.startX until hitbox.endX)`
*/
val intTilewiseHitbox: Hitbox
get() = Hitbox.fromTwoPoints(
hitbox.startX.plus(0.00001f).div(TILE_SIZE).floor(),
hitbox.startY.plus(0.00001f).div(TILE_SIZE).floor(),
hitbox.endX.plus(0.00001f).div(TILE_SIZE).floor(),
hitbox.endY.plus(0.00001f).div(TILE_SIZE).floor()
hitbox.endY.plus(0.00001f).div(TILE_SIZE).floor(),
true
)
/**
@@ -601,7 +612,8 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
hitbox.startX.div(TILE_SIZE).floor(),
hitbox.startY.div(TILE_SIZE).floor(),
hitbox.endX.minus(0.00001).div(TILE_SIZE).floor(),
hitbox.endY.minus(0.00001).div(TILE_SIZE).floor()
hitbox.endY.minus(0.00001).div(TILE_SIZE).floor(),
true
)
// offset 1 pixel to the down so that friction would work
@@ -1491,8 +1503,9 @@ open class ActorWBMovable(renderOrder: RenderOrder, val immobileBody: Boolean =
hitbox.startX.div(TILE_SIZE).floor(),
hitbox.startY.div(TILE_SIZE).floor(),
hitbox.endX.minus(0.00001).div(TILE_SIZE).floor(),
hitbox.endY.minus(0.00001).div(TILE_SIZE).floor()
)
hitbox.endY.minus(0.00001).div(TILE_SIZE).floor(),
true
) // NOT the same as intTilewiseHitbox !!
val tilePosList = ArrayList<BlockAddress>()
for (y in newTilewiseHitbox.startY.toInt()..newTilewiseHitbox.endY.toInt()) {

View File

@@ -10,7 +10,7 @@ import org.dyn4j.geometry.Vector2
*
* Created by minjaesong on 2016-01-15.
*/
class Hitbox(x1: Double, y1: Double, width: Double, height: Double) {
class Hitbox(x1: Double, y1: Double, width: Double, height: Double, var suppressWarning: Boolean = false) {
@Volatile var hitboxStart: Point2d
private set
@@ -25,6 +25,11 @@ class Hitbox(x1: Double, y1: Double, width: Double, height: Double) {
hitboxStart = Point2d(x1, y1)
this.width = width
this.height = height
if (!suppressWarning && (width == 0.0 || height == 0.0)) {
println("[Hitbox] width or height is zero ($this), perhaps you want to check it out?")
Thread.currentThread().stackTrace.forEach { println(it) }
}
}
override fun toString(): String {
@@ -59,6 +64,12 @@ class Hitbox(x1: Double, y1: Double, width: Double, height: Double) {
hitboxStart = Point2d(x1, y1)
this.width = width
this.height = height
if (!suppressWarning && (width == 0.0 || height == 0.0)) {
println("[Hitbox] width or height is zero ($this), perhaps you want to check it out?")
Thread.currentThread().stackTrace.forEach { println(it) }
}
return this
}
fun setFromTwoPoints(x1: Double, y1: Double, x2: Double, y2: Double): Hitbox {
@@ -72,8 +83,8 @@ class Hitbox(x1: Double, y1: Double, width: Double, height: Double) {
fun setPosition(x1: Double, y1: Double): Hitbox {
hitboxStart = Point2d(x1, y1)
if (width == 0.0 || height == 0.0) {
println("[Hitbox] width or height is zero, perhaps you want to check it out?")
if (!suppressWarning && (width == 0.0 || height == 0.0)) {
println("[Hitbox] width or height is zero ($this), perhaps you want to check it out?")
Thread.currentThread().stackTrace.forEach { println(it) }
}
@@ -125,7 +136,7 @@ class Hitbox(x1: Double, y1: Double, width: Double, height: Double) {
val centeredY: Double
get() = (hitboxStart.y + hitboxEnd.y) * 0.5
fun intersects(position: Point2d) =
infix fun intersects(position: Point2d) =
(position.x >= startX && position.x <= startX + width) &&
(position.y >= startY && position.y <= startY + height)
@@ -134,8 +145,8 @@ class Hitbox(x1: Double, y1: Double, width: Double, height: Double) {
fun clone(): Hitbox = Hitbox(startX, startY, width, height)
companion object {
fun fromTwoPoints(x1: Double, y1: Double, x2: Double, y2: Double) =
Hitbox(x1, y1, x2 - x1, y2 - y1)
fun fromTwoPoints(x1: Double, y1: Double, x2: Double, y2: Double, nowarn: Boolean = false) =
Hitbox(x1, y1, x2 - x1, y2 - y1, nowarn)
}
operator fun minus(other: Hitbox): Vector2 {