diff --git a/Military-Hero-Core/src/com/annimon/militaryhero/Enemy.java b/Military-Hero-Core/src/com/annimon/militaryhero/Enemy.java new file mode 100644 index 0000000..52664f3 --- /dev/null +++ b/Military-Hero-Core/src/com/annimon/militaryhero/Enemy.java @@ -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); + } +} diff --git a/Military-Hero-Core/src/com/annimon/militaryhero/ImageLoader.java b/Military-Hero-Core/src/com/annimon/militaryhero/ImageLoader.java index 63c521d..f61faf5 100644 --- a/Military-Hero-Core/src/com/annimon/militaryhero/ImageLoader.java +++ b/Military-Hero-Core/src/com/annimon/militaryhero/ImageLoader.java @@ -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 {