-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGhost.pde
More file actions
80 lines (76 loc) · 1.99 KB
/
Ghost.pde
File metadata and controls
80 lines (76 loc) · 1.99 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
75
76
77
78
79
80
public class Ghost{
int number;
int gx;
int gy;
int gpx;
int gpy;
int displacement = 0;
boolean hasPlayed = false;
boolean touchedPlayer = false;
int direction;
String temp;
//constructor
public Ghost(int n, int xm, int ym){
number = n;
gx = xm;
gy = ym;
gpx = gx*30;
gpy = gy*30;
direction = int(random(5));
}
void move(){
image(ghost,this.gpx,this.gpy,90,90);
for(int j = 0; j<3; j++){
for(int i = 0; i<3; i++){
if(matrixPosX == this.gx+i && matrixPosY == this.gy+j){
touchedPlayer = true;
};
}
}
/*
for(int l= 0 ; l<3; l++){
switch(this.direction){
case 0: secondaryMatrix[this.gy+3][this.gx+l] = 0;
case 1: secondaryMatrix[this.gy+l][this.gx-1] = 0;
case 2: secondaryMatrix[this.gy-1][this.gx+l] = 0;
case 3: secondaryMatrix[this.gy+l][this.gx+3] = 0;
}
}
*/
if(touchedPlayer && !hasPlayed){
death.play();
hasPlayed = true;
bMusic.stop();
playing = false;
freeze = true;
won = false;
}
//Part to make the ghost move in square
//0 = up, 1 = right, 2 = down, 3 = left
if(counter%10 == 0){
if(this.direction == 0 && this.displacement < 6){
this.gpy -= 30;
this.gy -= 1;
this.displacement += 1;
} else if(this.direction == 1 && this.displacement != 6) {
this.gpx += 30 ;
this.gx += 1;
this.displacement++;
} else if(this.direction == 2 && this.displacement != 6) {
this.gpy += 30;
this.gy += 1;
this.displacement++;
} else if(this.direction == 3 && this.displacement != 6) {
this.gpx -= 30 ;
this.gx -= 1;
this.displacement++;
} else if(this.direction == 3 && this.displacement == 6){
this.direction = 0;
this.displacement = 0;
} else if(this.displacement >= 6) {
this.direction ++;
this.displacement = 0;
}
}
}
}