collision detection and CCD: Not exactly fixed but it works good enough

Former-commit-id: 3feb9b1156fc941390b4efe4c1540ed4c5dbd109
Former-commit-id: 8c97b0ade765731800ef09b722e0742e44443338
This commit is contained in:
Song Minjae
2016-06-25 00:23:20 +09:00
parent e62f8feda5
commit 91f52eeab5
14 changed files with 400 additions and 481 deletions

View File

@@ -7,15 +7,15 @@ import org.dyn4j.geometry.Vector2
/**
* Created by minjaesong on 16-01-15.
*/
class Hitbox(x1: Double, y1: Double, width: Double, height: Double) {
class Hitbox(x1: Double, y1: Double, width: Double, height: Double) : Cloneable {
@Volatile var hitboxStart: Point2d
private set
@Volatile var hitboxEnd: Point2d
private set
var width: Double = 0.toDouble()
var width: Double = 0.0
private set
var height: Double = 0.toDouble()
var height: Double = 0.0
private set
init {
@@ -39,14 +39,16 @@ class Hitbox(x1: Double, y1: Double, width: Double, height: Double) {
val pointedY: Double
get() = hitboxEnd.y
val endPointX: Double
get() = hitboxEnd.x
val endPointY: Double
get() = hitboxEnd.y
/**
* Set to the point top left
* @param x1
* *
* @param y1
* *
* @param width
* *
* @param height
*/
fun set(x1: Double, y1: Double, width: Double, height: Double) {
@@ -56,6 +58,13 @@ class Hitbox(x1: Double, y1: Double, width: Double, height: Double) {
this.height = height
}
/**
* Set this hitbox from other
*/
fun set(other: Hitbox) {
set(other.posX, other.posY, other.width, other.height)
}
fun translate(x: Double, y: Double) {
setPosition(posX + x, posY + y)
}