-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbreakout_.pde
152 lines (133 loc) · 2.7 KB
/
breakout_.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
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;
// sounds
Minim minim;
AudioPlayer intro, point, bounce, life, win, loss;
// GIF
PImage[] space;
int frame;
//bricks
int [] x; //arrays
int [] y; //arrays
boolean [] alive;
int brickd;
int n;
int tempx, tempy;
// colors
color pink = #FF008D;
color green = #00FF3D;
color white = #FFFFFF;
color brown = #45201E;
color red = #A02D03;
color truered = #FF4B4B;
color orange = #FA8303;
color blue = #03ADFA;
color yellow = #E8BB3F;
color darkyellow = #FFAC12;
color black = #030303;
color darkblue = #272D4D;
color purple = #F50A60; //#B83564;
color mango = #FF6A5A;
// entity varables
float bx, by, bd; // paddle
float ballx, bally, balld; //ball
float vx, vy; // target velocity
float paddld;
// lives
int lives, timer, score;
// modes
int mode;
final int INTRO = 1;
final int GAME = 2;
final int PAUSE = 3;
final int GAMEOVER = 4;
PFont font;
void setup() {
// load animated gif
space = new PImage[9];
int j = 0;
while (j < 9) {
space[j] = loadImage("frame_" +j+ "_delay-0.04s.gif");
j = j + 1;
}
//initalize bricks
brickd = 50;
n = 22;
x = new int [n];
y = new int [n];
alive = new boolean[n];
tempx = 100; // starting point for bricks
tempy = 100; // starting point for bricks
int i = 0;
while (i < n) {
x[i] = tempx;
y[i] = tempy;
alive[i] = true;
tempx = tempx + 100;
i = i + 1;
//second row
if (tempx == 800) {
tempx = 100;
tempy = tempy + 100;
tempx = tempx + 50;
}
// third row
if (tempx == 750) {
tempx = 100;
tempy = tempy + 100;
tempx = tempx + 101;
}
// fourth row
if (tempx == 701) {
tempx = 100;
tempy = tempy + 100;
tempx = tempx + 150;
}
}
// general setup
size(800, 600);
mode = INTRO;
// initalize paddle
bx = width/2;
by = 600;
bd = 100;
// initialize ball
ballx = width/2;
bally = 500;
balld = 40;
vx = vx + 10;
vy = vy + 10;
paddld = 100;
// initialize score
lives = 3;
timer = 100;
score = 0;
// font
font = loadFont("Tahoma-Bold-48.vlw");
textFont(font, 48);
//minim
minim = new Minim(this);
intro = minim.loadFile("intro.wav");
point = minim.loadFile("beep.wav");
life = minim.loadFile("boop.wav");
win = minim.loadFile("win.wav");
loss = minim.loadFile("failure.wav");
bounce = minim.loadFile("wall.wav");
}
void draw() {
if (mode == INTRO) {
intro();
} else if (mode == GAME) {
game();
} else if (mode == PAUSE) {
pause();
} else if (mode == GAMEOVER) {
gameover();
} else {
println("Mode error: " + mode);
}
}