Index: proj/include/ent.h
===================================================================
--- proj/include/ent.h	(revision 344)
+++ proj/include/ent.h	(revision 345)
@@ -329,7 +329,7 @@
 typedef struct map map_t;
 /**
  * @brief Construct map.
- * @param   backgroup   XPM describing map as it should be rendered
+ * @param   background  XPM describing map as it should be rendered
  * @param   collide     XPM with transparency describing what parts of the map will cause collision
  * @return  Pointer to constructed map, or NULL if failed
  */
@@ -382,6 +382,7 @@
 void   (map_draw)(map_t *p);
 /**
  * @brief Evaluate if point collides with map.
+ * @param   p   Pointer to map
  * @param   x   X-position of the point
  * @param   y   Y-position of the point
  * @return true if the point collides with the map, false otherwise
Index: proj/include/interrupts_func.h
===================================================================
--- proj/include/interrupts_func.h	(revision 344)
+++ proj/include/interrupts_func.h	(revision 345)
@@ -8,6 +8,11 @@
  * @{
  */
 
+#include "timer.h"
+#include "kbc.h"
+#include "keyboard.h"
+#include "mouse.h"
+
 /**
  * @brief Subscribes all drivers used (timer->keyboard->mouse)
  * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
@@ -28,6 +33,15 @@
  */
 void interrupt_handler(uint8_t handler);
 
+/**
+ * @brief Blocking function that waits for an interrupt to occur.
+ *
+ * Rewrites the provided argument with the interrupt vector it gets.
+ *
+ * This function decisively reduces the complexity of an interrupt cycle, allowing
+ * for each menu to have its own, simplified interrupt cycle.
+ * @param   p   Pointer where interrupt vector will be saved
+ */
 int get_interrupts_vector(uint64_t *p);
 
 /**
Index: proj/include/makecode_map.h
===================================================================
--- proj/include/makecode_map.h	(revision 344)
+++ proj/include/makecode_map.h	(revision 345)
@@ -10,13 +10,13 @@
 
 #include <stdint.h>
 
-#define BASE_CODE    0x02
+/// @brief Error code
 #define ERROR_CODE      0
 
 /**
  * @brief Maps make code into char
  * @param code      Make code to map.
- * @return 0 if the char isn't valid, otherwise the character.
+ * @return ERROR_CODE if code char isn't valid, otherwise the character.
  */
 char (map_makecode)(uint8_t code);
 
Index: proj/include/proj.h
===================================================================
--- proj/include/proj.h	(nonexistent)
+++ proj/include/proj.h	(revision 345)
@@ -0,0 +1,16 @@
+#ifndef PROJ_H_INCLUDED
+#define PROJ_H_INCLUDED
+
+#include "sprite.h"
+#include "ent.h"
+
+basic_sprite_t       *bsp_crosshair;
+basic_sprite_t       *bsp_shooter  ;
+basic_sprite_t       *bsp_zombie   ;
+basic_sprite_t       *bsp_pistol   ;
+basic_sprite_t       *bsp_nothing  ;
+basic_sprite_t       *bsp_bullet   ;
+map_t                *map1         ;
+sprite_t             *sp_crosshair ;
+
+#endif //PROJ_H_INCLUDED

Property changes on: proj/include/proj.h
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/include/proj_func.h
===================================================================
--- proj/include/proj_func.h	(revision 344)
+++ proj/include/proj_func.h	(revision 345)
@@ -21,9 +21,38 @@
  */
 int cleanup(void);
 
+/**
+ * @brief Update key presses.
+ */
 void update_key_presses(void);
+/**
+ * @brief Get key presses.
+ * @return  keys_t containing key presses
+ */
+keys_t* (get_key_presses)(void);
 
 /**
+ * @brief Update mouse.
+ */
+void update_mouse(struct packet *p);
+/**
+ * @brief Get pointer to mouse X-position.
+ * @return  Pointer to mouse X-position.
+ */
+int16_t* get_mouse_X(void);
+/**
+ * @brief Get pointer to mouse Y-position.
+ * @return  Pointer to mouse Y-position.
+ */
+int16_t* get_mouse_Y(void);
+/**
+ * @brief Get cursor angle relative to a gunner in the screen.
+ * @param   p   Pointer to gunner
+ * @return      Angle of the mouse relative to the gunner
+ */
+double get_mouse_angle(gunner_t *p);
+
+/**
  * @brief Updates movement variables.
  */
 void update_movement(map_t *map, gunner_t *p, keys_t *keys, list_t *shooter_list);
@@ -39,28 +68,46 @@
  */
 void (get_random_spawn)(const map_t *map, gunner_t *p, list_t *l);
 
-void update_mouse(struct packet *p);
+/**
+ * @brief Update scale if the keys were pressed to change scale.
+ */
+void update_scale(void);
 
