-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbounce-game.pde
More file actions
329 lines (304 loc) · 8.35 KB
/
bounce-game.pde
File metadata and controls
329 lines (304 loc) · 8.35 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
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
float xbola = 20, ybola = 60, movbolax = 2, movbolay = 2; //bola
float xbar, movbar=35; //barra
float speed = 1; //velocidade
float xmissile = random(60, 520), ymissile = -80, ymovmissile = 2; //missil
int pontos, vidas = 3;
boolean dead = false; //estar ou não morto
PImage background, bar, bola, unmutedm, unmuteds, mutedm, muteds, block, block2, block3, missile;
//bar; //70x20
//bola; //20x20
//mutedm; //muted music
//muteds; //muted sounds
//block; //60x15 - topo - 50 pontos
//block2; //10x80 laterais - 25 pontos
//block3; //10x10 cantos - 100 pontos
//missile; //60x80
//sons e musica
import ddf.minim.*;
Minim minim;
AudioPlayer song, pointsound, loselife, gameover;
void setup() {
size(600, 400);
xbola = 620;
ybola = 420;
movbolax = 2;
movbolay = 2;
xmissile = random(60, 520);
ymissile = -80;
ymovmissile = 2;
pontos = 0;
vidas = 3;
dead = true;
minim = new Minim(this);
gameover = minim.loadFile("gameover.mp3");
loselife = minim.loadFile("loselife.mp3");
pointsound = minim.loadFile("pointsound.mp3");
song = minim.loadFile("song.mp3");
song.play();
song.loop();
background = loadImage("background.png");
background(background);
block = loadImage("block.png");
block2 = loadImage("block2.png");
block3 = loadImage("block3.png");
bar = loadImage("bar.jpg");
xbar=width/2-35;
bola = loadImage("bola.png");
mutedm = loadImage("mutedm.png");
unmutedm = loadImage("unmutedm.png");
muteds = loadImage("muteds.png");
unmuteds = loadImage("unmuteds.png");
missile = loadImage("missile.png");
frameRate(60);
}
void draw() {
background(background);
image(block, 270, 40); //blocos
image(block2, 0, 200);
image(block2, 590, 200);
image(block3, 590, 40);
image(block3, 0, 40);
textSize(15);
textAlign(LEFT);
fill(#666666);
text("Score: " + pontos, 12, 25);
text("Lives: " + vidas, 530, 25);
image(bola, xbola, ybola); //bola
xbola += movbolax * speed; // movimento em x da bola em função da velocidade
ybola += movbolay * speed; // movimento em y da bola em função da velocidade
//velocidade da bola e dos misseis em funçao dos pontos
if (pontos < 100)
speed = 1;
if ((pontos >= 100) && (pontos < 200)) {
speed = 1.1;
image(missile, xmissile, ymissile);
ymissile += ymovmissile * speed;
}
if ((pontos >= 200) && (pontos < 300)) {
speed = 1.2;
image(missile, xmissile, ymissile);
ymissile += ymovmissile * speed;
}
if ((pontos >= 300) && (pontos < 400)) {
speed = 1.3;
image(missile, xmissile, ymissile);
ymissile += ymovmissile * speed;
}
if ((pontos >= 400) && (pontos < 500)) {
speed = 1.4;
image(missile, xmissile, ymissile);
ymissile += ymovmissile * speed;
}
if ((pontos >= 500) && (pontos < 600)) {
speed = 1.5;
image(missile, xmissile, ymissile);
ymissile += ymovmissile * speed;
}
if ((pontos >= 600) && (pontos < 700)) {
speed = 1.6;
image(missile, xmissile, ymissile);
ymissile += ymovmissile * speed;
}
if ((pontos >= 700) && (pontos < 800)) {
speed = 1.7;
image(missile, xmissile, ymissile);
ymissile += ymovmissile * speed;
}
if ((pontos >= 800) && (pontos < 900)) {
speed = 1.8;
image(missile, xmissile, ymissile);
ymissile += ymovmissile * speed;
}
if ((pontos >= 900) && (pontos < 1000)) {
speed = 1.9;
image(missile, xmissile, ymissile);
ymissile += ymovmissile * speed;
}
if ((pontos >= 1000) && (pontos < 2000)) {
speed = 2;
image(missile, xmissile, ymissile);
ymissile += ymovmissile * speed;
}
if ((pontos >= 2000) && (pontos < 3000)) {
speed = 3;
image(missile, xmissile, ymissile);
ymissile += ymovmissile * speed;
}
if (pontos >= 3000) {
speed = 4;
image(missile, xmissile, ymissile);
ymissile += ymovmissile * speed;
}
//missil começar num x aleatorio
if (ymissile >= 480) {
ymissile = -80;
xmissile = random(60, 520);
}
//missil bate na barra // 70x20 barra / 60x80 missil
if (!dead && (xmissile + 60 >= xbar) && (xmissile <= xbar + 70) && (ymissile + 60 >= 380) && (ymissile <= 390)) {
vidas = vidas - 1;
dead = true;
xbola = 1000;
ybola = 1000;
loselife.play();
loselife.rewind();
ymovmissile = 0;
xmissile = 700;
}
if ((xbola >= width-20) || (xbola <= 0)) //reflexão da bola na janela em x
movbolax = -movbolax;
if (ybola <= 40) //reflexão da bola na janela em y
movbolay = -movbolay;
if (!dead && ybola >= height) { //perder vidas
vidas = vidas - 1;
dead = true;
loselife.play();
loselife.rewind();
ymovmissile = 0;
xmissile = 700;
}
//game over e restart
if (vidas == 0) {
gameover.play();
song.pause();
textSize(50);
textAlign(CENTER, CENTER);
text("GAME OVER", width/2, height/2-50);
textSize(30);
text("PRESS R TO RESTART", width/2, height/2);
} else if (dead) {
textSize(30);
textAlign(CENTER, CENTER);
text("PRESS SPACE TO START", width/2, height/2);
}
image(bar, xbar, 380); //barra
//pontos ao bater com a bola na barra
if ((xbola + 20 >= xbar) && (xbola <= xbar + 70) && (ybola + 20 > 380) && (ybola + 20 < 390)) { //reflexão da bola na barra
movbolay = -movbolay; //inverter sentido vertical
ybola--; //para a bola não ficar presa (bola sobe)
pontos+=10; //a cada reflexão ganha 1 ponto
pointsound.play();
pointsound.rewind();
if (((xbola + 20 >= xbar-10) && (xbola + 20 <= xbar+10)) || ((xbola >= xbar+60) && (xbola <= xbar+70)))
movbolax = -movbolax; //inverter sentido horizontal
}
//pontos ao bater no bloco do topo
if ((xbola + 20 >= 270) && (xbola <= 270 + 60) && (ybola >= 40) && (ybola <= 55)) {
movbolay = -movbolay;
ybola++;
pontos+=50;
pointsound.play();
pointsound.rewind();
if (((xbola + 20 >= 270) && (xbola + 20 <= 280)) || ((xbola >= 320) && (xbola <= 330)))
movbolax = -movbolax;
}
//pontos ao bater no bloco lateral esquerdo
if ((xbola >= 0) && (xbola <= 0 + 10) && (ybola + 20 >= 200) && (ybola <= 280)) {
movbolax = -movbolax;
xbola++;
pontos+=25;
pointsound.play();
pointsound.rewind();
if ((ybola + 20 >= 200) && (ybola + 20 <= 210)) {
movbolay = -movbolay;
ybola--;
}
if ((ybola >= 270) && (ybola <= 280)) {
movbolay = -movbolay;
ybola++;
}
}
//pontos ao bater no bloco lateral direito
if ((xbola + 20 >= 590) && (xbola + 20 <= 590 + 10) && (ybola + 20 >= 200) && (ybola <= 280)) {
movbolax = -movbolax;
xbola--;
pontos+=25;
pointsound.play();
pointsound.rewind();
if ((ybola + 20 >= 200) && (ybola + 20 <= 210)) {
movbolay = -movbolay;
ybola--;
}
if ((ybola >= 270) && (ybola <= 280)) {
movbolay = -movbolay;
ybola++;
}
}
//pontos ao bater no bloco do canto esquerdo
if ((xbola >= 0) && (xbola <= 0 + 10) && (ybola >= 40) && (ybola <= 50)) {
movbolay = -movbolay;
movbolax = -movbolax;
ybola++;
xbola++;
pontos+=100;
pointsound.play();
pointsound.rewind();
}
//pontos ao bater no bloco do canto direito
if ((xbola + 20 >= 590) && (xbola + 20 <= 590 + 10) && (ybola >= 40) && (ybola <= 50)) {
movbolay = -movbolay;
movbolax = -movbolax;
ybola--;
xbola--;
pontos+=100;
pointsound.play();
pointsound.rewind();
}
//imagem para muted music e unmuted music
if (song.isMuted()) {
image(mutedm, 0, 0);
} else {
image(unmutedm, 0, 0);
}
//imagem para muted sounds e unmuted sounds
if (pointsound.isMuted()) {
image(muteds, 0, 0);
} else {
image(unmuteds, 0, 0);
}
}
//movimento da barra
void keyPressed() {
if (dead && keyCode == ' ' && vidas>0) {
dead = false;
xbola = 20;
ybola = 60;
ymovmissile = 2;
xmissile = random(60, 520);
ymissile = -80;
}
if (keyCode == RIGHT)
xbar += movbar;
if (keyCode == LEFT)
xbar -= movbar;
if (keyCode == 'R') {
song.pause();
setup();
}
//limites da barra
if (xbar<=0)
xbar=0;
if (xbar>=width-71)
xbar=width-71;
//MUTE E UNMUTE MUSIC
switch (keyCode) {
case 'M':
if (song.isMuted())
song.unmute();
else
song.mute();
}
//MUTE E UNMUTE SOUNDS
switch (keyCode) {
case 'S':
if (pointsound.isMuted()) {
pointsound.unmute();
gameover.unmute();
loselife.unmute();
} else {
pointsound.mute();
gameover.mute();
loselife.mute();
}
}
}