summaryrefslogtreecommitdiff
path: root/src/main/kotlin/de/romjaki/pluggabledino
diff options
context:
space:
mode:
authorRoman Gräf <roman.graef@gmail.com>2018-07-14 22:46:14 +0200
committerGitHub <noreply@github.com>2018-07-14 22:46:14 +0200
commit6585706c47343bcaf8145d19e4eee2f23562ec57 (patch)
tree169b78e1dbf11377387a36d36bec43d766f2a750 /src/main/kotlin/de/romjaki/pluggabledino
parent7b1f56d5d381ec75e757e7df4714c7acdc3c4803 (diff)
parent5e36d9fec9020097cba3752416737ef1ab334de3 (diff)
downloadpluggabledino-6585706c47343bcaf8145d19e4eee2f23562ec57.tar.gz
pluggabledino-6585706c47343bcaf8145d19e4eee2f23562ec57.tar.bz2
pluggabledino-6585706c47343bcaf8145d19e4eee2f23562ec57.zip
Merge pull request #10 from romangraef/feature-BirdGeneration1.0Final
Birds Generation
Diffstat (limited to 'src/main/kotlin/de/romjaki/pluggabledino')
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/game/GameWorld.kt56
-rw-r--r--src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt4
2 files changed, 58 insertions, 2 deletions
diff --git a/src/main/kotlin/de/romjaki/pluggabledino/game/GameWorld.kt b/src/main/kotlin/de/romjaki/pluggabledino/game/GameWorld.kt
index b881a4a..87b7a2c 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 org.jbox2d.callbacks.ContactImpulse
import org.jbox2d.callbacks.ContactListener
import org.jbox2d.collision.Manifold
@@ -22,6 +24,10 @@ class GameWorld : ContactListener {
hurt = true
}
+ else if (bodies.contains(dino) && birdd.any { bodies.contains(it) }) {
+ hurt = true
+
+ }
}
override fun preSolve(contact: Contact?, oldManifold: Manifold?) {
@@ -38,6 +44,10 @@ class GameWorld : ContactListener {
val cactiBodyDef: BodyDef
+ val birdd = mutableListOf<Body>()
+
+ val birddBodyDef: BodyDef
+
var speed = 1000
val groundBody: Body
@@ -46,6 +56,8 @@ class GameWorld : ContactListener {
var delay = 0f
+ var bg = 0f
+
val dino: Body
val groundBodyDef: BodyDef
@@ -88,13 +100,44 @@ class GameWorld : ContactListener {
cactiBodyDef = BodyDef()
cactiBodyDef.type = BodyType.KINEMATIC
+ birddBodyDef = BodyDef()
+ birddBodyDef.type = BodyType.KINEMATIC
+
createCactus1()
+ createBird1()
}
+
+
+
+
+
fun rand(from: Int, to: Int): Int {
return random.nextInt(to - from) + from
}
+ fun createBird1(){
+
+
+
+ val body = world.createBody(birddBodyDef)
+ body.position.set(50f, 33f)
+ val shape = PolygonShape()
+ shape.setAsBox(1f, 1f)
+ val birddFixtureDef = FixtureDef()
+ birddFixtureDef.shape = dinoBox
+ birddFixtureDef.isSensor = true
+ birddFixtureDef.density = 0.1f
+ birddFixtureDef.friction = 0f
+ body.createFixture(birddFixtureDef)
+ birdd.add(body)
+ speed += 0
+
+ }
+
+
+
+
fun createCactus1() {
val body = world.createBody(cactiBodyDef)
@@ -116,19 +159,30 @@ class GameWorld : ContactListener {
fun update(delta: Float, input: Input) {
if (input.isKeyDown(Input.KEY_UP)) {
- tryJump();
+ tryJump()
}
delay -= delta
+ bg -= delta
if (delay < 0) {
createCactus1()
+
delay = random.nextFloat() + rand(2, 3)
}
+ if (bg < -5) {
+
+
+ createBird1()
+ bg = random.nextFloat() + rand(1, 2)
+ }
cacti.forEach {
it.linearVelocity.set(-delta * speed, 0f)
}
+ birdd.forEach {
+ it.linearVelocity.set(-delta * speed, 0f)
+ }
world.step(delta, 4, 3)
world.setContactListener(this)
diff --git a/src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt b/src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt
index 5786837..6e538b5 100644
--- a/src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt
+++ b/src/main/kotlin/de/romjaki/pluggabledino/states/GameState.kt
@@ -64,7 +64,9 @@ class GameState : BasicGameState() {
for (cactus in world.cacti) {
g.drawImage(cactusImg, cactus.position.x * WIDTH / 50, cactus.position.y * HEIGHT / 50 - cactusImg.height)
}
-
+ for (bird in world.birdd) {
+ g.drawImage(BirdImg, bird.position.x * WIDTH / 50, bird.position.y * HEIGHT / 50 - BirdImg.height)
+ }
Events.broadcastEvent(GameRenderEvent(g, game, container))
}