-keys_t* (get_key_presses)(void);
-
+/**
+ * @brief Shoot a bullet.
+ * @param   shooter     Pointer to gunner that shot the bullet
+ * @param   bullet_list List of the bullets in the map
+ * @param   bsp_bullet  Basic sprite that will be used to render the bullet
+ */
 void (shoot_bullet)(const gunner_t *shooter, list_t *bullet_list, const basic_sprite_t *bsp_bullet);
-
+/**
+ * @brief Update game state.
+ *
+ * This includes moving bullets accordingly, processing damages, collisions of
+ * bullets with walls, melee damage for the gunners that have autonomous melee.
+ * @param   map             Pointer to map
+ * @param   shooter_list    List of shooters
+ * @param   bullet_list     List of bullets in the map
+ */
 void (update_game_state)(const map_t *map, list_t *shooter_list, list_t *bullet_list);
 
-
-
-void update_scale(void);
-
-int16_t* get_mouse_X(void);
-
-int16_t* get_mouse_Y(void);
-
+/**
+ * @brief Wrapper to easen filling of the host_info_t.
+ * @param   p       Host info to fill
+ * @param   host    Host gunner
+ * @param   remote  Remote gunner
+ */
 void build_host_structure(host_info_t *p, gunner_t *host, gunner_t *remote);
-
+/**
+ * @brief Wrapper to easen filling of the remote_info_t.
+ * @param   p       Remote info to fill
+ * @param   keys    Key presses of remote
+ * @param   angle   Mouse angle of remote
+ */
 void build_remote_structure(remote_info_t *p, keys_t *keys, double angle);
 
-double get_mouse_angle(gunner_t *p);
 
+
 /**
  * @}
  */
@@ -82,15 +129,28 @@
     /// @brief Text.
     text_t *text;
 } text_timer_t;
+/**
+ * @brief Construct timer
+ * @param   fnt Font used to render timer text
+ * @return      Pointer to constructed timer, or NULL if failed
+ */
+text_timer_t* (text_timer_ctor)(const font_t *fnt);
+/**
+ * @brief Destruct timer.
+ * @param   p   Pointer to timer to be destructed
+ */
+void (text_timer_dtor)(text_timer_t *p);
+/**
+ * @brief   Update timer, by incrementing the number of seconds.
+ * @param   p   Pointer to timer
+ */
+void (text_timer_update)(text_timer_t *p);
+/**
+ * @brief   Reset timer to 0.
+ * @param   p   Pointer to timer
+ */
+void (text_timer_reset)(text_timer_t *p);
 
-text_timer_t* (timer_ctor)(const font_t *fnt);
-
-void (timer_dtor)(text_timer_t *p);
-
-void (timer_update)(text_timer_t *p);
-
-void (timer_reset)(text_timer_t *p);
-
 /**
  * @}
  */
Index: proj/include/zombies.h
===================================================================
--- proj/include/zombies.h	(nonexistent)
+++ proj/include/zombies.h	(revision 345)
@@ -0,0 +1,6 @@
+#ifndef ZOMBIES_H_INCLUDED
+#define ZOMBIES_H_INCLUDED
+
+int (zombies)(void);
+
+#endif //ZOMBIES_H_INCLUDED

Property changes on: proj/include/zombies.h
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/libs/graph/include/sprite.h
===================================================================
--- proj/libs/graph/include/sprite.h	(revision 344)
+++ proj/libs/graph/include/sprite.h	(revision 345)
@@ -13,8 +13,10 @@
 
 #include "basic_sprite.h"
 
+/**
+ * @brief Basic sprite.
+ */
 typedef struct sprite sprite_t;
-
 /**
  * @brief Construct sprite.
  * @param   bsp Basic sprite from which to build the sprite
Index: proj/libs/kbc/include/mouse.h
===================================================================
--- proj/libs/kbc/include/mouse.h	(revision 344)
+++ proj/libs/kbc/include/mouse.h	(revision 345)
@@ -70,6 +70,7 @@
  * Polls the mouse till data is available for reading
  * </summary>
  * @param data Pointer to variable where byte read from mouse will be stored
+ * @param   period  Time that the process should wait before polling again, in microseconds
  * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
  * @see {_ERRORS_H_::errors}
  */
Index: proj/libs/rtc/include/rtc.h
===================================================================
--- proj/libs/rtc/include/rtc.h	(revision 344)
+++ proj/libs/rtc/include/rtc.h	(revision 345)
@@ -19,8 +19,21 @@
  */
 int (subscribe_rtc_interrupt)(uint8_t interrupt_bit, int *interrupt_id);
 
+/**
+ * @brief Read RTC register.
+ * @param   reg     Register to read from
+ * @param   data    Pointer to save read data
+ * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
+ * @see {_ERRORS_H_::errors}
+ */
 int (rtc_read_register)(uint32_t reg, uint8_t *data);
