summaryrefslogtreecommitdiff
path: root/src/main/kotlin
diff options
context:
space:
mode:
authorRoman Gräf <roman.graef@gmail.com>2018-06-19 17:15:52 +0200
committerGitHub <noreply@github.com>2018-06-19 17:15:52 +0200
commitdd0f1c149db0df7c583c4f7bea4b5dd98f60250b (patch)
treecd94877016eaaa5e4298aafa856a9be2ba06a90d /src/main/kotlin
parentaf04f81ea010fed2288db8a5ec46ab353586e944 (diff)
parent13cc1ee89d34443baf1630ec1877b034fa70d5c9 (diff)
downloadpluggabledino-dd0f1c149db0df7c583c4f7bea4b5dd98f60250b.tar.gz
pluggabledino-dd0f1c149db0df7c583c4f7bea4b5dd98f60250b.tar.bz2
pluggabledino-dd0f1c149db0df7c583c4f7bea4b5dd98f60250b.zip
Merge pull request #9 from romangraef/feature-SpeedIncrease
speeed increase added
Diffstat (limited to 'src/main/kotlin')
-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)
}