summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/game/GameWorld.kt23
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/main.kt1
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt10
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/states/LostState.kt16
4 files changed, 36 insertions, 14 deletions
diff --git a/src/main/kotlin/de/romjaki/pluggabledino/game/GameWorld.kt b/src/main/kotlin/de/romjaki/pluggabledino/game/GameWorld.kt
index 9c405f0..edafa69 100644
--- a/src/main/kotlin/de/romjaki/pluggabledino/game/GameWorld.kt
+++ b/src/main/kotlin/de/romjaki/pluggabledino/game/GameWorld.kt
@@ -1,5 +1,7 @@
package de.romjaki.pluggabledino.game
+import de.romjaki.pluggabledino.highscore
+import de.romjaki.pluggabledino.score
import org.jbox2d.callbacks.ContactImpulse
import org.jbox2d.callbacks.ContactListener
import org.jbox2d.collision.Manifold
@@ -20,6 +22,7 @@ class GameWorld : ContactListener {
val bodies = listOf(contact.fixtureA.body, contact.fixtureB.body)
if (bodies.contains(dino) && cacti.any { bodies.contains(it) }) {
hurt = true
+
}
}
@@ -35,14 +38,16 @@ class GameWorld : ContactListener {
val cacti = mutableListOf<Body>()
- var delay = 0f
-
val cactiBodyDef: BodyDef
+ var speed = 1000
+
val groundBody: Body
val random = Random()
+ var delay = 0f
+
val dino: Body
val groundBodyDef: BodyDef
@@ -105,6 +110,7 @@ class GameWorld : ContactListener {
cactiFixtureDef.friction = 0f
body.createFixture(cactiFixtureDef)
cacti.add(body)
+ speed += 20
}
@@ -118,15 +124,20 @@ class GameWorld : ContactListener {
}
}
delay -= delta
- if (delay < 0) {
- createCactus1()
- delay = random.nextFloat() + rand(2, 3)-0.5f
+ if (delay < 0) {
+ createCactus1()
+ delay = random.nextFloat() + rand(2, 3)
}
+
+
+
+
cacti.forEach {
- it.linearVelocity.set(-delta * 1000, 0f)
+ it.linearVelocity.set(-delta * speed, 0f)
}
+
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 94d9444..07ca687 100644
--- a/src/main/kotlin/de/romjaki/pluggabledino/main.kt
+++ b/src/main/kotlin/de/romjaki/pluggabledino/main.kt
@@ -28,6 +28,7 @@ const val GAME = 2
const val LOST = 4
var lastscore = 0
var highscore = 0
+var score = 0
fun main(args: Array<String>) {
PluginLoader.loadPlugins()
diff --git a/src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt b/src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt
index 7ac2aa9..e579933 100644
--- a/src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt
+++ b/src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt
@@ -16,20 +16,17 @@ class GameState : BasicGameState() {
override fun enter(container: GameContainer?, game: StateBasedGame?) {
world = GameWorld()
count = 0
+
}
override fun update(container: GameContainer?, game: StateBasedGame?, delta: Int) {
count += delta
+
if (container!!.input.isKeyDown(Input.KEY_R)) {
world = GameWorld()
}
if (world.hurt) {
lastscore = count / 100
- if(lastscore > highscore){
-
- highscore = lastscore
-
- }
game!!.enterState(LOST)
}
world.update(delta / 1000f, container.input)
@@ -61,6 +58,7 @@ class GameState : BasicGameState() {
for (cactus in world.cacti) {
g.drawImage(cactusImg, cactus.position.x * WIDTH / 50, cactus.position.y * HEIGHT / 50 - cactusImg.height)
}
- }
+
+ }
}
diff --git a/src/main/kotlin/de/romjaki/pluggabledino/states/LostState.kt b/src/main/kotlin/de/romjaki/pluggabledino/states/LostState.kt
index cec408c..07c9742 100644
--- a/src/main/kotlin/de/romjaki/pluggabledino/states/LostState.kt
+++ b/src/main/kotlin/de/romjaki/pluggabledino/states/LostState.kt
@@ -12,9 +12,21 @@ class LostState : BasicGameState() {
override fun init(container: GameContainer?, game: StateBasedGame?) {
game!!
playAgain.addClickHandler {
+
+ if(lastscore > highscore){
+
+ highscore = lastscore
+
+ }
game.enterState(GAME)
}
back.addClickHandler {
+
+ if(lastscore > highscore){
+
+ highscore = lastscore
+
+ }
game.enterState(MAINMENU)
}
}
@@ -37,11 +49,11 @@ class LostState : BasicGameState() {
g.drawStringCentered(lastscore.toString(), WIDTH / 2f, HEIGHT /2f )
g.drawStringCentered("Score:", WIDTH / 2f , HEIGHT / 2f - 40f )
if(lastscore > highscore ) {
- g.drawStringCentered("NEUER HIGHSCORE:" + highscore, WIDTH / 2f, HEIGHT / 2f - 70f)
+ g.drawStringCentered("NEUER HIGHSCORE:" + lastscore, WIDTH / 2f, HEIGHT / 2f - 70f)
}
else {
- g.drawStringCentered("Highscore:" + highscore, WIDTH / 2f, HEIGHT / 2f - 70f)
+ g.drawStringCentered("Highscore:" + highscore, WIDTH / 2f, HEIGHT / 2f - 70f)
}