Files
Terrarum/src/net/torvald/terrarum/mapdrawer/MapCamera.kt
Song Minjae ac05b5edf1 separated Camera from TileDrawer (was MapCamera)
Former-commit-id: b2fe7716722634b03f3750fade420d26022500f9
Former-commit-id: 521826d176c6902007646e6b9b9c7b5d4f3468cf
2016-12-30 02:47:15 +09:00

39 lines
1.1 KiB
Kotlin

package net.torvald.terrarum.mapdrawer
import com.jme3.math.FastMath
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameworld.GameWorld
/**
* Created by SKYHi14 on 2016-12-30.
*/
object MapCamera {
private val world: GameWorld = Terrarum.ingame.world
private val TILE_SIZE = FeaturesDrawer.TILE_SIZE
var x = 0
private set
var y = 0
private set
var width: Int = 0
private set
var height: Int = 0
private set
fun update() {
val player = Terrarum.ingame.player
width = FastMath.ceil(Terrarum.WIDTH / Terrarum.ingame.screenZoom) // div, not mul
height = FastMath.ceil(Terrarum.HEIGHT / Terrarum.ingame.screenZoom)
// position - (WH / 2)
x = Math.round(// X only: ROUNDWORLD implementation
player.hitbox.centeredX.toFloat() - width / 2)
y = Math.round(FastMath.clamp(
player.hitbox.centeredY.toFloat() - height / 2,
TILE_SIZE.toFloat(),
world.height * TILE_SIZE - height - TILE_SIZE.toFloat()
))
}
}