-
Notifications
You must be signed in to change notification settings - Fork 0
/
Inky.java
57 lines (46 loc) · 1.38 KB
/
Inky.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
package PacmanPack;
public class Inky extends Ghost {
public Inky(Cell cell, int spriteLevel) {
super(cell, spriteLevel);
spriteBaseSpeed = 0.1;
spriteSpeed = spriteBaseSpeed;
homeCell1 = Pacman.field[29][22];
homeCell2 = Pacman.field[25][22];
homeCell = homeCell1;
ghostHouse = cell;
danceStance = 6;
loadNormalDanceStances();
startAnimation(normalDanceAnimation[0]);
}
@Override
protected Cell scatterStrategy() {
return homeCell;
}
@Override
protected Cell chaseStrategy() {
return inkyChaseStrategy();
}
private Cell inkyChaseStrategy() {
Cell targetCell = Pacman.pacman.getCell();
targetCell = cellsAhead(targetCell, 2);
Cell blinkyCell = Pacman.blinky.getCell();
int tRow = targetCell.getRow();
int tCol = targetCell.getCol();
int dRow = blinkyCell.getRow() - tRow;
int dCol = blinkyCell.getCol() - tCol;
tRow = tRow + 2 * dRow;
tCol = tCol + 2 * dCol;
if (tRow < 0) {
tRow = 0;
} else if (tRow > 30) {
tRow = 30;
}
if (tCol < 0) {
tCol = Math.abs(28 + tCol);
} else if (tCol > 27) {
tCol = Math.abs(tCol % 27);
}
targetCell = Pacman.field[tRow][tCol];
return targetCell;
}
}