forked from dtschust/javapacman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMover.java
54 lines (54 loc) · 1.31 KB
/
Mover.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
/* Ligeramente modificado, todos los creditos para: */
/* Drew Schuster */ /* https://github.com/dtschust/javapacman */
/* Both Player and Ghost inherit Mover. Has generic functions relevant to both*/
class Mover
{
/* Framecount is used to count animation frames*/
int frameCount=0;
/* State contains the game map */
boolean[][] state;
/* gridSize is the size of one square in the game.
max is the height/width of the game.
increment is the speed at which the object moves,
1 increment per move() call */
int gridSize;
int max;
int increment;
/* Generic constructor */
public Mover()
{
gridSize=20;
increment = 4;
max = 400;
state = new boolean[20][20];
for(int i =0;i<20;i++)
{
for(int j=0;j<20;j++)
{
state[i][j] = false;
}
}
}
/* Updates the state information */
public void updateState(boolean[][] state)
{
for(int i =0;i<20;i++)
{
for(int j=0;j<20;j++)
{
this.state[i][j] = state[i][j];
}
}
}
/* Determines if a set of coordinates is a valid destination.*/
public boolean isValidDest(int x, int y)
{
/* The first statements check that the x and y are inbounds. The last statement checks the map to
see if it's a valid location */
if ((((x)%20==0) || ((y)%20)==0) && 20<=x && x<400 && 20<= y && y<400 && state[x/20-1][y/20-1] )
{
return true;
}
return false;
}
}