-
Notifications
You must be signed in to change notification settings - Fork 0
/
pac.pde
83 lines (71 loc) · 1.71 KB
/
pac.pde
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
81
82
83
float pacDiameter = TILE_SIZE*.9;
float curPacSpeed = PAC_SPEED;
class Pac extends Man {
int lives;
float mouthState;
int mouthDirection;
float mouthAngle;
Pac() {
initialize();
lives = 3;
inBox = false;
isGhost = false;
}
void initialize() {
loc = new PVector(10.0,7.0);
direction = new PVector(1,0);
moveRequested = 0;
lastMove = 2;
moving = false;
speed = curPacSpeed;
mouthState = 0.0;
mouthDirection = 1;
inTunnel = false;
}
void update() {
updateMove();
if (!inTunnel) {
int curX = round(loc.x);
int curY = round(loc.y);
if (!level[curY][curX].eaten && (level[curY][curX].type == 'a' || level[curY][curX].type == 'A')) {
level[curY][curX].eaten = true;
dotsEaten++;
addScore(10);
if (level[curY][curX].dotType == 2) {
blinky.frighten();
pinky.frighten();
inky.frighten();
clyde.frighten();
phaseTimer += frightenedTime;
}
}
}
}
void drawPac() {
PVector drawLoc = getLoc(loc.y,loc.x);
ellipseMode(CENTER);
stroke(0);
fill(#FFF708);
// move mouth
if (lastMove==3) {
// SOUTH
mouthAngle = PI/2;
} else if (lastMove==1) {
// NORTH
mouthAngle = 3*PI/2;
} else if (lastMove==2) {
// EAST
mouthAngle = 0;
} else {
// WEST
mouthAngle = PI;
}
if (mouthState >= 1) {
mouthDirection = -1;
} else if (mouthState <= 0) {
mouthDirection = 1;
}
mouthState += 0.04*mouthDirection;
arc(drawLoc.x, drawLoc.y, pacDiameter, pacDiameter, mouthAngle+PI*mouthState/4, mouthAngle+2*PI-PI*mouthState/4);
}
}