-
+/**
+ * @brief Write RTC register.
+ * @param   reg     Register to write to
+ * @param   data    Data to write in register
+ * @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK
+ * @see {_ERRORS_H_::errors}
+ */
 int (rtc_write_register)(uint32_t reg, uint8_t data);
 
 /**
Index: proj/src/makecode_map.c
===================================================================
--- proj/src/makecode_map.c	(revision 344)
+++ proj/src/makecode_map.c	(revision 345)
@@ -1,6 +1,6 @@
 #include "makecode_map.h"
 
-static const char makecode_map[] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '\'', ERROR_CODE /*«*/, ERROR_CODE /*escape*/,
+static const char makecode_map[] = {ERROR_CODE, ERROR_CODE, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '\'', ERROR_CODE /*«*/, ERROR_CODE /*escape*/,
                                     ERROR_CODE /*tab*/, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '+', ERROR_CODE /* ´ */, ERROR_CODE /*enter*/,
                                     ERROR_CODE /*ctrl*/, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ERROR_CODE /* Ç */, ERROR_CODE /* º */, '\\', ERROR_CODE /*lshift*/, '~',
                                     'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '-', ERROR_CODE /*rshift*/, ERROR_CODE /*unkown*/, ERROR_CODE /*alt*/, ' ' /*space*/};
@@ -8,7 +8,6 @@
 static const int size = sizeof(makecode_map);
 
 char (map_makecode)(uint8_t code) {
-    int key = code - BASE_CODE;
-    if (key < 0 || key >= size) return ERROR_CODE;
-    return makecode_map[key];
+    if (code < 0 || code >= size) return ERROR_CODE;
+    return makecode_map[code];
 }
Index: proj/src/proj.c
===================================================================
--- proj/src/proj.c	(revision 344)
+++ proj/src/proj.c	(revision 345)
@@ -6,10 +6,6 @@
 #include "proj_macros.h"
 #include "proj_func.h"
 
-#include "kbc.h"
-#include "timer.h"
-#include "keyboard.h"
-#include "mouse.h"
 #include "graph.h"
 #include "menu.h"
 #include "rtc.h"
@@ -18,10 +14,9 @@
 #include "makecode_map.h"
 
 #include "graph.h"
-#include "sprite.h"
+
 #include "rectangle.h"
 #include "font.h"
-#include "ent.h"
 
 #include "crosshair.h"
 #include "shooter.h"
@@ -35,6 +30,8 @@
 
 #include "list.h"
 
+#include "proj.h"
+
 int main(int argc, char* argv[]) {
 
     lcf_set_language("EN-US");
@@ -50,15 +47,8 @@
     return 0;
 }
 
-static basic_sprite_t       *bsp_crosshair = NULL;
-static basic_sprite_t       *bsp_shooter   = NULL;
-static basic_sprite_t       *bsp_zombie    = NULL;
-static basic_sprite_t       *bsp_pistol    = NULL;
-static basic_sprite_t       *bsp_nothing   = NULL;
-static basic_sprite_t       *bsp_bullet    = NULL;
-static map_t                *map1          = NULL;
-static sprite_t             *sp_crosshair  = NULL;
 
+
 static int (singleplayer)(void);
 static int (multiplayer)(void);
 static int (chat)(void);
@@ -278,7 +268,7 @@
     nctp_set_processor(multiplayer_process);
 
     ent_set_scale(DEFAULT_SCALE);
-    text_timer_t *in_game_timer = timer_ctor(font_get_default());
+    text_timer_t *in_game_timer = text_timer_ctor(font_get_default());
 
     list_t *shooter_list = list_ctor();
 
@@ -323,7 +313,7 @@
                 interrupt_handler(i);
                 switch (i) {
                     case TIMER0_IRQ:
-                    if (timer_get_no_interrupts() % 60 == 0) timer_update(in_game_timer);
+                    if (timer_get_no_interrupts() % 60 == 0) text_timer_update(in_game_timer);
                     update_movement(map1, shooter1, keys, shooter_list);
                     update_movement(map1, shooter2, &(remote_info->remote_keys_pressed), shooter_list);
 
@@ -409,7 +399,7 @@
 
     nctp_set_processor(NULL);
 
-    timer_dtor(in_game_timer); in_game_timer = NULL;
+    text_timer_dtor(in_game_timer); in_game_timer = NULL;
 
     return 0;
 }
@@ -420,7 +410,7 @@
     nctp_set_processor(multiplayer_process);
 
     ent_set_scale(DEFAULT_SCALE);
-    text_timer_t *in_game_timer = timer_ctor(font_get_default());
+    text_timer_t *in_game_timer = text_timer_ctor(font_get_default());
 
     list_t *shooter_list = list_ctor();
 
@@ -458,7 +448,7 @@
                 interrupt_handler(i);
                 switch (i) {
                     case TIMER0_IRQ:
-                    if (timer_get_no_interrupts() % 60 == 0) timer_update(in_game_timer);
+                    if (timer_get_no_interrupts() % 60 == 0) text_timer_update(in_game_timer);
 
                     double angle = get_mouse_angle(shooter1) - M_PI_2;
 
@@ -552,13 +542,13 @@
 
     nctp_set_processor(NULL);
 
-    timer_dtor(in_game_timer); in_game_timer = NULL;
+    text_timer_dtor(in_game_timer); in_game_timer = NULL;
 
     return 0;
 }
 
 static int (campaign)(void);
-static int (zombies)(void);
+#include "zombies.h"
 static int (singleplayer)(void) {
 
     int r;
@@ -628,7 +618,7 @@
     int r;
 
     ent_set_scale(DEFAULT_SCALE);
-    text_timer_t *in_game_timer = timer_ctor(font_get_default());
+    text_timer_t *in_game_timer = text_timer_ctor(font_get_default());
 
     list_t *shooter_list = list_ctor();
 
@@ -667,7 +657,7 @@
                 switch (i) {
                     case TIMER0_IRQ:
 
-                    if (timer_get_no_interrupts() % 60 == 0) timer_update(in_game_timer);
+                    if (timer_get_no_interrupts() % 60 == 0) text_timer_update(in_game_timer);
                     update_movement(map1, shooter1, keys, shooter_list);
 
                     update_game_state(map1, shooter_list, bullet_list);
@@ -725,142 +715,13 @@
     }
     if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n");
 
-    timer_dtor(in_game_timer); in_game_timer = NULL;
+    text_timer_dtor(in_game_timer); in_game_timer = NULL;
 
     return SUCCESS;
 }
 
-#define ZOMBIES_NUM             5
-#define ZOMBIE_HEALTH_FACTOR    1.1
-static int (zombies)(void){
 
-    int r;
 
-    ent_set_scale(DEFAULT_SCALE);
-    text_timer_t *in_game_timer = timer_ctor(font_get_default());
-
-    list_t *shooter_list = list_ctor();
-
-    gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n");
-    gunner_set_spawn(shooter1, 980, 790);
-    gunner_set_pos(shooter1, 980, 790);
-
-    list_insert(shooter_list, list_end(shooter_list), shooter1);
-
-    list_t *bullet_list  = list_ctor();
-
-    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
-    gunner_get_y(shooter1)-ent_get_YLength()/2.0);
-
-    //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
-    uint8_t last_lb = 0;
-    struct packet pp;
-    keys_t *keys = get_key_presses();
-
-    /// loop stuff
-    uint64_t int_vector = 0;
-    int good = true;
-    int dead = false;
-
-    int health = 50;
-
-    map_make_dijkstra(map1, gunner_get_x(shooter1), gunner_get_y(shooter1));
-
-    while (good && !dead) {
-        /* Get a request message. */
-        if((r = get_interrupts_vector(&int_vector))) return r;
-        uint32_t n = 1;
-        for (uint8_t i = 0; i < 32; i++, n <<= 1) {
-            if(!good || dead) break;
-            if (int_vector & n) {
-                interrupt_handler(i);
-                switch (i) {
-                    case TIMER0_IRQ:
-                    if (timer_get_no_interrupts() % 60 == 0) timer_update(in_game_timer);
-                    if (timer_get_no_interrupts() %  6 == 0){
-                        map_make_dijkstra(map1, gunner_get_x(shooter1), gunner_get_y(shooter1));
-                    }
-
-                    update_movement(map1, shooter1, keys, shooter_list);
-
-                    update_game_state(map1, shooter_list, bullet_list);
-
-                    if(list_find(shooter_list, shooter1) == list_end(shooter_list)){
-                        good = false;
-                        dead = true;
-                        break;
-                    }
-
-                    double angle = get_mouse_angle(shooter1);
-                    gunner_set_angle(shooter1, angle - M_PI_2);
-
-                    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
-                                   gunner_get_y(shooter1)-ent_get_YLength()/2.0);
-
-                    while(list_size(shooter_list) < ZOMBIES_NUM+1){
-                        gunner_t *zombie = gunner_ctor(bsp_zombie, bsp_nothing, GUNNER_MELEE | GUNNER_FOLLOW, 3);
-                        gunner_set_health(zombie, health);
-                        gunner_set_curr_health(zombie, health);
-                        health *= ZOMBIE_HEALTH_FACTOR;
-                        get_random_spawn(map1, zombie, shooter_list);
-                        list_push_back(shooter_list, zombie);
-                    }
-
-                    graph_clear_screen();
-                    map_draw   (map1);
-                    bullet_draw_list(bullet_list);
-                    gunner_draw_list(shooter_list);
-
-                    text_draw(in_game_timer->text);
-
-                    sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
-                    sprite_draw(sp_crosshair);
-                    graph_draw();
-
-                    break;
-                    case KBC_IRQ:
-                    if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) {
-                        good = false;
-                    }
-                    break;
-                    case MOUSE_IRQ:
-                    if (mouse_get_counter_mouse_ih() >= 3) {
-                        mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp);
-                        update_mouse(&pp);
-                        if (last_lb ^ keys->lb_pressed && keys->lb_pressed)
-                        shoot_bullet(shooter1, bullet_list, bsp_bullet);
-                        last_lb = keys->lb_pressed;
-                        mouse_set_counter_mouse_ih(0);
-
-                    }
-                    break;
-                    case COM1_IRQ: nctp_ih(); break;
-                }
-            }
-        }
-    }
-
-    while(list_size(shooter_list) > 0){
-        gunner_t *p = list_erase(shooter_list, list_begin(shooter_list));
-        gunner_dtor(p);
-    }
-    if(list_dtor(shooter_list)) printf("COULD NOT DESTRUCT SHOOTER LIST\n");
-
-    while(list_size(bullet_list) > 0){
-        bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list));
-        bullet_dtor(p);
-    }
-    if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n");
-
-    if(dead){
-        printf("YOU DIED\n");
-    }
-
-    timer_dtor(in_game_timer); in_game_timer = NULL;
-
-    return SUCCESS;
-}
-
 #define CHAT_MAX_SIZE   75
 #define CHAT_MAX_NUM    19
 static text_t      *t_text[CHAT_MAX_NUM] = {NULL};
