summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorromangraef <romangraef@loves.dicksinhisan.us>2019-01-16 19:24:56 +0100
committerromangraef <romangraef@loves.dicksinhisan.us>2019-01-16 19:24:56 +0100
commit0a98f4c4c2689c488839ce16fb2adf618fd4af2a (patch)
tree31102fdac1d9d7a8d604cc9d41df5c3733fd8da4
parentf872cabbe7e4a3eda2aaff9bff8616e62c2d4ff4 (diff)
parentf58a6414f0df1115f86331762c7b7773a61a7e06 (diff)
downloadpluggabledino-0a98f4c4c2689c488839ce16fb2adf618fd4af2a.tar.gz
pluggabledino-0a98f4c4c2689c488839ce16fb2adf618fd4af2a.tar.bz2
pluggabledino-0a98f4c4c2689c488839ce16fb2adf618fd4af2a.zip
Merge branch 'master' of github.com:romangraef/pluggabledino
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/api/Button.kt9
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/api/Renderable.kt7
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/api/SettingsElement.kt6
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/api/ToggleButton.kt9
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/api/Updateable.kt8
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/events/InitEvent.kt3
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/events/PostInitEvent.kt3
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/events/PreInitEvent.kt3
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/game/GameWorld.kt7
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/main.kt6
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/states/SettingsState.kt15
11 files changed, 64 insertions, 12 deletions
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<String>, val x: Float, val y: Float) {
+class ToggleButton(private val texts: List<String>, 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<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) {
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/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/game/GameWorld.kt b/src/main/kotlin/de/romjaki/pluggabledino/game/GameWorld.kt
index 687fe62..682a82c 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)
diff --git a/src/main/kotlin/de/romjaki/pluggabledino/main.kt b/src/main/kotlin/de/romjaki/pluggabledino/main.kt
index e71a397..5ca540f 100644
--- a/src/main/kotlin/de/romjaki/pluggabledino/main.kt
+++ b/src/main/kotlin/de/romjaki/pluggabledino/main.kt
@@ -42,9 +42,9 @@ fun main(args: Array<String>) {
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()
}
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<SettingsElement>()
+
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) }
+
}
}