-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathInky.java
More file actions
76 lines (62 loc) · 2.27 KB
/
Inky.java
File metadata and controls
76 lines (62 loc) · 2.27 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
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
70
71
72
73
74
package sample;
import info.gridworld.actor.Actor;
import info.gridworld.grid.Grid;
import info.gridworld.grid.Location;
import java.awt.*;
import java.util.ArrayList;
public class Inky extends Enemy {
int totalMoves = 0;
Location previous;
boolean last = false;
public Inky() {
previous = this.getLocation();
this.setDirection(360);
this.setColor(Color.CYAN);
}
public void act() {
if(totalMoves < 30){}
else if(totalMoves == 30){
if(this.getGrid().get(new Location(7,9)) == null || getGrid().get(new Location(7,9)) instanceof SmallFood)
{
moveTo(new Location(7, 9));
}
}
else{
SmallFood food = new SmallFood();
if (last == true)
food.putSelfInGrid(getGrid(), previous);
moveTo(selectMoveLocation(getMoveLocations()));
}
totalMoves++;
}
public Location selectMoveLocation(ArrayList<Location> locs) {
if (totalMoves % 4 != 0) {
Location pacMan = findPacMan();
Location blinky = new Location(0, 0);
Location chosen = new Location(0, 0);
for (Object a : getActorList()) {
if (a instanceof Blinky)
blinky = ((Blinky) a).getLocation();
}
int row = blinky.getRow();
int col = blinky.getCol();
//90 degrees is added so it works with the unit circle
double dir = 90 + blinky.getDirectionToward(pacMan);
int distance = 2 * (int) Math.sqrt(Math.pow(blinky.getCol() - pacMan.getCol(), 2) +
Math.pow(blinky.getRow() - pacMan.getRow(), 2));
row += distance * Math.sin(dir);
col += distance * Math.cos(dir);
double min = 1000;
for (Location location : locs) {
int temp = (int) Math.sqrt((location.getCol() - col) * (location.getCol() - col) + (location.getRow() - row) * (location.getRow() - row));
if (temp < min) {
chosen = location;
min = temp;
}
}
chosen = checkTeleport(chosen);
return chosen;
}
else return this.getLocation();
}
}