1 package se
.umu
.cs
.dit06ajnajs
.agent
;
5 import java
.util
.logging
.Logger
;
7 import se
.umu
.cs
.dit06ajnajs
.Paintable
;
8 import se
.umu
.cs
.dit06ajnajs
.map
.Map
;
9 import se
.umu
.cs
.dit06ajnajs
.map
.MapSquare
;
10 import se
.umu
.cs
.dit06ajnajs
.map
.Traversable
;
12 public abstract class Unit
implements Agent
, Paintable
{
13 private static Logger logger
= Logger
.getLogger("AntiTD");
24 private Direction direction
;
26 private boolean alive
;
28 public Unit(int xPos
, int yPos
, int width
, int height
, int speed
, Direction direction
, Map map
) {
34 this.direction
= direction
;
40 public void setImage(Image img
) {
41 // TODO Auto-generated method stub
46 // Check if this unit has health left
47 if (this.health
>= 0) {
48 Point nextPos
= getNextPosition();
49 // TODO check for collision on next position
52 // Land on current square
53 MapSquare currentSquare
= map
.getMapSquareAtPoint(xPos
, yPos
);
54 if (currentSquare
instanceof Traversable
) {
55 ((Traversable
) currentSquare
).landOn(this);
64 public Point
getNextPosition() {
69 nextPos
= new Point(xPos
, yPos
- speed
);
73 nextPos
= new Point(xPos
, yPos
+ speed
);
77 nextPos
= new Point(xPos
- speed
, yPos
);
81 nextPos
= new Point(xPos
+ speed
, yPos
);
87 public void move(Point p
) {
92 public int getXPos() {
96 public void setXPos(int pos
) {
100 public int getYPos() {
104 public void setYPos(int pos
) {
108 public Point
getCenterPoint() {
109 return new Point(xPos
+ (width
/ 2),
110 yPos
- (height
/ 2));
113 public int getWidth() {
117 public void setWidth(int width
) {
121 public int getHeight() {
125 public void setHeight(int height
) {
126 this.height
= height
;
129 public int getSpeed() {
133 public void setSpeed(int speed
) {
137 public Direction
getDirection() {
141 public void setDirection(Direction direction
) {
142 this.direction
= direction
;
145 public boolean isAlive() {
149 public void setAlive(boolean state
) {
153 public int getHealth() {
158 * Decrease the units health
159 * @param damage The number of health points to substract
161 public void damage(int damage
) {
162 this.health
-= damage
;
165 public void setHealth(int health
) {
166 this.health
= health
;