Remove-Methode für Entity-Klasse hinzugefügt. Shots leben nicht außerhalb des Bildschirms weiter.

This commit is contained in:
Jan Philipp Timme 2014-10-30 22:42:08 +01:00
parent 52f8cbcb4d
commit 81f3cb7536
4 changed files with 18 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import de.teamteamteam.spacescooter.screen.Screen;
import de.teamteamteam.spacescooter.utility.GameConfig;
import de.teamteamteam.spacescooter.utility.Loader;
@ -63,4 +64,11 @@ public abstract class Entity implements Updateable, Paintable {
g.drawImage(this.img, this.x, this.y, null);
}
/**
* Removes entity from the game
*/
public void remove() {
Screen.currentScreen.removeEntity(this);
}
}

View File

@ -79,7 +79,7 @@ public abstract class LivingEntity extends Entity implements Collidable {
this.healthPoints -= damage;
if (this.isAlive() == false) {
if(GameConfig.DEBUG) System.out.println(this + " ist gestorben. RIP");
Screen.currentScreen.removeEntity(this);
this.remove();
}
}

View File

@ -1,5 +1,7 @@
package de.teamteamteam.spacescooter.entity;
import de.teamteamteam.spacescooter.utility.GameConfig;
public abstract class Shot extends LivingEntity {
public static final int RIGHT = 1;
@ -33,6 +35,12 @@ public abstract class Shot extends LivingEntity {
public void update() {
this.x += this.direction * this.speed;
//remove the shot in case it is out of the game window.
if ((this.x + this.getWidth()) < 0 || this.x > GameConfig.windowWidth
|| (this.y + this.getHeight()) < 0
|| this.y > GameConfig.windowHeight) {
this.remove();
}
}
}

View File

@ -1,7 +1,6 @@
package de.teamteamteam.spacescooter.screen;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.util.Iterator;
import java.util.LinkedList;
@ -46,3 +45,4 @@ public class GameScreen extends Screen {
}
}