com.torvald → net.torvald

Former-commit-id: 375604da8a20a6ba7cd0a8d05a44add02b2d04f4
Former-commit-id: 287287c5920b07618174d7a7573f049d350ded66
This commit is contained in:
Song Minjae
2016-04-12 12:29:02 +09:00
parent 2a34efb489
commit ac9f5b5138
148 changed files with 473 additions and 524 deletions

View File

@@ -0,0 +1,115 @@
package net.torvald.terrarum.gameactors
import net.torvald.point.Point2f
/**
* Created by minjaesong on 16-01-15.
*/
class Hitbox(x1: Float, y1: Float, width: Float, height: Float) {
var hitboxStart: Point2f
private set
var hitboxEnd: Point2f
private set
var width: Float = 0.toFloat()
private set
var height: Float = 0.toFloat()
private set
init {
hitboxStart = Point2f(x1, y1)
hitboxEnd = Point2f(x1 + width, y1 + height)
this.width = width
this.height = height
}
/**
* Returns bottom-centered point of hitbox.
* @return pointX
*/
val pointedX: Float
get() = hitboxStart.x + width / 2
/**
* Returns bottom-centered point of hitbox.
* @return pointY
*/
val pointedY: Float
get() = hitboxEnd.y
/**
* Set to the point top left
* @param x1
* *
* @param y1
* *
* @param width
* *
* @param height
*/
operator fun set(x1: Float, y1: Float, width: Float, height: Float) {
hitboxStart = Point2f(x1, y1)
hitboxEnd = Point2f(x1 + width, y1 + height)
this.width = width
this.height = height
}
fun setPosition(x1: Float, y1: Float) {
hitboxStart = Point2f(x1, y1)
hitboxEnd = Point2f(x1 + width, y1 + height)
}
fun setPositionX(x: Float) {
setPosition(x, posY)
}
fun setPositionY(y: Float) {
setPosition(posX, y)
}
fun setPositionFromPoint(x1: Float, y1: Float) {
hitboxStart = Point2f(x1 - width / 2, y1 - height)
hitboxEnd = Point2f(hitboxStart.x + width, hitboxStart.y + height)
}
fun setPositionXFromPoint(x: Float) {
setPositionFromPoint(x, pointedY)
}
fun setPositionYFromPoint(y: Float) {
setPositionFromPoint(pointedX, y)
}
fun translatePosX(d: Float) {
setPositionX(posX + d)
}
fun translatePosY(d: Float) {
setPositionY(posY + d)
}
fun setDimension(w: Float, h: Float) {
width = w
height = h
}
/**
* Returns x value of start point
* @return top-left point posX
*/
val posX: Float
get() = hitboxStart.x
/**
* Returns y value of start point
* @return top-left point posY
*/
val posY: Float
get() = hitboxStart.y
val centeredX: Float
get() = (hitboxStart.x + hitboxEnd.x) * 0.5f
val centeredY: Float
get() = (hitboxStart.y + hitboxEnd.y) * 0.5f
}