summaryrefslogtreecommitdiff
path: root/src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt
blob: 805632cd1c8ecc789269eacf8656a2fd95ea5aa9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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()
        }
        if (world.hurt) {
            game!!.enterState(LOST)
        }
        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.scale(WIDTH_RATIO, HEIGHT_RATIO)
        g.background = Color.white
        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 * WIDTH / 50, cactus.position.y * HEIGHT / 50 - cactusImg.height)
        }
    }

}