From 799aafbc88f33b7cadd0d07e2f0a87b19243a5a7 Mon Sep 17 00:00:00 2001 From: MehdiAyadi <91869915+MehdiAyadi@users.noreply.github.com> Date: Sun, 20 Nov 2022 11:12:16 +0100 Subject: [PATCH 1/5] Added Viewport scaling for Settings.kt --- .../kotlin/com/last/commit/screen/MainMenu.kt | 2 +- .../kotlin/com/last/commit/screen/Settings.kt | 22 +++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/core/src/main/kotlin/com/last/commit/screen/MainMenu.kt b/core/src/main/kotlin/com/last/commit/screen/MainMenu.kt index 7f80f8a..3a780bb 100644 --- a/core/src/main/kotlin/com/last/commit/screen/MainMenu.kt +++ b/core/src/main/kotlin/com/last/commit/screen/MainMenu.kt @@ -60,7 +60,7 @@ class MainMenu(val parent: Game) : TimeTravelScreen() { table.setFillParent(true); val newGame = TextButton("Play Game", uiSkin) - val preferences = TextButton("Preferences", uiSkin) + val preferences = TextButton("Settings", uiSkin) preferences.setSize(stage.viewport.screenWidth.toFloat(), stage.viewport.screenHeight.toFloat()) val exit = TextButton("Exit", uiSkin) diff --git a/core/src/main/kotlin/com/last/commit/screen/Settings.kt b/core/src/main/kotlin/com/last/commit/screen/Settings.kt index f6aa6dd..c37bce0 100644 --- a/core/src/main/kotlin/com/last/commit/screen/Settings.kt +++ b/core/src/main/kotlin/com/last/commit/screen/Settings.kt @@ -22,6 +22,8 @@ class Settings(val parent: Game) : TimeTravelScreen() { lateinit var musicOnOffLabel: Label lateinit var soundOnOffLabel: Label + val table = Table() + init { parent.state.assetManager.finishLoading() stage = Stage(ScreenViewport()) @@ -46,7 +48,11 @@ class Settings(val parent: Game) : TimeTravelScreen() { // Create a table that fills the screen. Everything else will go inside // this table. - val table = Table() + + } + + fun renderTable(x: Float, y: Float) { + table.reset() table.setFillParent(true) //table.setDebug(true); stage.addActor(table) @@ -101,17 +107,22 @@ class Settings(val parent: Game) : TimeTravelScreen() { soundOnOffLabel = Label("Sound Effect", skin) table.add(titleLabel).colspan(2) table.row().pad(10F, 0F, 0F, 10F) + table.row().size(x, y); table.add(volumeMusicLabel).left() table.add(volumeMusicSlider) + table.row().size(x, y); table.row().pad(10F, 0F, 0F, 10F) table.add(musicOnOffLabel).left() table.add(musicCheckbox) + table.row().size(x, y); table.row().pad(10F, 0F, 0F, 10F) table.add(volumeSoundLabel).left() table.add(soundMusicSlider) + table.row().size(x, y); table.row().pad(10F, 0F, 0F, 10F) table.add(soundOnOffLabel).left() table.add(soundEffectsCheckbox) + table.row().size(x, y); table.row().pad(10F, 0F, 0F, 10F) table.add(backButton).colspan(2) } @@ -127,7 +138,14 @@ class Settings(val parent: Game) : TimeTravelScreen() { } override fun resize(width: Int, height: Int) { - stage.viewport.update(width, height) + println("width $width, height $height") + stage.viewport.update(width, height, true); + + + val y = stage.viewport.screenHeight.toFloat() / 6 + val x = stage.viewport.screenWidth.toFloat() / 4 + + renderTable(x, y) } override fun pause() { From 5c834e82cb155f5bba3b7e838129e719f5b49659 Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 20 Nov 2022 13:20:30 +0100 Subject: [PATCH 2/5] Add introduction to story and keybindings --- .../kotlin/com/last/commit/map/TimeMap.kt | 2 +- .../com/last/commit/screen/FirstScreen.kt | 51 +++++++++--- .../com/last/commit/stages/DialogStage.kt | 26 +++++- .../com/last/commit/stages/PromptStage.kt | 80 +++++++++++++++++++ 4 files changed, 144 insertions(+), 15 deletions(-) create mode 100644 core/src/main/kotlin/com/last/commit/stages/PromptStage.kt 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 a19fa4a..c7801ee 100644 --- a/core/src/main/kotlin/com/last/commit/map/TimeMap.kt +++ b/core/src/main/kotlin/com/last/commit/map/TimeMap.kt @@ -63,7 +63,7 @@ class TimeMap(fileName: String, val state: GameState) { System.out.println("Teleporting to targetMap $targetMap") loadMap("tiled/$targetMap") val mapDescription = mapState.description - state.dialogStage.setTexts("You teleported to $mapDescription") + state.dialogStage.setTexts(4000L, "You teleported to $mapDescription") state.dialogStage.show() } } 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 47c05b8..fd72b07 100644 --- a/core/src/main/kotlin/com/last/commit/screen/FirstScreen.kt +++ b/core/src/main/kotlin/com/last/commit/screen/FirstScreen.kt @@ -16,6 +16,7 @@ import com.badlogic.gdx.utils.Json import com.badlogic.gdx.utils.viewport.Viewport import com.badlogic.gdx.utils.viewport.StretchViewport import com.badlogic.gdx.utils.viewport.FillViewport +import com.badlogic.gdx.scenes.scene2d.ui.Skin import com.last.commit.Game import com.last.commit.Player import com.last.commit.audio.GameMusic @@ -24,6 +25,7 @@ import com.last.commit.config.GameConfig import com.last.commit.map.Interactable import com.last.commit.map.TimeMap import com.last.commit.stages.UIStage +import com.last.commit.stages.PromptStage import kotlin.math.floor /** First screen of the application. Displayed after the application is created. */ @@ -50,6 +52,7 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { var pause = true var uiStage: UIStage + val promptStage: PromptStage init { @@ -64,13 +67,35 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { shapeRenderer.setAutoShapeType(true) gameState.soundEngine.play(GameMusic.WORLD_MUSIC, 0.25f) + promptStage = PromptStage(Skin(Gdx.files.internal("ui/uiskin.json"))) + promptStage.addText(""" + You are stranded in time. + The time traveling device you carry with you cannot be controlled anymore. + """.trimIndent()) + promptStage.addText(""" + You need to find the tools required to fix your time traveling device. + Look around the map to find them. + """.trimIndent()) + promptStage.addText(""" + You can use , , and to walk around the map. + Some doors require keys to be opened. + """.trimIndent()) + promptStage.addText(""" + At some locations you can press to travel to a random spot in time. + The top left indicates where you traveled to. + """.trimIndent()) + promptStage.addText(""" + Some items can only be collected in certain time locations. + A collectible item will be highlighted when hovering over it using the mouse + """.trimIndent()) + promptStage.visible = true viewport.camera = camera viewport.apply() } override fun getInputProcessors(): Array { - return arrayOf(gameState.dialogStage) + return arrayOf(gameState.dialogStage, promptStage) } override fun handleKeyInput(action: ActionCommand) { @@ -101,8 +126,6 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { override fun handleMouseInput(screenX: Int, screenY: Int, pointer: Int, button: Int) { if (!pause) { - - val mouseCoordinates: Vector2 = toWorldCoordinates(screenX.toFloat(), screenY.toFloat()) val playerDirection: Vector2 = player.getAbsoluteDirection() map.interactWith(playerDirection.x, playerDirection.y, player.getCollider()) @@ -111,7 +134,6 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { override fun show() { // Prepare your screen here. - resume() } @@ -124,15 +146,20 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { override fun render(delta: Float) { if (gameState.inventory.checkVictoryCondition()) { - gameState.dialogStage.show() - gameState.dialogStage.act(delta) - gameState.dialogStage.setTexts("You won!") - gameState.dialogStage.draw() + promptStage.visible = true + promptStage.act(delta) + promptStage.clearText() + promptStage.addText("You won!") + promptStage.draw() } else if (!pause) { uiStage.act(delta) gameState.dialogStage.act(delta) - handleInput(delta) - handleMapBorderCollision() + promptStage.act(delta) + + if (!promptStage.visible) { + handleInput(delta) + handleMapBorderCollision() + } val mousePosition: Vector2 = getMousePosition() player.lookAt(mousePosition) @@ -149,6 +176,7 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { uiStage.draw() gameState.dialogStage.draw() + promptStage.draw() viewport.apply() updateCamera() } @@ -259,6 +287,7 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { override fun resize(width: Int, height: Int) { // Resize your screen here. The parameters represent the new window size. uiStage.resize(width, height) + promptStage.resize(width, height) gameState.dialogStage.resize(width, height) viewport.update(width, height) viewport.apply() @@ -275,6 +304,8 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { override fun resume() { pause = false gameState.soundEngine.resume(); + this.viewport.apply() + this.updateCamera() // Invoked when your application is resumed after pause. } diff --git a/core/src/main/kotlin/com/last/commit/stages/DialogStage.kt b/core/src/main/kotlin/com/last/commit/stages/DialogStage.kt index 2f230d8..1928836 100644 --- a/core/src/main/kotlin/com/last/commit/stages/DialogStage.kt +++ b/core/src/main/kotlin/com/last/commit/stages/DialogStage.kt @@ -15,6 +15,7 @@ class DialogStage(skin: Skin?) : Stage(ExtendViewport(512f, 512f)) { private var isVisible = false private val texts = com.badlogic.gdx.utils.Array() private val area: TextArea + var closeIn: Long? = null init { area = TextArea("#", skin) @@ -29,6 +30,13 @@ class DialogStage(skin: Skin?) : Stage(ExtendViewport(512f, 512f)) { next() } + fun setTexts(duration: Long, vararg texts: String?) { + this.texts.clear() + this.texts.addAll(*texts) + this.closeIn = System.currentTimeMillis() + duration + next() + } + fun show() { isVisible = true } @@ -45,14 +53,24 @@ class DialogStage(skin: Skin?) : Stage(ExtendViewport(512f, 512f)) { override fun draw() { if (isVisible) { - this.viewport.apply() - super.draw() + if (closeIn != null && closeIn!! < System.currentTimeMillis()) { + closeIn = null + this.hide() + } else { + this.viewport.apply() + super.draw() + } } } override fun act() { if (isVisible) { - super.act() + if (closeIn != null && closeIn!! < System.currentTimeMillis()) { + closeIn = null + this.hide() + } else { + super.act() + } } } @@ -75,7 +93,7 @@ class DialogStage(skin: Skin?) : Stage(ExtendViewport(512f, 512f)) { hide() } } - return true + return false } override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { diff --git a/core/src/main/kotlin/com/last/commit/stages/PromptStage.kt b/core/src/main/kotlin/com/last/commit/stages/PromptStage.kt new file mode 100644 index 0000000..8f0f2d3 --- /dev/null +++ b/core/src/main/kotlin/com/last/commit/stages/PromptStage.kt @@ -0,0 +1,80 @@ +package com.last.commit.stages + +import com.badlogic.gdx.utils.viewport.ExtendViewport +import com.badlogic.gdx.utils.Align +import com.badlogic.gdx.scenes.scene2d.Stage +import com.badlogic.gdx.scenes.scene2d.ui.TextArea +import com.badlogic.gdx.scenes.scene2d.ui.Skin +import com.badlogic.gdx.graphics.g2d.Batch +import com.badlogic.gdx.Input + +class PromptStage(skin: Skin?): Stage(ExtendViewport(300f, 300f)) { + + private val textArea: TextArea; + var visible = false + private val text: ArrayList = ArrayList() + + init { + textArea = TextArea("", skin) + textArea.setSize(viewport.worldWidth * 0.8f, viewport.worldHeight * 0.6f) + textArea.setPosition(viewport.worldWidth * 0.1f, viewport.worldHeight * 0.2f) + textArea.setAlignment(Align.center) + + this.addActor(textArea) + } + + override fun act(delta: Float) { + if (visible) { + if (this.textArea.text.isEmpty()) { + this.next() + } + super.act(delta) + } + } + + override fun draw() { + if (visible) { + this.viewport.apply() + super.draw() + } + } + + fun clearText() { + this.text.clear() + } + + fun addText(text: String) { + this.text.add(text) + } + + fun resize(width: Int, height: Int) { + this.viewport.update(width, height) + this.camera.update() + } + + override fun keyDown(keyCode: Int): Boolean { + return if (!visible) { + false + } else if (keyCode == Input.Keys.SPACE) { + next() + false + } else { + false + } + } + + private operator fun next() { + textArea.clear() + + if (text.isNotEmpty()) { + val text = text.removeAt(0).trimIndent() + textArea.text = text + } else { + visible = false + } + } + + override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean { + return keyDown(Input.Keys.SPACE) + } +} \ No newline at end of file From bd6286bc9f34bcc6d3e0943392be5cef0201042d Mon Sep 17 00:00:00 2001 From: MehdiAyadi <91869915+MehdiAyadi@users.noreply.github.com> Date: Sun, 20 Nov 2022 13:27:27 +0100 Subject: [PATCH 3/5] merge and added settings can now modify soundengine --- .../main/kotlin/com/last/commit/ColorState.kt | 2 + core/src/main/kotlin/com/last/commit/Game.kt | 7 +- .../src/main/kotlin/com/last/commit/Player.kt | 2 +- .../com/last/commit/audio/SoundEngine.kt | 30 +++-- .../com/last/commit/config/GameSettings.kt | 40 ++++++- .../com/last/commit/screen/FirstScreen.kt | 22 ++-- .../kotlin/com/last/commit/screen/MainMenu.kt | 10 +- .../kotlin/com/last/commit/screen/Settings.kt | 110 +++++++++++------- 8 files changed, 147 insertions(+), 76 deletions(-) diff --git a/core/src/main/kotlin/com/last/commit/ColorState.kt b/core/src/main/kotlin/com/last/commit/ColorState.kt index 40da2b2..a7c6769 100644 --- a/core/src/main/kotlin/com/last/commit/ColorState.kt +++ b/core/src/main/kotlin/com/last/commit/ColorState.kt @@ -1,5 +1,7 @@ package com.last.commit; +import com.badlogic.gdx.math.MathUtils + class ColorState { public var red = 0f private set; diff --git a/core/src/main/kotlin/com/last/commit/Game.kt b/core/src/main/kotlin/com/last/commit/Game.kt index 67e4b87..305a9ab 100644 --- a/core/src/main/kotlin/com/last/commit/Game.kt +++ b/core/src/main/kotlin/com/last/commit/Game.kt @@ -52,10 +52,13 @@ class Game : Game() { } fun createState() { + val settings = GameSettings() + val soundEngine = SoundEngine(settings.sfxVolume, settings.musicVolume) + settings.soundEngin = soundEngine state = GameState( Inventory(), - GameSettings(), - SoundEngine(), + settings, + soundEngine, TimeTravelAssetManager(), null, DialogStage(Skin(Gdx.files.internal("ui/uiskin.json"))) diff --git a/core/src/main/kotlin/com/last/commit/Player.kt b/core/src/main/kotlin/com/last/commit/Player.kt index 65e0af5..e0210a2 100644 --- a/core/src/main/kotlin/com/last/commit/Player.kt +++ b/core/src/main/kotlin/com/last/commit/Player.kt @@ -36,7 +36,7 @@ class Player(private val textureRegion: TextureRegion, private val gameState: Ga updateCollider() if (System.currentTimeMillis() - lastStep > 500) { - gameState.soundEngine.play(GameSoundEffect.STEPS_INDOOR, 0.5f) + gameState.soundEngine.play(GameSoundEffect.STEPS_INDOOR) //0.5F lastStep = System.currentTimeMillis() } } 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 f5e8926..9d5b7de 100644 --- a/core/src/main/kotlin/com/last/commit/audio/SoundEngine.kt +++ b/core/src/main/kotlin/com/last/commit/audio/SoundEngine.kt @@ -4,24 +4,34 @@ import com.badlogic.gdx.Gdx import com.badlogic.gdx.audio.Music import com.badlogic.gdx.audio.Sound -public class SoundEngine { +public class SoundEngine(private val sfx: Float, private val music: Float) { + + + var volumeSfx = sfx + var volumeMusic = music + set(newValue) { + field = newValue + resume() + } private val sounds: ThreadLocal> = ThreadLocal.withInitial() { HashMap() } private val musicTracks: ThreadLocal> = ThreadLocal.withInitial() { HashMap() } - lateinit var backgroundMusic: Music + var backgroundMusic: Music + + init { + backgroundMusic = loadMusic("world_music.mp3") + } - fun play(gameSound: GameSound, volume: Float = 1f) { + fun play(gameSound: GameSound, ) { if (gameSound is GameSoundEffect) { val sound = loadEffect(gameSound.name) - sound.play(volume) + sound.play(volumeSfx) } else if (gameSound is GameMusic) { - backgroundMusic = loadMusic(gameSound.name) - backgroundMusic.volume = volume backgroundMusic.setLooping(true) - backgroundMusic.play() + resume() } } @@ -30,9 +40,11 @@ public class SoundEngine { } fun resume() { - backgroundMusic.play() + backgroundMusic.volume = volumeMusic + if (!backgroundMusic.isPlaying) { + backgroundMusic.play() + } } - private fun loadEffect(name: String): Sound { return loadSound("effects/$name") } diff --git a/core/src/main/kotlin/com/last/commit/config/GameSettings.kt b/core/src/main/kotlin/com/last/commit/config/GameSettings.kt index d3de7dc..db41fb9 100644 --- a/core/src/main/kotlin/com/last/commit/config/GameSettings.kt +++ b/core/src/main/kotlin/com/last/commit/config/GameSettings.kt @@ -2,24 +2,56 @@ package com.last.commit.config import com.badlogic.gdx.Input.Keys import com.badlogic.gdx.math.MathUtils +import com.last.commit.GameState +import com.last.commit.audio.SoundEngine import java.util.* -class GameSettings { +class GameSettings() { + lateinit var soundEngin : SoundEngine private val actionKeys: EnumMap> = EnumMap(ActionCommand::class.java) private val actionKeysReversed: HashMap = hashMapOf() var musicEnabled: Boolean = true + set(newValue: Boolean) { + field = newValue + soundEngin?.volumeMusic = musicVolume + } var sfxEnabled: Boolean = true + set(newValue: Boolean) { + field = newValue + soundEngin?.volumeSfx = sfxVolume + } var musicVolume: Float = 0.5F + get() { + return if (musicEnabled) { + field + } else { + 0F + } + } set(newValue: Float) { - field = MathUtils.clamp(newValue, 1f, 0f) + field = newValue + soundEngin?.volumeMusic = musicVolume } var sfxVolume: Float = 0.5F + get() { + return if (sfxEnabled) { + field + } else { + 0F + } + } set(newValue: Float) { - field = MathUtils.clamp(newValue, 1f, 0f) + field = newValue + + println("settings volume sfx :$sfxVolume") + soundEngin?.volumeSfx = sfxVolume + soundEngin?. let { + println("soundengine volume sfx :$sfxVolume") + } } @@ -33,8 +65,6 @@ class GameSettings { actionKeys[ActionCommand.INTERACT] = listOf(Keys.E) actionKeys[ActionCommand.JUMP] = listOf(Keys.SPACE) - musicVolume = 0.5F - setReversed(actionKeys) } 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 fd72b07..c45691d 100644 --- a/core/src/main/kotlin/com/last/commit/screen/FirstScreen.kt +++ b/core/src/main/kotlin/com/last/commit/screen/FirstScreen.kt @@ -50,7 +50,6 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { val highlightColor = Color(0f, 0f, 1f, 0.5f) - var pause = true var uiStage: UIStage val promptStage: PromptStage @@ -66,7 +65,6 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { uiStage = UIStage("sprites/genericItems_spritesheet_colored", gameState) shapeRenderer.setAutoShapeType(true) - gameState.soundEngine.play(GameMusic.WORLD_MUSIC, 0.25f) promptStage = PromptStage(Skin(Gdx.files.internal("ui/uiskin.json"))) promptStage.addText(""" You are stranded in time. @@ -99,7 +97,7 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { } override fun handleKeyInput(action: ActionCommand) { - if (!pause) { + when (action) { ActionCommand.INTERACT -> { openDoor() @@ -120,20 +118,21 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { //Gdx.app.exit() parent.changeScreen(Screens.MAIN_MENU) } - } + } override fun handleMouseInput(screenX: Int, screenY: Int, pointer: Int, button: Int) { - if (!pause) { + + val mouseCoordinates: Vector2 = toWorldCoordinates(screenX.toFloat(), screenY.toFloat()) val playerDirection: Vector2 = player.getAbsoluteDirection() map.interactWith(playerDirection.x, playerDirection.y, player.getCollider()) - } } override fun show() { - // Prepare your screen here. + + resume() } @@ -151,7 +150,7 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { promptStage.clearText() promptStage.addText("You won!") promptStage.draw() - } else if (!pause) { + } else { uiStage.act(delta) gameState.dialogStage.act(delta) promptStage.act(delta) @@ -296,21 +295,18 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { override fun pause() { - pause = true - gameState.soundEngine.stop() } override fun resume() { - pause = false - gameState.soundEngine.resume(); this.viewport.apply() this.updateCamera() // Invoked when your application is resumed after pause. } override fun hide() { - pause() + + //gameState.soundEngine.stop() } override fun dispose() { diff --git a/core/src/main/kotlin/com/last/commit/screen/MainMenu.kt b/core/src/main/kotlin/com/last/commit/screen/MainMenu.kt index 3a780bb..a65076e 100644 --- a/core/src/main/kotlin/com/last/commit/screen/MainMenu.kt +++ b/core/src/main/kotlin/com/last/commit/screen/MainMenu.kt @@ -3,6 +3,7 @@ package com.last.commit.screen import com.badlogic.gdx.Gdx import com.badlogic.gdx.InputProcessor import com.badlogic.gdx.graphics.GL20 +import com.badlogic.gdx.math.MathUtils import com.badlogic.gdx.scenes.scene2d.Actor import com.badlogic.gdx.scenes.scene2d.Stage import com.badlogic.gdx.scenes.scene2d.ui.Skin @@ -21,6 +22,7 @@ class MainMenu(val parent: Game) : TimeTravelScreen() { var table = Table() val uiSkin: Skin + val state = ColorState() init { parent.state.assetManager.finishLoading() @@ -93,13 +95,17 @@ class MainMenu(val parent: Game) : TimeTravelScreen() { } - val state = ColorState() override fun render(delta: Float) { 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) + + var red = MathUtils.clamp(state.red,0.1F, 0.5F) + var blue = MathUtils.clamp(state.green,0.1F, 0.5F) + var green = MathUtils.clamp(state.blue,0.1F, 0.5F) + + Gdx.gl.glClearColor(red, green, blue, 1f) // tell our stage to do actions and draw itself stage.act(Math.min(Gdx.graphics.getDeltaTime(), 1 / 30f)); diff --git a/core/src/main/kotlin/com/last/commit/screen/Settings.kt b/core/src/main/kotlin/com/last/commit/screen/Settings.kt index c37bce0..cb805c9 100644 --- a/core/src/main/kotlin/com/last/commit/screen/Settings.kt +++ b/core/src/main/kotlin/com/last/commit/screen/Settings.kt @@ -3,15 +3,16 @@ package com.last.commit.screen import com.badlogic.gdx.Gdx import com.badlogic.gdx.InputProcessor import com.badlogic.gdx.graphics.GL20 +import com.badlogic.gdx.math.MathUtils import com.badlogic.gdx.scenes.scene2d.Stage import com.badlogic.gdx.scenes.scene2d.ui.* import com.badlogic.gdx.utils.viewport.ScreenViewport +import com.last.commit.ColorState import com.last.commit.Game import com.last.commit.config.ActionCommand class Settings(val parent: Game) : TimeTravelScreen() { - var stage: Stage val skin: Skin @@ -22,84 +23,96 @@ class Settings(val parent: Game) : TimeTravelScreen() { lateinit var musicOnOffLabel: Label lateinit var soundOnOffLabel: Label + var sfxMusicSlider: Slider + var volumeMusicSlider: Slider + var musicCheckbox: CheckBox + var soundEffectsCheckbox: CheckBox + var backButton: Button + + + val state = ColorState() val table = Table() init { parent.state.assetManager.finishLoading() stage = Stage(ScreenViewport()) skin = parent.state.assetManager.getUiTexture() - } - - override fun handleKeyInput(action: ActionCommand) { - } - - override fun handleMouseInput(screenX: Int, screenY: Int, pointer: Int, button: Int) { - stage.touchDown(screenX, screenY, pointer, button) - stage.touchUp(screenX, screenY, pointer, button) - } - - override fun getInputProcessors(): Array { - return emptyArray() - } - - - override fun show() { - stage.clear() - - // Create a table that fills the screen. Everything else will go inside - // this table. - - } - - fun renderTable(x: Float, y: Float) { - table.reset() - table.setFillParent(true) - //table.setDebug(true); - stage.addActor(table) // music volume - val volumeMusicSlider = Slider(0f, 1f, 0.1f, false, skin) + volumeMusicSlider = Slider(0f, 1f, 0.1f, false, skin) volumeMusicSlider.value = parent.state.settings.musicVolume volumeMusicSlider.addListener { + println("volume slide ${volumeMusicSlider.value}") parent.state.settings.musicVolume = volumeMusicSlider.value // updateVolumeLabel(); false } // sound volume - val soundMusicSlider = Slider(0f, 1f, 0.1f, false, skin) - soundMusicSlider.value = parent.state.settings.sfxVolume - soundMusicSlider.addListener { - parent.state.settings.sfxVolume = soundMusicSlider.value + sfxMusicSlider = Slider(0f, 1f, 0.1f, false, skin) + sfxMusicSlider.value = parent.state.settings.sfxVolume + sfxMusicSlider.addListener { + + println("volume sfx :${sfxMusicSlider.value}") + parent.state.settings.sfxVolume = sfxMusicSlider.value // updateVolumeLabel(); false } // music on/off - val musicCheckbox = CheckBox(null, skin) - musicCheckbox.isChecked = parent.state.settings.musicEnabled + musicCheckbox = CheckBox(null, skin) + musicCheckbox.isChecked = !parent.state.settings.musicEnabled musicCheckbox.addListener { val enabled: Boolean = musicCheckbox.isChecked() - parent.state.settings.musicEnabled = enabled + parent.state.settings.musicEnabled = !enabled false } // sound on/off - val soundEffectsCheckbox = CheckBox(null, skin) - soundEffectsCheckbox.isChecked = parent.state.settings.sfxEnabled + soundEffectsCheckbox = CheckBox(null, skin) + soundEffectsCheckbox.isChecked = !parent.state.settings.sfxEnabled soundEffectsCheckbox.addListener { val enabled: Boolean = soundEffectsCheckbox.isChecked() - parent.state.settings.sfxEnabled = enabled + parent.state.settings.sfxEnabled = !enabled false } // return to main screen button - val backButton = TextButton("Back", skin) + backButton = TextButton("Back", skin) backButton.addListener { parent.changeScreen(Screens.MAIN_MENU) false } + + } + + override fun handleKeyInput(action: ActionCommand) { + } + + override fun handleMouseInput(screenX: Int, screenY: Int, pointer: Int, button: Int) { + stage.touchDown(screenX, screenY, pointer, button) + stage.touchUp(screenX, screenY, pointer, button) + } + + override fun getInputProcessors(): Array { + return emptyArray() + } + + + override fun show() { + stage.clear() + + } + + fun renderTable(x: Float, y: Float) { + table.reset() + table.setFillParent(true) + //table.setDebug(true); + stage.addActor(table) + + + titleLabel = Label("Preferences", skin) volumeMusicLabel = Label("Music Volume", skin) volumeSoundLabel = Label("Sound Volume", skin) @@ -117,7 +130,7 @@ class Settings(val parent: Game) : TimeTravelScreen() { table.row().size(x, y); table.row().pad(10F, 0F, 0F, 10F) table.add(volumeSoundLabel).left() - table.add(soundMusicSlider) + table.add(sfxMusicSlider) table.row().size(x, y); table.row().pad(10F, 0F, 0F, 10F) table.add(soundOnOffLabel).left() @@ -128,9 +141,17 @@ class Settings(val parent: Game) : TimeTravelScreen() { } override fun render(delta: Float) { - // clear the screen ready for next set of images to be drawn - Gdx.gl.glClearColor(0f, 0f, 0f, 1f) + + + 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) + var red = MathUtils.clamp(state.red,0.1F, 0.5F) + var blue = MathUtils.clamp(state.green,0.1F, 0.5F) + var green = MathUtils.clamp(state.blue,0.1F, 0.5F) + + Gdx.gl.glClearColor(red, green, blue, 1f) + // tell our stage to do actions and draw itself stage.act(Math.min(Gdx.graphics.deltaTime, 1 / 30f)) @@ -158,5 +179,6 @@ class Settings(val parent: Game) : TimeTravelScreen() { } override fun dispose() { + stage.dispose(); } } \ No newline at end of file From 0c107434dda099d2b175a616b0b6b23d01c5bd14 Mon Sep 17 00:00:00 2001 From: MehdiAyadi <91869915+MehdiAyadi@users.noreply.github.com> Date: Sun, 20 Nov 2022 13:29:16 +0100 Subject: [PATCH 4/5] removed println for volume --- core/src/main/kotlin/com/last/commit/config/GameSettings.kt | 4 ---- core/src/main/kotlin/com/last/commit/screen/Settings.kt | 2 -- 2 files changed, 6 deletions(-) diff --git a/core/src/main/kotlin/com/last/commit/config/GameSettings.kt b/core/src/main/kotlin/com/last/commit/config/GameSettings.kt index db41fb9..446cf4a 100644 --- a/core/src/main/kotlin/com/last/commit/config/GameSettings.kt +++ b/core/src/main/kotlin/com/last/commit/config/GameSettings.kt @@ -47,11 +47,7 @@ class GameSettings() { set(newValue: Float) { field = newValue - println("settings volume sfx :$sfxVolume") soundEngin?.volumeSfx = sfxVolume - soundEngin?. let { - println("soundengine volume sfx :$sfxVolume") - } } diff --git a/core/src/main/kotlin/com/last/commit/screen/Settings.kt b/core/src/main/kotlin/com/last/commit/screen/Settings.kt index cb805c9..3ceda20 100644 --- a/core/src/main/kotlin/com/last/commit/screen/Settings.kt +++ b/core/src/main/kotlin/com/last/commit/screen/Settings.kt @@ -43,7 +43,6 @@ class Settings(val parent: Game) : TimeTravelScreen() { volumeMusicSlider = Slider(0f, 1f, 0.1f, false, skin) volumeMusicSlider.value = parent.state.settings.musicVolume volumeMusicSlider.addListener { - println("volume slide ${volumeMusicSlider.value}") parent.state.settings.musicVolume = volumeMusicSlider.value // updateVolumeLabel(); false @@ -54,7 +53,6 @@ class Settings(val parent: Game) : TimeTravelScreen() { sfxMusicSlider.value = parent.state.settings.sfxVolume sfxMusicSlider.addListener { - println("volume sfx :${sfxMusicSlider.value}") parent.state.settings.sfxVolume = sfxMusicSlider.value // updateVolumeLabel(); false From d99c4cb609bc9ca7c627701b0b3f551df03db66f Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 20 Nov 2022 13:32:56 +0100 Subject: [PATCH 5/5] Fix win prompt --- core/src/main/kotlin/com/last/commit/screen/FirstScreen.kt | 7 +++++-- core/src/main/kotlin/com/last/commit/stages/PromptStage.kt | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) 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 fd72b07..c0cb359 100644 --- a/core/src/main/kotlin/com/last/commit/screen/FirstScreen.kt +++ b/core/src/main/kotlin/com/last/commit/screen/FirstScreen.kt @@ -78,9 +78,12 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { """.trimIndent()) promptStage.addText(""" You can use , , and to walk around the map. - Some doors require keys to be opened. """.trimIndent()) promptStage.addText(""" + Doors can be opened and items picked up with . + Some doors require keys to be opened. + """) + promptStage.addText(""" At some locations you can press to travel to a random spot in time. The top left indicates where you traveled to. """.trimIndent()) @@ -147,9 +150,9 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() { override fun render(delta: Float) { if (gameState.inventory.checkVictoryCondition()) { promptStage.visible = true - promptStage.act(delta) promptStage.clearText() promptStage.addText("You won!") + promptStage.act(delta) promptStage.draw() } else if (!pause) { uiStage.act(delta) diff --git a/core/src/main/kotlin/com/last/commit/stages/PromptStage.kt b/core/src/main/kotlin/com/last/commit/stages/PromptStage.kt index 8f0f2d3..1cc2171 100644 --- a/core/src/main/kotlin/com/last/commit/stages/PromptStage.kt +++ b/core/src/main/kotlin/com/last/commit/stages/PromptStage.kt @@ -70,6 +70,7 @@ class PromptStage(skin: Skin?): Stage(ExtendViewport(300f, 300f)) { val text = text.removeAt(0).trimIndent() textArea.text = text } else { + textArea.text = "" visible = false } }