|
|
|
@ -24,12 +24,13 @@ import kotlin.math.floor
|
|
|
|
|
|
|
|
|
|
/** First screen of the application. Displayed after the application is created. */
|
|
|
|
|
class FirstScreen(val game: Game) : 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 +46,7 @@ class FirstScreen(val game: Game) : Screen, InputProcessor {
|
|
|
|
|
val gameConfig = this.loadGameConfig()
|
|
|
|
|
val randomMap = gameConfig.getRandomMap()
|
|
|
|
|
map = TimeMap(randomMap)
|
|
|
|
|
handleRatioChange()
|
|
|
|
|
|
|
|
|
|
this.spawnPlayer()
|
|
|
|
|
this.updateCamera()
|
|
|
|
@ -75,10 +77,7 @@ class FirstScreen(val game: Game) : 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 +88,6 @@ class FirstScreen(val game: Game) : Screen, InputProcessor {
|
|
|
|
|
// TODO: auslagern in sperate Methode
|
|
|
|
|
renderInteractables(interactables)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inventoryStage.draw()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -112,7 +110,8 @@ class FirstScreen(val game: Game) : 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)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -126,13 +125,7 @@ class FirstScreen(val game: Game) : Screen, InputProcessor {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun handleInput() {
|
|
|
|
|
|
|
|
|
|
val horizontalMovement = Vector2()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//if (Gdx.input.isKeyPressed(game.settings.actionKeys.get(ActionCommand.LEFT)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Gdx.input.isKeyPressed(Keys.A) || Gdx.input.isKeyPressed(Keys.LEFT)) {
|
|
|
|
|
horizontalMovement.sub(Vector2.X)
|
|
|
|
|
}
|
|
|
|
@ -183,6 +176,7 @@ class FirstScreen(val game: Game) : 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) {
|
|
|
|
@ -205,6 +199,24 @@ class FirstScreen(val game: Game) : Screen, InputProcessor {
|
|
|
|
|
|
|
|
|
|
override fun resize(width: Int, height: Int) {
|
|
|
|
|
// 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() {
|
|
|
|
@ -246,6 +258,9 @@ class FirstScreen(val game: Game) : Screen, InputProcessor {
|
|
|
|
|
map.teleport(player)
|
|
|
|
|
} else if (game.settings.isOpenInventoryPressed(keyCode)) {
|
|
|
|
|
inventoryStage.visible = !inventoryStage.visible
|
|
|
|
|
} else if (character == 'p') {
|
|
|
|
|
player.inventory.add("compass")
|
|
|
|
|
inventoryStage.refresh()
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
@ -256,7 +271,7 @@ class FirstScreen(val game: Game) : Screen, InputProcessor {
|
|
|
|
|
|
|
|
|
|
val playerDirection: Vector2 = player.getAbsoluteDirection()
|
|
|
|
|
println("Player interactor is ${playerDirection.x}:${playerDirection.y}")
|
|
|
|
|
map.toggleDoorAt(playerDirection.x, playerDirection.y, player.getCollider())
|
|
|
|
|
map.interactWith(playerDirection.x, playerDirection.y, player.getCollider())
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
@ -265,7 +280,7 @@ class FirstScreen(val game: Game) : Screen, InputProcessor {
|
|
|
|
|
println("Attempt to toggle door")
|
|
|
|
|
val playerDirection: Vector2 = player.getAbsoluteDirection()
|
|
|
|
|
println("Player interactor is ${playerDirection.x}:${playerDirection.y}")
|
|
|
|
|
map.toggleDoorAt(playerDirection.x, playerDirection.y, player.getCollider())
|
|
|
|
|
map.interactWith(playerDirection.x, playerDirection.y, player.getCollider())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun toWorldCoordinates(x: Float, y: Float): Vector2 {
|
|
|
|
|