diff --git a/src/de/teamteamteam/spacescooter/entity/Entity.java b/src/de/teamteamteam/spacescooter/entity/Entity.java index 89d073b..ab65b85 100644 --- a/src/de/teamteamteam/spacescooter/entity/Entity.java +++ b/src/de/teamteamteam/spacescooter/entity/Entity.java @@ -28,6 +28,10 @@ public abstract class Entity implements Updateable, Paintable { private int width; private int height; + /** + * Whether or not the Entity is able to move using transpose. + */ + private boolean canMove; /** * Internal reference to the entities image. */ @@ -40,6 +44,7 @@ public abstract class Entity implements Updateable, Paintable { */ public Entity(int x, int y) { this.setPosition(x, y); + this.setCanMove(true); Screen.currentScreen.addEntity(this); } @@ -71,8 +76,10 @@ public abstract class Entity implements Updateable, Paintable { * Example: X = X + x_delta, Y = Y + y_delta. */ public void transpose(int x_delta, int y_delta) { - this.x += x_delta; - this.y += y_delta; + if(this.canMove) { + this.x += x_delta; + this.y += y_delta; + } } /** @@ -113,6 +120,20 @@ public abstract class Entity implements Updateable, Paintable { this.setDimensions(this.img.getWidth(), this.img.getHeight()); } + /** + * Set whether the Entity is able to move. + */ + public void setCanMove(boolean canMove) { + this.canMove = canMove; + } + + /** + * Returns true if the Entity is able to move. + */ + public boolean canMove() { + return this.canMove; + } + /** * The default way to paint the Entity. * Simply draw the Entities image on its current position. diff --git a/src/de/teamteamteam/spacescooter/entity/Player.java b/src/de/teamteamteam/spacescooter/entity/Player.java index 47ef7d1..a5c3791 100644 --- a/src/de/teamteamteam/spacescooter/entity/Player.java +++ b/src/de/teamteamteam/spacescooter/entity/Player.java @@ -10,8 +10,6 @@ import de.teamteamteam.spacescooter.utility.GameConfig; public class Player extends ShootingEntity implements KeyboardListener { - private boolean canMove = true; - private Keyboard keyboard = null; public Player(int x, int y) { @@ -33,7 +31,7 @@ public class Player extends ShootingEntity implements KeyboardListener { } public void update() { - if(this.canMove) { + if(this.canMove()) { super.update(); int offset = 3; if(Keyboard.isKeyDown(KeyEvent.VK_UP) && this.getY() > 0) { @@ -55,10 +53,6 @@ public class Player extends ShootingEntity implements KeyboardListener { } } - public void setCanMove(boolean canMove){ - this.canMove = canMove; - } - @Override public void explode() { super.explode();