summaryrefslogtreecommitdiff
path: root/src/main/kotlin/de/romjaki/pluggabledino/game
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/de/romjaki/pluggabledino/game')
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/game/GameWorld.kt35
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)
+
+}
}