Huge refactoring

main
Matthias 1 year ago
parent 9711e28341
commit 960577bcb1

@ -0,0 +1,62 @@
package com.last.commit
import com.badlogic.gdx.assets.AssetManager
import com.badlogic.gdx.audio.Music
import com.badlogic.gdx.audio.Sound
import com.badlogic.gdx.scenes.scene2d.ui.Skin
object TimeTravelAssetManager {
private val skin = "ui/uiskin.json"
private val assetManager = AssetManager()
fun loadSounds(vararg paths: String) {
println("Loading ${paths.size} sounds")
for (path in paths) {
assetManager.load(path, Sound::class.java)
}
}
fun loadMusics(vararg paths: String) {
println("Loading ${paths.size} musics")
for (path in paths) {
assetManager.load(path, Music::class.java)
}
}
fun loadSkins(vararg paths: String) {
println("Loading ${paths.size} skins")
for (path in paths) {
assetManager.load(path, Skin::class.java)
}
assetManager.load(skin, Skin::class.java);
}
fun loadTextures(vararg paths: String) {
println("Loading ${paths.size} textures")
for (path in paths) {
assetManager.load(path, Music::class.java)
}
}
fun getSkin(): Skin {
return assetManager.get(skin)
}
fun <T> get(path: String): T {
return assetManager.get(path)
}
fun finishLoading() {
assetManager.finishLoading()
}
fun update(): Boolean {
return assetManager.update()
}
fun dispose() {
assetManager.dispose()
}
}

