Add isVisible method
This commit is contained in:
parent
c3d05b56bb
commit
987e7b82e0
@ -13,24 +13,28 @@ public class Enemy {
|
|||||||
private static final int enemyHeight = enemy.getHeight();
|
private static final int enemyHeight = enemy.getHeight();
|
||||||
|
|
||||||
private final int x, y;
|
private final int x, y;
|
||||||
private boolean isVisible;
|
private boolean visible;
|
||||||
|
|
||||||
public Enemy(int x, int y) {
|
public Enemy(int x, int y) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
isVisible = true;
|
visible = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isVisible() {
|
||||||
|
return visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCollide(int sx, int sy) {
|
public boolean isCollide(int sx, int sy) {
|
||||||
if (inRange(sx, x, x + enemyWidth) && inRange(sy, y, y + enemyHeight)) {
|
if (inRange(sx, x, x + enemyWidth) && inRange(sy, y, y + enemyHeight)) {
|
||||||
isVisible = false;
|
visible = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw(Graphics g) {
|
public void draw(Graphics g) {
|
||||||
if (isVisible) {
|
if (visible) {
|
||||||
g.drawImage(enemy, x, y);
|
g.drawImage(enemy, x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user