The Entity now knows whether it is able to move.
This commit is contained in:
parent
d9b7128456
commit
2295d83ff9
|
@ -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,9 +76,11 @@ 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) {
|
||||
if(this.canMove) {
|
||||
this.x += x_delta;
|
||||
this.y += y_delta;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Entities width.
|
||||
|
@ -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.
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue