diff options
author | Roman Gräf <roman.graef@gmail.com> | 2018-06-19 17:15:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-19 17:15:52 +0200 |
commit | dd0f1c149db0df7c583c4f7bea4b5dd98f60250b (patch) | |
tree | cd94877016eaaa5e4298aafa856a9be2ba06a90d /src/main/kotlin/de/romjaki/pluggabledino/game/GameWorld.kt | |
parent | af04f81ea010fed2288db8a5ec46ab353586e944 (diff) | |
parent | 13cc1ee89d34443baf1630ec1877b034fa70d5c9 (diff) | |
download | pluggabledino-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/de/romjaki/pluggabledino/game/GameWorld.kt')
-rw-r--r-- | src/main/kotlin/de/romjaki/pluggabledino/game/GameWorld.kt | 23 |
1 files changed, 17 insertions, 6 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) } |