summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/api/Emulator.kt15
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/game/GameWorld.kt4
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/main.kt2
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt5
4 files changed, 22 insertions, 4 deletions
diff --git a/src/main/kotlin/de/romjaki/pluggabledino/api/Emulator.kt b/src/main/kotlin/de/romjaki/pluggabledino/api/Emulator.kt
new file mode 100644
index 0000000..a6e9aeb
--- /dev/null
+++ b/src/main/kotlin/de/romjaki/pluggabledino/api/Emulator.kt
@@ -0,0 +1,15 @@
+package de.romjaki.pluggabledino.api
+
+import de.romjaki.pluggabledino.game.GameWorld
+
+object Emulator {
+ fun emulate(delta: Float, shouldJump: (GameWorld) -> Boolean): Float {
+ val world = GameWorld()
+ var score = 0f
+ while (!world.hurt) {
+ world.update(delta / 1000f, shouldJump(world))
+ score += delta
+ }
+ return score / 100f
+ }
+} \ 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 3775faa..687fe62 100644
--- a/src/main/kotlin/de/romjaki/pluggabledino/game/GameWorld.kt
+++ b/src/main/kotlin/de/romjaki/pluggabledino/game/GameWorld.kt
@@ -147,8 +147,8 @@ class GameWorld : ContactListener {
}
- fun update(delta: Float, input: Input) {
- if (input.isKeyDown(Input.KEY_UP)) {
+ fun update(delta: Float, tryJump: Boolean) {
+ if (tryJump) {
tryJump()
}
delay -= delta
diff --git a/src/main/kotlin/de/romjaki/pluggabledino/main.kt b/src/main/kotlin/de/romjaki/pluggabledino/main.kt
index 970f38e..e71a397 100644
--- a/src/main/kotlin/de/romjaki/pluggabledino/main.kt
+++ b/src/main/kotlin/de/romjaki/pluggabledino/main.kt
@@ -1,5 +1,6 @@
package de.romjaki.pluggabledino
+import de.romjaki.pluggabledino.api.Emulator
import de.romjaki.pluggabledino.api.Events
import de.romjaki.pluggabledino.api.PluginLoader
import de.romjaki.pluggabledino.events.InitEvent
@@ -31,6 +32,7 @@ var highscore = 0
var score = 0
fun main(args: Array<String>) {
+ println(Emulator.emulate(16f) { true })
if (args.size > 1 && args[0] == "dev") {
PluginLoader.loadDevPlugin(args[1])
}
diff --git a/src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt b/src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt
index 205446b..db173f2 100644
--- a/src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt
+++ b/src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt
@@ -39,7 +39,8 @@ class GameState : BasicGameState() {
Events.broadcastEvent(GameLostEvent(lastscore))
return game.enterState(LOST)
}
- world.update(delta / 1000f, container.input)
+ println(delta)
+ world.update(delta / 1000f, container.input.isKeyDown(Input.KEY_UP))
dinoAnimated.update(delta.toLong())
Events.broadcastEvent(GameUpdateEvent(game, delta, container, world))
}
@@ -58,13 +59,13 @@ class GameState : BasicGameState() {
game!!
g.scale(WIDTH_RATIO, HEIGHT_RATIO)
- g.drawStringCentered((count / 100).toString(), WIDTH / 2f, HEIGHT / 2f)
g.background = Color.white
if (world.hurt) {
g.background = Color.red
}
g.color = Color.green
g.drawImage(background, 0f, 0f)
+ g.drawStringCentered((count / 100).toString(), WIDTH / 2f, HEIGHT / 2f)
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) {