From 79f63500e90199c44c4f0bc635b4476ccf069b41 Mon Sep 17 00:00:00 2001 From: Tyrannova Date: Sun, 13 Jan 2019 11:11:25 +0100 Subject: Fixed: remove offscreen cacti from list --- src/main/kotlin/de/romjaki/pluggabledino/game/GameWorld.kt | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/main/kotlin') diff --git a/src/main/kotlin/de/romjaki/pluggabledino/game/GameWorld.kt b/src/main/kotlin/de/romjaki/pluggabledino/game/GameWorld.kt index 3775faa..3375c92 100644 --- a/src/main/kotlin/de/romjaki/pluggabledino/game/GameWorld.kt +++ b/src/main/kotlin/de/romjaki/pluggabledino/game/GameWorld.kt @@ -170,9 +170,16 @@ class GameWorld : ContactListener { cacti.forEach { it.linearVelocity.set(-delta * speed, 0f) } + cacti.removeIf { + it.position.x < 0 + } + birdd.forEach { it.linearVelocity.set(-delta * speed, 0f) } + cacti.removeIf { + it.position.x < 0 + } world.step(delta, 4, 3) world.setContactListener(this) -- cgit From e5f3c9ea1a2d79308643d5c2cd70f8ea7bcad394 Mon Sep 17 00:00:00 2001 From: Tyrannova Date: Tue, 15 Jan 2019 16:40:18 +0100 Subject: Settings --- src/main/kotlin/de/romjaki/pluggabledino/api/Button.kt | 9 ++++++--- .../kotlin/de/romjaki/pluggabledino/api/Renderable.kt | 7 +++++++ .../de/romjaki/pluggabledino/api/SettingsElement.kt | 6 ++++++ .../kotlin/de/romjaki/pluggabledino/api/ToggleButton.kt | 9 ++++++--- .../kotlin/de/romjaki/pluggabledino/api/Updateable.kt | 8 ++++++++ .../de/romjaki/pluggabledino/states/SettingsState.kt | 15 +++++++++++++++ 6 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 src/main/kotlin/de/romjaki/pluggabledino/api/Renderable.kt create mode 100644 src/main/kotlin/de/romjaki/pluggabledino/api/SettingsElement.kt create mode 100644 src/main/kotlin/de/romjaki/pluggabledino/api/Updateable.kt (limited to 'src/main/kotlin') diff --git a/src/main/kotlin/de/romjaki/pluggabledino/api/Button.kt b/src/main/kotlin/de/romjaki/pluggabledino/api/Button.kt index edced5a..439acb8 100644 --- a/src/main/kotlin/de/romjaki/pluggabledino/api/Button.kt +++ b/src/main/kotlin/de/romjaki/pluggabledino/api/Button.kt @@ -6,7 +6,10 @@ import org.newdawn.slick.Input import java.awt.Rectangle import kotlin.math.max -class Button(private val text: String, val x: Float, val y: Float) { +class Button(private val text: String, val x: Float, val y: Float) : SettingsElement { + override fun render(g: Graphics) { + draw(g) + } val width = max(buttonImage.width, font.getWidth(text) + 10) val image = buttonImage.getScaledCopy(width, buttonImage.height) @@ -40,14 +43,14 @@ class Button(private val text: String, val x: Float, val y: Float) { override fun toString(): String = "X: $leftX - $rightX, $topY - $bottomY, width=$width" - fun enter() { + override fun enter() { lastClicked = true } fun isClicked(input: Input): Boolean = input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) && isMouseOver(input) - fun update(input: Input) { + override fun update(input: Input) { val ret = isClicked(input) if (!lastClicked && ret) { clickHandlers.forEach({ it() }) diff --git a/src/main/kotlin/de/romjaki/pluggabledino/api/Renderable.kt b/src/main/kotlin/de/romjaki/pluggabledino/api/Renderable.kt new file mode 100644 index 0000000..f7ac4be --- /dev/null +++ b/src/main/kotlin/de/romjaki/pluggabledino/api/Renderable.kt @@ -0,0 +1,7 @@ +package de.romjaki.pluggabledino.api + +import org.newdawn.slick.Graphics + +interface Renderable { + fun render(g: Graphics) +} diff --git a/src/main/kotlin/de/romjaki/pluggabledino/api/SettingsElement.kt b/src/main/kotlin/de/romjaki/pluggabledino/api/SettingsElement.kt new file mode 100644 index 0000000..8ca7a37 --- /dev/null +++ b/src/main/kotlin/de/romjaki/pluggabledino/api/SettingsElement.kt @@ -0,0 +1,6 @@ +package de.romjaki.pluggabledino.api + +import de.romjaki.pluggabledino.api.Renderable +import de.romjaki.pluggabledino.api.Updateable + +interface SettingsElement : Renderable, Updateable diff --git a/src/main/kotlin/de/romjaki/pluggabledino/api/ToggleButton.kt b/src/main/kotlin/de/romjaki/pluggabledino/api/ToggleButton.kt index cce59fc..b776637 100644 --- a/src/main/kotlin/de/romjaki/pluggabledino/api/ToggleButton.kt +++ b/src/main/kotlin/de/romjaki/pluggabledino/api/ToggleButton.kt @@ -8,7 +8,10 @@ import kotlin.math.max typealias ChangeListener = (index: Int) -> Unit -class ToggleButton(private val texts: List, val x: Float, val y: Float) { +class ToggleButton(private val texts: List, val x: Float, val y: Float) : SettingsElement { + override fun render(g: Graphics) { + draw(g) + } val width = max(buttonImage.width, texts.map { font.getWidth(it) + 10 }.max()!!) val image = buttonImage.getScaledCopy(width, buttonImage.height) @@ -43,14 +46,14 @@ class ToggleButton(private val texts: List, val x: Float, val y: Float) override fun toString(): String = "X: $leftX - $rightX, $topY - $bottomY, width=$width" - fun enter() { + override fun enter() { lastClicked = true } fun isClicked(input: Input): Boolean = input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) && isMouseOver(input) - fun update(input: Input) { + override fun update(input: Input) { val ret = isClicked(input) if (!lastClicked && ret) { index = (index + 1) % texts.size diff --git a/src/main/kotlin/de/romjaki/pluggabledino/api/Updateable.kt b/src/main/kotlin/de/romjaki/pluggabledino/api/Updateable.kt new file mode 100644 index 0000000..42798bc --- /dev/null +++ b/src/main/kotlin/de/romjaki/pluggabledino/api/Updateable.kt @@ -0,0 +1,8 @@ +package de.romjaki.pluggabledino.api + +import org.newdawn.slick.Input + +interface Updateable { + fun update(input: Input) + fun enter() +} diff --git a/src/main/kotlin/de/romjaki/pluggabledino/states/SettingsState.kt b/src/main/kotlin/de/romjaki/pluggabledino/states/SettingsState.kt index d79837d..d55d76f 100644 --- a/src/main/kotlin/de/romjaki/pluggabledino/states/SettingsState.kt +++ b/src/main/kotlin/de/romjaki/pluggabledino/states/SettingsState.kt @@ -2,6 +2,7 @@ package de.romjaki.pluggabledino.states import de.romjaki.pluggabledino.* import de.romjaki.pluggabledino.api.Button +import de.romjaki.pluggabledino.api.SettingsElement import de.romjaki.pluggabledino.api.ToggleButton import org.newdawn.slick.Color import org.newdawn.slick.GameContainer @@ -20,27 +21,41 @@ class SettingsState : BasicGameState() { override fun enter(container: GameContainer?, game: StateBasedGame?) { backButton.enter() scoreButton.enter() + additionals.forEach { + it.enter() + } } override fun update(container: GameContainer?, game: StateBasedGame?, delta: Int) { container!! scoreButton.update(container.input) backButton.update(container.input) + additionals.forEach { + it.update(container.input) + } } override fun getID(): Int = SETTINGS + fun addSettingsElement(el: SettingsElement) { + additionals.add(el) + } + val scoreButton = ToggleButton(listOf("ON", "OFF"), WIDTH * 3 / 4f, HEIGHT / 8f) val backButton = Button("BACK", WIDTH / 2f, HEIGHT / 8 * 7f) + val additionals = mutableListOf() + override fun render(container: GameContainer?, game: StateBasedGame?, g: Graphics?) { g!! g.scale(WIDTH_RATIO, HEIGHT_RATIO) g.background = Color.lightGray backButton.draw(g) scoreButton.draw(g) + additionals.forEach { it.render(g) } + } } -- cgit From f58a6414f0df1115f86331762c7b7773a61a7e06 Mon Sep 17 00:00:00 2001 From: Tyrannova Date: Tue, 15 Jan 2019 16:44:44 +0100 Subject: Settings --- src/main/kotlin/de/romjaki/pluggabledino/events/InitEvent.kt | 3 ++- src/main/kotlin/de/romjaki/pluggabledino/events/PostInitEvent.kt | 3 ++- src/main/kotlin/de/romjaki/pluggabledino/events/PreInitEvent.kt | 3 ++- src/main/kotlin/de/romjaki/pluggabledino/main.kt | 6 +++--- 4 files changed, 9 insertions(+), 6 deletions(-) (limited to 'src/main/kotlin') diff --git a/src/main/kotlin/de/romjaki/pluggabledino/events/InitEvent.kt b/src/main/kotlin/de/romjaki/pluggabledino/events/InitEvent.kt index e82529c..1c18682 100644 --- a/src/main/kotlin/de/romjaki/pluggabledino/events/InitEvent.kt +++ b/src/main/kotlin/de/romjaki/pluggabledino/events/InitEvent.kt @@ -1,5 +1,6 @@ package de.romjaki.pluggabledino.events import de.romjaki.pluggabledino.api.Event +import org.newdawn.slick.AppGameContainer -class InitEvent : Event +class InitEvent(val app: AppGameContainer) : Event diff --git a/src/main/kotlin/de/romjaki/pluggabledino/events/PostInitEvent.kt b/src/main/kotlin/de/romjaki/pluggabledino/events/PostInitEvent.kt index 757888e..675b4fd 100644 --- a/src/main/kotlin/de/romjaki/pluggabledino/events/PostInitEvent.kt +++ b/src/main/kotlin/de/romjaki/pluggabledino/events/PostInitEvent.kt @@ -1,5 +1,6 @@ package de.romjaki.pluggabledino.events import de.romjaki.pluggabledino.api.Event +import org.newdawn.slick.AppGameContainer -class PostInitEvent : Event +class PostInitEvent(val app: AppGameContainer) : Event diff --git a/src/main/kotlin/de/romjaki/pluggabledino/events/PreInitEvent.kt b/src/main/kotlin/de/romjaki/pluggabledino/events/PreInitEvent.kt index 75d7acc..f70e041 100644 --- a/src/main/kotlin/de/romjaki/pluggabledino/events/PreInitEvent.kt +++ b/src/main/kotlin/de/romjaki/pluggabledino/events/PreInitEvent.kt @@ -1,6 +1,7 @@ package de.romjaki.pluggabledino.events import de.romjaki.pluggabledino.api.Event +import org.newdawn.slick.AppGameContainer -class PreInitEvent : Event \ No newline at end of file +class PreInitEvent(val app: AppGameContainer) : Event \ No newline at end of file diff --git a/src/main/kotlin/de/romjaki/pluggabledino/main.kt b/src/main/kotlin/de/romjaki/pluggabledino/main.kt index 970f38e..678e7c6 100644 --- a/src/main/kotlin/de/romjaki/pluggabledino/main.kt +++ b/src/main/kotlin/de/romjaki/pluggabledino/main.kt @@ -40,9 +40,9 @@ fun main(args: Array) { app.setDisplayMode(REAL_WIDTH, REAL_HEIGHT, false) app.setTargetFrameRate(FPS) app.setShowFPS(true) - Events.broadcastEvent(PreInitEvent()) - Events.broadcastEvent(InitEvent()) - Events.broadcastEvent(PostInitEvent()) + Events.broadcastEvent(PreInitEvent(app)) + Events.broadcastEvent(InitEvent(app)) + Events.broadcastEvent(PostInitEvent(app)) app.start() } -- cgit