summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Gräf <roman.graef@gmail.com>2018-06-10 17:14:53 +0200
committerGitHub <noreply@github.com>2018-06-10 17:14:53 +0200
commitaf1e3e7849c3db103d2a3dc23922cad2c8254a13 (patch)
tree1c93a3ae7bb38adc424aee062d566eb3b339c58c
parent613331597541faf0c839be01d91fa8917bea85f4 (diff)
parentdea3ed0b7303356064f159e495a7f4da5b377082 (diff)
downloadpluggabledino-af1e3e7849c3db103d2a3dc23922cad2c8254a13.tar.gz
pluggabledino-af1e3e7849c3db103d2a3dc23922cad2c8254a13.tar.bz2
pluggabledino-af1e3e7849c3db103d2a3dc23922cad2c8254a13.zip
Merge pull request #4 from romangraef/feature-kacktussigeneration
Feature kacktussigeneration
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/game/GameWorld.kt29
1 files changed, 24 insertions, 5 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..21c0571 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 delay = 0f
+
val cactiBodyDef: BodyDef
val groundBody: Body
+ val random = Random()
+
val dino: Body
val groundBodyDef: BodyDef
@@ -51,7 +56,7 @@ class GameWorld : ContactListener {
val dinoFixtureDef: FixtureDef
init {
- val gravity = Vec2(0f, 10f)
+ val gravity = Vec2(0f, 40f)
world = World(gravity)
//#region GROUND
@@ -80,12 +85,17 @@ class GameWorld : ContactListener {
cactiBodyDef = BodyDef()
cactiBodyDef.type = BodyType.KINEMATIC
- createCactus()
+ createCactus1()
}
- fun createCactus() {
+ fun rand(from: Int, to: Int): Int {
+ return random.nextInt(to - from) + from
+ }
+
+ fun createCactus1() {
+
val body = world.createBody(cactiBodyDef)
- body.position.set(20f, 39f)
+ body.position.set(100f, 39f)
val shape = PolygonShape()
shape.setAsBox(1f, 1f)
val cactiFixtureDef = FixtureDef()
@@ -95,6 +105,8 @@ class GameWorld : ContactListener {
cactiFixtureDef.friction = 0f
body.createFixture(cactiFixtureDef)
cacti.add(body)
+
+
}
@@ -102,9 +114,16 @@ class GameWorld : ContactListener {
if (input.isKeyDown(Input.KEY_UP)) {
if (isDinoOnGround()) {
print("Jump")
- dino.applyForceToCenter(Vec2(0f, -2000f))
+ dino.applyForceToCenter(Vec2(0f, -4250f))
}
}
+ delay -= delta
+ if (delay < 0) {
+
+ createCactus1()
+ delay = random.nextFloat() + rand(1, 3)-0.5f
+
+ }
cacti.forEach {
it.linearVelocity.set(-delta * 1000, 0f)
}