@ -2,11 +2,10 @@ package com.last.commit
import com.badlogic.gdx.Game import com.badlogic.gdx.Game
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.InputMultiplexer import com.badlogic.gdx.Screen
import com.badlogic.gdx.graphics.g2d.BitmapFont
import com.badlogic.gdx.scenes.scene2d.ui.Skin import com.badlogic.gdx.scenes.scene2d.ui.Skin
import com.last.commit.audio.SoundEngine import com.last.commit.audio.SoundEngine
import com.last.commit.config.GameSettings
import com.last.commit.config.TimeTravelAssetManager
import com.last.commit.inventory.Inventory import com.last.commit.inventory.Inventory
import com.last.commit.screen.* import com.last.commit.screen.*
import com.last.commit.stages.DialogStage import com.last.commit.stages.DialogStage
@ -17,25 +16,23 @@ class Game : Game() {
lateinit var state: GameState lateinit var state: GameState
lateinit var menu: TimeTravelScreen lateinit var loading: Screen
lateinit var gameplay: TimeTravelScreen lateinit var menu: Screen
lateinit var settings: TimeTravelScreen lateinit var gameplay: Screen
val inputProcessors = InputMultiplexer() lateinit var settings: Screen
lateinit var inputProcessor: GameInputProcessor
lateinit var font: BitmapFont
override fun create() { override fun create() {
font = BitmapFont()
createState() createState()
createScreens() createScreens()
inputProcessor = GameInputProcessor(this)
gameplay.getInputProcessors().forEach { it -> inputProcessors.addProcessor(it) }
inputProcessors.addProcessor(inputProcessor)
Gdx.input.inputProcessor = inputProcessors
changeScreen(Screens.MAIN_MENU) changeScreen(Screens.LOADING)
} }
private fun createScreens() { private fun createScreens() {
loading = LoadingScreen(TimeTravelAssetManager, this)
menu = MainMenu(this) menu = MainMenu(this)
gameplay = FirstScreen(this) gameplay = FirstScreen(this)
settings = Settings(this) settings = Settings(this)
@ -44,22 +41,17 @@ class Game : Game() {
fun changeScreen(screen: Screens) { fun changeScreen(screen: Screens) {
println("changing screen to $screen") println("changing screen to $screen")
when (screen) { when (screen) {
Screens.LOADING -> setScreen(loading)
Screens.MAIN_MENU -> setScreen(menu) Screens.MAIN_MENU -> setScreen(menu)
Screens.SETTINGS -> setScreen(settings) Screens.SETTINGS -> setScreen(settings)
Screens.GAME -> setScreen(gameplay) Screens.GAME -> setScreen(gameplay)
} }
inputProcessor.activeScreen = getScreen() as TimeTravelScreen
} }
fun createState() { fun createState() {
val settings = GameSettings()
val soundEngine = SoundEngine(settings.sfxVolume, settings.musicVolume)
settings.soundEngin = soundEngine
state = GameState( state = GameState(
Inventory(), Inventory(),
settings, SoundEngine,
soundEngine,
TimeTravelAssetManager(),
null, null,
DialogStage(Skin(Gdx.files.internal("ui/uiskin.json"))) DialogStage(Skin(Gdx.files.internal("ui/uiskin.json")))
) )

@ -1,46 +0,0 @@
package com.last.commit
import com.badlogic.gdx.InputProcessor
import com.last.commit.screen.TimeTravelScreen
class GameInputProcessor(val game: Game) : InputProcessor {
lateinit var activeScreen: TimeTravelScreen
override fun keyUp(keycode: Int): Boolean {
return false
}
override fun keyTyped(character: Char): Boolean {
return false
}
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
activeScreen.handleMouseInput(screenX, screenY, pointer, button)
return false
}
override fun keyDown(keycode: Int): Boolean {
game.state.settings.getAction(keycode)?.let {
activeScreen.handleKeyInput(it)
}
return false
}
override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
return false
}
override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
return false
}
override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
return false
}
override fun scrolled(amountX: Float, amountY: Float): Boolean {
return false
}
}

@ -1,17 +1,13 @@
package com.last.commit package com.last.commit
import com.last.commit.audio.SoundEngine import com.last.commit.audio.SoundEngine
import com.last.commit.config.GameSettings
import com.last.commit.config.TimeTravelAssetManager
import com.last.commit.inventory.Inventory import com.last.commit.inventory.Inventory
import com.last.commit.map.MapState import com.last.commit.map.MapState
import com.last.commit.stages.DialogStage import com.last.commit.stages.DialogStage
data class GameState( data class GameState(
val inventory: Inventory, val inventory: Inventory,
val settings: GameSettings,
val soundEngine: SoundEngine, val soundEngine: SoundEngine,
val assetManager: TimeTravelAssetManager,
var map: MapState? = null, var map: MapState? = null,
val dialogStage: DialogStage val dialogStage: DialogStage
) { ) {

@ -4,7 +4,6 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.g2d.TextureRegion import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.badlogic.gdx.math.Rectangle import com.badlogic.gdx.math.Rectangle
import com.badlogic.gdx.math.Vector2 import com.badlogic.gdx.math.Vector2
import com.last.commit.audio.GameSoundEffect
class Player(private val textureRegion: TextureRegion, private val gameState: GameState) : Collidable { class Player(private val textureRegion: TextureRegion, private val gameState: GameState) : Collidable {
@ -36,7 +35,7 @@ class Player(private val textureRegion: TextureRegion, private val gameState: Ga
updateCollider() updateCollider()
if (System.currentTimeMillis() - lastStep > 500) { if (System.currentTimeMillis() - lastStep > 500) {
gameState.soundEngine.play(GameSoundEffect.STEPS_INDOOR) //0.5F gameState.soundEngine.play("STEPS_INDOOR") //0.5F
lastStep = System.currentTimeMillis() lastStep = System.currentTimeMillis()
} }
} }

@ -1,9 +0,0 @@
package com.last.commit.audio
import com.last.commit.audio.GameSound
class GameMusic(name: String): GameSound(name) {
companion object {
val WORLD_MUSIC = GameMusic("world_music.mp3")
}
}

@ -1,5 +0,0 @@
package com.last.commit.audio;
public abstract class GameSound(public val name: String) {
}

@ -1,19 +0,0 @@
package com.last.commit.audio;
import com.last.commit.audio.GameSound
public class GameSoundEffect(name: String): GameSound(name) {
companion object {
val STEPS_INDOOR: GameSoundEffect
get() = listOf(
GameSoundEffect("steps/steps_indoor_1.mp3"),
GameSoundEffect("steps/steps_indoor_2.mp3"),
GameSoundEffect("steps/steps_indoor_3.mp3"),
).random()
val DOOR_OPEN = GameSoundEffect("door_open.mp3")
val DOOR_CLOSE = GameSoundEffect("door_close.mp3")
val TIME_TRAVEL = GameSoundEffect("time_travel.mp3")
val GRAB = GameSoundEffect("grab.mp3")
}
}

@ -1,75 +1,80 @@
package com.last.commit.audio package com.last.commit.audio
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.audio.Music import com.badlogic.gdx.audio.Music
import com.badlogic.gdx.audio.Sound import com.badlogic.gdx.audio.Sound
import com.last.commit.TimeTravelAssetManager
public class SoundEngine(private val sfx: Float, private val music: Float) { object SoundEngine {
var sfxVolume = 1.0f
var volumeSfx = sfx var musicVolume = 1.0f
var volumeMusic = music
set(newValue) { set(newValue) {
field = newValue field = newValue
resume() resume()
} }
private val sounds: ThreadLocal<HashMap<String, Sound>> = fun play(gameSound: String) {
ThreadLocal.withInitial() { HashMap() } when (gameSound) {
private val musicTracks: ThreadLocal<HashMap<String, Music>> = "STEPS_INDOOR" -> {
ThreadLocal.withInitial() { HashMap() } val soundName = listOf(
"steps/steps_indoor_1.mp3",
"steps/steps_indoor_2.mp3",
"steps/steps_indoor_3.mp3",
).random()
val sound = loadEffect(soundName)
sound.play(sfxVolume)
}
var backgroundMusic: Music "DOOR_OPEN" -> {
val sound = loadEffect("door_open.mp3")
sound.play(sfxVolume)
}
init { "DOOR_CLOSE" -> {
backgroundMusic = loadMusic("world_music.mp3") val sound = loadEffect("door_close.mp3")
resume() sound.play(sfxVolume)
} }
fun play(gameSound: GameSound, ) { "TIME_TRAVEL" -> {
if (gameSound is GameSoundEffect) { val sound = loadEffect("time_travel.mp3")
val sound = loadEffect(gameSound.name) sound.play(sfxVolume)
sound.play(volumeSfx) }
} else if (gameSound is GameMusic) {
backgroundMusic.setLooping(true) "GRAB" -> {
resume() val sound = loadEffect("grab.mp3")
sound.play(sfxVolume)
}
"BACKGROUND_MUSIC" -> {
loadMusic("world_music.mp3").play()
}
else -> {
println("Could not find sound/music $gameSound")
}
} }
} }
fun stop() { fun stop() {
backgroundMusic.pause() loadMusic("world_music.mp3").pause()
} }
fun resume() { fun resume() {
backgroundMusic.volume = volumeMusic loadMusic("world_music.mp3").volume = musicVolume
if (!backgroundMusic.isPlaying) { if (!loadMusic("world_music.mp3").isPlaying) {
backgroundMusic.play() loadMusic("world_music.mp3").play()
} }
} }
private fun loadEffect(name: String): Sound { private fun loadEffect(name: String): Sound {
return loadSound("effects/$name") return loadSound("effects/$name")
} }
private fun loadMusic(name: String): Music { private fun loadMusic(name: String): Music {
var music = musicTracks.get().get(name) return TimeTravelAssetManager.get("sounds/music/$name")
if (music == null) {
println("Loading sound $name")
music = Gdx.audio.newMusic(Gdx.files.internal("sounds/music/$name"))
musicTracks.get()[name] = music
}
return music!!
} }
private fun loadSound(name: String): Sound { private fun loadSound(name: String): Sound {
var sound = sounds.get().get(name) return TimeTravelAssetManager.get("sounds/$name")
if (sound == null) {
println("Loading sound $name")
sound = Gdx.audio.newSound(Gdx.files.internal("sounds/$name"))
sounds.get()[name] = sound
}
return sound!!
} }
} }

@ -1,16 +0,0 @@
package com.last.commit.config
enum class ActionCommand {
//move
UP, DOWN, LEFT, RIGHT,
//interaction
TIME_TRAVEL,
INTERACT,
//program interaction
OPEN_MENU,
JUMP
}

@ -1,91 +0,0 @@
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() {
lateinit var soundEngin : SoundEngine
private val actionKeys: EnumMap<ActionCommand, List<Int>> = EnumMap(ActionCommand::class.java)
private val actionKeysReversed: HashMap<Int, ActionCommand> = 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 = newValue
soundEngin?.volumeMusic = musicVolume
}
var sfxVolume: Float = 0.5F
get() {
return if (sfxEnabled) {
field
} else {
0F
}
}
set(newValue: Float) {
field = newValue
soundEngin?.volumeSfx = sfxVolume
}
init {
actionKeys[ActionCommand.UP] = listOf(Keys.UP, Keys.W)
actionKeys[ActionCommand.DOWN] = listOf(Keys.DOWN, Keys.S)
actionKeys[ActionCommand.LEFT] = listOf(Keys.LEFT, Keys.A)
actionKeys[ActionCommand.RIGHT] = listOf(Keys.RIGHT, Keys.D)
actionKeys[ActionCommand.OPEN_MENU] = listOf(Keys.ESCAPE)
actionKeys[ActionCommand.TIME_TRAVEL] = listOf(Keys.T)
actionKeys[ActionCommand.INTERACT] = listOf(Keys.E)
actionKeys[ActionCommand.JUMP] = listOf(Keys.SPACE)
setReversed(actionKeys)
}
private fun setReversed(actionKeys: EnumMap<ActionCommand, List<Int>>) {
for (actionCode in actionKeys.keys) {
for (key in actionKeys.getValue(actionCode)) {
actionKeysReversed[key] = actionCode
}
}
}
fun getAction(keyCode: Int): ActionCommand? {
return actionKeysReversed[keyCode]
}
fun getKeyCode(actionCommand: ActionCommand): List<Int> {
return if (Objects.nonNull(actionKeys[actionCommand])) {
actionKeys[actionCommand]!!
} else {
listOf()
}
}
}

@ -1,22 +0,0 @@
package com.last.commit.config
import com.badlogic.gdx.assets.AssetManager
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.scenes.scene2d.ui.Skin
class TimeTravelAssetManager : AssetManager() {
val UI_TEXTURE_PATH = "ui/uiskin.json"
init {
loadTextures()
}
fun loadTextures() {
load(UI_TEXTURE_PATH, Skin::class.java)
}
fun getUiTexture() : Skin {
return get(UI_TEXTURE_PATH)
}
}

@ -7,8 +7,8 @@ class Inventory() {
private val requiredItems = listOf("ram", "iphone", "ipod", "screwdriver") private val requiredItems = listOf("ram", "iphone", "ipod", "screwdriver")
/** /**
* @param name the name of the subtexture loaded from xml * @param name the name of the subTexture loaded from xml
* @return wether the item was added * @return whether the item was added
*/ */
fun add(name: String) { fun add(name: String) {
items.add(InventoryItem(name)) items.add(InventoryItem(name))
@ -16,7 +16,7 @@ class Inventory() {
} }
fun hasItem(name: String): Boolean { fun hasItem(name: String): Boolean {
return this.items.find { it.name == name } == null return this.items.find { it.name == name } != null
} }
fun isFull(): Boolean { fun isFull(): Boolean {
@ -24,7 +24,7 @@ class Inventory() {
} }
fun remove(name: String) { fun remove(name: String) {
items.removeIf() { item -> item.name == name } items.removeIf { item -> item.name == name }
} }
fun checkVictoryCondition(): Boolean { fun checkVictoryCondition(): Boolean {

@ -4,8 +4,6 @@ import com.badlogic.gdx.math.Rectangle
import com.badlogic.gdx.math.Vector2 import com.badlogic.gdx.math.Vector2
import com.badlogic.gdx.scenes.scene2d.ui.Image import com.badlogic.gdx.scenes.scene2d.ui.Image
import com.last.commit.GameState import com.last.commit.GameState
import com.last.commit.audio.GameSoundEffect
import com.last.commit.inventory.InventoryItem
class Collectible( class Collectible(
name: String, name: String,
@ -23,9 +21,9 @@ class Collectible(
this.collider = Rectangle(pos.x, pos.y, size.x, size.y) this.collider = Rectangle(pos.x, pos.y, size.x, size.y)
} }
override fun interact(otherCollider: Rectangle, state: GameState) { override fun interact(otherCollider: Rectangle, state: GameState): Boolean {
println("Interacting with item $name") println("Interacting with item $name")
state.soundEngine.play(GameSoundEffect.GRAB) state.soundEngine.play("GRAB")
if (state.inventory.hasItem(this.name)) { if (state.inventory.hasItem(this.name)) {
state.dialogStage.setTexts("You already have this item.") state.dialogStage.setTexts("You already have this item.")
state.dialogStage.show() state.dialogStage.show()
@ -33,18 +31,16 @@ class Collectible(
state.dialogStage.setTexts("You can't carry anymore items.") state.dialogStage.setTexts("You can't carry anymore items.")
} else { } else {
state.inventory.add(this.name) state.inventory.add(this.name)
return true
} }
return false
} }
override fun canInteract(state: GameState): Boolean { override fun canInteract(state: GameState): Boolean {
if (requiredItem == "") { if (requiredItem == "") {
return true return true
} }
val item: InventoryItem? = state.inventory.items.find { it.name == requiredItem } state.inventory.items.find { it.name == requiredItem } ?: return false
if (item == null) {
return false
}
return true return true

@ -4,7 +4,6 @@ import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell
import com.badlogic.gdx.math.Rectangle import com.badlogic.gdx.math.Rectangle
import com.last.commit.GameState import com.last.commit.GameState
import com.last.commit.Wall import com.last.commit.Wall
import com.last.commit.audio.GameSoundEffect
import com.last.commit.inventory.InventoryItem import com.last.commit.inventory.InventoryItem
class Door(gridX: Int, gridY: Int, wallCollider: Rectangle, cell: Cell) : class Door(gridX: Int, gridY: Int, wallCollider: Rectangle, cell: Cell) :
@ -24,29 +23,29 @@ class Door(gridX: Int, gridY: Int, wallCollider: Rectangle, cell: Cell) :
result = requiredItem == item.name result = requiredItem == item.name
} }
if (result) { if (!result) {
} else {
state.dialogStage.setTexts("This dor is blocked. You need a key") state.dialogStage.setTexts("This dor is blocked. You need a key")
state.dialogStage.show() state.dialogStage.show()
} }
return result return result
} }
override fun interact(otherCollider: Rectangle, state: GameState) { override fun interact(otherCollider: Rectangle, state: GameState): Boolean {
println("interacting with door $this") println("interacting with door $this")
if (isClosed) { if (isClosed) {
state.soundEngine.play(GameSoundEffect.DOOR_OPEN) state.soundEngine.play("DOOR_OPEN")
isOpen = true isOpen = true
} else if (isOpen) { } else if (isOpen) {
if (getCollider().overlaps(otherCollider)) { if (getCollider().overlaps(otherCollider)) {
// can't close the door cause it is colliding with given collider // can't close the door cause it is colliding with given collider
} else { } else {
state.soundEngine.play(GameSoundEffect.DOOR_CLOSE) state.soundEngine.play("DOOR_CLOSE")
isOpen = false isOpen = false
} }
} }
println("Door is now open = $isOpen") println("Door is now open = $isOpen")
return false
} }
var isOpen: Boolean var isOpen: Boolean

@ -6,7 +6,7 @@ import com.last.commit.GameState
interface Interactable { interface Interactable {
fun getCollider(): Rectangle fun getCollider(): Rectangle
fun interact(otherCollider: Rectangle, state: GameState) fun interact(otherCollider: Rectangle, state: GameState): Boolean
fun canInteract(state: GameState): Boolean fun canInteract(state: GameState): Boolean
} }

@ -12,7 +12,6 @@ import com.badlogic.gdx.scenes.scene2d.ui.Image
import com.last.commit.Collidable import com.last.commit.Collidable
import com.last.commit.GameState import com.last.commit.GameState
import com.last.commit.Player import com.last.commit.Player
import com.last.commit.audio.GameSoundEffect
import com.last.commit.inventory.SpritesheetTextureLoader import com.last.commit.inventory.SpritesheetTextureLoader
@ -58,7 +57,7 @@ class TimeMap(fileName: String, val state: GameState) {
it.rectangle.contains(player.getX(), player.getY()) it.rectangle.contains(player.getX(), player.getY())
} }
if (teleporter != null) { if (teleporter != null) {
state.soundEngine.play(GameSoundEffect.TIME_TRAVEL) state.soundEngine.play("TIME_TRAVEL")
val targetMap = teleporter.properties.get("target", String::class.java) val targetMap = teleporter.properties.get("target", String::class.java)
System.out.println("Teleporting to targetMap $targetMap") System.out.println("Teleporting to targetMap $targetMap")
loadMap("tiled/$targetMap") loadMap("tiled/$targetMap")
@ -125,7 +124,10 @@ class TimeMap(fileName: String, val state: GameState) {
if (interactable.canInteract(state)) { if (interactable.canInteract(state)) {
println("Interacting with element at $gridX:$gridY") println("Interacting with element at $gridX:$gridY")
interactable.interact(blockingCollider, state) val collected = interactable.interact(blockingCollider, state)
if (collected && interactable is Collectible) {
state.map?.collectibles?.remove(interactable)
}
} else { } else {
println("Cannot interact with $gridX:$gridY") println("Cannot interact with $gridX:$gridY")
} }

@ -1,7 +1,6 @@
package com.last.commit.screen package com.last.commit.screen
import com.badlogic.gdx.Gdx import com.badlogic.gdx.*
import com.badlogic.gdx.InputProcessor
import com.badlogic.gdx.graphics.Color import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.GL20 import com.badlogic.gdx.graphics.GL20
import com.badlogic.gdx.graphics.OrthographicCamera import com.badlogic.gdx.graphics.OrthographicCamera
@ -12,37 +11,32 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import com.badlogic.gdx.math.MathUtils import com.badlogic.gdx.math.MathUtils
import com.badlogic.gdx.math.Vector2 import com.badlogic.gdx.math.Vector2
import com.badlogic.gdx.math.Vector3 import com.badlogic.gdx.math.Vector3
import com.badlogic.gdx.scenes.scene2d.ui.Skin
import com.badlogic.gdx.utils.Json 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.utils.viewport.FillViewport
import com.badlogic.gdx.scenes.scene2d.ui.Skin
import com.last.commit.Game import com.last.commit.Game
import com.last.commit.Player 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.config.GameConfig
import com.last.commit.map.Interactable import com.last.commit.map.Interactable
import com.last.commit.map.TimeMap import com.last.commit.map.TimeMap
import com.last.commit.stages.UIStage
import com.last.commit.stages.PromptStage import com.last.commit.stages.PromptStage
import com.last.commit.stages.UIStage
import kotlin.math.floor import kotlin.math.floor
/** First screen of the application. Displayed after the application is created. */ /** First screen of the application. Displayed after the application is created. */
class FirstScreen(private val parent: Game) : TimeTravelScreen() { class FirstScreen(private val parent: Game) : Screen, InputProcessor {
val gameState = parent.state val gameState = parent.state
val viewportSize = 1200f val viewportSize = 1200f
private var delta = 0.008f
private var isColliding = false private var isColliding = false
val batch = SpriteBatch() val batch = SpriteBatch()
val viewport = FillViewport(viewportSize, viewportSize) val viewport = FillViewport(viewportSize, viewportSize)
val camera = OrthographicCamera(viewportSize, viewportSize) val camera = OrthographicCamera(viewportSize, viewportSize)
var map: TimeMap lateinit var map: TimeMap
val playerTexture = Texture("sprites/characters.png") val playerTexture = Texture("sprites/characters.png")
val player = Player(TextureRegion(playerTexture, 300, 44, 35, 43), gameState) val player = Player(TextureRegion(playerTexture, 300, 44, 35, 43), gameState)
@ -50,11 +44,17 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() {
val highlightColor = Color(0f, 0f, 1f, 0.5f) val highlightColor = Color(0f, 0f, 1f, 0.5f)
var uiStage: UIStage lateinit var uiStage: UIStage
val promptStage: PromptStage lateinit var promptStage: PromptStage
val inputProcessors = InputMultiplexer()
init { init {
}
override fun show() {
val gameConfig = this.loadGameConfig() val gameConfig = this.loadGameConfig()
val randomMap = gameConfig.getRandomMap() val randomMap = gameConfig.getRandomMap()
map = TimeMap(randomMap, gameState) map = TimeMap(randomMap, gameState)
@ -66,77 +66,51 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() {
shapeRenderer.setAutoShapeType(true) shapeRenderer.setAutoShapeType(true)
promptStage = PromptStage(Skin(Gdx.files.internal("ui/uiskin.json"))) promptStage = PromptStage(Skin(Gdx.files.internal("ui/uiskin.json")))
promptStage.addText(""" promptStage.addText(
"""
You are stranded in time. You are stranded in time.
The time traveling device you carry with you cannot be controlled anymore. The time traveling device you carry with you cannot be controlled anymore.
""".trimIndent()) """.trimIndent()
promptStage.addText(""" )
promptStage.addText(
"""
You need to find the tools required to fix your time traveling device. You need to find the tools required to fix your time traveling device.
Look around the map to find them. Look around the map to find them.
""".trimIndent()) """.trimIndent()
promptStage.addText(""" )
promptStage.addText(
"""
You can use <W>, <A>, <S> and <D> to walk around the map. You can use <W>, <A>, <S> and <D> to walk around the map.
""".trimIndent()) """.trimIndent()
promptStage.addText(""" )
promptStage.addText(
"""
Doors can be opened and items picked up with <E>. Doors can be opened and items picked up with <E>.
Some doors require keys to be opened. Some doors require keys to be opened.
""") """
promptStage.addText(""" )
promptStage.addText(
"""
At some locations you can press <T> to travel to a random spot in time. At some locations you can press <T> to travel to a random spot in time.
The top left indicates where you traveled to. The top left indicates where you traveled to.
""".trimIndent()) """.trimIndent()
promptStage.addText(""" )
promptStage.addText(
"""
Some items can only be collected in certain time locations. Some items can only be collected in certain time locations.
A collectible item will be highlighted when hovering over it using the mouse A collectible item will be highlighted when hovering over it using the mouse
""".trimIndent()) """.trimIndent()
)
promptStage.visible = true promptStage.visible = true
viewport.camera = camera viewport.camera = camera
viewport.apply() viewport.apply()
}
override fun getInputProcessors(): Array<InputProcessor> {
return arrayOf(gameState.dialogStage, promptStage)
}
override fun handleKeyInput(action: ActionCommand) {
when (action) {
ActionCommand.INTERACT -> {
openDoor()
}
ActionCommand.TIME_TRAVEL -> {
map.teleport(player)
}
ActionCommand.JUMP -> {
gameState.dialogStage.setTexts("Hello", "Please read the documentation")
gameState.dialogStage.show()
}
else -> {}
}
if (action == 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())
val playerDirection: Vector2 = player.getAbsoluteDirection()
map.interactWith(playerDirection.x, playerDirection.y, player.getCollider())
}
override fun show() {
resume() resume()
inputProcessors.addProcessor(gameState.dialogStage)
inputProcessors.addProcessor(promptStage)
inputProcessors.addProcessor(this)
Gdx.input.inputProcessor = inputProcessors
} }
fun loadGameConfig(): GameConfig { fun loadGameConfig(): GameConfig {
@ -147,16 +121,14 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() {
} }
override fun render(delta: Float) { override fun render(delta: Float) {
uiStage.act(delta)
gameState.dialogStage.act(delta)
promptStage.act(delta)
if (gameState.inventory.checkVictoryCondition()) { if (gameState.inventory.checkVictoryCondition()) {
promptStage.visible = true promptStage.visible = true
promptStage.clearText() promptStage.clearText()
promptStage.addText("You won!") promptStage.addText("You won!")
promptStage.act(delta)
promptStage.draw()
} else { } else {
uiStage.act(delta)
gameState.dialogStage.act(delta)
promptStage.act(delta)
if (!promptStage.visible) { if (!promptStage.visible) {
handleInput(delta) handleInput(delta)
@ -166,7 +138,7 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() {
val mousePosition: Vector2 = getMousePosition() val mousePosition: Vector2 = getMousePosition()
player.lookAt(mousePosition) player.lookAt(mousePosition)
batch.projectionMatrix = camera.combined batch.projectionMatrix = camera.combined
batch.begin() batch.begin()
this.map.render(batch, camera, delta) this.map.render(batch, camera, delta)
@ -176,12 +148,12 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() {
val interactables = map.getInteractablesAt(player.getAbsoluteDirection()) val interactables = map.getInteractablesAt(player.getAbsoluteDirection())
renderInteractables(interactables) renderInteractables(interactables)
uiStage.draw()
gameState.dialogStage.draw()
promptStage.draw()
viewport.apply() viewport.apply()
updateCamera() updateCamera()
} }
promptStage.draw()
uiStage.draw()
gameState.dialogStage.draw()
} }
fun renderInteractables(interactables: List<Interactable>) { fun renderInteractables(interactables: List<Interactable>) {
@ -219,10 +191,10 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() {
private fun handleInput(delta: Float) { private fun handleInput(delta: Float) {
val horizontalMovement = Vector2() val horizontalMovement = Vector2()
if (isKeyPressed(gameState.settings.getKeyCode(ActionCommand.LEFT))) { if (Gdx.input.isKeyPressed(Input.Keys.A) || Gdx.input.isKeyPressed(Input.Keys.LEFT)) {
horizontalMovement.sub(Vector2.X) horizontalMovement.sub(Vector2.X)
} }
if (isKeyPressed(gameState.settings.getKeyCode(ActionCommand.RIGHT))) { if (Gdx.input.isKeyPressed(Input.Keys.D) || Gdx.input.isKeyPressed(Input.Keys.RIGHT)) {
horizontalMovement.add(Vector2.X) horizontalMovement.add(Vector2.X)
} }
this.player.move(horizontalMovement, delta) this.player.move(horizontalMovement, delta)
@ -232,10 +204,10 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() {
this.player.move(horizontalMovement, delta) this.player.move(horizontalMovement, delta)
} }
val verticalMovement = Vector2() val verticalMovement = Vector2()
if (isKeyPressed(gameState.settings.getKeyCode(ActionCommand.UP))) { if (Gdx.input.isKeyPressed(Input.Keys.W) || Gdx.input.isKeyPressed(Input.Keys.UP)) {
verticalMovement.add(Vector2.Y) verticalMovement.add(Vector2.Y)
} }
if (isKeyPressed(gameState.settings.getKeyCode(ActionCommand.DOWN))) { if (Gdx.input.isKeyPressed(Input.Keys.S) || Gdx.input.isKeyPressed(Input.Keys.DOWN)) {
verticalMovement.sub(Vector2.Y) verticalMovement.sub(Vector2.Y)
} }
this.player.move(verticalMovement, delta) this.player.move(verticalMovement, delta)
@ -244,7 +216,6 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() {
verticalMovement.rotateDeg(180f) verticalMovement.rotateDeg(180f)
this.player.move(verticalMovement, delta) this.player.move(verticalMovement, delta)
} }
val hasMoved = !horizontalMovement.isZero || !verticalMovement.isZero val hasMoved = !horizontalMovement.isZero || !verticalMovement.isZero
if (hasMoved) { if (hasMoved) {
updateCamera() updateCamera()
@ -268,8 +239,8 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() {
private fun checkCollision() { private fun checkCollision() {
this.isColliding = map.isCollidingWith(player) this.isColliding = map.isCollidingWith(player)
} }
private fun updateCamera() { private fun updateCamera() {
val mapSize = Vector2(map.width.toFloat(), map.height.toFloat()) val mapSize = Vector2(map.width.toFloat(), map.height.toFloat())
@ -286,6 +257,7 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() {
) )
camera.update() camera.update()
} }
override fun resize(width: Int, height: Int) { override fun resize(width: Int, height: Int) {
// Resize your screen here. The parameters represent the new window size. // Resize your screen here. The parameters represent the new window size.
uiStage.resize(width, height) uiStage.resize(width, height)
@ -331,4 +303,59 @@ class FirstScreen(private val parent: Game) : TimeTravelScreen() {
) )
} }
override fun keyDown(keycode: Int): Boolean {
return false
}
override fun keyUp(keycode: Int): Boolean {
when (keycode) {
Input.Keys.E -> {
openDoor()
}
Input.Keys.T -> {
map.teleport(player)
}
Input.Keys.ESCAPE -> {
parent.changeScreen(Screens.MAIN_MENU)
}
}
return false
}
override fun keyTyped(character: Char): Boolean {
return false
}
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
val mouseCoordinates: Vector2 = toWorldCoordinates(screenX.toFloat(), screenY.toFloat())
val playerDirection: Vector2 = player.getAbsoluteDirection()
map.interactWith(playerDirection.x, playerDirection.y, player.getCollider())
return false
}
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
}
} }

@ -0,0 +1,104 @@
package com.last.commit.screen
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Screen
import com.badlogic.gdx.graphics.GL20
import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.g2d.GlyphLayout
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.last.commit.Game
import com.last.commit.TimeTravelAssetManager
class LoadingScreen(private val assetManager: TimeTravelAssetManager, private val game: Game) : Screen {
companion object {
private const val FONTS = 1
private const val TEXTURES = 2
private const val SKINS = 3
private const val MUSICS = 4
private const val SOUNDS = 5
private const val FINISHED = 6
}
private var currentLoadingStage = 0
private val layout = GlyphLayout()
private var currentText = ""
private val camera = OrthographicCamera()
// timer for exiting loading screen
private var countDown = 1f // 5 seconds of waiting before menu screen
private val batch = SpriteBatch()
init {
camera.setToOrtho(false, 800f, 600f)
}
override fun show() {}
override fun render(delta: Float) {
Gdx.gl.glClearColor(0f, 0f, 0.2f, 1f)
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
if (assetManager.update()) {
currentLoadingStage += 1
when (currentLoadingStage) {
TEXTURES -> {
currentText = "Loading textures"
assetManager.loadTextures()
}
SKINS -> {
currentText = "Loading skins"
assetManager.loadSkins()
}
MUSICS -> {
currentText = "Loading musics"
assetManager.loadMusics("sounds/music/world_music.mp3")
}
SOUNDS -> {
currentText = "Loading sounds"
assetManager.loadSounds(
"sounds/effects/steps/steps_indoor_1.mp3",
"sounds/effects/steps/steps_indoor_2.mp3",
"sounds/effects/steps/steps_indoor_3.mp3",
"sounds/effects/door_open.mp3",
"sounds/effects/door_close.mp3",
"sounds/effects/time_travel.mp3",
"sounds/effects/grab.mp3"
)
}
FINISHED -> currentText = "Finished"
else -> currentText = "Key no found"
}
if (currentLoadingStage > 5) {
countDown -= delta // timer to stay on loading screen for short preiod once done loading
currentLoadingStage =
5 // cap loading stage to 5 as will use later to display progress bar anbd more than 5 would go off the screen
if (countDown < 0) { // countdown is complete
// game.getAudioManager().load()
game.changeScreen(Screens.MAIN_MENU)
}
}
}
layout.setText(game.font, currentText)
camera.update()
batch.projectionMatrix = camera.combined
batch.begin()
game.font.draw(batch, currentText, 800 / 2 - layout.width / 2, layout.height + 10)
batch.end()
}
override fun resize(width: Int, height: Int) {}
override fun pause() {}
override fun resume() {}
override fun hide() {
assetManager.finishLoading()
}
override fun dispose() {}
}

@ -1,7 +1,7 @@
package com.last.commit.screen package com.last.commit.screen
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.InputProcessor import com.badlogic.gdx.Screen
import com.badlogic.gdx.graphics.GL20 import com.badlogic.gdx.graphics.GL20
import com.badlogic.gdx.math.MathUtils import com.badlogic.gdx.math.MathUtils
import com.badlogic.gdx.scenes.scene2d.Actor import com.badlogic.gdx.scenes.scene2d.Actor
@ -13,67 +13,40 @@ import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener
import com.badlogic.gdx.utils.viewport.ScreenViewport import com.badlogic.gdx.utils.viewport.ScreenViewport
import com.last.commit.ColorState import com.last.commit.ColorState
import com.last.commit.Game import com.last.commit.Game
import com.last.commit.config.ActionCommand import com.last.commit.TimeTravelAssetManager
import com.last.commit.audio.SoundEngine
class MainMenu(val parent: Game) : TimeTravelScreen() { class MainMenu(val parent: Game) : Screen {
var stage: Stage var stage = Stage(ScreenViewport())
var table = Table()
val uiSkin: Skin
val state = ColorState() lateinit var uiSkin: Skin
init {
parent.state.assetManager.finishLoading()
stage = Stage(ScreenViewport())
uiSkin = parent.state.assetManager.getUiTexture()
}
override fun handleKeyInput(action: ActionCommand) {
parent.changeScreen(Screens.GAME)
}
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<InputProcessor> { val state = ColorState()
return emptyArray()
}
override fun show() { override fun show() {
Gdx.input.setInputProcessor(stage);
stage.addActor(table); SoundEngine.resume()
uiSkin = TimeTravelAssetManager.getSkin()
stage.clear()
val y = stage.viewport.screenHeight.toFloat() / 6
val x = stage.viewport.screenWidth.toFloat() / 4
println("x: $x, y: $y")
//add buttons to table //add buttons to table
renderTable(x, y); createTable();
} }
fun renderTable(x: Float, y: Float) { fun createTable(): Table {
table.reset() var table = Table()
table.setFillParent(true); table.setFillParent(true);
table.setDebug(true)
stage.addActor(table);
val newGame = TextButton("Play Game", uiSkin) val newGame = TextButton("Play Game", uiSkin)
val preferences = TextButton("Settings", uiSkin) val preferences = TextButton("Settings", uiSkin)
preferences.setSize(stage.viewport.screenWidth.toFloat(), stage.viewport.screenHeight.toFloat())
val exit = TextButton("Exit", uiSkin) val exit = TextButton("Exit", uiSkin)
table.row().size(x, y);
table.add(newGame).fillX().uniformX()
table.row().pad(10F, 0F, 10F, 0F)
table.row().size(x, y);
table.add(preferences).fillX().uniformX()
table.row().size(x, y);
table.add(exit).fillX().uniformX()
exit.addListener(object : ChangeListener() { exit.addListener(object : ChangeListener() {
override fun changed(event: ChangeEvent?, actor: Actor?) { override fun changed(event: ChangeEvent?, actor: Actor?) {
Gdx.app.exit() Gdx.app.exit()
@ -92,6 +65,13 @@ class MainMenu(val parent: Game) : TimeTravelScreen() {
} }
}) })
table.add(newGame).fillX().uniformX()
table.row().pad(10F, 0F, 10F, 0F)
table.add(preferences).fill().uniformX()
table.row()
table.add(exit).fillX().uniformX()
return table
} }
@ -101,9 +81,9 @@ class MainMenu(val parent: Game) : TimeTravelScreen() {
// Draw your screen here. "delta" is the time since last render in seconds. // Draw your screen here. "delta" is the time since last render in seconds.
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT) Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
var red = MathUtils.clamp(state.red,0.1F, 0.5F) var red = MathUtils.clamp(state.red, 0.1F, 0.5F)
var blue = MathUtils.clamp(state.green,0.1F, 0.5F) var blue = MathUtils.clamp(state.green, 0.1F, 0.5F)
var green = MathUtils.clamp(state.blue,0.1F, 0.5F) var green = MathUtils.clamp(state.blue, 0.1F, 0.5F)
Gdx.gl.glClearColor(red, green, blue, 1f) Gdx.gl.glClearColor(red, green, blue, 1f)
@ -117,12 +97,6 @@ class MainMenu(val parent: Game) : TimeTravelScreen() {
println("width $width, height $height") println("width $width, height $height")
stage.viewport.update(width, height, true); 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() { override fun pause() {

@ -3,5 +3,6 @@ package com.last.commit.screen
enum class Screens { enum class Screens {
MAIN_MENU, MAIN_MENU,
SETTINGS, SETTINGS,
GAME GAME,
LOADING
} }

@ -1,20 +1,23 @@
package com.last.commit.screen package com.last.commit.screen
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.InputProcessor import com.badlogic.gdx.Screen
import com.badlogic.gdx.graphics.GL20 import com.badlogic.gdx.graphics.GL20
import com.badlogic.gdx.math.MathUtils 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.Stage
import com.badlogic.gdx.scenes.scene2d.ui.* import com.badlogic.gdx.scenes.scene2d.ui.*
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener
import com.badlogic.gdx.utils.viewport.ScreenViewport import com.badlogic.gdx.utils.viewport.ScreenViewport
import com.last.commit.ColorState import com.last.commit.ColorState
import com.last.commit.Game import com.last.commit.Game
import com.last.commit.config.ActionCommand import com.last.commit.TimeTravelAssetManager
import com.last.commit.audio.SoundEngine
class Settings(val parent: Game) : TimeTravelScreen() { class Settings(val parent: Game) : Screen {
var stage: Stage val stage = Stage(ScreenViewport())
val skin: Skin lateinit var skin: Skin
lateinit var titleLabel: Label lateinit var titleLabel: Label
@ -23,83 +26,68 @@ class Settings(val parent: Game) : TimeTravelScreen() {
lateinit var musicOnOffLabel: Label lateinit var musicOnOffLabel: Label
lateinit var soundOnOffLabel: Label lateinit var soundOnOffLabel: Label
var sfxMusicSlider: Slider lateinit var sfxMusicSlider: Slider
var volumeMusicSlider: Slider lateinit var volumeMusicSlider: Slider
var musicCheckbox: CheckBox lateinit var musicCheckbox: CheckBox
var soundEffectsCheckbox: CheckBox lateinit var soundEffectsCheckbox: CheckBox
var backButton: Button lateinit var backButton: Button
val state = ColorState() val state = ColorState()
val table = Table() val table = Table()
init { override fun show() {
parent.state.assetManager.finishLoading() stage.clear()
stage = Stage(ScreenViewport()) Gdx.input.setInputProcessor(stage)
skin = parent.state.assetManager.getUiTexture() skin = TimeTravelAssetManager.getSkin()
// music volume // music volume
volumeMusicSlider = Slider(0f, 1f, 0.1f, false, skin) volumeMusicSlider = Slider(0f, 1f, 0.1f, false, skin)
volumeMusicSlider.value = parent.state.settings.musicVolume volumeMusicSlider.value = SoundEngine.musicVolume
volumeMusicSlider.addListener { volumeMusicSlider.addListener {
parent.state.settings.musicVolume = volumeMusicSlider.value SoundEngine.musicVolume = volumeMusicSlider.value
// updateVolumeLabel(); // updateVolumeLabel();
false false
} }
// sound volume // sound volume
sfxMusicSlider = Slider(0f, 1f, 0.1f, false, skin) sfxMusicSlider = Slider(0f, 1f, 0.1f, false, skin)
sfxMusicSlider.value = parent.state.settings.sfxVolume sfxMusicSlider.value = SoundEngine.sfxVolume
sfxMusicSlider.addListener { sfxMusicSlider.addListener {
parent.state.settings.sfxVolume = sfxMusicSlider.value SoundEngine.sfxVolume = sfxMusicSlider.value
// updateVolumeLabel(); // updateVolumeLabel();
false false
} }
// music on/off // music on/off
musicCheckbox = CheckBox(null, skin) musicCheckbox = CheckBox(null, skin)
musicCheckbox.isChecked = !parent.state.settings.musicEnabled musicCheckbox.isChecked = SoundEngine.musicVolume > 0
musicCheckbox.addListener { musicCheckbox.addListener {
val enabled: Boolean = musicCheckbox.isChecked() val enabled: Boolean = musicCheckbox.isChecked()
parent.state.settings.musicEnabled = !enabled //TODO: reimplement this
SoundEngine.musicVolume = if (enabled) 0.5f else 0f
false false
} }
// sound on/off // sound on/off
soundEffectsCheckbox = CheckBox(null, skin) soundEffectsCheckbox = CheckBox(null, skin)
soundEffectsCheckbox.isChecked = !parent.state.settings.sfxEnabled soundEffectsCheckbox.isChecked = SoundEngine.sfxVolume > 0
soundEffectsCheckbox.addListener { soundEffectsCheckbox.addListener {
val enabled: Boolean = soundEffectsCheckbox.isChecked() val enabled: Boolean = soundEffectsCheckbox.isChecked()
parent.state.settings.sfxEnabled = !enabled //TODO: reimplement this
SoundEngine.sfxVolume = if (enabled) 0.5f else 0f
false false
} }
// return to main screen button // return to main screen button
backButton = TextButton("Back", skin) backButton = TextButton("Back", skin)
backButton.addListener { backButton.addListener(object : ChangeListener() {
parent.changeScreen(Screens.MAIN_MENU) override fun changed(event: ChangeEvent?, actor: Actor?) {
false parent.changeScreen(Screens.MAIN_MENU)
} }
})
}
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<InputProcessor> {
return emptyArray()
}
override fun show() {
stage.clear()
} }
@ -144,15 +132,15 @@ class Settings(val parent: Game) : TimeTravelScreen() {
state.step((delta * 1000).toLong()) state.step((delta * 1000).toLong())
// Draw your screen here. "delta" is the time since last render in seconds. // Draw your screen here. "delta" is the time since last render in seconds.
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT) Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT)
var red = MathUtils.clamp(state.red,0.1F, 0.5F) var red = MathUtils.clamp(state.red, 0.1F, 0.5F)
var blue = MathUtils.clamp(state.green,0.1F, 0.5F) var blue = MathUtils.clamp(state.green, 0.1F, 0.5F)
var green = MathUtils.clamp(state.blue,0.1F, 0.5F) var green = MathUtils.clamp(state.blue, 0.1F, 0.5F)
Gdx.gl.glClearColor(red, green, blue, 1f) Gdx.gl.glClearColor(red, green, blue, 1f)
// tell our stage to do actions and draw itself // tell our stage to do actions and draw itself
stage.act(Math.min(Gdx.graphics.deltaTime, 1 / 30f)) stage.act(Math.min(delta, 1 / 30f))
stage.draw() stage.draw()
} }

@ -1,13 +0,0 @@
package com.last.commit.screen
import com.badlogic.gdx.InputProcessor
import com.badlogic.gdx.Screen
import com.last.commit.config.ActionCommand
abstract class TimeTravelScreen : Screen {
abstract fun handleKeyInput(action: ActionCommand)
abstract fun handleMouseInput(screenX: Int, screenY: Int, pointer: Int, button: Int)
abstract fun getInputProcessors(): Array<InputProcessor>
}

@ -1,14 +1,13 @@
package com.last.commit.stages package com.last.commit.stages
import com.badlogic.gdx.utils.viewport.ExtendViewport import com.badlogic.gdx.Input
import com.badlogic.gdx.utils.Align
import com.badlogic.gdx.scenes.scene2d.Stage 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.scenes.scene2d.ui.Skin
import com.badlogic.gdx.graphics.g2d.Batch import com.badlogic.gdx.scenes.scene2d.ui.TextArea
import com.badlogic.gdx.Input import com.badlogic.gdx.utils.Align
import com.badlogic.gdx.utils.viewport.ExtendViewport
class PromptStage(skin: Skin?): Stage(ExtendViewport(300f, 300f)) { class PromptStage(skin: Skin?) : Stage(ExtendViewport(300f, 300f)) {
private val textArea: TextArea; private val textArea: TextArea;
var visible = false var visible = false
@ -38,15 +37,15 @@ class PromptStage(skin: Skin?): Stage(ExtendViewport(300f, 300f)) {
super.draw() super.draw()
} }
} }
fun clearText() { fun clearText() {
this.text.clear() this.text.clear()
} }
fun addText(text: String) { fun addText(text: String) {
this.text.add(text) this.text.add(text)
} }
fun resize(width: Int, height: Int) { fun resize(width: Int, height: Int) {
this.viewport.update(width, height) this.viewport.update(width, height)
this.camera.update() this.camera.update()
@ -57,7 +56,7 @@ class PromptStage(skin: Skin?): Stage(ExtendViewport(300f, 300f)) {
false false
} else if (keyCode == Input.Keys.SPACE) { } else if (keyCode == Input.Keys.SPACE) {
next() next()
false true
} else { } else {
false false
} }

@ -66,4 +66,6 @@ class UIStage(path: String, val state: GameState) : Stage(ExtendViewport(512f, 5
addActor(mapLabel) addActor(mapLabel)
} }
} }
} }

Loading…
Cancel
Save