diff options
author | romangraef <roman.graef@gmail.com> | 2018-05-30 12:45:21 +0200 |
---|---|---|
committer | romangraef <roman.graef@gmail.com> | 2018-05-30 12:45:21 +0200 |
commit | 5a66413d8f226c0507788e5c8455f6f5f6d06887 (patch) | |
tree | 1187c7f83621f29364dc90f3aed1885d04dac42c /src/main/kotlin/de/romjaki/pluggabledino/states | |
parent | 2ac18d91635b023db7ff3918f5041cb51ed1c968 (diff) | |
download | pluggabledino-5a66413d8f226c0507788e5c8455f6f5f6d06887.tar.gz pluggabledino-5a66413d8f226c0507788e5c8455f6f5f6d06887.tar.bz2 pluggabledino-5a66413d8f226c0507788e5c8455f6f5f6d06887.zip |
Added lost state/losing
Diffstat (limited to 'src/main/kotlin/de/romjaki/pluggabledino/states')
-rw-r--r-- | src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt | 10 | ||||
-rw-r--r-- | src/main/kotlin/de/romjaki/pluggabledino/states/LostState.kt | 39 |
2 files changed, 47 insertions, 2 deletions
diff --git a/src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt b/src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt index 479f7f7..0d4fff0 100644 --- a/src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt +++ b/src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt @@ -21,6 +21,9 @@ class GameState : BasicGameState() { if (container!!.input.isKeyDown(Input.KEY_R)) { world = GameWorld() } + if (world.hurt) { + game!!.enterState(LOST) + } world.update(delta / 1000f, container.input) dinoAnimated.update(delta.toLong()) } @@ -34,11 +37,14 @@ class GameState : BasicGameState() { override fun render(container: GameContainer?, game: StateBasedGame?, g: Graphics?) { g!! g.background = Color.lightGray - g.color = Color.red + if (world.hurt) { + g.background = Color.red + } + g.color = Color.green g.drawImage(dinoAnimated.currentFrame, world.dino.position.x * WIDTH / 50, world.dino.position.y * HEIGHT / 50 - dinoAnimated.height) g.drawImage(groundline, 0f, HEIGHT * 39 / 50f) for (cactus in world.cacti) { - g.drawImage(cactusImg, cactus.position.x, cactus.position.y) + g.drawImage(cactusImg, cactus.position.x * WIDTH / 50, cactus.position.y * HEIGHT / 50 - cactusImg.height) } } diff --git a/src/main/kotlin/de/romjaki/pluggabledino/states/LostState.kt b/src/main/kotlin/de/romjaki/pluggabledino/states/LostState.kt new file mode 100644 index 0000000..ce245b6 --- /dev/null +++ b/src/main/kotlin/de/romjaki/pluggabledino/states/LostState.kt @@ -0,0 +1,39 @@ +package de.romjaki.pluggabledino.states + +import de.romjaki.pluggabledino.* +import de.romjaki.pluggabledino.api.Button +import org.newdawn.slick.Color +import org.newdawn.slick.GameContainer +import org.newdawn.slick.Graphics +import org.newdawn.slick.state.BasicGameState +import org.newdawn.slick.state.StateBasedGame + +class LostState : BasicGameState() { + override fun init(container: GameContainer?, game: StateBasedGame?) { + game!! + playAgain.addClickHandler { + game.enterState(GAME) + } + back.addClickHandler { + game.enterState(MAINMENU) + } + } + + override fun update(container: GameContainer?, game: StateBasedGame?, delta: Int) { + playAgain.update(container!!.input) + back.update(container.input) + } + + override fun getID(): Int = + LOST + + val back = Button("Back to Main Menu", WIDTH / 2f, HEIGHT / 2f + 50) + val playAgain = Button("PLAY AGAIN", WIDTH / 2f, HEIGHT / 2f + 100) + + override fun render(container: GameContainer?, game: StateBasedGame?, g: Graphics?) { + g!! + g.background = Color.red + back.draw(g) + playAgain.draw(g) + } +}
\ No newline at end of file |