diff options
author | romangraef <roman.graef@gmail.com> | 2018-05-30 12:06:31 +0200 |
---|---|---|
committer | romangraef <roman.graef@gmail.com> | 2018-05-30 12:06:31 +0200 |
commit | 2ac18d91635b023db7ff3918f5041cb51ed1c968 (patch) | |
tree | 8caffe3c5807e105eb474e2277ece57dc82823c3 /src/main/kotlin/de/romjaki/pluggabledino/states | |
download | pluggabledino-2ac18d91635b023db7ff3918f5041cb51ed1c968.tar.gz pluggabledino-2ac18d91635b023db7ff3918f5041cb51ed1c968.tar.bz2 pluggabledino-2ac18d91635b023db7ff3918f5041cb51ed1c968.zip |
Initial commit
Diffstat (limited to 'src/main/kotlin/de/romjaki/pluggabledino/states')
4 files changed, 180 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) + } + } + +} diff --git a/src/main/kotlin/de/romjaki/pluggabledino/states/MainMenu.kt b/src/main/kotlin/de/romjaki/pluggabledino/states/MainMenu.kt new file mode 100644 index 0000000..f10a470 --- /dev/null +++ b/src/main/kotlin/de/romjaki/pluggabledino/states/MainMenu.kt @@ -0,0 +1,52 @@ +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.Input +import org.newdawn.slick.state.BasicGameState +import org.newdawn.slick.state.StateBasedGame + +class MainMenu : BasicGameState() { + override fun init(container: GameContainer?, game: StateBasedGame?) { + game!! + settingsButton.addClickHandler { + game.enterState(SETTINGS) + } + playButton.addClickHandler { + game.enterState(GAME) + } + } + + override fun enter(container: GameContainer?, game: StateBasedGame?) { + settingsButton.enter() + playButton.enter() + } + + override fun update(container: GameContainer?, game: StateBasedGame?, delta: Int) { + container!! + game!! + dinoAnimated.update(delta.toLong()) + if (container.input.isKeyDown(Input.KEY_Q)) { + System.exit(0) + } + settingsButton.update(container.input) + playButton.update(container.input) + } + + override fun getID(): Int = + MAINMENU + + val playButton = Button("PLAY", WIDTH / 2f, HEIGHT / 2f + 50) + val settingsButton = Button("SETTINGS", WIDTH / 2f, HEIGHT / 2f + 100) + override fun render(container: GameContainer?, game: StateBasedGame?, g: Graphics?) { + g!! + g.background = Color.lightGray + g.drawImage(dinoAnimated.currentFrame, WIDTH / 2f - 16, HEIGHT / 2f - 16f) + playButton.draw(g) + settingsButton.draw(g) + } + +} diff --git a/src/main/kotlin/de/romjaki/pluggabledino/states/SettingsState.kt b/src/main/kotlin/de/romjaki/pluggabledino/states/SettingsState.kt new file mode 100644 index 0000000..5003232 --- /dev/null +++ b/src/main/kotlin/de/romjaki/pluggabledino/states/SettingsState.kt @@ -0,0 +1,42 @@ +package de.romjaki.pluggabledino.states + +import de.romjaki.pluggabledino.HEIGHT +import de.romjaki.pluggabledino.MAINMENU +import de.romjaki.pluggabledino.SETTINGS +import de.romjaki.pluggabledino.WIDTH +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 SettingsState : BasicGameState() { + override fun init(container: GameContainer?, game: StateBasedGame?) { + game!! + backButton.addClickHandler { + game.enterState(MAINMENU) + } + } + + override fun enter(container: GameContainer?, game: StateBasedGame?) { + backButton.enter() + } + + override fun update(container: GameContainer?, game: StateBasedGame?, delta: Int) { + container!! + backButton.update(container.input) + } + + override fun getID(): Int = + SETTINGS + + val backButton = Button("BACK", WIDTH / 2f, HEIGHT / 8 * 7f) + + override fun render(container: GameContainer?, game: StateBasedGame?, g: Graphics?) { + g!! + g.background = Color.lightGray + backButton.draw(g) + } + +} diff --git a/src/main/kotlin/de/romjaki/pluggabledino/states/SplashScreen.kt b/src/main/kotlin/de/romjaki/pluggabledino/states/SplashScreen.kt new file mode 100644 index 0000000..d39b31a --- /dev/null +++ b/src/main/kotlin/de/romjaki/pluggabledino/states/SplashScreen.kt @@ -0,0 +1,41 @@ +package de.romjaki.pluggabledino.states + +import de.romjaki.pluggabledino.* +import org.newdawn.slick.GameContainer +import org.newdawn.slick.Graphics +import org.newdawn.slick.Image +import org.newdawn.slick.Input +import org.newdawn.slick.state.BasicGameState +import org.newdawn.slick.state.StateBasedGame + + +class SplashScreen : BasicGameState() { + override fun init(container: GameContainer?, game: StateBasedGame?) { + } + + override fun update(container: GameContainer?, game: StateBasedGame?, delta: Int) { + container!! + game!! + val input = container.input + if (input.isMousePressed(Input.MOUSE_LEFT_BUTTON)) { + input.clearMousePressedRecord() + game.enterState(MAINMENU) + } + if (input.isKeyDown(Input.KEY_Q)) { + System.exit(0) + } + } + + override fun getID(): Int = + SPLASHSCREEN + + + override fun render(container: GameContainer?, game: StateBasedGame?, g: Graphics?) { + g!! + g.drawImage(splash, 0f, 0f) + g.drawStringCentered("CLICK ANYWHERE TO CONTINUE", WIDTH / 2f, HEIGHT / 2f) + } + +} + + |