|
|
|
@ -1,10 +1,7 @@
|
|
|
|
|
package com.last.commit.screen
|
|
|
|
|
|
|
|
|
|
import GameState
|
|
|
|
|
import com.badlogic.gdx.Gdx
|
|
|
|
|
import com.badlogic.gdx.Input.Keys
|
|
|
|
|
import com.badlogic.gdx.InputProcessor
|
|
|
|
|
import com.badlogic.gdx.Screen
|
|
|
|
|
import com.badlogic.gdx.Input
|
|
|
|
|
import com.badlogic.gdx.graphics.Color
|
|
|
|
|
import com.badlogic.gdx.graphics.GL20
|
|
|
|
|
import com.badlogic.gdx.graphics.OrthographicCamera
|
|
|
|
@ -16,52 +13,87 @@ import com.badlogic.gdx.math.MathUtils
|
|
|
|
|
import com.badlogic.gdx.math.Vector2
|
|
|
|
|
import com.badlogic.gdx.math.Vector3
|
|
|
|
|
import com.badlogic.gdx.utils.Json
|
|
|
|
|
import com.last.commit.ColorState
|
|
|
|
|
import com.last.commit.Game
|
|
|
|
|
import com.last.commit.Player
|
|
|
|
|
import com.last.commit.audio.GameMusic
|
|
|
|
|
import com.last.commit.config.ActionCommand
|
|
|
|
|
import com.last.commit.config.GameConfig
|
|
|
|
|
import com.last.commit.map.Interactable
|
|
|
|
|
import com.last.commit.map.TimeMap
|
|
|
|
|
import com.last.commit.stages.InventoryStage
|
|
|
|
|
import com.last.commit.audio.GameMusic
|
|
|
|
|
import kotlin.math.floor
|
|
|
|
|
|
|
|
|
|
/** First screen of the application. Displayed after the application is created. */
|
|
|
|
|
class FirstScreen(val gameState: GameState) : Screen, InputProcessor {
|
|
|
|
|
class FirstScreen(private val parent: Game) : TimeTravelScreen() {
|
|
|
|
|
|
|
|
|
|
val gameState = parent.state
|
|
|
|
|
|
|
|
|
|
val viewportSize = 800f
|
|
|
|
|
|
|
|
|
|
private var delta = 0f
|
|
|
|
|
private var delta = 0.008f
|
|
|
|
|
private var isColliding = false
|
|
|
|
|
val state = ColorState()
|
|
|
|
|
|
|
|
|
|
val batch = SpriteBatch()
|
|
|
|
|
val camera = OrthographicCamera(viewportSize, viewportSize)
|
|
|
|
|
lateinit var map: TimeMap // = TimeMap("tiled/base.tmx")
|
|
|
|
|
|
|
|
|
|
var map: TimeMap
|
|
|
|
|
|
|
|
|
|
val playerTexture = Texture("sprites/characters.png")
|
|
|
|
|
val player = Player(TextureRegion(playerTexture, 300, 44, 35, 43), gameState)
|
|
|
|
|
var shapeRenderer = ShapeRenderer()
|
|
|
|
|
|
|
|
|
|
val highlightColor = Color(0f, 0f, 1f, 0.5f)
|
|
|
|
|
|
|
|
|
|
lateinit var inventoryStage: InventoryStage
|
|
|
|
|
var inventoryStage: InventoryStage
|
|
|
|
|
|
|
|
|
|
override fun show() {
|
|
|
|
|
// Prepare your screen here.
|
|
|
|
|
|
|
|
|
|
init {
|
|
|
|
|
val gameConfig = this.loadGameConfig()
|
|
|
|
|
val randomMap = gameConfig.getRandomMap()
|
|
|
|
|
map = TimeMap(randomMap, gameState)
|
|
|
|
|
handleRatioChange()
|
|
|
|
|
|
|
|
|
|
this.spawnPlayer()
|
|
|
|
|
this.updateCamera()
|
|
|
|
|
|
|
|
|
|
player.addItemToInventory("drill")
|
|
|
|
|
handleRatioChange()
|
|
|
|
|
|
|
|
|
|
inventoryStage = InventoryStage("sprites/genericItems_spritesheet_colored", gameState.inventory)
|
|
|
|
|
shapeRenderer.setAutoShapeType(true)
|
|
|
|
|
|
|
|
|
|
Gdx.input.setInputProcessor(this)
|
|
|
|
|
player.addItemToInventory("drill")
|
|
|
|
|
}
|
|
|
|
|
override fun handleKeyInput(keyCode: Int) {
|
|
|
|
|
|
|
|
|
|
if (gameState.settings.getAction(keyCode) == ActionCommand.INTERACT) {
|
|
|
|
|
openDoor()
|
|
|
|
|
} else if (gameState.settings.getAction(keyCode) == ActionCommand.TIME_TRAVEL) {
|
|
|
|
|
map.teleport(player)
|
|
|
|
|
} else if (gameState.settings.getAction(keyCode) == ActionCommand.OPEN_INVENTORY) {
|
|
|
|
|
inventoryStage.visible = !inventoryStage.visible
|
|
|
|
|
} else if (keyCode == Input.Keys.P) {
|
|
|
|
|
gameState.inventory.add("compass")
|
|
|
|
|
inventoryStage.refresh()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gameState.settings.getAction(keyCode) == ActionCommand.OPEN_MENU) {
|
|
|
|
|
//Gdx.app.exit()
|
|
|
|
|
parent.changeScreen(Screens.MAIN_MENU)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun handleMouseInput(screenX: Int, screenY: Int, pointer: Int, button: Int) {
|
|
|
|
|
val mouseCoordinates: Vector2 = toWorldCoordinates(screenX.toFloat(), screenY.toFloat())
|
|
|
|
|
println("Mouse World coordinates is ${mouseCoordinates.x}:${mouseCoordinates.y}")
|
|
|
|
|
|
|
|
|
|
val playerDirection: Vector2 = player.getAbsoluteDirection()
|
|
|
|
|
println("Player interactor is ${playerDirection.x}:${playerDirection.y}")
|
|
|
|
|
map.interactWith(playerDirection.x, playerDirection.y, player.getCollider())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun show() {
|
|
|
|
|
// Prepare your screen here.
|
|
|
|
|
|
|
|
|
|
gameState.soundEngine.play(GameMusic.WORLD_MUSIC, 0.25f)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -73,18 +105,12 @@ class FirstScreen(val gameState: GameState) : Screen, InputProcessor {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun render(delta: Float) {
|
|
|
|
|
this.delta = delta
|
|
|
|
|
// state.step((delta * 1000).toLong())
|
|
|
|
|
// Draw your screen here. "delta" is the time since last render in seconds.
|
|
|
|
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
|
|
|
|
|
Gdx.gl.glClearColor(state.red, state.green, state.blue, 1f)
|
|
|
|
|
|
|
|
|
|
handleInput()
|
|
|
|
|
handleMapBorderCollision()
|
|
|
|
|
|
|
|
|
|
val mousePosition: Vector2 = getMousePosition()
|
|
|
|
|
player.lookAt(mousePosition)
|
|
|
|
|
val interactables = map.getInteractablesAt(player.getAbsoluteDirection())
|
|
|
|
|
|
|
|
|
|
batch.projectionMatrix = camera.combined
|
|
|
|
|
batch.begin()
|
|
|
|
@ -92,6 +118,7 @@ class FirstScreen(val gameState: GameState) : Screen, InputProcessor {
|
|
|
|
|
this.player.render(batch)
|
|
|
|
|
batch.end()
|
|
|
|
|
|
|
|
|
|
val interactables = map.getInteractablesAt(player.getAbsoluteDirection())
|
|
|
|
|
// TODO: auslagern in sperate Methode
|
|
|
|
|
renderInteractables(interactables)
|
|
|
|
|
|
|
|
|
@ -132,7 +159,6 @@ class FirstScreen(val gameState: GameState) : Screen, InputProcessor {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun handleInput() {
|
|
|
|
|
|
|
|
|
|
val horizontalMovement = Vector2()
|
|
|
|
|
if (isKeyPressed(gameState.settings.getKeyCode(ActionCommand.LEFT))) {
|
|
|
|
|
horizontalMovement.sub(Vector2.X)
|
|
|
|
@ -159,13 +185,14 @@ class FirstScreen(val gameState: GameState) : Screen, InputProcessor {
|
|
|
|
|
verticalMovement.rotateDeg(180f)
|
|
|
|
|
this.player.move(verticalMovement, delta)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val hasMoved = !horizontalMovement.isZero || !verticalMovement.isZero
|
|
|
|
|
if (hasMoved) {
|
|
|
|
|
updateCamera()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun isKeyPressed(keyCodes: List<Int>): Boolean{
|
|
|
|
|
private fun isKeyPressed(keyCodes: List<Int>): Boolean{
|
|
|
|
|
for (key in keyCodes) {
|
|
|
|
|
if (Gdx.input.isKeyPressed(key)) {
|
|
|
|
|
return true
|
|
|
|
@ -245,7 +272,6 @@ class FirstScreen(val gameState: GameState) : Screen, InputProcessor {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun hide() {
|
|
|
|
|
// This method is called when another screen replaces this one.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun dispose() {
|
|
|
|
@ -254,46 +280,6 @@ class FirstScreen(val gameState: GameState) : Screen, InputProcessor {
|
|
|
|
|
shapeRenderer.dispose()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun keyDown(keycode: Int): Boolean {
|
|
|
|
|
// TODO: Auto-generated method stub
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun keyUp(keycode: Int): Boolean {
|
|
|
|
|
if (gameState.settings.getAction(keycode) == ActionCommand.OPEN_MENU) {
|
|
|
|
|
Gdx.app.exit()
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun keyTyped(character: Char): Boolean {
|
|
|
|
|
val characterUpperCase = character.uppercase()
|
|
|
|
|
val characterKey = Keys.valueOf(characterUpperCase)
|
|
|
|
|
|
|
|
|
|
if (gameState.settings.getAction(characterKey) == ActionCommand.INTERACT) {
|
|
|
|
|
openDoor()
|
|
|
|
|
} else if (gameState.settings.getAction(characterKey) == ActionCommand.TIME_TRAVEL) {
|
|
|
|
|
map.teleport(player)
|
|
|
|
|
} else if (gameState.settings.getAction(characterKey) == ActionCommand.OPEN_INVENTORY) {
|
|
|
|
|
inventoryStage.visible = !inventoryStage.visible
|
|
|
|
|
} else if (character == 'p') {
|
|
|
|
|
gameState.inventory.add("compass")
|
|
|
|
|
inventoryStage.refresh()
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
|
|
|
|
val mouseCoordinates: Vector2 = toWorldCoordinates(screenX.toFloat(), screenY.toFloat())
|
|
|
|
|
println("Mouse World coordinates is ${mouseCoordinates.x}:${mouseCoordinates.y}")
|
|
|
|
|
|
|
|
|
|
val playerDirection: Vector2 = player.getAbsoluteDirection()
|
|
|
|
|
println("Player interactor is ${playerDirection.x}:${playerDirection.y}")
|
|
|
|
|
map.interactWith(playerDirection.x, playerDirection.y, player.getCollider())
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun openDoor() {
|
|
|
|
|
println("Attempt to toggle door")
|
|
|
|
|
val playerDirection: Vector2 = player.getAbsoluteDirection()
|
|
|
|
@ -309,23 +295,4 @@ class FirstScreen(val gameState: GameState) : Screen, InputProcessor {
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
|
|
|
|
|
// TODO: ("Not yet implemented")
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
|
|
|
|
|
// TODO: ("Not yet implemented")
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
|
|
|
|
|
// TODO: "Not yet implemented"
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun scrolled(amountX: Float, amountY: Float): Boolean {
|
|
|
|
|
// TODO: Not yet implemented
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|