1if(al_key_down(&keystate, ALLEGRO_KEY_F
))
2 {
3 player.x
= 2700;
4 player.y
= 535;
5 player.lives
= 10;
6 coinCount
= 11;
7 enemyKilled
= 11;
8 gotKey
= true;
9 }
10 if(al_key_down(&keystate, ALLEGRO_KEY_ENTER
) && level
== LVL2
)
11 {
12 changeLevel
(level, LV2P2
);
13 lv2P2
= true;
14 }
15 if(al_key_down(&keystate, ALLEGRO_KEY_BACKSPACE
) && level
== LV2P2
)
16 {
17 changeLevel
(level, LVL2
);
18 }
19 if(al_key_down(&keystate, ALLEGRO_KEY_D
))
20 {
21 velX
= player.speed
;
22 player.dir
= RIGHT
;
23 }
24 else if(al_key_down(&keystate, ALLEGRO_KEY_A
))
25 {
26 velX
= -player.speed
;
27 player.dir
= LEFT
;
28 }
29 else
30 {
31 velX
= 0;
32 active
= false;
33 }
34 if(al_key_down(&keystate, ALLEGRO_KEY_W
) && jump
)
35 {
36 velY
= -jumpSpeed
;
37 jump
= false;
38 al_play_sample(jumpSound,
1.
0,
0.
0,
1.
0, ALLEGRO_PLAYMODE_ONCE,
0);
39 }
40
41 player.playerAnimation
(active
);
42 }
43 if(!jump
)
44 velY
+= gravity
;
45 else
46 velY
= 0;
47 player.x
+= velX
;
48 player.y
+= velY
;
49
50 jump
= (player.y
+ 1 >= groundHeight
);
51
52 if(jump
)
53 {
54 player.y
= groundHeight
- 1;
55 } draw
= true;
56
57 if(event.timer.source
== enemyTimer
)
58 {
59 enemyAnimation
(enemy, enemyImg2, NUM_ENEMY
);
60 coinAnimation
(coin, coinImg2, NUM_COIN
);
61 teleportAnimation
(teleport, teleImg
);
62 }
63
64
65
66 cameraUpdate
(cameraPosition, player,
32,
32);
67 al_identity_transform(&camera
);
68 al_translate_transform(&camera,
-cameraPosition
[0],
-cameraPosition
[1]);
69 al_use_transform(&camera
);
70
71 }
72
73 if(state
== MENU)
74 {}
75 else if(state
== PLAYING
&& level
== LVL1
)
76 {
77 updateArrow
(arrow, NUM_ARROW, player
);
78 updateEnemy
(enemy, NUM_ENEMY
);
79 }
80 else if(state
== PLAYING
&& level
== LVL2
)
81 {
82 updateArrow
(arrow, NUM_ARROW, player
);
83 }
84 else if(state
== PLAYING
&& level
== LV2P2
)
85 {
86 updateArrow
(arrow, NUM_ARROW, player
);
87 }
88 if(level
== LVL1
)
89 {
90 if(collision
(player,
377,
461,
308,
28,
32,
32))//First Platform (long)
91 {
92 handlePlatCollision
(player,
377,
461,
308,
28,
32,
32, groundHeight, velY
);
93 }
94 else if(collision
(player,
74,
380,
196,
28,
32,
32))//Second Platform (short)
95 {
96 handlePlatCollision
(player,
74,
380,
196,
28,
32,
32, groundHeight, velY
);
97 }
98 else if(collision
(player,
74,
260,
196,
28,
32,
32))//Third Platform (short)
99 {
100 handlePlatCollision
(player,
74,
260,
196,
28,
32,
32, groundHeight, velY
);
101 }
102 else if(collision
(player,
312,
206,
252,
28,
32,
32))//Fourth Platform (Medium)
103 {
104 handlePlatCollision
(player,
312,
206,
252,
28,
32,
32, groundHeight, velY
);
105 }
106 else if(collision
(player,
656,
155,
28,
28,
32,
32)) //Fifth Platform (first tiny)
107 {
108 handlePlatCollision
(player,
655,
155,
28,
28,
32,
32, groundHeight, velY
);
109 }
110 else if(collision
(player,
584,
63,
28,
28,
32,
32))//Sixth Platform (second tiny)
111 {
112 handlePlatCollision
(player,
584,
63,
28,
28,
32,
32, groundHeight, velY
);
113 }
114 else if(collision
(player,
751,
18,
28,
28,
32,
32))//Seventh Platform (third tiny)
115 {
116 handlePlatCollision
(player,
751,
18,
28,
28,
32,
32, groundHeight, velY
);
117 }
118 else if(collision
(player,
928,
63,
196,
28,
32,
32))//Eighth Platform (short)
119 {
120 handlePlatCollision
(player,
928,
63,
196,
28,
32,
32, groundHeight, velY
);
121 }
122 else if(collision
(player,
928,
140,
196,
28,
32,
32))//Ninth platform (short)
123 {
124 handlePlatCollision
(player,
928,
140,
200,
38,
32,
32, groundHeight, velY
);
125 }
126 else if(collision
(player,
1203,
110,
28,
28,
32,
32))//Tenth platform (fourth tiny)
127 {
128 handlePlatCollision
(player,
1203,
110,
28,
28,
32,
32, groundHeight, velY
);
129 }
130 else if(collision
(player,
1158,
318,
112,
28,
32,
32))//11th Platform (first short medium)
131 {
132 handlePlatCollision
(player,
1158,
318,
112,
28,
32,
32, groundHeight, velY
);
133 }
134 else if(collision
(player,
1047,
317,
28,
28,
32,
32))//12th Platform (fifth tiny)
135 {
136 handlePlatCollision
(player,
1047,
317,
28,
28,
32,
32, groundHeight, velY
);
137 }
138 else if(collision
(player,
917,
317,
28,
28,
32,
32))//13th Platform (sixth tiny)
139 {
140 handlePlatCollision
(player,
917,
317,
28,
28,
32,
32, groundHeight, velY
);
141 }
142 else if(collision
(player,
1295,
217,
252,
28,
32,
32))//14th Platform (medium)
143 {
144 handlePlatCollision
(player,
1395,
217,
252,
28,
32,
32, groundHeight, velY
);
145 }
146 else if(collision
(player,
1478,
139,
28,
28,
32,
32))//15th platform (seventh tiny)
147 {
148 handlePlatCollision
(player,
1478,
139,
28,
28,
32,
32, groundHeight, velY
);
149 }
150 else if(collision
(player,
1407,
64,
28,
28,
32,
32))//16th platform (eighth tiny)
151 {
152 handlePlatCollision
(player,
1407,
64,
28,
28,
32,
32, groundHeight, velY
);
153 }
154 else if(collision
(player,
1578,
47,
616,
28,
32,
32))//17th platform (ex long)
155 {
156 handlePlatCollision
(player,
1578,
47,
616,
28,
32,
32, groundHeight, velY
);
157 }
158 else if(collision
(player,
2372,
168,
28,
28,
32,
32))//18th platform (ninth tiny)
159 {
160 handlePlatCollision
(player,
2372,
168,
28,
28,
32,
32, groundHeight, velY
);
161 }
162 else if(collision
(player,
2169,
321,
112,
28,
32,
32))//19th platform (second short medium)
163 {
164 handlePlatCollision
(player,
2169,
321,
112,
28,
32,
32, groundHeight, velY
);
165 }
166 else if(collision
(player,
2389,
371,
28,
28,
32,
32))//20th platform (10th tiny)
167 {
168 handlePlatCollision
(player,
2389,
371,
28,
28,
32,
32, groundHeight, velY
);
169 }
170 else if(collision
(player,
2498,
424,
28,
28,
32,
32))//21th platform (11th tiny)
171 {
172 handlePlatCollision
(player,
2498,
424,
28,
28,
32,
32, groundHeight, velY
);
173 }
174 else if(collision
(player,
2618,
484,
28,
28,
32,
32))//22th platform (12th tiny)
175 {
176 handlePlatCollision
(player,
2618,
484,
28,
28,
32,
32, groundHeight, velY
);
177 }
178 else
179 {
180 groundHeight
= 518;
181 }
182
183 for(int i
= 0; i
< NUM_COIN
; i
++)
184 {
185 if(collision
(player, coin
[i
].x, coin
[i
].y, coin
[i
].width, coin
[i
].height, player.width, player.height
))
186 {
187 coin
[i
].live
= false;
188 coin
[i
].x
= -500;
189 coin
[i
].y
= -500;
190 player.score
+= 5;
191 al_play_sample(coinCollect,
1.
0,
0.
0,
1.
0, ALLEGRO_PLAYMODE_ONCE,
0);
192 }
193 }
194
195 for(int i
= 0; i
< NUM_ARROW
; i
++)
196 {
197 for(int j
= 0; j
< NUM_ENEMY
; j
++)
198 {
199 if(collideArrow
(player, enemy
[j
].x, enemy
[j
].y, enemy
[j
].width, enemy
[j
].height,
200 arrow
[i
].x, arrow
[i
].y, arrow
[i
].width, arrow
[i
].height, enemy
[j
].live, arrow
[i
].live
))
201 {
202 enemy
[j
].live
= false;
203 enemy
[j
].x
= -500;
204 enemy
[j
].y
= -500;
205 arrow
[i
].live
= false;
206 player.score
+= 10;
207 ++enemyKilled
;
208 }
209 }
210 }
211
212 if(collision
(player, key.x, key.y, key.width, key.height, player.width, player.height
))//Collide with key
213 {
214 al_play_sample(keyCollection,
1.
0,
0.
0,
1.
0, ALLEGRO_PLAYMODE_ONCE,
0);
215 key.x
= -500;
216 key.y
= -500;
217 key.live
= false;
218 gotKey
= true;
219 player.score
+= 25;
220 }
221 for(int i
= 0; i
< NUM_ENEMY
; i
++)
222 {
223 if(collision
(player, enemy
[i
].x, enemy
[i
].y, enemy
[i
].width, enemy
[i
].height, player.width, player.height
))
224 {
225 player.x
= 10;
226 player.y
= 518;
227 --player.lives
;
228 player.dir
= RIGHT
;
229 }
230 }
231
232 if(collision
(player,
712,
535,
110,
18, player.width, player.height
)) //Snake collision
233 {
234 player.x
= 10;
235 player.y
= 535;
236 --player.lives
;
237 al_play_sample(snakeSound,
1.
0,
0.
0,
1.
0, ALLEGRO_PLAYMODE_ONCE,
0);
238 }
239 if(collision
(player,
1618,
518,
1017,
58, player.width, player.height
))//Void thing colllision
240 {
241 player.x
= 10;
242 player.y
= 518;
243 --player.lives
;
244 }
245 if(collision
(player,
2200,
330,
32,
32, player.width, player.height
)) //High jump thing
246 {
247 jumpSpeed
= 25.
0;
248 }
249 else
250 jumpSpeed
= 15.
0;
251 if(player.x
<= -10)//Collision with left side of screen
252 {
253 player.x
+= player.speed
;
254 active
= false;
255 }
256 if(player.x
>= 2980 && enemyKilled
!= 10 && coinCount
!= 11 && gotKey
== false)/*If player hasn't killed all enemies,
257 got all coins and not got the key. Cannot to proceed to next level*/
258 {
259 player.x
-= player.speed
;
260 }
261 else if(player.x
>= 2980 && enemyKilled
== 11 && coinCount
== 11 && gotKey
)
262 {
263 changeLevel
(level, LVL2
);//Change level to level 2
264 }
265 }
266 //////////////////////////////////////////////////////////////////////////////
267 // THE LIVE CHANGES BACK TO 3 WHEN CHANGING TO LEVEL 2 - FIX THAT!! //
268 //////////////////////////////////////////////////////////////////////////////
269 else if(level
== LVL2
&& level
!= LV2P2
)
270 {
271 text.animateText
();
272 if(collision
(player,
84,
340,
196,
28, player.width, player.height
))
273 {
274 handlePlatCollision
(player,
84,
340,
196,
28, player.width, player.height, groundHeight, velY
);
275 }
276 else if(collision
(player,
458,
235,
196,
28, player.width, player.height
))
277 {
278 handlePlatCollision
(player,
458,
235,
196,
28, player.width, player.height, groundHeight, velY
);
279 }
280 else if(collision
(player,
70,
42,
112,
28, player.width, player.height
))
281 {
282 handlePlatCollision
(player,
70,
42,
112,
28, player.width, player.height, groundHeight, velY
);
283 }
284 else
285 groundHeight
= 518;
286
287 if(collision
(player,
675,
518,
315,
50, player.width, player.height
))
288 {
289 player.x
= 10;
290 player.y
= 518;
291 --player.lives
;
292 }
293 else if(collision
(player,
1486,
518,
524,
50, player.width, player.height
))
294 {
295 player.x
= 10;
296 player.y
= 518;
297 --player.lives
;
298 }
299 else if(collision
(player,
2570,
518,
253,
50, player.width, player.height
))
300 {
301 player.x
= 10;
302 player.y
= 518;
303 --player.lives
;
304 }
305
306 if(collision
(player, teleport.x, teleport.y, teleport.width, teleport.height, player.width, player.height
))
307 {
308 player.x
= 1020;
309 player.y
= 518;
310 }
311 }