From 1141a53481222c03f5531776ac08c1ba1d7dc435 Mon Sep 17 00:00:00 2001 From: Licht Date: Tue, 4 Nov 2014 13:43:49 +0100 Subject: [PATCH] Added Big Explosion, Structed explosion-handling --- res/images/explosion_proto.png | Bin 0 -> 187 bytes .../spacescooter/entity/Explosion.java | 71 ++++++++++-------- .../spacescooter/entity/ExplosionOne.java | 43 +++++++++++ .../spacescooter/entity/ExplosionTwo.java | 71 ++++++++++++++++++ .../spacescooter/entity/LivingEntity.java | 8 +- .../spacescooter/screen/GameScreen.java | 2 + 6 files changed, 157 insertions(+), 38 deletions(-) create mode 100644 res/images/explosion_proto.png create mode 100644 src/de/teamteamteam/spacescooter/entity/ExplosionOne.java create mode 100644 src/de/teamteamteam/spacescooter/entity/ExplosionTwo.java diff --git a/res/images/explosion_proto.png b/res/images/explosion_proto.png new file mode 100644 index 0000000000000000000000000000000000000000..fa650180341b9695cb0f8a3db3666d9dcbb41544 GIT binary patch literal 187 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=jKx9jP7LeL$-D$|*pj^6T^Rm@ z;DWu&Cj&(|3p^r=85p>QL70(Y)*K0-AbW|YuPggKZWeA$33uI@Pk}-lC9V-A&iT2y zsd*&~-_A_i4-`}Pba4!+xb^lRBQKD5Xu)^?Tt4#!KqfM1C}(zXU|?Kd#rFav?CI*~ Jvd$@?2>?~iE@S`z literal 0 HcmV?d00001 diff --git a/src/de/teamteamteam/spacescooter/entity/Explosion.java b/src/de/teamteamteam/spacescooter/entity/Explosion.java index 6db501c..caa8391 100644 --- a/src/de/teamteamteam/spacescooter/entity/Explosion.java +++ b/src/de/teamteamteam/spacescooter/entity/Explosion.java @@ -1,44 +1,53 @@ package de.teamteamteam.spacescooter.entity; +import java.util.Random; -public class Explosion extends Entity { +import de.teamteamteam.spacescooter.screen.Screen; - private int count = 71; + +public class Explosion extends LivingEntity { + + private boolean isActive = true; public Explosion(int x, int y) { super(x, y); - this.setImage("images/explosion1.png"); + this.setImage("images/explosion_proto.png"); this.setPosition(x - (this.getWidth()/2), y - (this.getHeight()/2)); + Random rand = new Random(); + if (rand.nextInt(99) <= 70) { + Screen.currentScreen.addEntity(new ExplosionOne(x, y)); + } else { + Screen.currentScreen.addEntity(new ExplosionTwo(x, y)); + } + } + + public Explosion(final int x, final int y, final int count, final int height, final int width) { + super(x, y); + this.setImage("images/explosion_proto.png"); + this.setPosition(x, y); + Thread explosionThread = new Thread(new Runnable() { //not yet compatible + public void run() { + Random rnd = new Random(); + for (int i = 0; i <= count; i++) { + new Explosion(x + (int) (width*rnd.nextDouble()), y + (int) (height*rnd.nextDouble())); + try { + Thread.sleep(5); + } catch (InterruptedException e) { + e.printStackTrace(); + } + if (i == count - 1) { + isActive = false; + } + } + } + }); + explosionThread.start(); + if(!this.isActive) { + this.remove(); + } } public void update() { - if (count >= 0) { - count--; - } else { - this.remove(); - } - switch (count) { - case 70: - this.setImage("images/explosion1.png"); - break; - case 60: - this.setImage("images/explosion2.png"); - break; - case 50: - this.setImage("images/explosion3.png"); - break; - case 40: - this.setImage("images/explosion4.png"); - break; - case 30: - this.setImage("images/explosion5.png"); - break; - case 20: - this.setImage("images/explosion6.png"); - break; - case 10: - this.setImage("images/explosion7.png"); - break; - } + } } diff --git a/src/de/teamteamteam/spacescooter/entity/ExplosionOne.java b/src/de/teamteamteam/spacescooter/entity/ExplosionOne.java new file mode 100644 index 0000000..6c8f96c --- /dev/null +++ b/src/de/teamteamteam/spacescooter/entity/ExplosionOne.java @@ -0,0 +1,43 @@ +package de.teamteamteam.spacescooter.entity; + +public class ExplosionOne extends LivingEntity { + + private int count = 71; + + public ExplosionOne(int x, int y) { + super(x, y); + this.setImage("images/explosion_proto.png"); + this.setPosition(x - (this.getWidth()/2), y - (this.getHeight()/2)); + } + + public void update() { + if (count >= 0) { + count--; + } else { + this.remove(); + } + switch (count) { + case 70: + this.setImage("images/explosion1.png"); + break; + case 60: + this.setImage("images/explosion2.png"); + break; + case 50: + this.setImage("images/explosion3.png"); + break; + case 40: + this.setImage("images/explosion4.png"); + break; + case 30: + this.setImage("images/explosion5.png"); + break; + case 20: + this.setImage("images/explosion6.png"); + break; + case 10: + this.setImage("images/explosion7.png"); + break; + } + } +} diff --git a/src/de/teamteamteam/spacescooter/entity/ExplosionTwo.java b/src/de/teamteamteam/spacescooter/entity/ExplosionTwo.java new file mode 100644 index 0000000..b5defd0 --- /dev/null +++ b/src/de/teamteamteam/spacescooter/entity/ExplosionTwo.java @@ -0,0 +1,71 @@ +package de.teamteamteam.spacescooter.entity; + +public class ExplosionTwo extends LivingEntity { + + private int count = 141; + + public ExplosionTwo(int x, int y) { + super(x, y); + this.setImage("images/explosion_proto.png"); + this.setPosition(x - (this.getWidth()/2), y - (this.getHeight()/2)); + } + + public void update() { + if (count >= 0) { + count--; + } else { + this.remove(); + } + switch (count) { + case 150: + this.setImage("images/explosion2_1.png"); + break; + case 140: + this.setImage("images/explosion2_2.png"); + break; + case 130: + this.setImage("images/explosion2_3.png"); + break; + case 120: + this.setImage("images/explosion2_4.png"); + break; + case 110: + this.setImage("images/explosion2_5.png"); + break; + case 100: + this.setImage("images/explosion2_6.png"); + break; + case 90: + this.setImage("images/explosion2_7.png"); + break; + case 80: + this.setImage("images/explosion2_8.png"); + break; + case 70: + this.setImage("images/explosion2_9.png"); + break; + case 60: + this.setImage("images/explosion2_10.png"); + break; + case 50: + this.setImage("images/explosion2_11.png"); + break; + case 40: + this.setImage("images/explosion2_12.png"); + break; + case 30: + this.setImage("images/explosion2_13.png"); + break; + case 20: + this.setImage("images/explosion2_14.png"); + break; + case 10: + this.setImage("images/explosion2_15.png"); + break; + case 1: + this.setImage("images/explosion2_16.png"); + break; + } + } + +} diff --git a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java index 0c2f8a6..17244a9 100644 --- a/src/de/teamteamteam/spacescooter/entity/LivingEntity.java +++ b/src/de/teamteamteam/spacescooter/entity/LivingEntity.java @@ -2,7 +2,6 @@ package de.teamteamteam.spacescooter.entity; import java.awt.Rectangle; import java.util.LinkedList; -import java.util.Random; import de.teamteamteam.spacescooter.screen.Screen; import de.teamteamteam.spacescooter.utility.GameConfig; @@ -86,12 +85,7 @@ public abstract class LivingEntity extends Entity implements Collidable { } private void explode() { - Random rnd = new Random(); - if (rnd.nextInt(99) < 70) { - Screen.currentScreen.addEntity(new Explosion(this.x, this.y)); - } else { - Screen.currentScreen.addEntity(new ExplosionBig(this.x, this.y)); - } + Screen.currentScreen.addEntity(new Explosion(this.x, this.y)); } public void setHealthPoints(int hp) { diff --git a/src/de/teamteamteam/spacescooter/screen/GameScreen.java b/src/de/teamteamteam/spacescooter/screen/GameScreen.java index 7aef9ad..1b712c6 100644 --- a/src/de/teamteamteam/spacescooter/screen/GameScreen.java +++ b/src/de/teamteamteam/spacescooter/screen/GameScreen.java @@ -13,6 +13,7 @@ import de.teamteamteam.spacescooter.entity.EnemyFour; import de.teamteamteam.spacescooter.entity.EnemyThree; import de.teamteamteam.spacescooter.entity.EnemyTwo; import de.teamteamteam.spacescooter.entity.Entity; +import de.teamteamteam.spacescooter.entity.Explosion; import de.teamteamteam.spacescooter.entity.Player; public class GameScreen extends Screen { @@ -31,6 +32,7 @@ public class GameScreen extends Screen { this.entities.add(new EnemyThree(450, 100)); this.entities.add(new EnemyTwo(750, 550)); this.entities.add(new EnemyTwo(150, 250)); + this.entities.add(new Explosion(200, 200, 50, 120, 120)); } @Override