Project

General

Profile

Revision 355

changed place of stuff

View differences:

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
7 0

  
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
7 0

  
proj/include/proj_func.h
1
#ifndef PROJ_FUNC_H_INCLUDED
2
#define PROJ_FUNC_H_INCLUDED
3

  
4
/**
5
 * @defgroup proj_func proj_func
6
 * @brief Project helper functions.
7
 *
8
 * @{
9
 */
10

  
11
#include "libs.h"
12
#include "proj_structures.h"
13

  
14
//#include <stdint.h>
15

  
16
/**
17
 * @brief Cleans up all memory, unsubscribes interrupts.
18
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
19
 * @see {_ERRORS_H_::errors}
20
 */
21
int cleanup(void);
22

  
23
/**
24
 * @brief Update key presses.
25
 */
26
void update_key_presses(void);
27
/**
28
 * @brief Get key presses.
29
 * @return  keys_t containing key presses
30
 */
31
keys_t* (get_key_presses)(void);
32

  
33
/**
34
 * @brief Update mouse.
35
 */
36
void update_mouse(struct packet *p);
37
/**
38
 * @brief Get pointer to mouse X-position.
39
 * @return  Pointer to mouse X-position.
40
 */
41
int16_t* get_mouse_X(void);
42
/**
43
 * @brief Get pointer to mouse Y-position.
44
 * @return  Pointer to mouse Y-position.
45
 */
46
int16_t* get_mouse_Y(void);
47
/**
48
 * @brief Get cursor angle relative to a gunner in the screen.
49
 * @param   p   Pointer to gunner
50
 * @return      Angle of the mouse relative to the gunner
51
 */
52
double get_mouse_angle(gunner_t *p);
53

  
54
/**
55
 * @brief Updates movement variables.
56
 */
57
void update_movement(map_t *map, gunner_t *p, keys_t *keys, list_t *shooter_list);
58

  
59
/**
60
 * @brief Get random spawn (actually, position) for new gunner.
61
 *
62
 * The new position cannot collide with the map, nor with any of the gunners
63
 * already in the list.
64
 * @param   map     Pointer to map
65
 * @param   p       Pointer to new gunner
66
 * @param   l       List of gunners that already exist
67
 */
68
void (get_random_spawn)(const map_t *map, gunner_t *p, list_t *l);
69

  
70
/**
71
 * @brief Update scale if the keys were pressed to change scale.
72
 */
73
void update_scale(void);
74

  
75
/**
76
 * @brief Shoot a bullet.
77
 * @param   shooter     Pointer to gunner that shot the bullet
78
 * @param   bullet_list List of the bullets in the map
79
 * @param   bsp_bullet  Basic sprite that will be used to render the bullet
80
 */
81
void (shoot_bullet)(const gunner_t *shooter, list_t *bullet_list, const basic_sprite_t *bsp_bullet);
82
/**
83
 * @brief Update game state.
84
 *
85
 * This includes moving bullets accordingly, processing damages, collisions of
86
 * bullets with walls, melee damage for the gunners that have autonomous melee.
87
 * @param   map             Pointer to map
88
 * @param   shooter_list    List of shooters
89
 * @param   bullet_list     List of bullets in the map
90
 */
91
void (update_game_state)(const map_t *map, list_t *shooter_list, list_t *bullet_list);
92

  
93
/**
94
 * @brief Wrapper to easen filling of the host_info_t.
95
 * @param   p       Host info to fill
96
 * @param   host    Host gunner
97
 * @param   remote  Remote gunner
98
 */
99
void build_host_structure(host_info_t *p, gunner_t *host, gunner_t *remote);
100
/**
101
 * @brief Wrapper to easen filling of the remote_info_t.
102
 * @param   p       Remote info to fill
103
 * @param   keys    Key presses of remote
104
 * @param   angle   Mouse angle of remote
105
 */
106
void build_remote_structure(remote_info_t *p, keys_t *keys, double angle);
107

  
108

  
109

  
110
/**
111
 * @}
112
 */
113

  
114
/**
115
 * @defgroup text_timer_t text_timer_t
116
 * @ingroup proj_func
117
 * @brief Text timer.
118
 *
119
 * @{
120
 */
121

  
122
/**
123
 * @brief Text timer.
124
 */
125
typedef struct {
126
    /// @brief Time since construction.
127
    int time;
128
    /// @brief Text.
129
    text_t *text;
130
} text_timer_t;
131
/**
132
 * @brief Construct timer
133
 * @param   fnt Font used to render timer text
134
 * @return      Pointer to constructed timer, or NULL if failed
135
 */
136
text_timer_t* (text_timer_ctor)(const font_t *fnt);
137
/**
138
 * @brief Destruct timer.
139
 * @param   p   Pointer to timer to be destructed
140
 */
141
void (text_timer_dtor)(text_timer_t *p);
142
/**
143
 * @brief   Update timer, by incrementing the number of seconds.
144
 * @param   p   Pointer to timer
145
 */
146
void (text_timer_update)(text_timer_t *p);
147
/**
148
 * @brief   Reset timer to 0.
149
 * @param   p   Pointer to timer
150
 */
151
void (text_timer_reset)(text_timer_t *p);
152

  
153
/**
154
 * @}
155
 */
156

  
157
#endif /* end of include guard: PROJ_FUNC_H_INCLUDED */
158 0

  
proj/include/makecode_map.h
1
#ifndef MAKE_CODE_MAP_H_
2
#define MAKE_CODE_MAP_H_
3

  
4
/**
5
 * @defgroup makecode_map makecode_map
6
 * @brief Makecode map.
7
 *
8
 * @{
9
 */
