Revision 295
managed to separate. working on needless stuff
proj/src/proj.c | ||
---|---|---|
98 | 98 |
sp_crosshair = sprite_ctor(bsp_crosshair); if(sp_crosshair == NULL) printf("Failed to get crosshair sprite\n"); |
99 | 99 |
} |
100 | 100 |
|
101 |
ent_set_scale(DEFAULT_SCALE); |
|
102 |
|
|
103 |
text_timer_t *in_game_timer = timer_ctor(consolas); |
|
104 |
|
|
105 | 101 |
#ifndef DIOGO |
106 | 102 |
menu_t *main_menu = menu_ctor(consolas); |
107 | 103 |
#endif |
108 | 104 |
|
109 |
list_t *shooter_list = list_ctor(); |
|
110 |
|
|
111 |
gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol); if(shooter1 == NULL) printf("Failed to get shooter1\n"); |
|
112 |
gunner_set_spawn(shooter1, 75, 75); |
|
113 |
gunner_set_pos(shooter1, 75, 75); |
|
114 |
|
|
115 |
gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_nothing); |
|
116 |
gunner_set_spawn(shooter2, 975, 75); |
|
117 |
gunner_set_pos(shooter2, 775, 75); |
|
118 |
|
|
119 |
list_insert(shooter_list, list_end(shooter_list), shooter1); |
|
120 |
list_insert(shooter_list, list_end(shooter_list), shooter2); |
|
121 |
|
|
122 |
list_t *bullet_list = list_ctor(); |
|
123 |
|
|
124 |
ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
|
125 |
gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
|
126 |
|
|
127 | 105 |
#ifndef DIOGO |
128 | 106 |
//uint32_t refresh_count_value = sys_hz() / REFRESH_RATE; |
129 | 107 |
uint8_t last_lb = 0; |
... | ... | |
133 | 111 |
/// loop stuff |
134 | 112 |
int ipc_status; |
135 | 113 |
message msg; |
136 |
int game_state = MENU; |
|
137 | 114 |
|
138 | 115 |
#ifdef DIOGO |
139 | 116 |
char buffer[1024]; // buffer |
... | ... | |
147 | 124 |
char *s = NULL; |
148 | 125 |
#endif |
149 | 126 |
|
150 |
while (game_state != EXIT) { |
|
127 |
int good = true; |
|
128 |
|
|
129 |
while (good) { |
|
151 | 130 |
/* Get a request message. */ |
152 | 131 |
if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { |
153 | 132 |
printf("driver_receive failed with %d", r); |
... | ... | |
162 | 141 |
switch (i) { |
163 | 142 |
#ifndef DIOGO |
164 | 143 |
case TIMER0_IRQ: |
165 |
switch (game_state) { |
|
166 |
case MENU: |
|
167 |
graph_clear_screen(); |
|
168 |
switch(menu_update_state(main_menu, click)){ |
|
169 |
case -1: game_state = MENU; break; |
|
170 |
case 0: game_state = GAME; game(); break; |
|
171 |
case 1: game_state = TEST; break; |
|
172 |
case 2: game_state = EXIT; break; |
|
173 |
} |
|
174 |
menu_draw(main_menu); |
|
175 | 144 |
|
176 |
click = 0; |
|
145 |
graph_clear_screen(); |
|
146 |
switch(menu_update_state(main_menu, click)){ |
|
147 |
case -1: break; |
|
148 |
case 0: game(); break; |
|
149 |
case 1: good = false; break; |
|
150 |
case 2: good = false; break; |
|
151 |
} |
|
152 |
menu_draw(main_menu); |
|
177 | 153 |
|
178 |
sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
|
179 |
sprite_draw(sp_crosshair); |
|
180 |
graph_draw(); |
|
181 |
break; |
|
182 |
case GAME: |
|
183 |
if (no_interrupts % 60 == 0) timer_update(in_game_timer); |
|
184 |
update_movement(map1, shooter1, keys, shooter_list); |
|
154 |
click = 0; |
|
185 | 155 |
|
186 |
update_game_state(map1, shooter_list, bullet_list); |
|
156 |
sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
|
157 |
sprite_draw(sp_crosshair); |
|
158 |
graph_draw(); |
|
187 | 159 |
|
188 |
//update_scale(); |
|
189 |
double angle = get_mouse_angle(shooter1); |
|
190 |
gunner_set_angle(shooter1, angle - M_PI_2); |
|
191 |
|
|
192 |
ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
|
193 |
gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
|
194 |
|
|
195 |
graph_clear_screen(); |
|
196 |
map_draw (map1); |
|
197 |
gunner_draw_list(shooter_list); |
|
198 |
bullet_draw_list(bullet_list); |
|
199 |
|
|
200 |
text_draw(in_game_timer->text); |
|
201 |
|
|
202 |
sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
|
203 |
sprite_draw(sp_crosshair); |
|
204 |
graph_draw(); |
|
205 |
break; |
|
206 |
} |
|
207 | 160 |
break; |
208 | 161 |
#endif |
209 | 162 |
case KBC_IRQ: |
210 |
switch (game_state) { |
|
211 |
case MENU: |
|
212 |
if ((scancode[0]) == ESC_BREAK_CODE) game_state = EXIT; |
|
213 |
#ifdef DIOGO |
|
214 |
else if ((scancode[0]) == ENTER_MAKE_CODE) { |
|
215 |
buffer[buffer_pos] = '\0'; |
|
216 |
printf("\nSending string -%s-", buffer); |
|
217 |
printf(" (output: %d)\n", |
|
218 |
hltp_send_string(buffer)); |
|
219 |
buffer_pos = 0; |
|
220 |
} |
|
221 |
else { |
|
222 |
char c = map_makecode(scancode[0]); |
|
223 |
if (c == ERROR_CODE) break; |
|
224 |
buffer[buffer_pos++] = c; |
|
225 |
printf("%c", c); |
|
226 |
} |
|
227 |
#endif |
|
228 |
break; |
|
229 |
case GAME: |
|
230 |
if ((scancode[0]) == ESC_BREAK_CODE) { |
|
231 |
game_state = MENU; |
|
232 |
// reset game |
|
233 |
while(list_size(bullet_list) > 0){ |
|
234 |
bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list)); |
|
235 |
bullet_dtor(p); |
|
236 |
} |
|
237 |
list_node_t *it = list_begin(shooter_list); |
|
238 |
while (it != list_end(shooter_list)) { |
|
239 |
gunner_t *p = *(gunner_t**)list_node_val(it); |
|
240 |
get_random_spawn(map1, p); |
|
241 |
gunner_set_curr_health(p, gunner_get_health(p)); |
|
242 |
it = list_node_next(it); |
|
243 |
} |
|
244 |
timer_reset(in_game_timer); |
|
245 |
} |
|
246 |
break; |
|
163 |
if ((scancode[0]) == ESC_BREAK_CODE) good = false; |
|
164 |
#ifdef DIOGO |
|
165 |
else if ((scancode[0]) == ENTER_MAKE_CODE) { |
|
166 |
buffer[buffer_pos] = '\0'; |
|
167 |
printf("\nSending string -%s-", buffer); |
|
168 |
printf(" (output: %d)\n", |
|
169 |
hltp_send_string(buffer)); |
|
170 |
buffer_pos = 0; |
|
247 | 171 |
} |
248 |
break; |
|
172 |
else { |
|
173 |
char c = map_makecode(scancode[0]); |
|
174 |
if (c == ERROR_CODE) break; |
|
175 |
buffer[buffer_pos++] = c; |
|
176 |
printf("%c", c); |
|
177 |
} |
|
178 |
#endif |
|
249 | 179 |
#ifndef DIOGO |
250 | 180 |
case MOUSE_IRQ: |
251 | 181 |
if (counter_mouse_ih >= 3) { |
252 | 182 |
mouse_parse_packet(packet_mouse_ih, &pp); |
253 | 183 |
update_mouse(&pp); |
254 |
switch (game_state) { |
|
255 |
case MENU: |
|
256 |
if (!click) click = last_lb ^ keys->lb_pressed && keys->lb_pressed; |
|
257 |
break; |
|
258 |
case GAME: |
|
259 |
if (last_lb ^ keys->lb_pressed && keys->lb_pressed) |
|
260 |
shoot_bullet(shooter1, bullet_list, bsp_bullet); |
|
261 |
break; |
|
262 |
} |
|
184 |
if (!click) click = last_lb ^ keys->lb_pressed && keys->lb_pressed; |
|
263 | 185 |
last_lb = keys->lb_pressed; |
264 | 186 |
counter_mouse_ih = 0; |
265 |
|
|
266 | 187 |
} |
267 | 188 |
break; |
268 | 189 |
#endif |
... | ... | |
284 | 205 |
} |
285 | 206 |
} |
286 | 207 |
|
287 |
#ifdef DIOGO |
|
288 |
free(s); |
|
289 |
#endif |
|
290 |
|
|
291 |
while(list_size(shooter_list) > 0){ |
|
292 |
gunner_t *p = list_erase(shooter_list, list_begin(shooter_list)); |
|
293 |
gunner_dtor(p); |
|
294 |
} |
|
295 |
|
|
296 |
while(list_size(bullet_list) > 0){ |
|
297 |
bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list)); |
|
298 |
bullet_dtor(p); |
|
299 |
} |
|
300 |
if(list_dtor(shooter_list)) printf("COULD NOT DESTRUCT SHOOTER LIST\n"); |
|
301 |
if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n"); |
|
302 |
|
|
303 |
timer_dtor(in_game_timer); in_game_timer = NULL; |
|
304 |
|
|
305 | 208 |
basic_sprite_dtor (bsp_crosshair); bsp_crosshair = NULL; |
306 | 209 |
basic_sprite_dtor (bsp_shooter ); bsp_shooter = NULL; |
307 | 210 |
sprite_dtor (sp_crosshair ); sp_crosshair = NULL; |
... | ... | |
327 | 230 |
} |
328 | 231 |
|
329 | 232 |
static int (game)(void){ |
233 |
|
|
234 |
int r; |
|
235 |
|
|
236 |
ent_set_scale(DEFAULT_SCALE); |
|
237 |
text_timer_t *in_game_timer = timer_ctor(consolas); |
|
238 |
|
|
239 |
list_t *shooter_list = list_ctor(); |
|
240 |
|
|
241 |
gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol); if(shooter1 == NULL) printf("Failed to get shooter1\n"); |
|
242 |
gunner_set_spawn(shooter1, 75, 75); |
|
243 |
gunner_set_pos(shooter1, 75, 75); |
|
244 |
|
|
245 |
gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_nothing); |
|
246 |
gunner_set_spawn(shooter2, 975, 75); |
|
247 |
gunner_set_pos(shooter2, 775, 75); |
|
248 |
|
|
249 |
list_insert(shooter_list, list_end(shooter_list), shooter1); |
|
250 |
list_insert(shooter_list, list_end(shooter_list), shooter2); |
|
251 |
|
|
252 |
list_t *bullet_list = list_ctor(); |
|
253 |
|
|
254 |
ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
|
255 |
gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
|
256 |
|
|
257 |
//uint32_t refresh_count_value = sys_hz() / REFRESH_RATE; |
|
258 |
uint8_t last_lb = 0; |
|
259 |
struct packet pp; |
|
260 |
keys_t *keys = get_key_presses(); |
|
261 |
|
|
262 |
/// loop stuff |
|
263 |
int ipc_status; |
|
264 |
message msg; |
|
265 |
int game_state = GAME; |
|
266 |
|
|
267 |
while (game_state == GAME) { |
|
268 |
/* Get a request message. */ |
|
269 |
if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { |
|
270 |
printf("driver_receive failed with %d", r); |
|
271 |
continue; |
|
272 |
} |
|
273 |
if (is_ipc_notify(ipc_status)) { /* received notification */ |
|
274 |
switch (_ENDPOINT_P(msg.m_source)) { |
|
275 |
case HARDWARE: /* hardware interrupt notification */ |
|
276 |
for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) { |
|
277 |
if (msg.m_notify.interrupts & n) { |
|
278 |
interrupt_handler(i); |
|
279 |
switch (i) { |
|
280 |
case TIMER0_IRQ: |
|
281 |
|
|
282 |
if (no_interrupts % 60 == 0) timer_update(in_game_timer); |
|
283 |
update_movement(map1, shooter1, keys, shooter_list); |
|
284 |
|
|
285 |
update_game_state(map1, shooter_list, bullet_list); |
|
286 |
|
|
287 |
//update_scale(); |
|
288 |
double angle = get_mouse_angle(shooter1); |
|
289 |
gunner_set_angle(shooter1, angle - M_PI_2); |
|
290 |
|
|
291 |
ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
|
292 |
gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
|
293 |
|
|
294 |
graph_clear_screen(); |
|
295 |
map_draw (map1); |
|
296 |
gunner_draw_list(shooter_list); |
|
297 |
bullet_draw_list(bullet_list); |
|
298 |
|
|
299 |
text_draw(in_game_timer->text); |
|
300 |
|
|
301 |
sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
|
302 |
sprite_draw(sp_crosshair); |
|
303 |
graph_draw(); |
|
304 |
|
|
305 |
break; |
|
306 |
case KBC_IRQ: |
|
307 |
if ((scancode[0]) == ESC_BREAK_CODE) { |
|
308 |
game_state = MENU; |
|
309 |
// reset game |
|
310 |
while(list_size(bullet_list) > 0){ |
|
311 |
bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list)); |
|
312 |
bullet_dtor(p); |
|
313 |
} |
|
314 |
list_node_t *it = list_begin(shooter_list); |
|
315 |
while (it != list_end(shooter_list)) { |
|
316 |
gunner_t *p = *(gunner_t**)list_node_val(it); |
|
317 |
get_random_spawn(map1, p); |
|
318 |
gunner_set_curr_health(p, gunner_get_health(p)); |
|
319 |
it = list_node_next(it); |
|
320 |
} |
|
321 |
timer_reset(in_game_timer); |
|
322 |
} |
|
323 |
break; |
|
324 |
case MOUSE_IRQ: |
|
325 |
if (counter_mouse_ih >= 3) { |
|
326 |
mouse_parse_packet(packet_mouse_ih, &pp); |
|
327 |
update_mouse(&pp); |
|
328 |
if (last_lb ^ keys->lb_pressed && keys->lb_pressed) |
|
329 |
shoot_bullet(shooter1, bullet_list, bsp_bullet); |
|
330 |
last_lb = keys->lb_pressed; |
|
331 |
counter_mouse_ih = 0; |
|
332 |
|
|
333 |
} |
|
334 |
break; |
|
335 |
} |
|
336 |
} |
|
337 |
} |
|
338 |
break; |
|
339 |
default: |
|
340 |
break; /* no other notifications expected: do nothing */ |
|
341 |
} |
|
342 |
} else { /* received standart message, not a notification */ |
|
343 |
/* no standart message expected: do nothing */ |
|
344 |
} |
|
345 |
} |
|
346 |
|
|
347 |
#ifdef DIOGO |
|
348 |
free(s); |
|
349 |
#endif |
|
350 |
|
|
351 |
while(list_size(shooter_list) > 0){ |
|
352 |
gunner_t *p = list_erase(shooter_list, list_begin(shooter_list)); |
|
353 |
gunner_dtor(p); |
|
354 |
} |
|
355 |
|
|
356 |
while(list_size(bullet_list) > 0){ |
|
357 |
bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list)); |
|
358 |
bullet_dtor(p); |
|
359 |
} |
|
360 |
if(list_dtor(shooter_list)) printf("COULD NOT DESTRUCT SHOOTER LIST\n"); |
|
361 |
if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n"); |
|
362 |
|
|
363 |
timer_dtor(in_game_timer); in_game_timer = NULL; |
|
364 |
|
|
330 | 365 |
return SUCCESS; |
331 | 366 |
} |
Also available in: Unified diff