-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.pde
221 lines (184 loc) · 5.06 KB
/
game.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
/*
* this class performs the gameplay operations
* using objects of other classes, such as fish, obstacle, and fishingLine
*/
class game {
//all fish and obstacles in play are stored here
ArrayList<fish> creatures;
ArrayList<obstacle> things;
int score;
fishingLine myLine;
ArrayList<Integer> bonkedXCoords; //for fish that have been knocked ("bonked") off the fishing line
ArrayList<Integer> bonkedYCoords;
//only used for animations / the images are not of objects in play
PImage penguin;
PImage feesh;
PImage standingFeesh;
int startTime;
int endTime;
int timeLeft;
int minutes;
int seconds;
public game() {
score = 0;
minutes = 0;
seconds = 0;
startTime = 0;
endTime = 0;
timeLeft = 0;
creatures = new ArrayList<fish>();
things = new ArrayList<obstacle>();
bonkedXCoords = new ArrayList<Integer>();
bonkedYCoords = new ArrayList<Integer>();
myLine = new fishingLine();
penguin = loadImage("smallPenguin.png");
feesh = loadImage("fish.png");
standingFeesh = loadImage("uprightFish.png");
}
void displayGamePlay(){
background(255);
//sea background
fill(0, 345, 255);
rect(0, 200, 1000, 700);
displayFisherman();
displayScore();
displayTimer();
//garbage collection on old fish and obstacles
removeOldFish();
removeOldObstacles();
fishActions();
obstacleActions();
spawnNewObjects();
bonkedFish();
}
void displayScore() {
fill(0, 0, 0);
textSize(25);
text("score: " + score, 45, 45);
}
void displayTimer(){
fill(0,0,0);
textSize(25);
minutes = (endTime-millis())/60000;
seconds = ((endTime-millis())/1000) - minutes*60;
text( "time left: " + minutes + ":" + nf(seconds,2) , 10, 90);
}
void displayFisherman() {
//fisherman penguin
image(penguin, 610, 20);
myLine.showPole();
myLine.show();
caughtFishStack();
}
void fishActions() {
for (fish fishy : creatures) {
if (fishy.isOnHook(myLine)) {
fishy.showOnHook(myLine);
for (obstacle tings : things) {
if (tings.hit(myLine)) {
fishy.slippedOffHook(myLine);
bonkedXCoords.add(myLine.getX());
bonkedYCoords.add(myLine.getY());
}
}
} else {
fishy.show();
fishy.swim();
}
}
}
void obstacleActions() {
for (obstacle stuff : things) {
stuff.show();
stuff.move();
}
}
void spawnNewObjects() {
if (frameCount%105==0 && creatures.size() < 10) {
fish baby = new fish();
creatures.add(baby);
}
if (frameCount%120 == 0) {
obstacle trash = new obstacle();
things.add(trash);
}
}
/**
* removes fish that are out of frame or have been caught
* from the game's arraylist of fish
**/
void removeOldFish() {
for (int i=0; i < creatures.size(); i++) {
creatures.get(i).updateInFrame();
if ( creatures.get(i).getInFrame() == false || creatures.get(i).inCooler()) {
if (creatures.get(i).inCooler()) {
myLine.setFishOnHook(false);
}
creatures.remove(i);
i--;
}
}
}
/**
* removes obstacles that are out of frame
* from the game's arraylist of obstacles
**/
void removeOldObstacles() {
for ( int i=0; i < things.size(); i++) {
things.get(i).setRemoveMe();
if ( things.get(i).getRemoveMe() == true ) {
things.remove(i);
i--;
}
}
}
// displays stack of fish that have been caught in upper left corner
void caughtFishStack() {
for (int i=0; i < score; i++) {
if( i < 13 ){
image(feesh, 200, 100-(10*i));
}
}
}
//animates fish zooming away after they have been knocked off the fishing line
void bonkedFish() {
for (int i=0; i < bonkedXCoords.size(); i++) {
bonkedXCoords.set(i, bonkedXCoords.get(i) + 10);
bonkedYCoords.set(i, bonkedYCoords.get(i) + 10);
image(standingFeesh, bonkedXCoords.get(i) - 30, bonkedYCoords.get(i) - 100 );
}
removeFarawayBonkedFish();
}
//prevents fish from continuing to be animated when they have zoomed out of frame
void removeFarawayBonkedFish() {
for (int x=0; x < bonkedXCoords.size(); x++) {
if (bonkedXCoords.get(x) > 1100) {
bonkedXCoords.remove(x);
bonkedYCoords.remove(x);
x--;
}
}
}
void setStartTime(int time){
startTime = time;
endTime = time + 120000;
}
public boolean isTimeLeft(){
if(endTime - millis() > 0){
return true;
}
return false;
}
public fishingLine getMyLine() {
return myLine;
}
public ArrayList<fish> getCreatures() {
return creatures;
}
public void addScore(int add) {
score += add;
}
public int getScore(){
return score;
}
}