10

  
11
#include <stdint.h>
12

  
13
/// @brief Error code
14
#define ERROR_CODE      0
15

  
16
/**
17
 * @brief Maps make code into char
18
 * @param code      Make code to map.
19
 * @return ERROR_CODE if code char isn't valid, otherwise the character.
20
 */
21
char (map_makecode)(uint8_t code);
22

  
23
/**
24
 * @}
25
 */
26

  
27
#endif /* end of include guard: MAKE_CODE_MAP_H_ */
28 0

  
proj/include/ent.h
1
#ifndef ENT_H_INCLUDED
2
#define ENT_H_INCLUDED
3

  
4
/**
5
 * @defgroup ent ent
6
 * @brief Entities module
7
 *
8
 * @{
9
 */
10

  
11
#include "libs.h"
12

  
13
/**
14
 * @brief Set scale.
15
 * @param   n   Scale
16
 */
17
void (ent_set_scale) (double n);
18
/**
19
 * @brief Set origin of screen (upper-left corner) in game referential coordinates.
20
 * @param   x   X-position of the upper-left corner of the screen
21
 * @param   y   Y-position of the upper-left corner of the screen
22
 */
23
void (ent_set_origin)(double x, double y);
24
/**
25
 * @brief Get scale.
26
 * @return  Scale
27
 */
28
double (ent_get_scale)  (void);
29
/**
30
 * @brief Get X-length of the screen in game referencial coordinates.
31
 * @return X-length
32
 */
33
double (ent_get_XLength)(void);
34
/**
35
 * @brief Get Y-length of the screen in game referencial coordinates.
36
 * @return Y-length
37
 */
38
double (ent_get_YLength)(void);
39

  
40
/**
41
 * @}
42
 */
43

  
44
/**
45
 * @defgroup gunner_t gunner_t
46
 * @ingroup ent
47
 * @brief Gunner module.
48
 *
49
 * @{
50
 */
51

  
52
/// @brief Identifier of a melee gunner
53
#define GUNNER_MELEE    BIT(0)
54
/// @brief Identifier of a ranged gunner
55
#define GUNNER_RANGED   BIT(1)
56
/// @brief Identifier of a player-controlled gunner
57
#define GUNNER_PLAYER   BIT(2)
58
/// @brief Identifier of an automatic follower gunner
59
#define GUNNER_FOLLOW   BIT(3)
60

  
61
/**
62
 * @brief Gunner.
63
 */
64
typedef struct gunner gunner_t;
65
/**
66
 * @brief Construct gunner.
67
 * @param   dude    Basic sprite representing the gunner
68
 * @param   weapon  Basic sprite representing the weapon of the gunner
69
 * @param   type    Type of gunner. Can be one of the identifier macros and also the OR-merge of any combination of them
70
 * @param   team    Team of the gunner. 1 for player 1, 2 for player 2, 3 for opponents and 0 for no team (temporary gunner)
71
 */
72
gunner_t* (gunner_ctor)(basic_sprite_t *dude, basic_sprite_t *weapon, uint16_t type, int team);
73
/**
74
 * @brief Destruct gunner.
75
 * @param   p   Pointer to gunner to be destructed
76
 */
77
void      (gunner_dtor)(gunner_t *p);
78
/**
79
 * @brief   Set gunner position.
80
 * @param   p   Pointer to gunner
81
 * @param   x   X-position of the gunner in game coordinates
82
 * @param   y   Y-position of the gunner in game coordinates
83
 */
84
void (gunner_set_pos)               (gunner_t *p, double x, double y);
85
/**
86
 * @brief   Set gunner spawn position.
87
 * @param   p   Pointer to gunner
88
 * @param   x   Spawn X-position of the gunner in game coordinates
89
 * @param   y   Spawn Y-position of the gunner in game coordinates
90
 */
91
void (gunner_set_spawn)             (gunner_t *p, double x, double y);
92
/**
93
 * @brief   Set gunner angle.
94
 * @param   p       Pointer to gunner
95
 * @param   angle   Angle in radians
96
 */
97
void (gunner_set_angle)             (gunner_t *p, double angle);
98
/**
99
 * @brief   Set gunner health (total, max health).
100
 * @param   p       Pointer to gunner
101
 * @param   health  Health
102
 */
103
void (gunner_set_health)            (gunner_t *p, double health);
104
/**
105
 * @brief   Set gunner current health.
106
 * @param   p       Pointer to gunner
107
 * @param   health  Current health
108
 */
109
void (gunner_set_curr_health)       (gunner_t *p, double health);
110
/**
111
 * @brief   Get gunner X-position.
112
 * @param   p   Pointer to gunner
113
 * @return  X-position of the gunner
114
 */
115
double  (gunner_get_x)              (const gunner_t *p);
116
/**
117
 * @brief   Get gunner Y-position.
118
 * @param   p   Pointer to gunner
119
 * @return  Y-position of the gunner
120
 */
121
double  (gunner_get_y)              (const gunner_t *p);
122
/**
123
 * @brief   Get gunner spawn X-position.
124
 * @param   p   Pointer to gunner
125
 * @return  Spawn X-position of the gunner
126
 */
127
double  (gunner_get_spawn_x)        (const gunner_t *p);
128
/**
129
 * @brief   Get gunner spawn Y-position.
130
 * @param   p   Pointer to gunner
131
 * @return  Spawn Y-position of the gunner
132
 */
133
double  (gunner_get_spawn_y)        (const gunner_t *p);
134
/**
135
 * @brief   Get gunner angle.
136
 * @param   p   Pointer to gunner
137
 * @return  Angle of the gunner
138
 */
