From 13cc1ee89d34443baf1630ec1877b034fa70d5c9 Mon Sep 17 00:00:00 2001 From: azoooooo <118elemente@gmail.com> Date: Mon, 18 Jun 2018 17:17:21 +0200 Subject: speeed increase added --- .../de/romjaki/pluggabledino/game/GameWorld.kt | 23 ++++++++++++++++------ src/main/kotlin/de/romjaki/pluggabledino/main.kt | 1 + .../de/romjaki/pluggabledino/states/GameState.kt | 10 ++++------ .../de/romjaki/pluggabledino/states/LostState.kt | 16 +++++++++++++-- 4 files changed, 36 insertions(+), 14 deletions(-) (limited to 'src') 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
() - 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