Add introduction to story and keybindings

main
trivernis 1 year ago
parent ca7ac1f5fd
commit 5c834e82cb
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -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()
}
}

@ -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 <W>, <A>, <S> and <D> to walk around the map.
Some doors require keys to be opened.
""".trimIndent())
promptStage.addText("""
At some locations you can press <T> 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<InputProcessor> {
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.
}

@ -15,6 +15,7 @@ class DialogStage(skin: Skin?) : Stage(ExtendViewport(512f, 512f)) {
private var isVisible = false
private val texts = com.badlogic.gdx.utils.Array<String>()
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 {

@ -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<String> = 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)
}
}
Loading…
Cancel
Save