139
double  (gunner_get_angle)          (const gunner_t *p);
140
/**
141
 * @brief   Get gunner max health.
142
 * @param   p   Pointer to gunner
143
 * @return  Max health of the gunner
144
 */
145
double  (gunner_get_health)         (const gunner_t *p);
146
/**
147
 * @brief   Get gunner current health.
148
 * @param   p   Pointer to gunner
149
 * @return  Current health of the gunner
150
 */
151
double  (gunner_get_curr_health)    (const gunner_t *p);
152
/**
153
 * @brief   Get gunner X-position in screen coordinates.
154
 * @param   p   Pointer to gunner
155
 * @return  X-position of the gunner in screen coordinates
156
 */
157
int16_t (gunner_get_x_screen)       (const gunner_t *p);
158
/**
159
 * @brief   Get gunner Y-position in screen coordinates.
160
 * @param   p   Pointer to gunner
161
 * @return  Y-position of the gunner in screen coordinates
162
 */
163
int16_t (gunner_get_y_screen)       (const gunner_t *p);
164
/**
165
 * @brief   Get gunner type.
166
 * @param   p   Pointer to gunner
167
 * @return  Type of gunner
168
 */
169
uint16_t (gunner_get_type)          (const gunner_t *p);
170
/**
171
 * @brief   Get gunner team.
172
 * @param   p   Pointer to gunner
173
 * @return  Team of gunner
174
 */
175
int     (gunner_get_team)           (const gunner_t *p);
176
/**
177
 * @brief   Draw gunner on screen buffer.
178
 * @param   p   Pointer to gunner
179
 */
180
void (gunner_draw)(gunner_t *p);
181
/**
182
 * @brief   Draw gunner health bar on screen buffer.
183
 * @param   p   Pointer to gunner
184
 */
185
void (gunner_draw_health)(const gunner_t *p);
186
/**
187
 * @brief   Draw list of gunners on screen buffer.
188
 * @param   shooter_list    List of gunners
189
 */
190
void (gunner_draw_list)(list_t *shooter_list);
191
/**
192
 * @brief Get distance between two gunners.
193
 * @param   p1  Gunner 1
194
 * @param   p2  Gunner 2
195
 * @return  Euclidian distance between the two gunners
196
 */
197
double (gunner_distance)(const gunner_t *p1, const gunner_t *p2);
198
/**
199
 * @brief Check if two gunners are colliding.
200
 * @param   p1  Gunner 1
201
 * @param   p2  Gunner 2
202
 * @return  true if the two gunners are colliding, false otherwise
203
 */
204
int (gunner_collides_gunner)(const gunner_t *p1, const gunner_t *p2);
205

  
206
/**
207
 * @}
208
 */
209

  
210
/**
211
 * @defgroup bullet_t bullet_t
212
 * @ingroup ent
213
 * @brief Bullet module.
214
 *
215
 * @{
216
 */
217

  
218
/**
219
 * @brief Bullet.
220
 */
221
typedef struct bullet bullet_t;
222
/**
223
 * @brief Construct bullet.
224
 * @param   shooter Pointer to gunner that shot that bullet
225
 * @param   b       Basic sprite of the bullet
226
 * @param   x       X-position
227
 * @param   y       Y-position
228
 * @param   vx      X-speed
229
 * @param   vy      Y-speed
230
 * @return Pointer to constructed bullet, or NULL if failed
231
 */
232
bullet_t* (bullet_ctor)(const gunner_t *shooter, const basic_sprite_t *b, double x, double y, double vx, double vy);
233
/**
234
 * @brief Destruct bullet.
235
 * @param   p   Pointer to bullet to be destructed
236
 */
237
void      (bullet_dtor)(bullet_t *p);
238
/**
239
 * @brief   Get bullet X-position.
240
 * @param   p   Pointer to bullet
241
 * @return  X-position of the bullet
242
 */
243
double  (bullet_get_x)       (const bullet_t *p);
244
/**
245
 * @brief   Get bullet Y-position.
246
 * @param   p   Pointer to bullet
247
 * @return  Y-position of the bullet
248
 */
249
double  (bullet_get_y)       (const bullet_t *p);
250
/**
251
 * @brief   Get bullet X-speed.
252
 * @param   p   Pointer to bullet
253
 * @return  X-speed of the bullet
254
 */
255
double  (bullet_get_vx)      (const bullet_t *p);
256
/**
257
 * @brief   Get bullet Y-speed.
258
 * @param   p   Pointer to bullet
259
 * @return  Y-speed of the bullet
260
 */
261
double  (bullet_get_vy)      (const bullet_t *p);
262
/**
263
 * @brief   Get bullet X-position in screen coordinates.
264
 * @param   p   Pointer to bullet
265
 * @return  X-position of the bullet in screen coordinates
266
 */
267
int16_t (bullet_get_x_screen)(const bullet_t *p);
268
/**
269
 * @brief   Get bullet Y-position in screen coordinates.
270
 * @param   p   Pointer to bullet
271
 * @return  Y-position of the bullet in screen coordinates
272
 */
273
int16_t (bullet_get_y_screen)(const bullet_t *p);
274
/**
275
 * @brief   Get bullet damage.
276
 * @param   p   Pointer to bullet
277
 * @return  Damage
278
 */
279
double  (bullet_get_damage)  (const bullet_t *p);
280
/**
281
 * @brief   Set bullet damage.
282
 * @param   p   Pointer to bullet
283
 * @param   damage  Damage
284
 */
285
void    (bullet_set_damage)  (bullet_t *p, double damage);
286
/**
287
 * @brief Get gunner that shot the bullet.
288
 * @param   p   Pointer to bullet
289
 * @return  Pointer to gunner that shot the bullet
290
 */
