From 5baeff583f28fe3316a850eacee83db37c6adb6e Mon Sep 17 00:00:00 2001 From: JJTCM Date: Tue, 18 Nov 2014 13:51:10 +0100 Subject: [PATCH] Replace Player Iritaion with getPlayer() Added a Boss Fix Item Pickup --- res/images/boss.png | Bin 0 -> 715 bytes res/images/enemybossminion.png | Bin 0 -> 580 bytes .../spacescooter/entity/Entity.java | 12 ++++ .../spacescooter/entity/ShootingEntity.java | 14 ++++ .../spacescooter/entity/enemy/EnemyBoss.java | 61 ++++++++++++++++++ .../entity/enemy/EnemyBossMinion.java | 59 +++++++++++++++++ .../spacescooter/entity/enemy/EnemyThree.java | 27 +++----- .../spacescooter/entity/item/Item.java | 14 +--- .../spacescooter/gui/BossBar.java | 48 ++++++++++++++ .../spacescooter/screen/GameScreen.java | 8 ++- 10 files changed, 208 insertions(+), 35 deletions(-) create mode 100644 res/images/boss.png create mode 100644 res/images/enemybossminion.png create mode 100644 src/de/teamteamteam/spacescooter/entity/enemy/EnemyBoss.java create mode 100644 src/de/teamteamteam/spacescooter/entity/enemy/EnemyBossMinion.java create mode 100644 src/de/teamteamteam/spacescooter/gui/BossBar.java diff --git a/res/images/boss.png b/res/images/boss.png new file mode 100644 index 0000000000000000000000000000000000000000..95182c203392d0d719e24c4e10fb16ea947df427 GIT binary patch literal 715 zcmV;+0yO=JP)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2i^-3 z3>qPverg*4000?uMObu0Z*6U5Zgc=ca%Ew3Wn>_CX>@2HM@dakSAh-}0006eNklX7fx1gu7wxQ=OjE%9egI6$t>~?g97&Wo8 z;9B4qciijVyT5ngOhxvGEcbkKW@g#-lu}e=w3-Ksh{z8np2_i_?Y7Yc)`mkb$@Q$! zipP4<%9{o&UppI75>iZwSa||GTMw{R(l(y<>l9M{+VI31LB!*Ukw?G-Ob_gII_kGV z99NsWsV?C5<0YG4B1oyxDB4p53Ge`T00_uOP$s3-JPd93gE5(Og4TV2q2eGQ?@ll) zk6;Bc3siL$sMq%>OA_)55RiB7zrDW_5z+S6j*|-j0*cCgCIJL23jw;EpUs|gsRkgx z6#}I4ve%cvy}zp@U>b~@2ICZub9b))Ou}D6CLRcIi2&0azkj%k+#B-&#gMcEcfNAfawkqH$v8oZEyRVQ`dAu>=`ZSnz;AwGJ xJpgZvzysg`ARtXha`48;su3Vbz}w@F#24*}I)@6;(s=*?002ovPDHLkV1iv;E%N{X literal 0 HcmV?d00001 diff --git a/res/images/enemybossminion.png b/res/images/enemybossminion.png new file mode 100644 index 0000000000000000000000000000000000000000..53ae9538f495b6ff64e1cf85f793f445b97167d4 GIT binary patch literal 580 zcmV-K0=xZ*P)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2i^-3 z3?DNRu_CX>@2HM@dakSAh-}0004>NkloVGy#s zn@5}{4mv`xs}5XJJe$sw?~hOYOfN_|A$17(hB&b}!Qcp^gIIa(bvB*j84myeA4`0F zE;10hYYO71I!-)3U1P^<5x7i4Sb51m@S0ikv4rcoXXV&#c38DL=yg50YIk7wMJ90) z@tQprkQ2zmg2NGlH9ifk*t(1h!_fdQ)Az&$AIqyZ>HT~o3_|9_7TXs}fXVSgDOY7; zWjEn)G&nnsYBTDaFydU=eUZ8Tu;3R@11o#}_2g8?keM{1Jmn;fsAvQ$AS!^Xvp^-F zehf33hUvQhIRJ&#Bu_+jxKJ9PE*C1dVrmyE0o37wRrL>QcKn-nL*t-&QTYYLDa4Wf SE!Hpq0000 player.getY()){ + this.newY -= ySpeed; + this.setPosition(this.getX(), (int) newY); + } + } +} diff --git a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyThree.java b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyThree.java index 167ca86..4a538d4 100644 --- a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyThree.java +++ b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyThree.java @@ -1,11 +1,9 @@ package de.teamteamteam.spacescooter.entity.enemy; -import de.teamteamteam.spacescooter.datastructure.ConcurrentIterator; -import de.teamteamteam.spacescooter.entity.Entity; import de.teamteamteam.spacescooter.entity.Player; import de.teamteamteam.spacescooter.entity.explosion.MultiExplosion; import de.teamteamteam.spacescooter.entity.item.Item; -import de.teamteamteam.spacescooter.screen.Screen; +import de.teamteamteam.spacescooter.screen.GameScreen; import de.teamteamteam.spacescooter.utility.GameConfig; import de.teamteamteam.spacescooter.utility.Random; @@ -13,7 +11,6 @@ public class EnemyThree extends Enemy{ private double newY; private double ySpeed = 0.4; - private ConcurrentIterator entityIterator; public EnemyThree(int x, int y) { super(x, y); @@ -28,7 +25,6 @@ public class EnemyThree extends Enemy{ this.setScore(30); this.setPosition(GameConfig.windowWidth, Random.nextInt(GameConfig.windowHeight - this.getHeight() - 50) +50); this.newY = this.getY(); - this.entityIterator = Screen.currentScreen.createEntityIterator(); } /** @@ -57,20 +53,13 @@ public class EnemyThree extends Enemy{ this.remove(); new EnemyThree(0, 0); } - entityIterator.reset(); - while (entityIterator.hasNext()) { - Entity entity = entityIterator.next(); - if(entity instanceof Player){ - Player player = (Player) entity; - if(this.getY() < player.getY()){ - this.newY += ySpeed; - this.setPosition(this.getX(), (int) newY); - }else if(this.getY() > player.getY()){ - this.newY -= ySpeed; - this.setPosition(this.getX(), (int) newY); - } - } + Player player = GameScreen.getPlayer(); + if(this.getY() < player.getY()){ + this.newY += ySpeed; + this.setPosition(this.getX(), (int) newY); + }else if(this.getY() > player.getY()){ + this.newY -= ySpeed; + this.setPosition(this.getX(), (int) newY); } } - } diff --git a/src/de/teamteamteam/spacescooter/entity/item/Item.java b/src/de/teamteamteam/spacescooter/entity/item/Item.java index 8854bdc..b85ecba 100644 --- a/src/de/teamteamteam/spacescooter/entity/item/Item.java +++ b/src/de/teamteamteam/spacescooter/entity/item/Item.java @@ -1,21 +1,15 @@ package de.teamteamteam.spacescooter.entity.item; -import de.teamteamteam.spacescooter.datastructure.ConcurrentIterator; import de.teamteamteam.spacescooter.entity.CollidableEntity; -import de.teamteamteam.spacescooter.entity.Entity; import de.teamteamteam.spacescooter.entity.Player; import de.teamteamteam.spacescooter.entity.spi.Collidable; -import de.teamteamteam.spacescooter.screen.Screen; import de.teamteamteam.spacescooter.sound.SoundSystem; public abstract class Item extends CollidableEntity { - private ConcurrentIterator entityIterator; - public Item(int x, int y) { super(x, y); - this.entityIterator = Screen.currentScreen.createEntityIterator(); } /** @@ -24,12 +18,7 @@ public abstract class Item extends CollidableEntity { public void collideWith(Collidable entity) { if(entity instanceof Player) { SoundSystem.playSound("sounds/powerup_pickup.wav"); - while(entityIterator.hasNext()) { - Entity e = entityIterator.next(); - if(e instanceof Player){ - itemCollected((Player) e); - } - } + itemCollected((Player) entity); this.remove(); } } @@ -39,7 +28,6 @@ public abstract class Item extends CollidableEntity { if(this.getX() < 0-this.getWidth()){ this.remove(); }; - entityIterator.reset(); } public abstract void itemCollected(Player player); diff --git a/src/de/teamteamteam/spacescooter/gui/BossBar.java b/src/de/teamteamteam/spacescooter/gui/BossBar.java new file mode 100644 index 0000000..e853aca --- /dev/null +++ b/src/de/teamteamteam/spacescooter/gui/BossBar.java @@ -0,0 +1,48 @@ +package de.teamteamteam.spacescooter.gui; + +import java.awt.Color; +import java.awt.Font; +import java.awt.Graphics2D; + +import de.teamteamteam.spacescooter.entity.Entity; +import de.teamteamteam.spacescooter.entity.enemy.Enemy; + +public class BossBar extends Entity { + + private int width = 150; + private int height = 14; + private int health = 0; + private int fullhealth = 0; + private int healthwidth = 0; + private static Enemy boss; + + public BossBar(int x, int y, Enemy ent) { + super(x, y); + BossBar.boss = ent; + this.fullhealth = boss.getHealthPoints(); + } + + public void paint(Graphics2D g) { + try { + this.health = (int) (((double) boss.getHealthPoints() / (double) this.fullhealth) * 100); + this.healthwidth = ((this.width) * this.health) / 100; + } catch(Exception e) { + this.healthwidth = 0; + } + g.setColor(Color.WHITE); + g.setFont(new Font("Monospace", 0, 16)); + g.drawString("Boss:", this.getX(), this.getY()+12); + g.setColor(Color.PINK); + g.fillRect(this.getX()+70, this.getY(), this.healthwidth, this.height); + g.setColor(Color.WHITE); + g.drawRect(this.getX()+70, this.getY(), this.width, this.height); + } + + public void update() { + if (boss.isAlive() == false || boss.isRemoved() == true) { + this.remove(); + } + + } + +} diff --git a/src/de/teamteamteam/spacescooter/screen/GameScreen.java b/src/de/teamteamteam/spacescooter/screen/GameScreen.java index 646ad8c..205b4a1 100644 --- a/src/de/teamteamteam/spacescooter/screen/GameScreen.java +++ b/src/de/teamteamteam/spacescooter/screen/GameScreen.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import de.teamteamteam.spacescooter.background.StarBackground; import de.teamteamteam.spacescooter.control.Keyboard; import de.teamteamteam.spacescooter.entity.Player; +import de.teamteamteam.spacescooter.entity.enemy.EnemyBoss; import de.teamteamteam.spacescooter.entity.enemy.EnemyFour; import de.teamteamteam.spacescooter.entity.enemy.EnemyThree; import de.teamteamteam.spacescooter.entity.item.ItemChance; @@ -41,9 +42,10 @@ public class GameScreen extends Screen { new HealthBar(10, 5); new ShieldBar(10, 27); new ScoreBar(575, 33); - new EnemyFour(800, 400, points); - new EnemyThree(650, 300); - new EnemyThree(450, 100); + //new EnemyFour(800, 400, points); + //new EnemyThree(650, 300); + //new EnemyThree(450, 100); + new EnemyBoss(200, 300); } @Override