Revision 347
actually now i added the files
proj/include/campaign.h | ||
---|---|---|
1 |
#ifndef CAMPAIGN_H_INCLUDED |
|
2 |
#define CAMPAIGN_H_INCLUDED |
|
3 |
|
|
4 |
int (campaign)(void); |
|
5 |
|
|
6 |
#endif //CAMPAIGN_H_INCLUDED |
|
0 | 7 |
proj/include/chat.h | ||
---|---|---|
1 |
#ifndef CHAT_H_INCLUDED |
|
2 |
#define CHAT_H_INCLUDED |
|
3 |
|
|
4 |
int (chat)(void); |
|
5 |
|
|
6 |
#endif //CHAT_H_INCLUDED |
|
0 | 7 |
proj/include/singleplayer.h | ||
---|---|---|
1 |
#ifndef SINGLEPLAYER_H_INCLUDED |
|
2 |
#define SINGLEPLAYER_H_INCLUDED |
|
3 |
|
|
4 |
int (singleplayer)(void); |
|
5 |
|
|
6 |
#endif //SINGLEPLAYER_H_INCLUDED |
|
0 | 7 |
proj/src/campaign.c | ||
---|---|---|
1 |
#include <lcom/lcf.h> |
|
2 |
|
|
3 |
#include "campaign.h" |
|
4 |
|
|
5 |
#include "proj.h" |
|
6 |
|
|
7 |
#include "proj_macros.h" |
|
8 |
#include "proj_func.h" |
|
9 |
#include "ent.h" |
|
10 |
#include "interrupts_func.h" |
|
11 |
#include "graph.h" |
|
12 |
#include "hltp.h" |
|
13 |
#include "errors.h" |
|
14 |
#include <math.h> |
|
15 |
|
|
16 |
int (campaign)(void){ |
|
17 |
|
|
18 |
int r; |
|
19 |
|
|
20 |
ent_set_scale(DEFAULT_SCALE); |
|
21 |
text_timer_t *in_game_timer = text_timer_ctor(font_get_default()); |
|
22 |
|
|
23 |
list_t *shooter_list = list_ctor(); |
|
24 |
|
|
25 |
gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n"); |
|
26 |
gunner_set_spawn(shooter1, 75, 75); |
|
27 |
gunner_set_pos(shooter1, 75, 75); |
|
28 |
|
|
29 |
gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_nothing, GUNNER_PLAYER, 2); |
|
30 |
gunner_set_spawn(shooter2, 975, 75); |
|
31 |
gunner_set_pos(shooter2, 775, 75); |
|
32 |
|
|
33 |
list_insert(shooter_list, list_end(shooter_list), shooter1); |
|
34 |
list_insert(shooter_list, list_end(shooter_list), shooter2); |
|
35 |
|
|
36 |
list_t *bullet_list = list_ctor(); |
|
37 |
|
|
38 |
ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
|
39 |
gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
|
40 |
|
|
41 |
//uint32_t refresh_count_value = sys_hz() / REFRESH_RATE; |
|
42 |
uint8_t last_lb = 0; |
|
43 |
struct packet pp; |
|
44 |
keys_t *keys = get_key_presses(); |
|
45 |
|
|
46 |
/// loop stuff |
|
47 |
uint64_t int_vector = 0; |
|
48 |
int good = true; |
|
49 |
while (good) { |
|
50 |
/* Get a request message. */ |
|
51 |
if((r = get_interrupts_vector(&int_vector))) return r; |
|
52 |
uint32_t n = 1; |
|
53 |
for (uint8_t i = 0; i < 32; i++, n <<= 1) { |
|
54 |
if(!good) break; |
|
55 |
if (int_vector & n) { |
|
56 |
interrupt_handler(i); |
|
57 |
switch (i) { |
|
58 |
case TIMER0_IRQ: |
|
59 |
|
|
60 |
if (timer_get_no_interrupts() % 60 == 0) text_timer_update(in_game_timer); |
|
61 |
update_movement(map1, shooter1, keys, shooter_list); |
|
62 |
|
|
63 |
update_game_state(map1, shooter_list, bullet_list); |
|
64 |
|
|
65 |
//update_scale(); |
|
66 |
double angle = get_mouse_angle(shooter1); |
|
67 |
gunner_set_angle(shooter1, angle - M_PI_2); |
|
68 |
|
|
69 |
ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
|
70 |
gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
|
71 |
|
|
72 |
graph_clear_screen(); |
|
73 |
map_draw (map1); |
|
74 |
bullet_draw_list(bullet_list); |
|
75 |
gunner_draw_list(shooter_list); |
|
76 |
|
|
77 |
text_draw(in_game_timer->text); |
|
78 |
|
|
79 |
sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
|
80 |
sprite_draw(sp_crosshair); |
|
81 |
graph_draw(); |
|
82 |
|
|
83 |
break; |
|
84 |
case KBC_IRQ: |
|
85 |
if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) { |
|
86 |
good = false; |
|
87 |
} |
|
88 |
break; |
|
89 |
case MOUSE_IRQ: |
|
90 |
if (mouse_get_counter_mouse_ih() >= 3) { |
|
91 |
mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp); |
|
92 |
update_mouse(&pp); |
|
93 |
if (last_lb ^ keys->lb_pressed && keys->lb_pressed) |
|
94 |
shoot_bullet(shooter1, bullet_list, bsp_bullet); |
|
95 |
last_lb = keys->lb_pressed; |
|
96 |
mouse_set_counter_mouse_ih(0); |
|
97 |
|
|
98 |
} |
|
99 |
break; |
|
100 |
case COM1_IRQ: nctp_ih(); break; |
|
101 |
} |
|
102 |
} |
|
103 |
} |
|
104 |
} |
|
105 |
|
|
106 |
while(list_size(shooter_list) > 0){ |
|
107 |
gunner_t *p = list_erase(shooter_list, list_begin(shooter_list)); |
|
108 |
gunner_dtor(p); |
|
109 |
} |
|
110 |
if(list_dtor(shooter_list)) printf("COULD NOT DESTRUCT SHOOTER LIST\n"); |
|
111 |
|
|
112 |
while(list_size(bullet_list) > 0){ |
|
113 |
bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list)); |
|
114 |
bullet_dtor(p); |
|
115 |
} |
|
116 |
if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n"); |
|
117 |
|
|
118 |
text_timer_dtor(in_game_timer); in_game_timer = NULL; |
|
119 |
|
|
120 |
return SUCCESS; |
|
121 |
} |
|
0 | 122 |
proj/src/chat.c | ||
---|---|---|
1 |
#include <lcom/lcf.h> |
|
2 |
|
|
3 |
#include "chat.h" |
|
4 |
|
|
5 |
#include "proj.h" |
|
6 |
|
|
7 |
#include "proj_macros.h" |
|
8 |
#include "proj_func.h" |
|
9 |
#include "ent.h" |
|
10 |
#include "interrupts_func.h" |
|
11 |
#include "graph.h" |
|
12 |
#include "rectangle.h" |
|
13 |
#include "hltp.h" |
|
14 |
#include "makecode_map.h" |
|
15 |
#include "errors.h" |
|
16 |
#include <math.h> |
|
17 |
|
|
18 |
#define CHAT_MAX_SIZE 75 |
|
19 |
#define CHAT_MAX_NUM 19 |
|
20 |
static text_t *t_text[CHAT_MAX_NUM] = {NULL}; |
|
21 |
static rectangle_t *r_text = NULL; |
|
22 |
|
|
23 |
static void chat_process(const uint8_t *p, const size_t sz){ |
|
24 |
char buffer2[CHAT_MAX_NUM+3]; |
|
25 |
void *dest = NULL; |
|
26 |
hltp_type tp = hltp_interpret(p, sz, &dest); |
|
27 |
switch(tp){ |
|
28 |
case hltp_type_string: |
|
29 |
strcpy(buffer2, dest); |
|
30 |
strncat(buffer2, " <", 2); |
|
31 |
for(size_t i = CHAT_MAX_NUM-1; i; --i) |
|
32 |
text_set_string(t_text[i], text_get_string(t_text[i-1])); |
|
33 |
text_set_string(t_text[0], buffer2); |
|
34 |
for(size_t i = 0; i < CHAT_MAX_NUM; ++i){ |
|
35 |
if(text_get_string(t_text[i])[0] == '>'){ |
|
36 |
text_set_pos(t_text[i], rectangle_get_x(r_text)+50, text_get_y(t_text[i])); |
|
37 |
text_set_halign(t_text[i], text_halign_left); |
|
38 |
}else{ |
|
39 |
text_set_pos(t_text[i], rectangle_get_x(r_text)+rectangle_get_w(r_text)-50, text_get_y(t_text[i])); |
|
40 |
text_set_halign(t_text[i], text_halign_right); |
|
41 |
} |
|
42 |
} |
|
43 |
break; |
|
44 |
case hltp_type_invalid: break; |
|
45 |
case hltp_type_bullet : break; |
|
46 |
case hltp_type_host : break; |
|
47 |
case hltp_type_remote : break; |
|
48 |
} |
|
49 |
} |
|
50 |
|
|
51 |
int (chat)(void){ |
|
52 |
int r; |
|
53 |
|
|
54 |
nctp_dump(); |
|
55 |
nctp_set_processor(chat_process); |
|
56 |
|
|
57 |
struct packet pp; |
|
58 |
|
|
59 |
char buffer[CHAT_MAX_SIZE] = ""; |
|
60 |
rectangle_t *r_buffer = NULL; { |
|
61 |
r_buffer = rectangle_ctor(0,0,900,70); |
|
62 |
rectangle_set_pos(r_buffer, graph_get_XRes()/2 -rectangle_get_w(r_buffer)/2, |
|
63 |
(int16_t)(graph_get_YRes()*0.87-rectangle_get_h(r_buffer)/2)); |
|
64 |
rectangle_set_fill_color (r_buffer, GRAPH_BLACK); |
|
65 |
rectangle_set_outline_width(r_buffer, 2); |
|
66 |
rectangle_set_outline_color(r_buffer, GRAPH_WHITE); |
|
67 |
rectangle_set_fill_trans(r_buffer, GRAPH_TRANSPARENT); |
|
68 |
} |
|
69 |
text_t *t_buffer = NULL; { |
|
70 |
t_buffer = text_ctor(font_get_default(), ""); |
|
71 |
text_set_pos(t_buffer, rectangle_get_x(r_buffer)+50, |
|
72 |
rectangle_get_y(r_buffer)+rectangle_get_h(r_buffer)/2); |
|
73 |
text_set_halign(t_buffer, text_halign_left); |
|
74 |
text_set_valign(t_buffer, text_valign_center); |
|
75 |
text_set_color (t_buffer, TEXT_COLOR); |
|
76 |
} |
|
77 |
text_t *t_size = NULL; { |
|
78 |
t_size = text_ctor(font_get_default(), ""); |
|
79 |
text_set_pos(t_size, rectangle_get_x(r_buffer)+rectangle_get_w(r_buffer)-5, |
|
80 |
rectangle_get_y(r_buffer)+rectangle_get_h(r_buffer)-5); |
|
81 |
text_set_halign(t_size, text_halign_right); |
|
82 |
text_set_valign(t_size, text_valign_bottom); |
|
83 |
text_set_color (t_size, TEXT_COLOR); |
|
84 |
text_set_size (t_size, 18); |
|
85 |
char buffer2[20]; |
|
86 |
sprintf(buffer2, "%d/%d", strlen(buffer), CHAT_MAX_SIZE); |
|
87 |
text_set_string(t_size, buffer2); |
|
88 |
} |
|
89 |
|
|
90 |
/** r_text */ { |
|
91 |
r_text = rectangle_ctor(0,0,900,550); |
|
92 |
rectangle_set_pos(r_text, graph_get_XRes()/2 -rectangle_get_w(r_buffer)/2, |
|
93 |
(int16_t)(graph_get_YRes()*0.09)); |
|
94 |
rectangle_set_fill_color (r_text, GRAPH_BLACK); |
|
95 |
rectangle_set_outline_width(r_text, 2); |
|
96 |
rectangle_set_outline_color(r_text, GRAPH_WHITE); |
|
97 |
rectangle_set_fill_trans(r_text, GRAPH_TRANSPARENT); |
|
98 |
} |
|
99 |
/** t_text */ { |
|
100 |
for(uint16_t i = 0; i < CHAT_MAX_NUM; ++i){ |
|
101 |
t_text[i] = text_ctor(font_get_default(), " "); |
|
102 |
text_set_pos(t_text[i], rectangle_get_x(r_text)+50, |
|
103 |
rectangle_get_y(r_text)+rectangle_get_h(r_text)-30-25*i); |
|
104 |
text_set_halign(t_text[i], text_halign_left); |
|
105 |
text_set_valign(t_text[i], text_valign_bottom); |
|
106 |
text_set_color (t_text[i], TEXT_COLOR); |
|
107 |
} |
|
108 |
} |
|
109 |
|
|
110 |
/// loop stuff |
|
111 |
uint64_t int_vector = 0; |
|
112 |
int good = true; |
|
113 |
while (good) { |
|
114 |
/* Get a request message. */ |
|
115 |
if((r = get_interrupts_vector(&int_vector))) return r; |
|
116 |
uint32_t n = 1; |
|
117 |
for (uint8_t i = 0; i < 32; i++, n <<= 1) { |
|
118 |
if (int_vector & n) { |
|
119 |
interrupt_handler(i); |
|
120 |
switch (i) { |
|
121 |
case TIMER0_IRQ: |
|
122 |
graph_clear_screen(); |
|
123 |
sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
|
124 |
|
|
125 |
rectangle_draw(r_buffer); |
|
126 |
text_draw(t_buffer); |
|
127 |
text_draw(t_size); |
|
128 |
|
|
129 |
rectangle_draw(r_text); |
|
130 |
for(size_t j = 0; j < CHAT_MAX_NUM; ++j) text_draw(t_text[j]); |
|
131 |
|
|
132 |
sprite_draw(sp_crosshair); |
|
133 |
graph_draw(); |
|
134 |
break; |
|
135 |
case KBC_IRQ: |
|
136 |
if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) good = false; |
|
137 |
else if (keyboard_get_scancode()[0] == ENTER_MAKE_CODE) { |
|
138 |
hltp_send_string(buffer); |
|
139 |
char buffer2[CHAT_MAX_SIZE+3] = "> "; |
|
140 |
strncat(buffer2, buffer, strlen(buffer)); |
|
141 |
for(size_t j = CHAT_MAX_NUM-1; j; --j) text_set_string(t_text[i], text_get_string(t_text[i-1])); |
|
142 |
text_set_string(t_text[0], buffer2); |
|
143 |
for(size_t j = 0; j < CHAT_MAX_NUM; ++j){ |
|
144 |
if(text_get_string(t_text[j])[0] == '>'){ |
|
145 |
text_set_pos(t_text[j], rectangle_get_x(r_text)+50, text_get_y(t_text[j])); |
|
146 |
text_set_halign(t_text[j], text_halign_left); |
|
147 |
}else{ |
|
148 |
text_set_pos(t_text[j], rectangle_get_x(r_text)+rectangle_get_w(r_text)-50, text_get_y(t_text[j])); |
|
149 |
text_set_halign(t_text[j], text_halign_right); |
|
150 |
} |
|
151 |
} |
|
152 |
buffer[0] = '\0'; |
|
153 |
} else if(keyboard_get_scancode()[0] == BACKSPACE_MAKE_CODE){ |
|
154 |
buffer[strlen(buffer)-1] = '\0'; |
|
155 |
} else { |
|
156 |
char c = map_makecode(keyboard_get_scancode()[0]); |
|
157 |
if (c == ERROR_CODE) break; |
|
158 |
if(strlen(buffer) < CHAT_MAX_SIZE) strncat(buffer, &c, 1); |
|
159 |
else printf("Char limit exceeded\n"); |
|
160 |
} |
|
161 |
text_set_string(t_buffer, buffer); |
|
162 |
char buffer2[20]; |
|
163 |
sprintf(buffer2, "%d/%d", strlen(buffer), CHAT_MAX_SIZE); |
|
164 |
text_set_string(t_size, buffer2); |
|
165 |
case MOUSE_IRQ: |
|
166 |
if (mouse_get_counter_mouse_ih() >= 3) { |
|
167 |
mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp); |
|
168 |
update_mouse(&pp); |
|
169 |
mouse_set_counter_mouse_ih(0); |
|
170 |
} |
|
171 |
break; |
|
172 |
case COM1_IRQ: nctp_ih(); break; |
|
173 |
} |
|
174 |
} |
|
175 |
} |
|
176 |
} |
|
177 |
|
|
178 |
rectangle_dtor(r_buffer); |
|
179 |
text_dtor (t_buffer); |
|
180 |
|
|
181 |
rectangle_dtor(r_text); |
|
182 |
for(size_t i = 0; i < CHAT_MAX_NUM; ++i) text_dtor(t_text[i]); |
|
183 |
|
|
184 |
nctp_set_processor(NULL); |
|
185 |
|
|
186 |
return SUCCESS; |
|
187 |
} |
|
0 | 188 |
proj/src/singleplayer.c | ||
---|---|---|
1 |
#include <lcom/lcf.h> |
|
2 |
|
|
3 |
#include "singleplayer.h" |
|
4 |
|
|
5 |
#include "proj.h" |
|
6 |
|
|
7 |
#include "proj_macros.h" |
|
8 |
#include "proj_func.h" |
|
9 |
#include "ent.h" |
|
10 |
#include "interrupts_func.h" |
|
11 |
#include "graph.h" |
|
12 |
#include "hltp.h" |
|
13 |
#include "errors.h" |
|
14 |
#include "menu.h" |
|
15 |
|
|
16 |
#include "campaign.h" |
|
17 |
#include "zombies.h" |
|
18 |
|
|
19 |
int (singleplayer)(void) { |
|
20 |
|
|
21 |
int r; |
|
22 |
|
|
23 |
menu_t *main_menu = menu_ctor(font_get_default()); |
|
24 |
menu_add_item(main_menu, "Campaign"); |
|
25 |
menu_add_item(main_menu, "Zombies"); |
|
26 |
menu_add_item(main_menu, "Back"); |
|
27 |
|
|
28 |
//uint32_t refresh_count_value = sys_hz() / REFRESH_RATE; |
|
29 |
uint8_t last_lb = 0; |
|
30 |
struct packet pp; |
|
31 |
keys_t *keys = get_key_presses(); |
|
32 |
|
|
33 |
/// loop stuff |
|
34 |
int click = 0; |
|
35 |
uint64_t int_vector = 0; |
|
36 |
int good = true; |
|
37 |
while (good) { |
|
38 |
/* Get a request message. */ |
|
39 |
if((r = get_interrupts_vector(&int_vector))) return r; |
|
40 |
uint32_t n = 1; |
|
41 |
for (uint8_t i = 0; i < 32; i++, n <<= 1) { |
|
42 |
if (int_vector & n) { |
|
43 |
interrupt_handler(i); |
|
44 |
switch (i) { |
|
45 |
case TIMER0_IRQ: |
|
46 |
|
|
47 |
graph_clear_screen(); |
|
48 |
switch(menu_update_state(main_menu, click)){ |
|
49 |
case -1: break; |
|
50 |
case 0: campaign(); break; |
|
51 |
case 1: zombies(); break; |
|
52 |
case 2: good = false; break; |
|
53 |
} |
|
54 |
menu_draw(main_menu); |
|
55 |
|
|
56 |
click = 0; |
|
57 |
|
|
58 |
sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
|
59 |
sprite_draw(sp_crosshair); |
|
60 |
graph_draw(); |
|
61 |
|
|
62 |
break; |
|
63 |
case KBC_IRQ: |
|
64 |
if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) good = false; |
|
65 |
case MOUSE_IRQ: |
|
66 |
if (mouse_get_counter_mouse_ih() >= 3) { |
|
67 |
mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp); |
|
68 |
update_mouse(&pp); |
|
69 |
if (!click) click = last_lb ^ keys->lb_pressed && keys->lb_pressed; |
|
70 |
last_lb = keys->lb_pressed; |
|
71 |
mouse_set_counter_mouse_ih(0); |
|
72 |
} |
|
73 |
break; |
|
74 |
case COM1_IRQ: nctp_ih(); break; |
|
75 |
} |
|
76 |
} |
|
77 |
} |
|
78 |
} |
|
79 |
|
|
80 |
return 0; |
|
81 |
} |
|
0 | 82 |
Also available in: Unified diff