summaryrefslogtreecommitdiff
path: root/src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt
diff options
context:
space:
mode:
authorromangraef <roman.graef@gmail.com>2018-05-30 12:06:31 +0200
committerromangraef <roman.graef@gmail.com>2018-05-30 12:06:31 +0200
commit2ac18d91635b023db7ff3918f5041cb51ed1c968 (patch)
tree8caffe3c5807e105eb474e2277ece57dc82823c3 /src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt
downloadpluggabledino-2ac18d91635b023db7ff3918f5041cb51ed1c968.tar.gz
pluggabledino-2ac18d91635b023db7ff3918f5041cb51ed1c968.tar.bz2
pluggabledino-2ac18d91635b023db7ff3918f5041cb51ed1c968.zip
Initial commit
Diffstat (limited to 'src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt')
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt b/src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt
new file mode 100644
index 0000000..479f7f7
--- /dev/null
+++ b/src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt
@@ -0,0 +1,45 @@
+package de.romjaki.pluggabledino.states
+
+import de.romjaki.pluggabledino.*
+import de.romjaki.pluggabledino.game.GameWorld
+import org.newdawn.slick.Color
+import org.newdawn.slick.GameContainer
+import org.newdawn.slick.Graphics
+import org.newdawn.slick.Input
+import org.newdawn.slick.state.BasicGameState
+import org.newdawn.slick.state.StateBasedGame
+
+class GameState : BasicGameState() {
+ override fun init(container: GameContainer?, game: StateBasedGame?) {
+ }
+
+ override fun enter(container: GameContainer?, game: StateBasedGame?) {
+ world = GameWorld()
+ }
+
+ override fun update(container: GameContainer?, game: StateBasedGame?, delta: Int) {
+ if (container!!.input.isKeyDown(Input.KEY_R)) {
+ world = GameWorld()
+ }
+ world.update(delta / 1000f, container.input)
+ dinoAnimated.update(delta.toLong())
+ }
+
+ lateinit var world: GameWorld
+
+ override fun getID(): Int =
+ GAME
+
+
+ override fun render(container: GameContainer?, game: StateBasedGame?, g: Graphics?) {
+ g!!
+ g.background = Color.lightGray
+ g.color = Color.red
+ 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)
+ }
+ }
+
+}