mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-12 11:34:05 +09:00
resolving issue #5
Former-commit-id: 12d11b683a242172a7c3ec831efb7d65f552951f Former-commit-id: fd276318b77ac5ef9b1963e84fb33380ddbae45c
This commit is contained in:
@@ -529,18 +529,27 @@ constructor() : BasicGameState() {
|
||||
|
||||
fun Double.sqr() = this * this
|
||||
fun Int.sqr() = this * this
|
||||
fun min(vararg d: Double): Double {
|
||||
var ret = Double.MAX_VALUE
|
||||
d.forEach { if (it < ret) ret = it }
|
||||
return ret
|
||||
}
|
||||
private fun distToActorSqr(a: ActorWithBody, p: ActorWithBody) =
|
||||
Math.min(// take min of normal position and wrapped (x < 0) position
|
||||
min(// take min of normal position and wrapped (x < 0) position
|
||||
(a.hitbox.centeredX - p.hitbox.centeredX).sqr() +
|
||||
(a.hitbox.centeredY - p.hitbox.centeredY).sqr(),
|
||||
(a.hitbox.centeredX - p.hitbox.centeredX + world.width * TILE_SIZE).sqr() +
|
||||
(a.hitbox.centeredY - p.hitbox.centeredY).sqr(),
|
||||
(a.hitbox.centeredX - p.hitbox.centeredX - world.width * TILE_SIZE).sqr() +
|
||||
(a.hitbox.centeredY - p.hitbox.centeredY).sqr()
|
||||
)
|
||||
private fun distToCameraSqr(a: ActorWithBody) =
|
||||
Math.min(
|
||||
min(
|
||||
(a.hitbox.posX - MapCamera.cameraX).sqr() +
|
||||
(a.hitbox.posY - MapCamera.cameraY).sqr(),
|
||||
(a.hitbox.posX - MapCamera.cameraX + world.width * TILE_SIZE).sqr() +
|
||||
(a.hitbox.posY - MapCamera.cameraY).sqr(),
|
||||
(a.hitbox.posX - MapCamera.cameraX - world.width * TILE_SIZE).sqr() +
|
||||
(a.hitbox.posY - MapCamera.cameraY).sqr()
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user