-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetTargetTile.m
More file actions
36 lines (35 loc) · 1.41 KB
/
getTargetTile.m
File metadata and controls
36 lines (35 loc) · 1.41 KB
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
function tile = getTargetTile(ghost, pacman)
global ghosts;
global BLINKY PINKY INKY CLYDE DIR_UP;
switch ghost
case BLINKY
tile = pacman.tile;
case PINKY
% pinky targets four tiles ahead of pacman
tile.x = pacman.tile.x + 4*pacman.dir.x;
tile.y = pacman.tile.y + 4*pacman.dir.y;
if (pacman.dirEnum == DIR_UP)
tile.x = tile.x - 4;
end
case INKY
% inky targets twice the distance from blinky to two tiles ahead of pacman
tile.x = pacman.tile.x + 2*pacman.dir.x;
tile.y = pacman.tile.y + 2*pacman.dir.y;
if (pacman.dirEnum == DIR_UP)
tile.x = tile.x - 2;
end
tile.x = ghosts(BLINKY).tile.x + 2*(tile.x - ghosts(BLINKY).tile.x);
tile.y = ghosts(BLINKY).tile.y + 2*(tile.y - ghosts(BLINKY).tile.y);
case CLYDE
% clyde targets pacman if >=8 tiles away, otherwise targets home
dx = pacman.tile.x - (ghosts(ghost).tile.x + ghosts(ghost).dir.x);
dy = pacman.tile.y - (ghosts(ghost).tile.y + ghosts(ghost).dir.y);
dist = dx*dx+dy*dy;
if (dist >= 64)
tile = pacman.tile;
else
tile = ghosts(ghost).cornerTile;
ghosts(ghost).targeting = 3;
end
end
end