diff options
author | azoooooo <118elemente@gmail.com> | 2018-06-10 16:44:07 +0200 |
---|---|---|
committer | azoooooo <118elemente@gmail.com> | 2018-06-10 16:44:07 +0200 |
commit | c5772e96b0ccf40a99ef50636302c2a86efcbfe3 (patch) | |
tree | 1356852e157010d8b7cd926400f9642e1ddad470 /src/main/kotlin/de/romjaki/pluggabledino/game | |
parent | 613331597541faf0c839be01d91fa8917bea85f4 (diff) | |
download | pluggabledino-c5772e96b0ccf40a99ef50636302c2a86efcbfe3.tar.gz pluggabledino-c5772e96b0ccf40a99ef50636302c2a86efcbfe3.tar.bz2 pluggabledino-c5772e96b0ccf40a99ef50636302c2a86efcbfe3.zip |
Rand generator implement
Diffstat (limited to 'src/main/kotlin/de/romjaki/pluggabledino/game')
-rw-r--r-- | src/main/kotlin/de/romjaki/pluggabledino/game/GameWorld.kt | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/src/main/kotlin/de/romjaki/pluggabledino/game/GameWorld.kt b/src/main/kotlin/de/romjaki/pluggabledino/game/GameWorld.kt index aac55e2..f7e5dc2 100644 --- a/src/main/kotlin/de/romjaki/pluggabledino/game/GameWorld.kt +++ b/src/main/kotlin/de/romjaki/pluggabledino/game/GameWorld.kt @@ -8,6 +8,7 @@ import org.jbox2d.common.Vec2 import org.jbox2d.dynamics.* import org.jbox2d.dynamics.contacts.Contact import org.newdawn.slick.Input +import java.util.Random class GameWorld : ContactListener { override fun endContact(contact: Contact?) { @@ -34,10 +35,14 @@ class GameWorld : ContactListener { val cacti = mutableListOf<Body>() + var i = 0 + val cactiBodyDef: BodyDef val groundBody: Body + val random = Random() + val dino: Body val groundBodyDef: BodyDef @@ -83,18 +88,26 @@ class GameWorld : ContactListener { createCactus() } + fun rand(from: Int, to: Int) : Int { + return random.nextInt(to - from) + from + } + fun createCactus() { - val body = world.createBody(cactiBodyDef) - body.position.set(20f, 39f) - val shape = PolygonShape() - shape.setAsBox(1f, 1f) - val cactiFixtureDef = FixtureDef() - cactiFixtureDef.shape = dinoBox - cactiFixtureDef.isSensor = true - cactiFixtureDef.density = 0.1f - cactiFixtureDef.friction = 0f - body.createFixture(cactiFixtureDef) - cacti.add(body) +while (i<100) { + i++ + val body = world.createBody(cactiBodyDef) + body.position.set(i*30f+rand(30, to = 40), 39f) + val shape = PolygonShape() + shape.setAsBox(1f, 1f) + val cactiFixtureDef = FixtureDef() + cactiFixtureDef.shape = dinoBox + cactiFixtureDef.isSensor = true + cactiFixtureDef.density = 0.1f + cactiFixtureDef.friction = 0f + body.createFixture(cactiFixtureDef) + cacti.add(body) + +} } |