|
|
|
@ -21,15 +21,17 @@ import com.last.commit.map.TimeMap
|
|
|
|
|
import com.last.commit.stages.InventoryStage
|
|
|
|
|
import kotlin.math.floor
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** First screen of the application. Displayed after the application is created. */
|
|
|
|
|
class FirstScreen : Screen, InputProcessor {
|
|
|
|
|
|
|
|
|
|
val viewportSize = 800f
|
|
|
|
|
|
|
|
|
|
private var delta = 0f
|
|
|
|
|
private var isColliding = false
|
|
|
|
|
val state = ColorState()
|
|
|
|
|
|
|
|
|
|
val batch = SpriteBatch()
|
|
|
|
|
val camera = OrthographicCamera(800f, 600f)
|
|
|
|
|
val camera = OrthographicCamera(viewportSize, viewportSize)
|
|
|
|
|
lateinit var map: TimeMap // = TimeMap("tiled/base.tmx")
|
|
|
|
|
val playerTexture = Texture("sprites/characters.png")
|
|
|
|
|
val player = Player(TextureRegion(playerTexture, 300, 44, 35, 43))
|
|
|
|
@ -45,6 +47,7 @@ class FirstScreen : Screen, InputProcessor {
|
|
|
|
|
val gameConfig = this.loadGameConfig()
|
|
|
|
|
val randomMap = gameConfig.getRandomMap()
|
|
|
|
|
map = TimeMap(randomMap)
|
|
|
|
|
handleRatioChange()
|
|
|
|
|
|
|
|
|
|
this.spawnPlayer()
|
|
|
|
|
this.updateCamera()
|
|
|
|
@ -75,10 +78,7 @@ class FirstScreen : Screen, InputProcessor {
|
|
|
|
|
|
|
|
|
|
val mousePosition: Vector2 = getMousePosition()
|
|
|
|
|
player.lookAt(mousePosition)
|
|
|
|
|
val interactables = map.getInteractablesAt(
|
|
|
|
|
player.getAbsoluteDirection()
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
val interactables = map.getInteractablesAt(player.getAbsoluteDirection())
|
|
|
|
|
|
|
|
|
|
batch.projectionMatrix = camera.combined
|
|
|
|
|
batch.begin()
|
|
|
|
@ -89,7 +89,6 @@ class FirstScreen : Screen, InputProcessor {
|
|
|
|
|
// TODO: auslagern in sperate Methode
|
|
|
|
|
renderInteractables(interactables)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inventoryStage.draw()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -112,7 +111,8 @@ class FirstScreen : Screen, InputProcessor {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun getMousePosition(): Vector2 {
|
|
|
|
|
val unprojectedMousePosition = camera.unproject(Vector3(Gdx.input.x.toFloat(), Gdx.input.y.toFloat(), 0f))
|
|
|
|
|
val unprojectedMousePosition =
|
|
|
|
|
camera.unproject(Vector3(Gdx.input.x.toFloat(), Gdx.input.y.toFloat(), 0f))
|
|
|
|
|
return Vector2(unprojectedMousePosition.x, unprojectedMousePosition.y)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -177,6 +177,7 @@ class FirstScreen : Screen, InputProcessor {
|
|
|
|
|
val playerYPosition: Float = this.player.getY()
|
|
|
|
|
val mapWidth: Int = map.width
|
|
|
|
|
val mapHeight: Int = map.height
|
|
|
|
|
|
|
|
|
|
cX = if (playerXPosition < halfScreenWidth) {
|
|
|
|
|
halfScreenWidth
|
|
|
|
|
} else if (playerXPosition > mapWidth - halfScreenWidth) {
|
|
|
|
@ -198,8 +199,25 @@ class FirstScreen : Screen, InputProcessor {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun resize(width: Int, height: Int) {
|
|
|
|
|
inventoryStage.resize(width, height)
|
|
|
|
|
// Resize your screen here. The parameters represent the new window size.
|
|
|
|
|
inventoryStage.resize(width, height)
|
|
|
|
|
handleRatioChange()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun handleRatioChange() {
|
|
|
|
|
val height = Gdx.graphics.height
|
|
|
|
|
val width = Gdx.graphics.width
|
|
|
|
|
|
|
|
|
|
val wRatio = width.toFloat() / height.toFloat()
|
|
|
|
|
val hRatio = height.toFloat() / width.toFloat()
|
|
|
|
|
if (wRatio < 1) {
|
|
|
|
|
camera.viewportWidth = viewportSize * wRatio
|
|
|
|
|
camera.viewportHeight = viewportSize
|
|
|
|
|
} else {
|
|
|
|
|
camera.viewportHeight = viewportSize * hRatio
|
|
|
|
|
camera.viewportWidth = viewportSize
|
|
|
|
|
}
|
|
|
|
|
updateCamera()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun pause() {
|
|
|
|
|