291
const gunner_t* (bullet_get_shooter)(const bullet_t *p);
292
/**
293
 * @brief Update bullet position (i.e., advance it according to its speed).
294
 * @param   p   Pointer to bullet
295
 */
296
void (bullet_update_movement)(bullet_t *p);
297
/**
298
 * @brief Update movement of bullets in a list.
299
 * @param   bullet_list     Pointer to bullet list
300
 */
301
void (bullet_update_movement_list)(list_t *bullet_list);
302
/**
303
 * @brief Draw bullet on screen buffer.
304
 * @param   p   Pointer to bullet
305
 */
306
void (bullet_draw)(bullet_t *p);
307
/**
308
 * @brief Draw bullets in list on screen buffer.
309
 * @param   bullet_list     Pointer to bullet list
310
 */
311
void (bullet_draw_list)(list_t *bullet_list);
312

  
313
/**
314
 * @}
315
 */
316

  
317
/**
318
 * @defgroup map_t map_t
319
 * @ingroup ent
320
 * @brief Bullet module.
321
 *
322
 * @{
323
 */
324

  
325
/**
326
 * @brief Map.
327
 */
328
typedef struct map map_t;
329
/**
330
 * @brief Construct map.
331
 * @param   background  XPM describing map as it should be rendered
332
 * @param   collide     XPM with transparency describing what parts of the map will cause collision
333
 * @return  Pointer to constructed map, or NULL if failed
334
 */
335
map_t* (map_ctor)(const char *const *background, const char *const *collide);
336
/**
337
 * @brief Destruct map.
338
 * @param   p   Pointer to map to be destructed
339
 */
340
void   (map_dtor)(map_t *p);
341
/**
342
 * @brief Get map width.
343
 * @param   p   Pointer to map
344
 * @return      Width of map
345
 */
346
uint16_t (map_get_width)   (const map_t *p);
347
/**
348
 * @brief Get map height.
349
 * @param   p   Pointer to map
350
 * @return      Height of map
351
 */
352
uint16_t (map_get_height)  (const map_t *p);
353
/**
354
 * @brief Use Dijkstra's path-finding algorithm.
355
 *
356
 * Allows a follower to know where to move so it gets closer to a given target.
357
 *
358
 * This function is implemented in a clever way that reduces the time of execution.
359
 * On the other hand, it might not always give the shortest path, but it is
360
 * guaranteeed to provide a decent, valid path to the target.
361
 *
362
 * @param   p   Pointer to map
363
 * @param   x_  X-position of the target
364
 * @param   y_  Y-position of the target
365
 * @return  SUCCESS if operation is successful, false otherwise
366
 */
367
int (map_make_dijkstra)(map_t *p, double x_, double y_);
368
/**
369
 * @brief Get the direction a follower should move to get closer to the target.
370
 * @param   p       Pointer to map
371
 * @param   x       X-position of the follower
372
 * @param   y       Y-position of the follower
373
 * @param   theta   Pointer to angle that will be updated
374
 * @return SUCCESS if operation was successful, other value otherwise
375
 */
376
int (map_where_to_follow)(const map_t *p, double x, double y, double *theta);
377
/**
378
 * @brief Draw map on screen buffer.
379
 * @param   p   Pointer to map
380
 */
381
void   (map_draw)(map_t *p);
382
/**
383
 * @brief Evaluate if point collides with map.
384
 * @param   p   Pointer to map
385
 * @param   x   X-position of the point
386
 * @param   y   Y-position of the point
387
 * @return true if the point collides with the map, false otherwise
388
 */
389
int    (map_collides_point)(const map_t *p, double x, double y);
390

  
391
/**
392
 * @}
393
 */
394

  
395
/**
396
 * @brief Evaluate if gunner is colliding with map.
397
 * @param   p       Pointer to map
398
 * @param   gunner  Pointer to gunner
399
 * @return true if the gunner collides with the map, false otherwise
400
 */
401
int    (map_collides_gunner)(const map_t *p, const gunner_t *gunner);
402
/**
403
 * @brief Evaluate if bullet is colliding with map.
404
 * @param   p       Pointer to map
405
 * @param   bullet  Pointer to bullet
406
 * @return true if the bullet collides with the map, false otherwise
407
 */
408
int    (map_collides_bullet)(const map_t *p, const bullet_t *bullet);
409
/**
410
 * @brief Evaluate if bullet is colliding with gunner.
411
 * @param   shooter     Pointer to gunner
412
 * @param   bull        Pointer to bullet
413
 * @return true if the bullet collides with the gunner, false otherwise
414
 */
415
int (gunner_collides_bullet)(const gunner_t *shooter, const bullet_t *bull);
416

  
417
#endif //ENT_H_INCLUDED
418 0

  
proj/include/scoreboards.h
1
#ifndef SCOREBOARD_H_INCLUDED
2
#define SCOREBOARD_H_INCLUDED
3

  
4
/**
5
 * @defgroup scoreboards scoreboards
6
 * @brief Scoreboards module.
7
 *
8
 * @{
9
 */
10

  
11
#include "libs.h"
12
#include <stdint.h>
13

  
14
/**
15
 * @brief Score.
16
 */
17
typedef struct  score_info score_info_t;
18

  
19
/**
20
 * @brief Table of highscores.
21
 */
22
typedef struct highscores highscores_t;
23
/**
24
 * @brief Construct score.
25
 * @param   score           Game score.
26
 * @param   time_played     Time elapsed on game.
27
 * @return      Pointer to constructed score, or NULL if failed.
28
 */
