From 9b109fe7223bbaf114566a1eb2be28aaf39a9a8d Mon Sep 17 00:00:00 2001 From: ramapcsx2 Date: Sun, 30 Nov 2014 16:54:30 +0100 Subject: [PATCH] Unify enemy delete routine for when they leave the screen --- .../teamteamteam/spacescooter/entity/enemy/Enemy.java | 11 +++++++---- .../spacescooter/entity/enemy/EnemyThree.java | 3 --- .../spacescooter/entity/enemy/EnemyTwo.java | 3 --- src/de/teamteamteam/spacescooter/level/Level.java | 3 ++- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/de/teamteamteam/spacescooter/entity/enemy/Enemy.java b/src/de/teamteamteam/spacescooter/entity/enemy/Enemy.java index 0e3aac4..fad2d2e 100644 --- a/src/de/teamteamteam/spacescooter/entity/enemy/Enemy.java +++ b/src/de/teamteamteam/spacescooter/entity/enemy/Enemy.java @@ -38,13 +38,16 @@ public abstract class Enemy extends ShootingEntity { */ public void update() { super.update(); + + // enemy has fully left the screen ..to the left! + if(this.getX() + this.getWidth() < 0){ + this.remove(); + return; + } + if(willShoot == true){ this.shoot(); } - // ToDo: ??? - if(this.getX() < 0-this.getWidth()) { - this.remove(); - } } /** diff --git a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyThree.java b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyThree.java index 1836b3b..b455d63 100644 --- a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyThree.java +++ b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyThree.java @@ -47,9 +47,6 @@ public class EnemyThree extends Enemy{ public void update() { super.update(); this.setPosition(this.getX()-1, this.getY()); - if(this.getX() < 0-getWidth()){ - this.remove(); - } Player player = GameScreen.getPlayer(); if(this.getY() < player.getY()){ this.newY += ySpeed; diff --git a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyTwo.java b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyTwo.java index 38c5a64..65c3352 100644 --- a/src/de/teamteamteam/spacescooter/entity/enemy/EnemyTwo.java +++ b/src/de/teamteamteam/spacescooter/entity/enemy/EnemyTwo.java @@ -24,9 +24,6 @@ public class EnemyTwo extends Enemy{ public void update() { super.update(); this.setPosition(this.getX()-1, this.getY()); - if(this.getX() < 0-getWidth()){ - this.remove(); - } } @Override diff --git a/src/de/teamteamteam/spacescooter/level/Level.java b/src/de/teamteamteam/spacescooter/level/Level.java index 3f3d22e..b9241ee 100644 --- a/src/de/teamteamteam/spacescooter/level/Level.java +++ b/src/de/teamteamteam/spacescooter/level/Level.java @@ -90,7 +90,8 @@ public final class Level { //If the rule matches the current time, spawn the configured Entity in the configured amount: for(int i=0; i