Index: proj/src/proj_func.c
===================================================================
--- proj/src/proj_func.c	(revision 344)
+++ proj/src/proj_func.c	(revision 345)
@@ -26,75 +26,6 @@
 }
 
 static keys_t key_presses;
-
-host_info_t* host_info_ctor(gunner_t *host, gunner_t *remote) {
-    host_info_t *ret = (host_info_t*)malloc(sizeof(host_info_t));
-    if (ret == NULL) return ret;
-
-    ret->host_x               = (int16_t)gunner_get_x          (host);
-    ret->host_y               = (int16_t)gunner_get_y          (host);
-    ret->host_angle           = (int16_t)gunner_get_angle      (host);
-    ret->host_health          = (int16_t)gunner_get_health     (host);
-    ret->host_current_health  = (int16_t)gunner_get_curr_health(host);
-
-    // remote
-    ret->remote_x               = (int16_t)gunner_get_x          (remote);
-    ret->remote_y               = (int16_t)gunner_get_y          (remote);
-    ret->remote_angle           = (int16_t)gunner_get_angle      (remote);
-    ret->remote_health          = (int16_t)gunner_get_health     (remote);
-    ret->remote_current_health  = (int16_t)gunner_get_curr_health(remote);
-
-    //ret->no_bullets = 0;
-
-    return ret;
-}
-
-void host_info_dtor(host_info_t *p) {
-    if (p==NULL) return;
-    /*
-    if ((p->bullets_x) != NULL){ free(p->bullets_x); p->bullets_x = NULL; }
-
-    if ((p->bullets_y) != NULL){ free(p->bullets_y); p->bullets_y = NULL; }
-
-    if ((p->bullets_vx) != NULL){ free(p->bullets_vx); p->bullets_vx = NULL; }
-
-    if ((p->bullets_vy) != NULL){ free(p->bullets_vy); p->bullets_vy = NULL; }
-
-    if ((p->bullets_shooter) != NULL){ free(p->bullets_shooter); p->bullets_shooter = NULL; }
-    */
-    free(p);
-}
-
-remote_info_t* remote_info_ctor(void) {
-    remote_info_t *ret = (remote_info_t*)malloc(sizeof(remote_info_t));
-    if (ret == NULL) return ret;
-
-    memset(&(ret->remote_keys_pressed), 0, sizeof(keys_t));
-
-    ret->remote_angle = 0;
-
-    return ret;
-}
-
-void remote_info_dtor(remote_info_t *p) {
-    if (p==NULL) return;
-    free(p);
-}
-
-bullet_info_t* bullet_info_ctor(void) {
-    bullet_info_t *ret = (bullet_info_t*)malloc(sizeof(bullet_info_t));
-    if (ret == NULL) return ret;
-
-    ret->new_bullet = false;
-
-    return ret;
-}
-
-void bullet_info_dtor(bullet_info_t *p) {
-    if (p == NULL) return;
-    free(p);
-}
-
 void update_key_presses(void) {
     if (keyboard_get_size() == 1) {
         switch(keyboard_get_scancode()[0]) {
@@ -115,7 +46,26 @@
         }
     }
 }