29
score_info_t* (score_ctor)(int score, int time_played);
30

  
31
/**
32
 * @brief Destruct score.
33
 * @param   p   Pointer to score to destruct
34
 */
35
void (score_dtor)(score_info_t *p);
36

  
37
/**
38
 * @brief Construct highscores.
39
 * @param   fnt     Font to use when rendering highscores text
40
 * @param   path    Path to file to be read with highscores values.
41
 * @return      Pointer to constructed highscores, or NULL if failed.
42
 */
43
highscores_t* (highscores_ctor)(const font_t *fnt, const char *path);
44
/**
45
 * @brief Save highscore into file.
46
 * @param f     Path to file to be written
47
 */
48
void (highscores_save)(const highscores_t *p, const char *path);
49
/**
50
 * @brief Destruct menu.
51
 * @param   p   Pointer to menu to destruct
52
 */
53
void (highscores_dtor)(highscores_t *p);
54

  
55
/**
56
 * @}
57
 */
58

  
59

  
60
#endif /* end of include guard: SCOREBOARD_H_INCLUDED */
61 0

  
proj/include/zombies.h
1
#ifndef ZOMBIES_H_INCLUDED
2
#define ZOMBIES_H_INCLUDED
3

  
4
int (zombies)(void);
5

  
6
#endif //ZOMBIES_H_INCLUDED
7 0

  
proj/include/interrupts_func.h
1
#ifndef INTERRUPTS_FUNC_H_INCLUDED
2
#define INTERRUPTS_FUNC_H_INCLUDED
3

  
4
/**
5
 * @defgroup interrupts_func interrupts_func
6
 * @brief Interrupts functions.
7
 *
8
 * @{
9
 */
10

  
11
#include "libs.h"
12

  
13
/**
14
 * @brief Subscribes all drivers used (timer->keyboard->mouse)
15
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
16
 * @see {_ERRORS_H_::errors}
17
 */
18
int (subscribe_all)(void);
19

  
20
/**
21
 * @brief Unsubscribes all subscribed interrupts
22
 * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
23
 * @see {_ERRORS_H_::errors}
24
 */
25
int (unsubscribe_all)(void);
26

  
27
/**
28
 * @brief Calls interrupt handler corresponding to the bit specified by the argument.
29
 * @param handler Interrupt handler to call
30
 */
31
void interrupt_handler(uint8_t handler);
32

  
33
/**
34
 * @brief Blocking function that waits for an interrupt to occur.
35
 *
36
 * Rewrites the provided argument with the interrupt vector it gets.
37
 *
38
 * This function decisively reduces the complexity of an interrupt cycle, allowing
39
 * for each menu to have its own, simplified interrupt cycle.
40
 * @param   p   Pointer where interrupt vector will be saved
41
 */
42
int get_interrupts_vector(uint64_t *p);
43

  
44
/**
45
 * @}
46
 */
47

  
48
#endif /* end of include guard: INTERRUPTS_FUNC_H_INCLUDED */
49 0

  
proj/include/proj.h
1
#ifndef PROJ_H_INCLUDED
2
#define PROJ_H_INCLUDED
3

  
4
#include "libs.h"
5

  
6
#include "ent.h"
7

  
8
basic_sprite_t       *bsp_crosshair;
9
basic_sprite_t       *bsp_shooter  ;
10
basic_sprite_t       *bsp_zombie   ;
11
basic_sprite_t       *bsp_pistol   ;
12
basic_sprite_t       *bsp_nothing  ;
13
basic_sprite_t       *bsp_bullet   ;
14
map_t                *map1         ;
15
sprite_t             *sp_crosshair ;
16

  
17
#endif //PROJ_H_INCLUDED
18 0

  
proj/include/proj_structures.h
1
#ifndef PROJ_STRUCTURES_H_INCLUDED
2
#define PROJ_STRUCTURES_H_INCLUDED
3

  
4
/**
5
 * @defgroup proj_structures proj_structures
6
 * @brief Project structures.
7
 *
8
 * @{
9
 */
10

  
11
#include <stdint.h>
12
#include "ent.h"
13

  
14
/**
15
 * @}
16
 */
17

  
18
/**
19
 * @defgroup keys_t keys_t
20
 * @ingroup proj_structures
21
 * @brief Keys pressed module.
22
 *
23
 * @{
24
 */
25

  
26
/**
27
 * @brief Keys pressed.
28
 */
29
typedef struct {
30
    /// @brief W is pressed when 1
31
    uint8_t w_pressed       : 1;
32
    /// @brief A is pressed when 1
33
    uint8_t a_pressed       : 1;
34
    /// @brief S is pressed when 1
35
    uint8_t s_pressed       : 1;
36
    /// @brief D is pressed when 1
37
    uint8_t d_pressed       : 1;
38
    /// @brief Ctrl is pressed when 1
39
    uint8_t ctrl_pressed    : 1;
40
    /// @brief Plus (+) is pressed when 1
41
    uint8_t plus_pressed    : 1;
42
    /// @brief Minus (-) is pressed when 1
43
    uint8_t minus_pressed   : 1;
44
    /// @brief Mouse left button is pressed when 1
45
    uint8_t lb_pressed      : 1;
46
} keys_t;
47

  
48
/**
49
 * @}
50
 */
51

  
52
/**
53
* @defgroup host_info_t host_info_t
54
* @ingroup proj_structures
55
* @brief Host info module.
56
*
57
* @{
58
*/
59

  
60
/**
61
 * @brief Information to transmit from host to remote.
62
 */
