-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYaqi_FinalProjectDraft_Fishing_Master.pde
281 lines (223 loc) · 5.72 KB
/
Yaqi_FinalProjectDraft_Fishing_Master.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
//Yaqi Qiu Final Project -- Fishing Master (Game)
//I used object, loop, conditional, and intersect features as the main part of this game.
//I also add timer, Images, and sound to make this game more interesting.
//Pleasse enjoy it!
import ddf.minim.*;
//image
PImage sea;
PImage begin;
PImage state1;
PImage coinbag;
PImage end;
PImage end2;
PImage button2;
PFont heading;
PFont f;
//declare all sound variables
Minim minim;
//sound effects
AudioPlayer background_music;
AudioPlayer match;
AudioPlayer boom;
AudioPlayer coin;
AudioPlayer failed;
AudioPlayer congratulation;
//declare all class variables
Net net;
Fish [] fishes;
Boom [] booms;
Money [] money;
Bubbles[] bubbles;
int totalFish = 0;
int totalBoom = 0;
int totalMoney = 0;
int totalBubbles = 0;
//coin number
public int point = 0;
//timer
Timer timer;
public int totalTime;
//game state
int gameState = 0;
void setup(){
size(970, 545);
smooth();
minim = new Minim(this);
sea = loadImage("background.png");
begin = loadImage("state0.jpg");
state1 = loadImage("state1.jpg");
coinbag = loadImage("money.png");
end = loadImage("state3.jpg");
end2 = loadImage("end2.jpg");
button2 = loadImage("button2.png");
background_music = minim.loadFile("seaworld.mp3");
match = minim.loadFile("match.mp3");
boom = minim.loadFile("boom.wav");
coin = minim.loadFile("coin.wav");
failed = minim.loadFile("failed.mp3");
congratulation = minim.loadFile("Congratulation.mp3");
fishes = new Fish[20];
for (int i = 0; i < fishes.length; i++){
fishes[i] = new Fish( random(-1000,-100), random(150,400));
}
booms = new Boom[4];
for (int i = 0; i < booms.length; i++){
booms[i] = new Boom( random(150,780), random(-500, 0));
}
money = new Money[2];
for (int i = 0; i < money.length; i++){
money[i] = new Money( random(200,700), random(-1500, 1000));
}
bubbles = new Bubbles[20];
for (int i = 0; i < bubbles.length; i++){
bubbles[i] = new Bubbles(random(width), 550, random(10,20));
}
net = new Net(mouseX, mouseY, 25);
timer = new Timer(20);
}//setup
void draw(){
gameBegin();
gameHelp();
game();
gameEnd();
gameFailed();
}//draw
void gameBegin () {
if (gameState == 0){
background(255);
image(begin, 0, 0);
}//state0
}//gameBegin
void gameHelp () {
if (gameState == 1){
background(255);
image (state1,0,0);
}//state1
}//gameHelp
void game () {
if (gameState == 2){
background(255);
image(sea, 0,0);
noCursor();
image(coinbag, 18,18);
f = loadFont("Breathe-Regular-26.vlw");
textAlign(CENTER);
fill(252,109,25);
textFont(f, 24);
text("Coin:", 130, 56);
text(point, 170, 56);
timer.update();
if(timer.totalTime >= 10){
text("Time: 00 : " + timer.totalTime, 165, 85);
} else {
text("Time: 00 : 0" + timer.totalTime, 165, 85);
}
//fish
for( int i = 0; i < fishes.length; i++){
fishes[i].move();
fishes[i].display();
if (net.intersect(fishes[i])){
fishes[i].caught();
match = minim.loadFile("match.mp3");
match.play();
}
}
//boom
for( int i = 0; i < booms.length; i++){
booms[i].move();
booms[i].display();
if (net.intersect(booms[i])){
booms[i].caught();
boom = minim.loadFile("boom.wav");
boom.play();
gameState=4;
background_music.close();
}
}
//moneybag
for( int i = 0; i < money.length; i++){
money[i].move();
money[i].display();
if (net.intersect(money[i])){
money[i].caught();
coin = minim.loadFile("coin.wav");
coin.play();
}
}
//bubbles
for (int i = 0; i < bubbles.length; i++){
bubbles[i].move();
bubbles[i].display();
}
//hand
net.move(mouseX, mouseY);
net.display();
}//state2
}//game
void gameEnd () {
if(timer.finished){
gameState=3;
background_music.close();
}
if (gameState == 3){
cursor();
//background(255);
image(end,0,0);
image(button2, 430, 300);
heading = loadFont("AGaramondPro-BoldItalic-58.vlw");
textFont(heading, 72);
textAlign(CENTER);
fill(255, 112, 3);
//text("Congratulation!", 350, 250);
textFont(heading, 42);
strokeWeight(8);
textAlign(CENTER);
fill(255, 166, 0);
text("You got " + point, 210, 340);
text("coins", 362, 340);
congratulation.play();
}//state3
}//gameEnd
void gameFailed () {
if (gameState == 4){
cursor();
image(end2, 0,0);
image(button2, 650, 420);
heading = loadFont("AGaramondPro-BoldItalic-58.vlw");
textFont(heading, 72);
textAlign(CENTER);
fill(255);
text("You Failed...", width/2, 320);
//failed = minim.loadFile("failed.mp3");
failed.play();
}//state4
}//gameFailed
void mousePressed(){ //switch game in different states
if (gameState == 0 && mouseY > 410 && mouseY < 470){
if (mouseX > 610 && mouseX < 680){
gameState = 1;
}else if (mouseX > 310 && mouseX < 410){
gameState = 2;
timer.start();
point = 0;
background_music = minim.loadFile("seaworld.mp3");
background_music.play();
}
}
if (gameState == 1 && mouseX > 460 && mouseX < 550 && mouseY > 410 && mouseY < 470){
gameState = 0;
timer = new Timer(20);
timer.start();
}
if (gameState == 3 && mouseX > 430 && mouseX < 570 && mouseY > 280 && mouseY < 360 ){
gameState = 0;
timer = new Timer(20);
timer.start();
congratulation.close();
}
if (gameState == 4 && mouseX > 650 && mouseX < 780 && mouseY > 420 && mouseY < 500 ){
gameState = 0;
timer = new Timer(20);
timer.start();
}
}//mousepressed