+keys_t* (get_key_presses)(void) {
+    return &key_presses;
+}
 
+static int16_t mouse_x = 0, mouse_y = 0;
+void (update_mouse)(struct packet *p) {
+    mouse_x = max_16(0, mouse_x + p->delta_x);
+    mouse_x = min_16(mouse_x, (int16_t)graph_get_XRes() - 1);
+
+    mouse_y = max_16(0, mouse_y - p->delta_y);
+    mouse_y = min_16(mouse_y, (int16_t)graph_get_YRes() - 1);
+
+    key_presses.lb_pressed = p->lb;
+}
+int16_t* get_mouse_X(void) { return &mouse_x; }
+int16_t* get_mouse_Y(void) { return &mouse_y; }
+double get_mouse_angle(gunner_t *p) {
+    return atan2(gunner_get_y_screen(p) - mouse_y, mouse_x - gunner_get_x_screen(p));
+}
+
 void update_movement(map_t *map, gunner_t *p, keys_t *keys, list_t *shooter_list) {
     /** Player movement */{
         int ver_mov = keys->s_pressed - keys->w_pressed;
@@ -183,6 +133,49 @@
     }
 }
 
+void (get_random_spawn)(const map_t *map, gunner_t *p, list_t *l) {
+    uint16_t w = map_get_width(map), h = map_get_height(map);
+    double x, y;
+
+    while(true){
+        x = rand() % w;
+        y = rand() % h;
+        gunner_set_pos(p, x, y);
+        if(map_collides_gunner(map, p)) continue;
+        int collides = false;
+        list_node_t *it = list_begin(l);
+        while(it != list_end(l)){
+            if(gunner_collides_gunner(p, *list_node_val(it))){
+                collides = true;
+                break;
+            }
+            it = list_node_next(it);
+        }
+        if(!collides) return;
+    }
+}
+
+void update_scale(void) {
+    static uint8_t last_plus = 0, last_minus = 0;
+    if (key_presses.ctrl_pressed) {
+        if (key_presses.plus_pressed && !last_plus) {
+            double scale = ent_get_scale();
+            scale *= 1.1;
+            if (scale <= MAX_SCALE) ent_set_scale(scale);
+        }
+        else if (key_presses.minus_pressed && !last_minus) {
+            double scale = ent_get_scale();
+            scale /= 1.1;
+            if (scale >= MIN_SCALE) ent_set_scale(scale);
+        }
+
+        //printf("SCALE: %d\n", (int)(ent_get_scale()*1000));
+    }
+
+    last_plus = key_presses.plus_pressed;
+    last_minus = key_presses.minus_pressed;
+}
+
 void (shoot_bullet)(const gunner_t *shooter, list_t *bullet_list, const basic_sprite_t *bsp_bullet) {
     double angle = gunner_get_angle(shooter);
     double vx = -BULLET_SPEED * fm_sin(angle);
@@ -251,72 +244,95 @@
     }
 }
 