63
typedef struct {
64
    // host
65
    /// @brief Host player X-position
66
    int16_t    host_x;
67
    /// @brief Host player Y-postition
68
    int16_t    host_y;
69
    /// @brief Host player angle
70
    float      host_angle;
71
    /// @brief Host player health
72
    int16_t    host_health;
73
    /// @brief Host player current health
74
    int16_t    host_current_health;
75

  
76
    // remote
77
    /// @brief Remote player X-position
78
    int16_t    remote_x;
79
    /// @brief Remote player Y-postition
80
    int16_t    remote_y;
81
    /// @brief Remote player angle
82
    float      remote_angle;
83
    /// @brief Remote player health
84
    int16_t    remote_health;
85
    /// @brief Remote player current health
86
    int16_t    remote_current_health;
87
    /*
88
    // bullets
89
    /// @brief Number of bullets
90
    uint8_t    no_bullets;
91
    /// @brief X-position of the bullets
92
    int16_t   *bullets_x;
93
    /// @brief Y-position of the bullets
94
    int16_t   *bullets_y;
95
    /// @brief X-speed of the bullets
96
    int16_t   *bullets_vx;
97
    /// @brief Y-speed of the bullets
98
    int16_t   *bullets_vy;
99
    /// @brief Who shot each bullet
100
    bool      *bullets_shooter; // false for host, true for remote
101
    */
102
} host_info_t;
103
/**
104
 * @brief Construct host information.
105
 * @param   host    Pointer to host gunner
106
 * @param   remote  Pointer to remote gunner
107
 * @return  Pointer to constructed host information, or NULL if failed
108
 */
109
host_info_t* host_info_ctor(gunner_t *host, gunner_t *remote);
110
/**
111
 * @brief Destruct host information.
112
 * @param   p   Pointer to host information to be destructed
113
 */
114
void host_info_dtor(host_info_t *p);
115

  
116
/**
117
 * @}
118
 */
119

  
120
/**
121
* @defgroup remote_info_t remote_info_t
122
* @ingroup proj_structures
123
* @brief Remote info module.
124
*
125
* @{
126
*/
127

  
128
/**
129
 * @brief Information to transmit from remote to host.
130
 */
131
typedef struct {
132
    /// @brief Remote keys that are pressed
133
    keys_t  remote_keys_pressed;
134
    /// @brief Remote player angle
135
    double  remote_angle;
136
} remote_info_t;
137
/**
138
 * @brief Construct remote information.
139
 * @return  Pointer to constructed remote information, or NULL if failed
140
 */
141
remote_info_t* remote_info_ctor(void);
142
/**
143
 * @brief Destruct remote information.
144
 * @param   p   Pointer to remote information to be destructed
145
 */
146
void remote_info_dtor(remote_info_t *p);
147

  
148
/**
149
 * @}
150
 */
151

  
152
/**
153
* @defgroup bullet_info_t bullet_info_t
154
* @ingroup proj_structures
155
* @brief Bullet event module.
156
*
157
* @{
158
*/
159

  
160

  
161
/**
162
 * @brief Bullet event to transmit from remote to host.
163
 */
164
typedef struct {
165
    /// @brief New bullet signal from remote
166
    bool   new_bullet;
167
} bullet_info_t;
168
/**
169
 * @brief Construct bullet event.
170
 * @return  Pointer to constructed bullet event, or NULL if failed
171
 */
172
bullet_info_t* bullet_info_ctor(void);
173
/**
174
 * @brief Destruct bullet event.
175
 * @param   p   Pointer to bullet event to be destructed
176
 */
177
void bullet_info_dtor(bullet_info_t *p);
178

  
179
/**
180
 * @}
181
 */
182

  
183
#endif /* end of include guard: PROJ_STRUCTURES_H_INCLUDED */
184 0

  
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
7 0

  
proj/include/proj_macros.h
1
#ifndef PROJ_MACROS_H_INCLUDED
2
#define PROJ_MACROS_H_INCLUDED
3

  
4
/**
5
 * @defgroup proj_macros proj_macros
6
 * @brief Project macros.
7
 *
8
 * @{
9
 */
10

  
11
// Movement Directions
12
/** @brief Moving to the top side of screen */
13
#define UP      -1
14
/** @brief Moving to the bottom side of screen */
15
#define DOWN    1
16
/** @brief Moving to the left side of screen */
17
#define LEFT    -1
18
/** @brief Moving to the right side of screen */
19
#define RIGHT   1
20
/** @brief Not moving */
21
#define REST    0
22

  
23
// Movement Constants
24
/** @brief Shooter speed */
25
#define SHOOTER_SPEED   5
26
/** @brief Bullet speet */
27
#define BULLET_SPEED    8
28

  
29
// Refresh Rate
30
/** @brief Screen refresh rate */
31
#define REFRESH_RATE    60
32

  
33
//Graphics mode
34
/** @brief Graphic mode used */
35
#define GRAPH_MODE      DIRECT_1024_768_888
36
/** @brief Minimum zoom */
37
#define MIN_SCALE       0.2
38
/** @brief Default zoom */
39
#define DEFAULT_SCALE   0.5
40
/** @brief Maximum zoom */
41
#define MAX_SCALE       10.0
42

  
43
// Colors
44
/** @brief Text color */
45
#define TEXT_COLOR              0xFFFFFF
46
/** @brief Highlight color */
47
#define HIGHLIGHT_COLOR         0x404040
48
/** @brief Delimiter color */
49
#define DELIMITER_COLOR         0x404040
50

  
51
/** @brief Melee attacks range */
52
#define MELEE_RANGE    80
53
/** @brief Melee attack damage (for zombies). */
54
#define MELEE_DAMAGE   1
55
/** @brief Zombie speed */
56
#define ZOMBIE_SPEED    1.0
57

  
58
/**
59
 * @}
60
 */
