From f6a7cfaafb6f1da4dca60f66eebe3a38eda66bb0 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 20 Nov 2022 08:57:25 +0100 Subject: [PATCH] remove noisy logs --- assets/tiled/level_fruehling.tmx | 2 +- .../com/last/commit/audio/SoundEngine.kt | 9 ++-- .../kotlin/com/last/commit/map/TimeMap.kt | 15 ++---- .../com/last/commit/screen/FirstScreen.kt | 50 +++++++++---------- 4 files changed, 34 insertions(+), 42 deletions(-) diff --git a/assets/tiled/level_fruehling.tmx b/assets/tiled/level_fruehling.tmx index 21e243e..d215622 100644 --- a/assets/tiled/level_fruehling.tmx +++ b/assets/tiled/level_fruehling.tmx @@ -497,7 +497,7 @@ - + diff --git a/core/src/main/kotlin/com/last/commit/audio/SoundEngine.kt b/core/src/main/kotlin/com/last/commit/audio/SoundEngine.kt index e8de357..f5e8926 100644 --- a/core/src/main/kotlin/com/last/commit/audio/SoundEngine.kt +++ b/core/src/main/kotlin/com/last/commit/audio/SoundEngine.kt @@ -7,17 +7,16 @@ import com.badlogic.gdx.audio.Sound public class SoundEngine { private val sounds: ThreadLocal> = - ThreadLocal.withInitial() { HashMap() } + ThreadLocal.withInitial() { HashMap() } private val musicTracks: ThreadLocal> = - ThreadLocal.withInitial() { HashMap() } + ThreadLocal.withInitial() { HashMap() } - lateinit var backgroundMusic : Music + lateinit var backgroundMusic: Music fun play(gameSound: GameSound, volume: Float = 1f) { if (gameSound is GameSoundEffect) { val sound = loadEffect(gameSound.name) sound.play(volume) - println("Playing sound ${gameSound.name}") } else if (gameSound is GameMusic) { backgroundMusic = loadMusic(gameSound.name) backgroundMusic.volume = volume @@ -30,7 +29,7 @@ public class SoundEngine { backgroundMusic.pause() } - fun resume() { + fun resume() { backgroundMusic.play() } diff --git a/core/src/main/kotlin/com/last/commit/map/TimeMap.kt b/core/src/main/kotlin/com/last/commit/map/TimeMap.kt index 050b82c..1498316 100644 --- a/core/src/main/kotlin/com/last/commit/map/TimeMap.kt +++ b/core/src/main/kotlin/com/last/commit/map/TimeMap.kt @@ -1,23 +1,19 @@ package com.last.commit.map +import GameState import com.badlogic.gdx.Gdx import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.g2d.SpriteBatch -import com.badlogic.gdx.maps.objects.RectangleMapObject import com.badlogic.gdx.maps.tiled.TiledMap -import com.badlogic.gdx.maps.tiled.TiledMapTileLayer import com.badlogic.gdx.maps.tiled.TmxMapLoader import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer import com.badlogic.gdx.math.Rectangle import com.badlogic.gdx.math.Vector2 -import com.badlogic.gdx.utils.Array import com.badlogic.gdx.scenes.scene2d.ui.Image import com.last.commit.Collidable import com.last.commit.Player -import com.last.commit.Wall import com.last.commit.audio.GameSoundEffect import com.last.commit.inventory.InventoryItemTextureLoader -import GameState class TimeMap(fileName: String, val state: GameState) { @@ -33,7 +29,7 @@ class TimeMap(fileName: String, val state: GameState) { val gridWidth: Int get() = mapState.gridSize.x.toInt() - val gridHeight: Int + val gridHeight: Int get() = mapState.gridSize.y.toInt() val width: Int @@ -56,12 +52,12 @@ class TimeMap(fileName: String, val state: GameState) { mapRenderer = OrthogonalTiledMapRenderer(map) this.textureLoader.parse() } - + fun teleport(player: Player) { val teleporter = mapState.teleporters.find { it.rectangle.contains(player.getX(), player.getY()) - } + } if (teleporter != null) { state.soundEngine.play(GameSoundEffect.TIME_TRAVEL) val targetMap = teleporter.properties.get("target", String::class.java) @@ -120,7 +116,6 @@ class TimeMap(fileName: String, val state: GameState) { fun interactWith(x: Float, y: Float, blockingCollider: Rectangle) { val gridX = x.toInt() / CELL_SIZE val gridY = y.toInt() / CELL_SIZE - println("Interacting with element at $gridX:$gridY") //if no door is found return val interactable: Interactable = this.findInteractableAtPosition(gridX, gridY) ?: return @@ -141,7 +136,7 @@ class TimeMap(fileName: String, val state: GameState) { fun render(batch: SpriteBatch, camera: OrthographicCamera, delta: Float) { mapRenderer.setView(camera) mapRenderer.render() - this.mapState.collectibles.forEach { coll -> + this.mapState.collectibles.forEach { coll -> val image = Image(textureLoader.getTexture(coll.name)) image.x = coll.pos.x + this.getTileWidth() * 0.1f image.y = coll.pos.y + this.getTileHeight() * 0.1f diff --git a/core/src/main/kotlin/com/last/commit/screen/FirstScreen.kt b/core/src/main/kotlin/com/last/commit/screen/FirstScreen.kt index 487ab95..e0b431c 100644 --- a/core/src/main/kotlin/com/last/commit/screen/FirstScreen.kt +++ b/core/src/main/kotlin/com/last/commit/screen/FirstScreen.kt @@ -1,7 +1,6 @@ package com.last.commit.screen import com.badlogic.gdx.Gdx -import com.badlogic.gdx.Input import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.GL20 import com.badlogic.gdx.graphics.OrthographicCamera @@ -65,18 +64,20 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { gameState.soundEngine.play(GameMusic.WORLD_MUSIC, 0.25f) } + override fun handleKeyInput(action: ActionCommand) { if (!pause) { when (action) { ActionCommand.INTERACT -> { openDoor() } + ActionCommand.TIME_TRAVEL -> { map.teleport(player) } + else -> {} } - println(action) if (action == ActionCommand.OPEN_MENU) { //Gdx.app.exit() parent.changeScreen(Screens.MAIN_MENU) @@ -89,10 +90,8 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { if (!pause) { 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()) } } @@ -140,10 +139,10 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { shapeRenderer.begin(ShapeRenderer.ShapeType.Filled) for (interactable in interactables) { shapeRenderer.rect( - interactable.getCollider().x, - interactable.getCollider().y, - interactable.getCollider().width, - interactable.getCollider().height + interactable.getCollider().x, + interactable.getCollider().y, + interactable.getCollider().width, + interactable.getCollider().height ) } shapeRenderer.end() @@ -152,7 +151,7 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { private fun getMousePosition(): Vector2 { val unprojectedMousePosition = - camera.unproject(Vector3(Gdx.input.x.toFloat(), Gdx.input.y.toFloat(), 0f)) + camera.unproject(Vector3(Gdx.input.x.toFloat(), Gdx.input.y.toFloat(), 0f)) return Vector2(unprojectedMousePosition.x, unprojectedMousePosition.y) } @@ -165,7 +164,7 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { this.player.setPosition(playerX, playerY) } - private fun handleInput(delta : Float) { + private fun handleInput(delta: Float) { val horizontalMovement = Vector2() if (isKeyPressed(gameState.settings.getKeyCode(ActionCommand.LEFT))) { horizontalMovement.sub(Vector2.X) @@ -199,7 +198,7 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { } } - private fun isKeyPressed(keyCodes: List): Boolean{ + private fun isKeyPressed(keyCodes: List): Boolean { for (key in keyCodes) { if (Gdx.input.isKeyPressed(key)) { return true @@ -229,20 +228,20 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { val mapHeight: Int = map.height cX = if (playerXPosition < halfScreenWidth) { - halfScreenWidth - } else if (playerXPosition > mapWidth - halfScreenWidth) { - mapWidth - halfScreenWidth - } else { - playerXPosition - } + halfScreenWidth + } else if (playerXPosition > mapWidth - halfScreenWidth) { + mapWidth - halfScreenWidth + } else { + playerXPosition + } cY = if (playerYPosition < halfScreenHeight) { - halfScreenHeight - } else if (playerYPosition > mapHeight - halfScreenHeight) { - mapHeight - halfScreenHeight - } else { - playerYPosition - } + halfScreenHeight + } else if (playerYPosition > mapHeight - halfScreenHeight) { + mapHeight - halfScreenHeight + } else { + playerYPosition + } camera.position[cX, cY] = 0f camera.update() @@ -295,15 +294,14 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { fun openDoor() { println("Attempt to toggle door") val playerDirection: Vector2 = player.getAbsoluteDirection() - println("Player interactor is ${playerDirection.x}:${playerDirection.y}") map.interactWith(playerDirection.x, playerDirection.y, player.getCollider()) } fun toWorldCoordinates(x: Float, y: Float): Vector2 { val mouseInWorldPosition = camera.unproject(Vector3(x, y, 0f)) return Vector2( - floor(mouseInWorldPosition.x.toDouble() / this.map.getTileWidth()).toFloat(), - floor(mouseInWorldPosition.y.toDouble() / this.map.getTileHeight()).toFloat() + floor(mouseInWorldPosition.x.toDouble() / this.map.getTileWidth()).toFloat(), + floor(mouseInWorldPosition.y.toDouble() / this.map.getTileHeight()).toFloat() ) }