-
Notifications
You must be signed in to change notification settings - Fork 1
/
Hero.java
69 lines (58 loc) · 2.51 KB
/
Hero.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.awt.Rectangle;
public class Hero {
protected int xPosition = 0;
protected int yPosition = 0;
protected int xDirection = 0;
protected int yDirection = 0;
protected boolean isAlive = true;
public int GetXPosition() {
return this.xPosition;
}
public int GetYPosition() {
return this.yPosition;
}
public boolean GetIsAlive() {
return this.isAlive;
}
public boolean Move(Map mapPacman) {
if (this.GetIsAlive()) {
if (
(this.xPosition + this.xDirection < 19 || this.xDirection + this.xPosition > (mapPacman.GetWidth() - 2) * 19)
&& (mapPacman.GetMap((this.xDirection*18 + this.xPosition) / 19, this.yPosition / 19)) != 0
&& this.yPosition%19==0){
if (this.xPosition + this.xDirection == 0)
this.xPosition = 19 * (mapPacman.GetWidth() - 1) - 1;
else if (this.xPosition + this.xDirection == 19 * (mapPacman.GetWidth() - 1))
this.xPosition = 1;
else {
this.xPosition = this.xPosition + this.xDirection;
}
return true;
} else if (
mapPacman.GetMap((this.xPosition + this.xDirection) / 19,(this.yPosition + this.yDirection) / 19) != 0
&& mapPacman.GetMap(((this.xPosition + this.xDirection + 18) / 19),((this.yPosition + this.yDirection + 18) / 19)) != 0
&& mapPacman.GetMap(((this.xPosition + this.xDirection) / 19),((this.yPosition + this.yDirection + 18) / 19)) != 0
&& mapPacman.GetMap(((this.xPosition + this.xDirection + 18) / 19),((this.yPosition + this.yDirection) / 19)) != 0
)
{
this.xPosition += this.xDirection;
this.yPosition += this.yDirection;
return true;
} else {
this.xDirection = 0;
this.yDirection = 0;
return false;
}
}
return false;
}
public boolean TryToKill(Hero killed) {
Rectangle rectKilled = new Rectangle(killed.GetXPosition() - 3, killed.GetYPosition() - 3, 13, 13);
Rectangle rectKiller = new Rectangle(this.GetXPosition() - 3, this.GetYPosition() - 3, 13, 13);
if (rectKiller.intersects(rectKilled) && this.isAlive && killed.isAlive) {
killed.isAlive = false;
return true;
} else
return false;
}
}