61

  
62
#endif /* end of include guard: PROJ_MACROS_H_INCLUDED */
63 0

  
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

  
12
#include "libs.h"
13

  
14
#include "campaign.h"
15
#include "zombies.h"
16

  
17
int (singleplayer)(void) {
18

  
19
    int r;
20

  
21
    menu_t *main_menu = menu_ctor(font_get_default());
22
    menu_add_item(main_menu, "Campaign");
23
    menu_add_item(main_menu, "Zombies");
24
    menu_add_item(main_menu, "Back");
25

  
26
    //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
27
    uint8_t last_lb = 0;
28
    struct packet pp;
29
    keys_t *keys = get_key_presses();
30

  
31
    /// loop stuff
32
    int click = 0;
33
    uint64_t int_vector = 0;
34
    int good = true;
35
    while (good) {
36
        /* Get a request message. */
37
        if((r = get_interrupts_vector(&int_vector))) return r;
38
        uint32_t n = 1;
39
        for (uint8_t i = 0; i < 32; i++, n <<= 1) {
40
            if (int_vector & n) {
41
                interrupt_handler(i);
42
                switch (i) {
43
                    case TIMER0_IRQ:
44

  
45
                    graph_clear_screen();
46
                    switch(menu_update_state(main_menu, click)){
47
                        case -1: break;
48
                        case  0: campaign(); break;
49
                        case  1: zombies(); break;
50
                        case  2: good = false; break;
51
                    }
52
                    menu_draw(main_menu);
53

  
54
                    click = 0;
55

  
56
                    sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
57
                    sprite_draw(sp_crosshair);
58
                    graph_draw();
59

  
60
                    break;
61
                    case KBC_IRQ:
62
                    if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) good = false;
63
                    case MOUSE_IRQ:
64
                    if (mouse_get_counter_mouse_ih() >= 3) {
65
                        mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp);
66
                        update_mouse(&pp);
67
                        if (!click) click = last_lb ^ keys->lb_pressed && keys->lb_pressed;
68
                        last_lb = keys->lb_pressed;
69
                        mouse_set_counter_mouse_ih(0);
70
                    }
71
                    break;
72
                    case COM1_IRQ: nctp_ih(); break;
73
                }
74
            }
75
        }
76
    }
77

  
78
    return 0;