-void update_scale(void) {
-    static uint8_t last_plus = 0, last_minus = 0;
-    if (key_presses.ctrl_pressed) {
-        if (key_presses.plus_pressed && !last_plus) {
-            double scale = ent_get_scale();
-            scale *= 1.1;
-            if (scale <= MAX_SCALE) ent_set_scale(scale);
-        }
-        else if (key_presses.minus_pressed && !last_minus) {
-            double scale = ent_get_scale();
-            scale /= 1.1;
-            if (scale >= MIN_SCALE) ent_set_scale(scale);
-        }
+text_timer_t* (text_timer_ctor)(const font_t *fnt){
+    if(fnt == NULL) return NULL;
+    text_timer_t *ret = malloc(sizeof(timer_t));
+    if (ret == NULL) return NULL;
+    ret->time = 0;
+    ret->text = text_ctor(fnt, "000s");
+    text_set_color(ret->text, TEXT_COLOR);
+    return ret;
+}
+void (text_timer_update)(text_timer_t *p){
+    if (p->time >= 999) return;
+    p->time++;
+    char buffer[100];
+    sprintf(buffer, "%03ds", p->time);
+    text_set_string(p->text, buffer);
+}
+void (text_timer_reset)(text_timer_t *p){
+    text_set_string(p->text, "000s");
+}
+void (text_timer_dtor)(text_timer_t *p){
+    if (p == NULL) return;
+    text_dtor(p->text);
+    free(p);
+}
 
-        //printf("SCALE: %d\n", (int)(ent_get_scale()*1000));
-    }
+host_info_t* host_info_ctor(gunner_t *host, gunner_t *remote) {
+    host_info_t *ret = (host_info_t*)malloc(sizeof(host_info_t));
+    if (ret == NULL) return ret;
 
-    last_plus = key_presses.plus_pressed;
-    last_minus = key_presses.minus_pressed;
-}
+    ret->host_x               = (int16_t)gunner_get_x          (host);
+    ret->host_y               = (int16_t)gunner_get_y          (host);
+    ret->host_angle           = (int16_t)gunner_get_angle      (host);
+    ret->host_health          = (int16_t)gunner_get_health     (host);
+    ret->host_current_health  = (int16_t)gunner_get_curr_health(host);
 
-void (get_random_spawn)(const map_t *map, gunner_t *p, list_t *l) {
-    uint16_t w = map_get_width(map), h = map_get_height(map);
-    double x, y;
+    // remote
+    ret->remote_x               = (int16_t)gunner_get_x          (remote);
+    ret->remote_y               = (int16_t)gunner_get_y          (remote);
+    ret->remote_angle           = (int16_t)gunner_get_angle      (remote);
+    ret->remote_health          = (int16_t)gunner_get_health     (remote);
+    ret->remote_current_health  = (int16_t)gunner_get_curr_health(remote);
 
-    while(true){
-        x = rand() % w;
-        y = rand() % h;
-        gunner_set_pos(p, x, y);
-        if(map_collides_gunner(map, p)) continue;
-        int collides = false;
-        list_node_t *it = list_begin(l);
-        while(it != list_end(l)){
-            if(gunner_collides_gunner(p, *list_node_val(it))){
-                collides = true;
-                break;
-            }
-            it = list_node_next(it);
-        }
-        if(!collides) return;
-    }
+    //ret->no_bullets = 0;
+
+    return ret;
 }
+void host_info_dtor(host_info_t *p) {
+    if (p==NULL) return;
+    /*
+    if ((p->bullets_x) != NULL){ free(p->bullets_x); p->bullets_x = NULL; }
 
-static int16_t mouse_x = 0, mouse_y = 0;
+    if ((p->bullets_y) != NULL){ free(p->bullets_y); p->bullets_y = NULL; }
 
-void (update_mouse)(struct packet *p) {
-    mouse_x = max_16(0, mouse_x + p->delta_x);
-    mouse_x = min_16(mouse_x, (int16_t)graph_get_XRes() - 1);
+    if ((p->bullets_vx) != NULL){ free(p->bullets_vx); p->bullets_vx = NULL; }
 
-    mouse_y = max_16(0, mouse_y - p->delta_y);
-    mouse_y = min_16(mouse_y, (int16_t)graph_get_YRes() - 1);
+    if ((p->bullets_vy) != NULL){ free(p->bullets_vy); p->bullets_vy = NULL; }
 
-    key_presses.lb_pressed = p->lb;
+    if ((p->bullets_shooter) != NULL){ free(p->bullets_shooter); p->bullets_shooter = NULL; }
+    */
+    free(p);
 }
 
-keys_t* (get_key_presses)(void) {
-    return &key_presses;
+remote_info_t* remote_info_ctor(void) {
+    remote_info_t *ret = (remote_info_t*)malloc(sizeof(remote_info_t));
+    if (ret == NULL) return ret;
+
+    memset(&(ret->remote_keys_pressed), 0, sizeof(keys_t));
+
+    ret->remote_angle = 0;
+
+    return ret;
 }
+void remote_info_dtor(remote_info_t *p) {
+    if (p==NULL) return;
+    free(p);
+}
 
-int16_t* get_mouse_X(void) { return &mouse_x; }
+bullet_info_t* bullet_info_ctor(void) {
+    bullet_info_t *ret = (bullet_info_t*)malloc(sizeof(bullet_info_t));
+    if (ret == NULL) return ret;
 
-int16_t* get_mouse_Y(void) { return &mouse_y; }
+    ret->new_bullet = false;
 
-double get_mouse_angle(gunner_t *p) {
-    return atan2(gunner_get_y_screen(p) - mouse_y, mouse_x - gunner_get_x_screen(p));
+    return ret;
 }
+void bullet_info_dtor(bullet_info_t *p) {
+    if (p == NULL) return;
+    free(p);
+}
 
 void build_host_structure(host_info_t *p, gunner_t *host, gunner_t *remote) {
     // host
@@ -356,36 +372,7 @@
     }
     */
 }
-
 void build_remote_structure(remote_info_t *p, keys_t *keys, double angle) {
     memcpy(&(p->remote_keys_pressed), keys, sizeof(keys_t));
     p->remote_angle = angle;
 }
-
-text_timer_t* (timer_ctor)(const font_t *fnt){
-    if(fnt == NULL) return NULL;
-    text_timer_t *ret = malloc(sizeof(timer_t));
-    if (ret == NULL) return NULL;
-    ret->time = 0;
-    ret->text = text_ctor(fnt, "000s");
-    text_set_color(ret->text, TEXT_COLOR);
-    return ret;
-}
-
-void (timer_update)(text_timer_t *p){
-    if (p->time >= 999) return;
-    p->time++;
-    char buffer[100];
-    sprintf(buffer, "%03ds", p->time);
-    text_set_string(p->text, buffer);
-}
-
-void (timer_reset)(text_timer_t *p){
-    text_set_string(p->text, "000s");
-}
-
-void (timer_dtor)(text_timer_t *p){
-    if (p == NULL) return;
-    text_dtor(p->text);
-    free(p);
-}
Index: proj/src/zombies.c
===================================================================
--- proj/src/zombies.c	(nonexistent)
+++ proj/src/zombies.c	(revision 345)
@@ -0,0 +1,145 @@
+#include <lcom/lcf.h>
+
+#include "zombies.h"
+
+#include "proj.h"
+
+#include "proj_macros.h"
+#include "proj_func.h"
+#include "ent.h"
+#include "interrupts_func.h"
+#include "graph.h"
+#include "hltp.h"
+#include "errors.h"
+#include <math.h>
+
+#define ZOMBIES_NUM             5
+#define ZOMBIE_HEALTH_FACTOR    1.1
+int (zombies)(void){
+
+    int r;
+
+    ent_set_scale(DEFAULT_SCALE);
+    text_timer_t *in_game_timer = text_timer_ctor(font_get_default());
+
+    list_t *shooter_list = list_ctor();
+
+    gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n");
+    gunner_set_spawn(shooter1, 980, 790);
+    gunner_set_pos(shooter1, 980, 790);
+
+    list_insert(shooter_list, list_end(shooter_list), shooter1);
+
+    list_t *bullet_list  = list_ctor();
+
+    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
+    gunner_get_y(shooter1)-ent_get_YLength()/2.0);
+
+    //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
+    uint8_t last_lb = 0;
+    struct packet pp;
+    keys_t *keys = get_key_presses();
+
+    /// loop stuff
+    uint64_t int_vector = 0;
+    int good = true;
+    int dead = false;
+
+    int health = 50;
+
+    map_make_dijkstra(map1, gunner_get_x(shooter1), gunner_get_y(shooter1));
+
+    while (good && !dead) {
+        /* Get a request message. */
+        if((r = get_interrupts_vector(&int_vector))) return r;
+        uint32_t n = 1;
+        for (uint8_t i = 0; i < 32; i++, n <<= 1) {
+            if(!good || dead) break;
+            if (int_vector & n) {
+                interrupt_handler(i);
+                switch (i) {
+                    case TIMER0_IRQ:
+                    if (timer_get_no_interrupts() % 60 == 0) text_timer_update(in_game_timer);
+                    if (timer_get_no_interrupts() %  6 == 0){
+                        map_make_dijkstra(map1, gunner_get_x(shooter1), gunner_get_y(shooter1));
+                    }
+
+                    update_movement(map1, shooter1, keys, shooter_list);
+
+                    update_game_state(map1, shooter_list, bullet_list);
+
+                    if(list_find(shooter_list, shooter1) == list_end(shooter_list)){
+                        good = false;
+                        dead = true;
+                        break;
+                    }
+
+                    double angle = get_mouse_angle(shooter1);
+                    gunner_set_angle(shooter1, angle - M_PI_2);
+
+                    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
+                                   gunner_get_y(shooter1)-ent_get_YLength()/2.0);
+
+                    while(list_size(shooter_list) < ZOMBIES_NUM+1){
+                        gunner_t *zombie = gunner_ctor(bsp_zombie, bsp_nothing, GUNNER_MELEE | GUNNER_FOLLOW, 3);
+                        gunner_set_health(zombie, health);
+                        gunner_set_curr_health(zombie, health);
+                        health *= ZOMBIE_HEALTH_FACTOR;
+                        get_random_spawn(map1, zombie, shooter_list);
+                        list_push_back(shooter_list, zombie);
+                    }
+
+                    graph_clear_screen();
+                    map_draw   (map1);
+                    bullet_draw_list(bullet_list);
+                    gunner_draw_list(shooter_list);
+
+                    text_draw(in_game_timer->text);
+
+                    sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
+                    sprite_draw(sp_crosshair);
+                    graph_draw();
+
+                    break;
+                    case KBC_IRQ:
+                    if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) {
+                        good = false;
+                    }
+                    break;
+                    case MOUSE_IRQ:
+                    if (mouse_get_counter_mouse_ih() >= 3) {
+                        mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp);
+                        update_mouse(&pp);
+                        if (last_lb ^ keys->lb_pressed && keys->lb_pressed)
+                        shoot_bullet(shooter1, bullet_list, bsp_bullet);
+                        last_lb = keys->lb_pressed;
+                        mouse_set_counter_mouse_ih(0);
+
+                    }
+                    break;
+                    case COM1_IRQ: nctp_ih(); break;
+                }
+            }
+        }
+    }
+
+    while(list_size(shooter_list) > 0){
+        gunner_t *p = list_erase(shooter_list, list_begin(shooter_list));
+        gunner_dtor(p);
+    }
+    if(list_dtor(shooter_list)) printf("COULD NOT DESTRUCT SHOOTER LIST\n");
+
+    while(list_size(bullet_list) > 0){
+        bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list));
+        bullet_dtor(p);
+    }
+    if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n");
+
+    if(dead){
+        printf("YOU DIED\n");
+    }
+
+    text_timer_dtor(in_game_timer); in_game_timer = NULL;
+
+    return SUCCESS;
+}

Property changes on: proj/src/zombies.c
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: proj/Makefile
===================================================================
--- proj/Makefile	(revision 344)
+++ proj/Makefile	(revision 345)
@@ -9,7 +9,7 @@
 .PATH: ${.CURDIR}/libs/classes/src
 .PATH: ${.CURDIR}/libs/utils/src
 
-SRCS= list.c queue.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c fast_math.c xpm_utils.c rtc.c uart.c makecode_map.c menu.c proj_func.c rectangle.c font.c ent.c proj.c hltp.c
+SRCS= list.c queue.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c fast_math.c xpm_utils.c rtc.c uart.c makecode_map.c menu.c proj_func.c rectangle.c font.c ent.c proj.c hltp.c zombies.c
 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
 
 CPPFLAGS += -pedantic ${IPATHS} -D LCOM_MACRO #-D __LCOM_OPTIMIZED__ -Wall -Wextra -Wshadow -Wunreachable-code #-Weverything -Wno-padded -Wno-unused-macros
