-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlevel1.pde
214 lines (190 loc) · 4.33 KB
/
level1.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
class level1{
float time;
int score=0;
Frog frog;
path paths[];
Coin coin[];
int lives=4;
Timer timer;
int index=0;
rectangle rect,rect2,rect3,rect4;
PImage water;
level1(){
water = loadImage("data/images/water.jpg");
water.resize(680,680);
this.score=0;
this.timer = new Timer(65);
this.frog = new Frog(0.15*grid, height-0.65*grid, 0.65*grid);
this.paths = new path[36];
this.coin = new Coin[16];
rect=new rectangle(grid,height-grid,width-grid,grid);
rect2=new rectangle(0,height-3*grid,width-grid,grid);
rect3=new rectangle(grid,height-5*grid,width-grid,grid);
rect4=new rectangle(0,height-7*grid,width-grid,grid);
draw_path();
}//end constractor
float x;
void coinarray(){
int k=0;
for ( int i =0; i<4; i++){
for(int j =0; j<4; j++){
x=2*grid + j*85+50;
float y= height- 1.75*1*grid-i*2*1*grid+20;
coin[k++]= new Coin(x , y, 60);
}
}
}//end coinarray.
void drawlevel1(){
background(water);
rect.DrawRec();
rect2.DrawRec();
rect3.DrawRec();
rect4.DrawRec();
for (path pat : paths) {
pat.show();
//when finsh level one
if(frog.intersect(paths[29])){
frog.x=-100;
for (Coin coins : Level1.coin) {
coins.x=-100;
coins.y=-100;
}
gameScreen=2; //level2
level2.lives=4;
resetGame();
redraw();
}
if(frog.intersect(rect) || frog.intersect(rect2) || frog.intersect(rect3) || frog.intersect(rect4))
{
if (this.lives == 1 ){
for (Coin coins : coin) {
coins.x=-100;
coins.y=-100;
}
frog.x=-100;
l=1;
gameScreen=4;
}
else{
frog.x=0.15*grid;
frog.y=height-0.65*grid;
resetGame();
}
}
}
timer.countDown();
time=timer.getTime();
if(time<=0 && this.lives==1){
for (Coin coins : coin) {
coins.x=-100;
coins.y=-100;
}
frog.x=-100;
l=1;
gameScreen =4; //game over
}
else if(time<=0)
{
frog.x=0.15*grid;
frog.y=height-0.65*grid;
resetGame();
}
for (Coin coins : coin) {
coins.showCoin();
if (frog.intersect(coins)){
coins.x=-100;
coins.y=-100;
score+=1;
}
}
//frog
if (keyCode == UP){
frog.showUp();
}
else if (keyCode == LEFT){
frog.showLeft();
}
else if (keyCode == DOWN){
frog.showDown();
}
else if (keyCode == RIGHT){
frog.showRight();
}
else if (keyCode == ENTER){
timer.stopTime();
resume resume=new resume(140,140,400,400);
resume.show_resume();
}
else if(keyCode== ' ' && (lives==0)){
gameScreen=1;
this.lives=4;
resetGame();
redraw();
}
else {
frog.showUp();
}
play(1); //inital wrtite level one and time in screen
}
//end draw
void draw_path()
{
//row1
int index=0;
for (int i = 0; i < 2; i++) {
float x =0;
float y= height-1*grid-1*i*grid;
paths[index] = new path(x, y, 1*grid, 1*grid);
index++;
}
//row2
for (int i = 0; i < 7; i++) {
float x = 1*grid+i*1*grid;
float y= height-2*1*grid;
paths[index] = new path(x, y, grid*1, grid*1);
index++;
}
//row3
for (int i = 0; i < 2; i++) {
float x = width-1*grid;
float y= height-3*1*grid-1*i*grid;
paths[index] = new path(x, y, grid*1, grid*1);
index++;
}
//row4
for (int i = 0; i < 7; i++) {
float x = width-2*1*grid-i*grid*1;
float y= height-4*1*grid;
paths[index] = new path(x, y, grid*1, grid*1);
index++;
}
//row5
for (int i = 0; i < 2; i++) {
float x = 0;
float y= height-5*1*grid-i*grid*1;
paths[index] = new path(x, y, grid*1, grid*1);
index++;
}
//row6
for (int i = 0; i < 7; i++) {
float x = 1*grid+i*1*grid;
float y= height-6*grid;
paths[index] = new path(x, y, grid*1, grid*1);
index++;
}
//row7
for (int i = 0; i < 2; i++) {
float x = width-1*grid;
float y= height-7*1*grid-i*grid*1;
paths[index] = new path(x, y, grid*1, grid*1);
index++;
}
//row8
for (int i = 0; i < 7; i++) {
float x =i*grid*1;
float y= 0;
paths[index] = new path(x, y, grid*1, grid*1);
index++;
}
}
}