-
Notifications
You must be signed in to change notification settings - Fork 0
/
PacManMotion5.pde
260 lines (211 loc) · 5 KB
/
PacManMotion5.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
import japplemenubar.*;
/* OpenProcessing Tweak of *@*http://www.openprocessing.org/sketch/40274*@* */
/* !do not delete the line above, required for linking your tweak if you re-upload */
import ddf.minim.*;
Minim minim;
AudioSample deathSound, introSound;
//import org.openkinect.*;
import org.openkinect.freenect.*;
import org.openkinect.processing.*;
// Showing how we can farm all the kinect stuff out to a separate class
KinectTracker tracker;
// Kinect Library object
Kinect kinect;
//import fullscreen.*;
//FullScreen fs;
int paused = 1;
Pac pac;
Blinky blinky;
Pinky pinky;
Inky inky;
Clyde clyde;
color yellow = #FFF708;
boolean levelStarted = false;
int timer, phaseTimer;
int phaseTimes[] = {6000,14000,6000,14000,4000,999999};
int phaseModes[] = {0,1,0,1,0,1};
int curLevel = 1, curPhase = 0;
float PAC_SPEED = 4.5/60.0;
int inkyDots, clydeDots;
PFont font,font2;
int score = 0, hiscore = 0;
boolean animation = true;
boolean gameStarted = false;
boolean invincible = false;
boolean enableHiscore = false;
boolean startGame = false;
void setup() {
//fullScreen();
size(640,480);
//frame.setBackground(new java.awt.Color(0,0,0));
frameRate(30);
// create the fullscreen object
//fs = new FullScreen(this);
// enter fullscreen mode
//fs.enter();
smooth();
readMapFile();
font = loadFont("GungsuhChe-20.vlw");
font2 = loadFont("ARDESTINE-50.vlw");
minim = new Minim(this);
deathSound = minim.loadSample("pacman_death.wav");
introSound = minim.loadSample("pacman_beginning.wav");
kinect = new Kinect(this);
tracker = new KinectTracker();
setupGame();
}
void setupGame() {
pac = new Pac();
blinky = new Blinky();
pinky = new Pinky();
inky = new Inky();
clyde = new Clyde();
score = 0;
setupLevel();
curLevel = 1;
}
void setupLevel() {
curPhase = 0;
curLevel++;
initializeDots();
dotsEaten = 0;
// set level parameters
if (curLevel < 4) {
curPacSpeed = .8*PAC_SPEED;
curGhostSpeed = .7*PAC_SPEED;
frightenedTime = 9000;
inkyDots = 90;
clydeDots = 130;
} else if (curLevel >= 4 && curLevel < 7) {
curPacSpeed = .9*PAC_SPEED;
curGhostSpeed = .82*PAC_SPEED;
frightenedTime = 8000;
inkyDots = 70;
clydeDots = 110;
} else if (curLevel >= 7 && curLevel < 10) {
curPacSpeed = PAC_SPEED;
curGhostSpeed = .95*PAC_SPEED;
frightenedTime = 7000;
inkyDots = 50;
clydeDots = 90;
} else {
curPacSpeed = .9*PAC_SPEED;
curGhostSpeed = .92*PAC_SPEED;
frightenedTime = 5000;
inkyDots = 30;
clydeDots = 70;
}
reset();
}
void draw() {
background(0);
fill(yellow);
// Run the tracking analysis
tracker.track();
// Show the image
tracker.display();
move();
if (key=='g') {
startLevel();
}
drawLevel();
drawHeader();
if (!animation)
runGame();
else
runAnimation();
if (paused == 0) {
loop();
} else if (paused == 1) {
noLoop();
fill(yellow);
textAlign(CENTER);
text("CLICK TO START!", width/2, height/2 + 20);
}
}
void runGame() {
if (levelStarted) {
pac.update();
blinky.updateCondition();
pinky.updateCondition();
inky.updateCondition();
clyde.updateCondition();
} else {
textFont(font,20);
fill(yellow);
text("Get ready!", width/2, 100);
if (millis() - readyTimer > 2000) {
startLevel();
}
}
pac.drawPac();
blinky.drawGhost();
pinky.drawGhost();
inky.drawGhost();
clyde.drawGhost();
drawTunnel();
gameUpdate();
}
void gameUpdate() {
if (levelStarted) {
if (millis() - phaseTimer > phaseTimes[curPhase] && curPhase < 5) {
// change phase
phaseTimer = millis();
curPhase++;
blinky.mode = phaseModes[curPhase];
blinky.reverseGhost = true;
pinky.mode = phaseModes[curPhase];
pinky.reverseGhost = true;
inky.mode = phaseModes[curPhase];
inky.reverseGhost = true;
clyde.mode = phaseModes[curPhase];
clyde.reverseGhost = true;
}
if (millis() - timer > 1000) {
// release pinky
pinky.moving = true;
}
if (dotsEaten >= inkyDots) {
// release inky
inky.moving = true;
}
if (dotsEaten >= clydeDots) {
// release clyde
clyde.moving = true;
}
// did we finish the level??
if (dotsEaten >= totalDots) {
// if (dotsEaten >= 3) {
animation = true;
levelCompleteAnimation = true;
levelCompleteAngle = 0;
}
}
}
void drawHeader() {
fill(textC);
textFont(font,30);
textAlign(CENTER);
// score
text("SCORE", 50, 30);
textFont(font,25);
text(score,50,62);
// level
textFont(font,30);
text ("LEVEL " + curLevel, width/2, 30);
// lives
text("LIVES", width - 50, 30);
int offSet = 0;
for (int i=0; i<pac.lives; i++) {
// yellow circle
fill(#FFF708);
noStroke();
arc(width-22-offSet, 55, 20, 20, PI/4, 2*PI-PI/4);
offSet += 30;
}
}
void stop() {
deathSound.close();
introSound.close();
super.stop();
}