Revision 291
changed menu to file
proj/include/proj_func.h | ||
---|---|---|
56 | 56 |
*/ |
57 | 57 |
double get_mouse_angle(gunner_t *p); |
58 | 58 |
|
59 |
typedef struct menu menu_t; |
|
60 |
|
|
61 |
menu_t* (menu_ctor)(const font_t *fnt); |
|
62 |
|
|
63 |
int (menu_update_state)(menu_t *menu, int click); |
|
64 |
|
|
65 |
void (menu_draw)(menu_t *menu); |
|
66 |
|
|
67 |
void (menu_dtor)(menu_t *p); |
|
68 |
|
|
69 | 59 |
typedef struct timer { |
70 | 60 |
int time; |
71 | 61 |
text_t *text; |
proj/libs/graph/include/menu.h | ||
---|---|---|
1 |
#ifndef MENU_H_INCLUDED |
|
2 |
#define MENU_H_INCLUDED |
|
3 |
|
|
4 |
#include "font.h" |
|
5 |
|
|
6 |
typedef struct menu menu_t; |
|
7 |
|
|
8 |
menu_t* (menu_ctor)(const font_t *fnt); |
|
9 |
|
|
10 |
int (menu_update_state)(menu_t *menu, int click); |
|
11 |
|
|
12 |
void (menu_draw)(menu_t *menu); |
|
13 |
|
|
14 |
void (menu_dtor)(menu_t *p); |
|
15 |
|
|
16 |
#endif //MENU_H_INCLUDED |
|
0 | 17 |
proj/libs/graph/src/menu.c | ||
---|---|---|
1 |
#include <lcom/lcf.h> |
|
2 |
|
|
3 |
#include "menu.h" |
|
4 |
|
|
5 |
#include "graph.h" |
|
6 |
#include "rectangle.h" |
|
7 |
#include "proj_func.h" |
|
8 |
#include "proj_macros.h" |
|
9 |
|
|
10 |
struct menu { |
|
11 |
size_t sz; |
|
12 |
rectangle_t **r; |
|
13 |
text_t **t; |
|
14 |
rectangle_t *frame; |
|
15 |
}; |
|
16 |
|
|
17 |
menu_t* (menu_ctor)(const font_t *fnt){ |
|
18 |
if(fnt == NULL) return NULL; |
|
19 |
menu_t *ret = (menu_t*)malloc(sizeof(menu_t)); |
|
20 |
if (ret == NULL) return NULL; |
|
21 |
ret->sz = 0; |
|
22 |
ret->r = NULL; |
|
23 |
ret->t = NULL; |
|
24 |
|
|
25 |
ret->frame = rectangle_ctor(0, 0, 800, 500); |
|
26 |
rectangle_set_fill_color(ret->frame, GRAPH_BLACK); |
|
27 |
rectangle_set_outline_width(ret->frame, 6); |
|
28 |
rectangle_set_outline_color(ret->frame, GRAPH_WHITE); |
|
29 |
rectangle_set_fill_trans(ret->frame, GRAPH_TRANSPARENT); |
|
30 |
|
|
31 |
|
|
32 |
ret->sz = 3; |
|
33 |
ret->r = realloc(ret->r, ret->sz*sizeof(rectangle_t*)); |
|
34 |
ret->t = realloc(ret->t, ret->sz*sizeof(text_t *)); |
|
35 |
ret->r[0] = rectangle_ctor(0, 0, 400, 100); |
|
36 |
ret->r[1] = rectangle_ctor(0, 0, 400, 100); |
|
37 |
ret->r[2] = rectangle_ctor(0, 0, 400, 100); |
|
38 |
ret->t[0] = text_ctor(fnt, "Play"); |
|
39 |
ret->t[1] = text_ctor(fnt, "Test"); |
|
40 |
ret->t[2] = text_ctor(fnt, "Exit"); |
|
41 |
|
|
42 |
if (ret->r[0] == NULL || ret->r[1] == NULL || ret->r[2] == NULL || |
|
43 |
ret->t[0] == NULL || ret->t[1] == NULL || ret->t[2] == NULL || |
|
44 |
ret->frame == NULL) return NULL; |
|
45 |
// VISUAL |
|
46 |
rectangle_set_fill_color(ret->r[0], GRAPH_BLACK); |
|
47 |
rectangle_set_outline_width(ret->r[0], 2); |
|
48 |
rectangle_set_outline_color(ret->r[0], GRAPH_WHITE); |
|
49 |
rectangle_set_fill_trans(ret->r[0], GRAPH_TRANSPARENT); |
|
50 |
|
|
51 |
rectangle_set_fill_color(ret->r[1], GRAPH_BLACK); |
|
52 |
rectangle_set_outline_width(ret->r[1], 2); |
|
53 |
rectangle_set_outline_color(ret->r[1], GRAPH_WHITE); |
|
54 |
rectangle_set_fill_trans(ret->r[1], GRAPH_TRANSPARENT); |
|
55 |
|
|
56 |
rectangle_set_fill_color(ret->r[2], GRAPH_BLACK); |
|
57 |
rectangle_set_outline_width(ret->r[2], 2); |
|
58 |
rectangle_set_outline_color(ret->r[2], GRAPH_WHITE); |
|
59 |
rectangle_set_fill_trans(ret->r[2], GRAPH_TRANSPARENT); |
|
60 |
|
|
61 |
text_set_valign(ret->t[0], text_valign_center); |
|
62 |
text_set_halign(ret->t[0], text_halign_center); |
|
63 |
text_set_color(ret->t[0], TEXT_COLOR); |
|
64 |
|
|
65 |
text_set_valign(ret->t[1], text_valign_center); |
|
66 |
text_set_halign(ret->t[1], text_halign_center); |
|
67 |
text_set_color(ret->t[1], TEXT_COLOR); |
|
68 |
|
|
69 |
text_set_valign(ret->t[2], text_valign_center); |
|
70 |
text_set_halign(ret->t[2], text_halign_center); |
|
71 |
text_set_color(ret->t[2], TEXT_COLOR); |
|
72 |
// POSITIONS |
|
73 |
rectangle_set_pos(ret->r[0], |
|
74 |
graph_get_XRes()/2 - rectangle_get_w(ret->r[0])/2, |
|
75 |
graph_get_YRes()*0.35 - rectangle_get_h(ret->r[0])/2); |
|
76 |
|
|
77 |
|
|
78 |
rectangle_set_pos(ret->r[1], |
|
79 |
graph_get_XRes()/2 - rectangle_get_w(ret->r[1])/2, |
|
80 |
graph_get_YRes()*0.5 - rectangle_get_h(ret->r[1])/2); |
|
81 |
|
|
82 |
|
|
83 |
rectangle_set_pos(ret->r[2], |
|
84 |
graph_get_XRes()/2 - rectangle_get_w(ret->r[2])/2, |
|
85 |
graph_get_YRes()*0.65 - rectangle_get_h(ret->r[2])/2); |
|
86 |
|
|
87 |
text_set_pos(ret->t[0], rectangle_get_x(ret->r[0])+rectangle_get_w(ret->r[0])/2, |
|
88 |
rectangle_get_y(ret->r[0])+rectangle_get_h(ret->r[0])/2); |
|
89 |
|
|
90 |
text_set_pos(ret->t[1], rectangle_get_x(ret->r[1])+rectangle_get_w(ret->r[1])/2, |
|
91 |
rectangle_get_y(ret->r[1])+rectangle_get_h(ret->r[1])/2); |
|
92 |
|
|
93 |
text_set_pos(ret->t[2], rectangle_get_x(ret->r[2])+rectangle_get_w(ret->r[2])/2, |
|
94 |
rectangle_get_y(ret->r[2])+rectangle_get_h(ret->r[2])/2); |
|
95 |
|
|
96 |
rectangle_set_pos(ret->frame, |
|
97 |
graph_get_XRes()/2 - rectangle_get_w(ret->frame)/2, |
|
98 |
graph_get_YRes()*0.5 - rectangle_get_h(ret->frame)/2); |
|
99 |
return ret; |
|
100 |
} |
|
101 |
|
|
102 |
static int highlighted = -1; |
|
103 |
|
|
104 |
int (menu_update_state)(menu_t *menu, int click) { |
|
105 |
|
|
106 |
if (rectangle_collide_point(menu->r[0], *get_mouse_X(), *get_mouse_Y())) { |
|
107 |
highlighted = GAME; |
|
108 |
if (click) return GAME; |
|
109 |
} else if (rectangle_collide_point(menu->r[1], *get_mouse_X(), *get_mouse_Y())) { |
|
110 |
highlighted = TEST; |
|
111 |
if (click) return TEST; |
|
112 |
} else if (rectangle_collide_point(menu->r[2], *get_mouse_X(), *get_mouse_Y())) { |
|
113 |
highlighted = EXIT; |
|
114 |
if (click) return EXIT; |
|
115 |
} else { |
|
116 |
highlighted = -1; |
|
117 |
} |
|
118 |
return MENU; |
|
119 |
} |
|
120 |
|
|
121 |
void (menu_draw)(menu_t *menu) { |
|
122 |
rectangle_draw(menu->frame); |
|
123 |
switch (highlighted) { |
|
124 |
case GAME: |
|
125 |
rectangle_set_fill_color(menu->r[0], HIGHLIGHT_COLOR); |
|
126 |
rectangle_draw(menu->r[0]); |
|
127 |
rectangle_draw(menu->r[1]); |
|
128 |
rectangle_draw(menu->r[2]); |
|
129 |
rectangle_set_fill_color(menu->r[0], GRAPH_BLACK); |
|
130 |
break; |
|
131 |
case TEST: |
|
132 |
rectangle_set_fill_color(menu->r[1], HIGHLIGHT_COLOR); |
|
133 |
rectangle_draw(menu->r[0]); |
|
134 |
rectangle_draw(menu->r[1]); |
|
135 |
rectangle_draw(menu->r[2]); |
|
136 |
rectangle_set_fill_color(menu->r[1], GRAPH_BLACK); |
|
137 |
break; |
|
138 |
case EXIT: |
|
139 |
rectangle_set_fill_color(menu->r[2], HIGHLIGHT_COLOR); |
|
140 |
rectangle_draw(menu->r[0]); |
|
141 |
rectangle_draw(menu->r[1]); |
|
142 |
rectangle_draw(menu->r[2]); |
|
143 |
rectangle_set_fill_color(menu->r[2], GRAPH_BLACK); |
|
144 |
break; |
|
145 |
default: |
|
146 |
rectangle_draw(menu->r[0]); |
|
147 |
rectangle_draw(menu->r[1]); |
|
148 |
rectangle_draw(menu->r[2]); |
|
149 |
break; |
|
150 |
} |
|
151 |
for(size_t i = 0; i < menu->sz; ++i) |
|
152 |
text_draw(menu->t[i]); |
|
153 |
} |
|
154 |
|
|
155 |
void (menu_dtor)(menu_t *p){ |
|
156 |
for(size_t i = 0; i < p->sz; ++i){ |
|
157 |
rectangle_dtor(p->r[i]); |
|
158 |
text_dtor (p->t[i]); |
|
159 |
} |
|
160 |
rectangle_dtor(p->frame); |
|
161 |
free(p); |
|
162 |
} |
|
0 | 163 |
proj/src/proj.c | ||
---|---|---|
11 | 11 |
#include "keyboard.h" |
12 | 12 |
#include "mouse.h" |
13 | 13 |
#include "graph.h" |
14 |
#include "menu.h" |
|
14 | 15 |
#include "rtc.h" |
15 | 16 |
#include "hltp.h" |
16 | 17 |
#include "interrupts_func.h" |
proj/src/proj_func.c | ||
---|---|---|
189 | 189 |
return atan2(gunner_get_y_screen(p) - mouse_y, mouse_x - gunner_get_x_screen(p)); |
190 | 190 |
} |
191 | 191 |
|
192 |
struct menu { |
|
193 |
rectangle_t *r0, *r1, *r2; |
|
194 |
text_t *t0, *t1, *t2; |
|
195 |
rectangle_t *frame; |
|
196 |
}; |
|
197 |
|
|
198 |
menu_t* (menu_ctor)(const font_t *fnt){ |
|
199 |
if(fnt == NULL) return NULL; |
|
200 |
menu_t *ret = (menu_t*)malloc(sizeof(menu_t)); |
|
201 |
if (ret == NULL) return NULL; |
|
202 |
ret->r0 = rectangle_ctor(0, 0, 400, 100); |
|
203 |
ret->r1 = rectangle_ctor(0, 0, 400, 100); |
|
204 |
ret->r2 = rectangle_ctor(0, 0, 400, 100); |
|
205 |
ret->t0 = text_ctor(fnt, "PLAY"); |
|
206 |
ret->t1 = text_ctor(fnt, "TEST"); |
|
207 |
ret->t2 = text_ctor(fnt, "EXIT"); |
|
208 |
ret->frame = rectangle_ctor(0, 0, 800, 500); |
|
209 |
if (ret->r0 == NULL || ret->r1 == NULL || ret->r2 == NULL || |
|
210 |
ret->t0 == NULL || ret->t1 == NULL || ret->t2 == NULL || |
|
211 |
ret->frame == NULL) return NULL; |
|
212 |
// VISUAL |
|
213 |
rectangle_set_fill_color(ret->r0, GRAPH_BLACK); |
|
214 |
rectangle_set_outline_width(ret->r0, 2); |
|
215 |
rectangle_set_outline_color(ret->r0, GRAPH_WHITE); |
|
216 |
rectangle_set_fill_trans(ret->r0, GRAPH_TRANSPARENT); |
|
217 |
rectangle_set_fill_color(ret->r1, GRAPH_BLACK); |
|
218 |
rectangle_set_outline_width(ret->r1, 2); |
|
219 |
rectangle_set_outline_color(ret->r1, GRAPH_WHITE); |
|
220 |
rectangle_set_fill_trans(ret->r1, GRAPH_TRANSPARENT); |
|
221 |
rectangle_set_fill_color(ret->r2, GRAPH_BLACK); |
|
222 |
rectangle_set_outline_width(ret->r2, 2); |
|
223 |
rectangle_set_outline_color(ret->r2, GRAPH_WHITE); |
|
224 |
rectangle_set_fill_trans(ret->r2, GRAPH_TRANSPARENT); |
|
225 |
text_set_valign(ret->t0, text_valign_center); |
|
226 |
text_set_halign(ret->t0, text_halign_center); |
|
227 |
text_set_color(ret->t0, TEXT_COLOR); |
|
228 |
text_set_valign(ret->t1, text_valign_center); |
|
229 |
text_set_halign(ret->t1, text_halign_center); |
|
230 |
text_set_color(ret->t1, TEXT_COLOR); |
|
231 |
text_set_valign(ret->t2, text_valign_center); |
|
232 |
text_set_halign(ret->t2, text_halign_center); |
|
233 |
text_set_color(ret->t2, TEXT_COLOR); |
|
234 |
rectangle_set_fill_color(ret->frame, GRAPH_BLACK); |
|
235 |
rectangle_set_outline_width(ret->frame, 6); |
|
236 |
rectangle_set_outline_color(ret->frame, GRAPH_WHITE); |
|
237 |
rectangle_set_fill_trans(ret->frame, GRAPH_TRANSPARENT); |
|
238 |
// POSITIONS |
|
239 |
rectangle_set_pos(ret->r0, |
|
240 |
graph_get_XRes()/2 - rectangle_get_w(ret->r0)/2, |
|
241 |
graph_get_YRes()*0.35 - rectangle_get_h(ret->r0)/2); |
|
242 |
|
|
243 |
|
|
244 |
rectangle_set_pos(ret->r1, |
|
245 |
graph_get_XRes()/2 - rectangle_get_w(ret->r1)/2, |
|
246 |
graph_get_YRes()*0.5 - rectangle_get_h(ret->r1)/2); |
|
247 |
|
|
248 |
|
|
249 |
rectangle_set_pos(ret->r2, |
|
250 |
graph_get_XRes()/2 - rectangle_get_w(ret->r2)/2, |
|
251 |
graph_get_YRes()*0.65 - rectangle_get_h(ret->r2)/2); |
|
252 |
|
|
253 |
text_set_pos(ret->t0, rectangle_get_x(ret->r0)+rectangle_get_w(ret->r0)/2, |
|
254 |
rectangle_get_y(ret->r0)+rectangle_get_h(ret->r0)/2); |
|
255 |
|
|
256 |
text_set_pos(ret->t1, rectangle_get_x(ret->r1)+rectangle_get_w(ret->r1)/2, |
|
257 |
rectangle_get_y(ret->r1)+rectangle_get_h(ret->r1)/2); |
|
258 |
|
|
259 |
text_set_pos(ret->t2, rectangle_get_x(ret->r2)+rectangle_get_w(ret->r2)/2, |
|
260 |
rectangle_get_y(ret->r2)+rectangle_get_h(ret->r2)/2); |
|
261 |
|
|
262 |
rectangle_set_pos(ret->frame, |
|
263 |
graph_get_XRes()/2 - rectangle_get_w(ret->frame)/2, |
|
264 |
graph_get_YRes()*0.5 - rectangle_get_h(ret->frame)/2); |
|
265 |
return ret; |
|
266 |
} |
|
267 |
|
|
268 |
static int highlighted = -1; |
|
269 |
|
|
270 |
int (menu_update_state)(menu_t *menu, int click) { |
|
271 |
|
|
272 |
if (rectangle_collide_point(menu->r0, mouse_x, mouse_y)) { |
|
273 |
highlighted = GAME; |
|
274 |
if (click) return GAME; |
|
275 |
} else if (rectangle_collide_point(menu->r1, mouse_x, mouse_y)) { |
|
276 |
highlighted = TEST; |
|
277 |
if (click) return TEST; |
|
278 |
} else if (rectangle_collide_point(menu->r2, mouse_x, mouse_y)) { |
|
279 |
highlighted = EXIT; |
|
280 |
if (click) return EXIT; |
|
281 |
} else { |
|
282 |
highlighted = -1; |
|
283 |
} |
|
284 |
return MENU; |
|
285 |
} |
|
286 |
|
|
287 |
void (menu_draw)(menu_t *menu) { |
|
288 |
rectangle_draw(menu->frame); |
|
289 |
switch (highlighted) { |
|
290 |
case GAME: |
|
291 |
rectangle_set_fill_color(menu->r0, HIGHLIGHT_COLOR); |
|
292 |
rectangle_draw(menu->r0); |
|
293 |
rectangle_draw(menu->r1); |
|
294 |
rectangle_draw(menu->r2); |
|
295 |
rectangle_set_fill_color(menu->r0, GRAPH_BLACK); |
|
296 |
break; |
|
297 |
case TEST: |
|
298 |
rectangle_set_fill_color(menu->r1, HIGHLIGHT_COLOR); |
|
299 |
rectangle_draw(menu->r0); |
|
300 |
rectangle_draw(menu->r1); |
|
301 |
rectangle_draw(menu->r2); |
|
302 |
rectangle_set_fill_color(menu->r1, GRAPH_BLACK); |
|
303 |
break; |
|
304 |
case EXIT: |
|
305 |
rectangle_set_fill_color(menu->r2, HIGHLIGHT_COLOR); |
|
306 |
rectangle_draw(menu->r0); |
|
307 |
rectangle_draw(menu->r1); |
|
308 |
rectangle_draw(menu->r2); |
|
309 |
rectangle_set_fill_color(menu->r2, GRAPH_BLACK); |
|
310 |
break; |
|
311 |
default: |
|
312 |
rectangle_draw(menu->r0); |
|
313 |
rectangle_draw(menu->r1); |
|
314 |
rectangle_draw(menu->r2); |
|
315 |
break; |
|
316 |
} |
|
317 |
text_draw(menu->t0); |
|
318 |
text_draw(menu->t1); |
|
319 |
text_draw(menu->t2); |
|
320 |
} |
|
321 |
|
|
322 |
void (menu_dtor)(menu_t *p){ |
|
323 |
rectangle_dtor(p->r0); |
|
324 |
rectangle_dtor(p->r1); |
|
325 |
rectangle_dtor(p->r2); |
|
326 |
rectangle_dtor(p->frame); |
|
327 |
text_dtor(p->t0); |
|
328 |
text_dtor(p->t1); |
|
329 |
text_dtor(p->t2); |
|
330 |
free(p); |
|
331 |
} |
|
332 |
|
|
333 | 192 |
text_timer_t* (timer_ctor)(const font_t *fnt){ |
334 | 193 |
if(fnt == NULL) return NULL; |
335 | 194 |
text_timer_t *ret = malloc(sizeof(timer_t)); |
proj/DR.mk | ||
---|---|---|
9 | 9 |
.PATH: ${.CURDIR}/libs/classes/src |
10 | 10 |
.PATH: ${.CURDIR}/libs/utils/src |
11 | 11 |
|
12 |
SRCS= proj.c list.c queue.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c rectangle.c font.c xpm_utils.c ent.c rtc.c uart.c hltp.c makecode_map.c |
|
12 |
SRCS= proj.c list.c queue.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c rectangle.c font.c xpm_utils.c ent.c rtc.c uart.c hltp.c makecode_map.c menu.c
|
|
13 | 13 |
IPATHS=-I./include -I./libs/graph/include -I./libs/kbc/include -I./libs/rtc/include -I./libs/timer/include -I./libs/uart/include -I./libs/classes/include -I./libs/utils/include -I./maps -I./media/xpm |
14 | 14 |
|
15 | 15 |
CPPFLAGS += -pedantic ${IPATHS} -D LCOM_MACRO #-D __LCOM_OPTIMIZED_ |
proj/Makefile | ||
---|---|---|
9 | 9 |
.PATH: ${.CURDIR}/libs/classes/src |
10 | 10 |
.PATH: ${.CURDIR}/libs/utils/src |
11 | 11 |
|
12 |
SRCS= proj.c list.c queue.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c rectangle.c font.c xpm_utils.c ent.c rtc.c uart.c hltp.c makecode_map.c |
|
12 |
SRCS= proj.c list.c queue.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c rectangle.c font.c xpm_utils.c ent.c rtc.c uart.c hltp.c makecode_map.c menu.c
|
|
13 | 13 |
IPATHS=-I./include -I./libs/graph/include -I./libs/kbc/include -I./libs/rtc/include -I./libs/timer/include -I./libs/uart/include -I./libs/classes/include -I./libs/utils/include -I./maps -I./media/xpm |
14 | 14 |
|
15 | 15 |
CPPFLAGS += -pedantic ${IPATHS} -D LCOM_MACRO #-D __LCOM_OPTIMIZED_ |
proj/TB.mk | ||
---|---|---|
9 | 9 |
.PATH: ${.CURDIR}/libs/classes/src |
10 | 10 |
.PATH: ${.CURDIR}/libs/utils/src |
11 | 11 |
|
12 |
SRCS= proj.c list.c queue.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c rectangle.c font.c xpm_utils.c ent.c rtc.c uart.c makecode_map.c |
|
12 |
SRCS= proj.c list.c queue.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c rectangle.c font.c xpm_utils.c ent.c rtc.c uart.c makecode_map.c menu.c
|
|
13 | 13 |
IPATHS=-I./include -I./libs/graph/include -I./libs/kbc/include -I./libs/rtc/include -I./libs/timer/include -I./libs/uart/include -I./libs/classes/include -I./libs/utils/include -I./maps -I./media/xpm |
14 | 14 |
|
15 | 15 |
CPPFLAGS += -pedantic ${IPATHS} -D LCOM_MACRO #-D __LCOM_OPTIMIZED_ |
proj/tasks.md | ||
---|---|---|
9 | 9 |
- [ ] Implement zombie mode (single-player or co-op). |
10 | 10 |
- [ ] Implement algorithm to decide when gunner AI needs to shoot. |
11 | 11 |
- [ ] Implement campaign mode (single-player or co-op). |
12 |
- [ ] Visibility algorithm |
|
12 | 13 |
|
13 | 14 |
### Low Priority |
14 | 15 |
- [ ] Change sprites. |
Also available in: Unified diff