79
}
80 0

  
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 "libs.h"
12
#include "makecode_map.h"
13
#include <math.h>
14

  
15
#include "hltp.h"
16

  
17
#define CHAT_MAX_SIZE   75
18
#define CHAT_MAX_NUM    19
19
static text_t      *t_text[CHAT_MAX_NUM] = {NULL};
20
static rectangle_t *r_text               =  NULL;
21

  
22
static void chat_process(const uint8_t *p, const size_t sz){
23
    char buffer2[CHAT_MAX_NUM+3];
24
    void *dest = NULL;
25
    hltp_type tp = hltp_interpret(p, sz, &dest);
26
    switch(tp){
27
        case hltp_type_string:
28
        strcpy(buffer2, dest);
29
        strncat(buffer2, " <", 2);
30
        for(size_t i = CHAT_MAX_NUM-1; i; --i)
31
        text_set_string(t_text[i], text_get_string(t_text[i-1]));
32
        text_set_string(t_text[0], buffer2);
33
        for(size_t i = 0; i < CHAT_MAX_NUM; ++i){
34
            if(text_get_string(t_text[i])[0] == '>'){
35
                text_set_pos(t_text[i], rectangle_get_x(r_text)+50, text_get_y(t_text[i]));
36
                text_set_halign(t_text[i], text_halign_left);
37
            }else{
38
                text_set_pos(t_text[i], rectangle_get_x(r_text)+rectangle_get_w(r_text)-50, text_get_y(t_text[i]));
39
                text_set_halign(t_text[i], text_halign_right);
40
            }
41
        }
42
        break;
43
        case hltp_type_invalid: break;
44
        case hltp_type_bullet : break;
45
        case hltp_type_host   : break;
46
        case hltp_type_remote : break;
47
    }
48
}
49

  
50
int (chat)(void){
51
    int r;
52

  
53
    nctp_dump();
54
    nctp_set_processor(chat_process);
55

  
56
    struct packet pp;
57

  
58
    char buffer[CHAT_MAX_SIZE] = "";
59
    rectangle_t *r_buffer = NULL; {
60
        r_buffer = rectangle_ctor(0,0,900,70);
61
        rectangle_set_pos(r_buffer, graph_get_XRes()/2  -rectangle_get_w(r_buffer)/2,
62
        (int16_t)(graph_get_YRes()*0.87-rectangle_get_h(r_buffer)/2));
63
        rectangle_set_fill_color   (r_buffer, GRAPH_BLACK);
64
        rectangle_set_outline_width(r_buffer, 2);
65
        rectangle_set_outline_color(r_buffer, GRAPH_WHITE);
66
        rectangle_set_fill_trans(r_buffer, GRAPH_TRANSPARENT);
67
    }
68
    text_t      *t_buffer = NULL; {
69
        t_buffer = text_ctor(font_get_default(), "");
70
        text_set_pos(t_buffer, rectangle_get_x(r_buffer)+50,
71
        rectangle_get_y(r_buffer)+rectangle_get_h(r_buffer)/2);
72
        text_set_halign(t_buffer, text_halign_left);
73
        text_set_valign(t_buffer, text_valign_center);
74
        text_set_color (t_buffer, TEXT_COLOR);
75
    }
76
    text_t      *t_size   = NULL; {
77
        t_size = text_ctor(font_get_default(), "");
78
        text_set_pos(t_size, rectangle_get_x(r_buffer)+rectangle_get_w(r_buffer)-5,
79
        rectangle_get_y(r_buffer)+rectangle_get_h(r_buffer)-5);
80
        text_set_halign(t_size, text_halign_right);
81
        text_set_valign(t_size, text_valign_bottom);
82
        text_set_color (t_size, TEXT_COLOR);
83
        text_set_size  (t_size, 18);
84
        char buffer2[20];
85
        sprintf(buffer2, "%d/%d", strlen(buffer), CHAT_MAX_SIZE);
86
        text_set_string(t_size, buffer2);
87
    }
88

  
89
    /** r_text */ {
90
    r_text = rectangle_ctor(0,0,900,550);
91
    rectangle_set_pos(r_text, graph_get_XRes()/2  -rectangle_get_w(r_buffer)/2,
92
    (int16_t)(graph_get_YRes()*0.09));
93
    rectangle_set_fill_color   (r_text, GRAPH_BLACK);
94
    rectangle_set_outline_width(r_text, 2);
95
    rectangle_set_outline_color(r_text, GRAPH_WHITE);
96
    rectangle_set_fill_trans(r_text, GRAPH_TRANSPARENT);
97
    }
98
    /** t_text */ {
99
    for(uint16_t i = 0; i < CHAT_MAX_NUM; ++i){
100
        t_text[i] = text_ctor(font_get_default(), " ");
101
        text_set_pos(t_text[i], rectangle_get_x(r_text)+50,
102
        rectangle_get_y(r_text)+rectangle_get_h(r_text)-30-25*i);
103
        text_set_halign(t_text[i], text_halign_left);
104
        text_set_valign(t_text[i], text_valign_bottom);
105
        text_set_color (t_text[i], TEXT_COLOR);
106
    }
107
}
108

  
109
/// loop stuff
110
uint64_t int_vector = 0;
111
int good = true;
112
while (good) {
113
    /* Get a request message. */
114
    if((r = get_interrupts_vector(&int_vector))) return r;
115
    uint32_t n = 1;
116
    for (uint8_t i = 0; i < 32; i++, n <<= 1) {
117
        if (int_vector & n) {
118
            interrupt_handler(i);
119
            switch (i) {
120
                case TIMER0_IRQ:
121
                graph_clear_screen();
122
                sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
123

  
124
                rectangle_draw(r_buffer);
125
                text_draw(t_buffer);
126
                text_draw(t_size);
127

  
128
                rectangle_draw(r_text);
129
                for(size_t j = 0; j < CHAT_MAX_NUM; ++j) text_draw(t_text[j]);
130

  
131
                sprite_draw(sp_crosshair);
132
                graph_draw();
133
                break;
134
                case KBC_IRQ:
135
                if      (keyboard_get_scancode()[0] == ESC_BREAK_CODE) good = false;
136
                else if (keyboard_get_scancode()[0] == ENTER_MAKE_CODE) {
137
                    hltp_send_string(buffer);
138
                    char buffer2[CHAT_MAX_SIZE+3] = "> ";
139
                    strncat(buffer2, buffer, strlen(buffer));
140
                    for(size_t j = CHAT_MAX_NUM-1; j; --j) text_set_string(t_text[i], text_get_string(t_text[i-1]));
141
                    text_set_string(t_text[0], buffer2);
142
                    for(size_t j = 0; j < CHAT_MAX_NUM; ++j){
143
                        if(text_get_string(t_text[j])[0] == '>'){
144
                            text_set_pos(t_text[j], rectangle_get_x(r_text)+50, text_get_y(t_text[j]));
145
                            text_set_halign(t_text[j], text_halign_left);
146
                        }else{
147
                            text_set_pos(t_text[j], rectangle_get_x(r_text)+rectangle_get_w(r_text)-50, text_get_y(t_text[j]));
148
                            text_set_halign(t_text[j], text_halign_right);
149
                        }
150
                    }
151
                    buffer[0] = '\0';
152
                } else if(keyboard_get_scancode()[0] == BACKSPACE_MAKE_CODE){
153
                    buffer[strlen(buffer)-1] = '\0';
154
                } else {
155
                    char c = map_makecode(keyboard_get_scancode()[0]);
156
                    if (c == ERROR_CODE) break;
157
                    if(strlen(buffer) < CHAT_MAX_SIZE) strncat(buffer, &c, 1);
158
                    else                               printf("Char limit exceeded\n");
159
                }
160
                text_set_string(t_buffer, buffer);
161
                char buffer2[20];
162
                sprintf(buffer2, "%d/%d", strlen(buffer), CHAT_MAX_SIZE);
163
                text_set_string(t_size, buffer2);
164
                case MOUSE_IRQ:
165
                if (mouse_get_counter_mouse_ih() >= 3) {
166
                    mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp);
167
                    update_mouse(&pp);
168
                    mouse_set_counter_mouse_ih(0);
169
                }
170
                break;
171
                case COM1_IRQ: nctp_ih(); break;
172
            }
173
        }
174
    }
175
}
176

  
177
rectangle_dtor(r_buffer);
178
text_dtor     (t_buffer);
179

  
180
rectangle_dtor(r_text);
181
for(size_t i = 0; i < CHAT_MAX_NUM; ++i) text_dtor(t_text[i]);
182

  
183
nctp_set_processor(NULL);
184

  
185
return SUCCESS;
186
}
187 0

  
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

  
12
#include "libs.h"
13

  
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

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff