Add enemy class
This commit is contained in:
parent
ad8b40ab3a
commit
138d9eaaa3
41
Military-Hero-Core/src/com/annimon/militaryhero/Enemy.java
Normal file
41
Military-Hero-Core/src/com/annimon/militaryhero/Enemy.java
Normal file
@ -0,0 +1,41 @@
|
||||
package com.annimon.militaryhero;
|
||||
|
||||
import com.annimon.jecp.Graphics;
|
||||
import com.annimon.jecp.Image;
|
||||
|
||||
/**
|
||||
* @author aNNiMON
|
||||
*/
|
||||
public class Enemy {
|
||||
|
||||
private static final Image enemy = ImageLoader.load(ImageLoader.ENEMY);
|
||||
private static final int enemyWidth = enemy.getWidth();
|
||||
private static final int enemyHeight = enemy.getHeight();
|
||||
|
||||
private final int x, y;
|
||||
private boolean isVisible;
|
||||
|
||||
public Enemy(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
isVisible = true;
|
||||
}
|
||||
|
||||
public boolean isCollide(int sx, int sy) {
|
||||
if (inRange(sx, x, x + enemyWidth) && inRange(sy, y, y + enemyHeight)) {
|
||||
isVisible = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void draw(Graphics g) {
|
||||
if (isVisible) {
|
||||
g.drawImage(enemy, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean inRange(int value, int min, int max) {
|
||||
return (value >= min) && (value <= max);
|
||||
}
|
||||
}
|
@ -11,8 +11,8 @@ public class ImageLoader {
|
||||
public static final String
|
||||
SNIPER_AIM = "sniper_aim.png",
|
||||
BACKGROUND = "background.jpg",
|
||||
OBSTACLES = "obstacles.png";
|
||||
|
||||
OBSTACLES = "obstacles.png",
|
||||
ENEMY = "enemy.png";
|
||||
|
||||
public static Image load(String name) {
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user