-
Notifications
You must be signed in to change notification settings - Fork 0
/
Follow_me.pde
293 lines (239 loc) · 5.35 KB
/
Follow_me.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
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
float coinGain;
float ballNumber = 3;
int score = 0;
int die = 0;
int gameScreen = 0;
PImage powerCoin;
Paddle paddle;
PImage SpiderSp;
PGraphics pg;
//import processing.sound.*;
//SoundFile cfile;
//SoundFile sfile;
spider Spider[] = new spider [3];
Bball bball[]= new Bball [2];
pCoins Pcoins[]= new pCoins [4];
void setup() {
size(800, 600);
pg = createGraphics(width, height);
pg.beginDraw();
for ( int i = 0; i < height; i ++) {
pg.stroke(i-150, i-150, i);
pg.line(0, i, width, i);
}
pg.endDraw();
powerCoin = loadImage("papaCoin.png");
SpiderSp = loadImage("SpiderSpritenew.png");
paddle = new Paddle(0, 0, 120, 10);
bball[0] = new Bball(width/2, 0, 2, 3);
bball[1] = new Bball(width/4, 0, 2, 2);
//bball[2] = new Bball(width/4,0,2,2);
for (int i = 0; i < Pcoins.length; i ++) {
Pcoins[i] = new pCoins(random(width), random(height), 4);
}
for ( int i = 0; i < Spider.length; i ++) {
Spider[i] = new spider(random(width), 0, random(250, 350), 480);
}
//cfile = new SoundFile(this, "coinSound.wav");
//sfile = new SoundFile(this, "SpiderHit.wav");
}
void draw() {
// Display the contents of the current screen
if (gameScreen == 0) {
initScreen();
} else if (gameScreen == 1) {
gameScreen();
} else if (gameScreen == 2) {
gameOverScreen();
}
}
void initScreen() {
background(255, 204, 0);
textSize(32);
fill(25, 32, 152);
textAlign(CENTER);
text("click to start! ", width/2, height/2);
// codes of initial screen
}
void gameScreen(){
image(pg, 0, 0);
for ( int i = 0; i < bball.length; i ++) {
bball[i].display();
bball[i].bounce();
bball[i].BallHitPaddle(paddle);
}
for (int i = 0; i < Pcoins.length; i ++) {
Pcoins[i].coinDisplay();
Pcoins[i].coinFall();
Pcoins[i].coinHitPaddle(paddle);
}
for (int i = 0; i < Spider.length; i ++) {
Spider[i].showSpider();
Spider[i].spiderHitPaddle(paddle);
}
paddle.show();
paddle.movePaddle();
textSize(20);
text("score " + score, width/8, 30);
if (die > 3) {
gameOver();
}
// game contents
}
void gameOverScreen() {
background(51);
textSize(32);
textAlign(CENTER);
fill(255, 178, 23);
text("score " + score, width/2, height/2);
String screen = "Looks like the spider ate you!";
text(screen, width/2, height/4); // Text wraps within text box
// codes for game over screen
}
/********* INPUTS *********/
public void mousePressed() {
// if we are on the initial screen when clicked, start the game
if (gameScreen==0) {
startGame();
}
}
/********* OTHER FUNCTIONS *********/
// This method sets the necessary variables to start the game
void startGame() {
gameScreen=1;
}
void gameOver(){
gameScreen=2;
}
class Paddle {
float w;
float h;
float px;
float py;
Paddle ( float px, float py, float w, float h) {
this.px=px;
this.py=py;
this.w=w;
this.h=h;
}
void show() {
rectMode(CENTER);
fill(191, 78, 8);
rect(px, py, w, h );
}
void movePaddle() {
px = constrain(mouseX, 0, width-w/2);
py = 500;
}
}
class Bball {
float bx;
float by;
float bxs;
float bys;
float r;
Bball(float x, float y, float xs, float ys) {
this.bx = x;
this.by = y;
this.bxs = xs;
this.bys = ys;
r = 15;
}
void display() {
noStroke();
fill(7, 121, 59);
circle(bx, by, r*2);
}
void bounce() {
bx = bx + bxs;
by = by + bys;
if (bx < 0 || bx > width - 10) {
bxs = -bxs;
}
if (by < 0) {
bys = -bys;
}
}
//void GoToNewLevel() {
// if (ballNumber = 0){
// }
//}
void BallHitPaddle(Paddle p) {
if ( by + r > p.py - (p.h/2) && by - r < p.py + (p.h/2) &&(bx - r > (p.px-p.w/2)
|| bx + r > (p.px-p.w/2))&& (bx + r < (p.px-p.w/2) + p.w || bx - r < (p.px-p.w/2) + p.w)) {
score ++;
bys = abs(bys)*-1;
}
}
}
class pCoins {
boolean cdebouncer;
float cx;
float cy;
float cys;
int cr;
pCoins(float cx, float cy, float cys) {
this.cx = cx;
this.cy = cy;
this.cys = cys;
cr = 25;
powerCoin.resize(cr, cr);
}
void coinDisplay() {
if (cdebouncer == false) {
image(powerCoin, cx, cy);
}
}
void coinFall() {
cy = cy + cys;
if (cy > height) {
cdebouncer = false;
cy = -cr*2;
cx = random(width);
}
}
void coinHitPaddle(Paddle p) {
if ( cy + cr == p.py - (p.h/2) && (cx + cr > (p.px-p.w/2) && cx - cr < (p.px+p.w/2)) ) {
cdebouncer = true;
score ++;
//cfile.play();
}
}
}
class spider {
boolean sdebouncer;
float Sx;
float Sy;
float Sx2;
float period;
float amplitude;
int Ss;
spider(float Sx, float Sy, float period, float amplitude) {
this.Sx = Sx;
this.Sy = Sy;
this.period = period;
this.amplitude =amplitude;
Ss = 40;
SpiderSp.resize(Ss, Ss);
}
void showSpider() {
fill(250);
strokeWeight(10);
line(0, 0, 0, Sy);
image(SpiderSp, Sx, Sy);
Sy = abs(amplitude*sin((frameCount/period)*TWO_PI));
}
void update() {
}
void spiderHitPaddle(Paddle p) {
if ( Sy+40 > p.py - (p.h/2) && sdebouncer == false && (Sx > (p.px-p.w/2) && Sx < (p.px+p.w/2))) {
sdebouncer = true;
score --;
die ++;
//sfile.stop();
//sfile.play();
} else if (sdebouncer == true && Sy < height/2 ) {
sdebouncer = false;
}
}
}