Remove superfluos calls to currentScreen.addEntity()

Since the entity class itself takes care that all entities are on the
screen, you don't need to worry about this. :-)
This commit is contained in:
Jan Philipp Timme 2014-11-04 19:41:15 +01:00
parent 881b802e7a
commit e2c34366e3
7 changed files with 13 additions and 16 deletions

View File

@ -35,16 +35,16 @@ public abstract class Items extends LivingEntity{
int auswahl = ItemChance.choose();
switch (auswahl) {
case 0:
Screen.currentScreen.addEntity(new TestItem1(x, y));
new TestItem1(x, y);
break;
case 1:
Screen.currentScreen.addEntity(new TestItem2(x, y));
new TestItem2(x, y);
break;
case 2:
Screen.currentScreen.addEntity(new TestItem3(x, y));
new TestItem3(x, y);
break;
case 3:
Screen.currentScreen.addEntity(new TestItem4(x, y));;
new TestItem4(x, y);;
break;
}
}

View File

@ -94,7 +94,7 @@ public abstract class LivingEntity extends Entity implements Collidable {
}
public void explode() {
Screen.currentScreen.addEntity(new Explosion(this.x, this.y));
new Explosion(this.x, this.y);
}
public void setHealthPoints(int hp) {

View File

@ -62,9 +62,9 @@ public class Player extends ShootingEntity implements KeyboardListener {
*/
@Override
public void remove() {
super.remove();
this.keyboard.removeListener(this);
this.keyboard = null;
super.remove();
}
@Override

View File

@ -1,7 +1,6 @@
package de.teamteamteam.spacescooter.entity;
import de.teamteamteam.spacescooter.entity.shot.SingleBlueShot;
import de.teamteamteam.spacescooter.screen.Screen;
public abstract class ShootingEntity extends LivingEntity {
@ -25,7 +24,7 @@ public abstract class ShootingEntity extends LivingEntity {
protected void shoot() {
if(this.currentShootDelay == 0) {
Screen.currentScreen.addEntity(new SingleBlueShot(this.x + this.shootSpawnX, this.y + this.shootSpawnY, this.shootDirection, this.shootSpeed, this.damageValue));
new SingleBlueShot(this.x + this.shootSpawnX, this.y + this.shootSpawnY, this.shootDirection, this.shootSpeed, this.damageValue);
this.currentShootDelay = this.shootDelay;
}
}

View File

@ -35,11 +35,11 @@ public class EnemyThree extends Enemy{
this.setPosition(this.getX()-1, this.getY());
if(this.getX() < 0-getWidth()){
this.remove();
Screen.currentScreen.addEntity(new EnemyThree(0, 0));
new EnemyThree(0, 0);
}
if(!this.isAlive()){
if(random.nextInt(10) < 5) Items.create(getX(), getY());
Screen.currentScreen.addEntity(new EnemyThree(0, 0));
new EnemyThree(0, 0);
}
LinkedList<Entity> list = Screen.currentScreen.getEntities();
Iterator<Entity> i = list.iterator();

View File

@ -2,7 +2,6 @@ package de.teamteamteam.spacescooter.entity.enemy;
import java.util.Random;
import de.teamteamteam.spacescooter.screen.Screen;
import de.teamteamteam.spacescooter.utility.GameConfig;
public class EnemyTwo extends Enemy{
@ -25,10 +24,10 @@ public class EnemyTwo extends Enemy{
this.setPosition(this.getX()-1, this.getY());
if(this.getX() < 0-getWidth()){
this.remove();
Screen.currentScreen.addEntity(new EnemyTwo(0, 0));
new EnemyTwo(0, 0);
}
if(!this.isAlive()){
Screen.currentScreen.addEntity(new EnemyTwo(0, 0));
new EnemyTwo(0, 0);
}
}

View File

@ -3,7 +3,6 @@ package de.teamteamteam.spacescooter.entity.explosion;
import java.util.Random;
import de.teamteamteam.spacescooter.entity.Entity;
import de.teamteamteam.spacescooter.screen.Screen;
public class Explosion extends Entity {
@ -33,9 +32,9 @@ public class Explosion extends Entity {
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));
new ExplosionOne(x, y);
} else {
Screen.currentScreen.addEntity(new ExplosionTwo(x, y));
new ExplosionTwo(x, y);
}
}