diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/asset_defs.c | 2 | ||||
| -rw-r--r-- | src/drops.c | 1 | ||||
| -rw-r--r-- | src/game.c | 2 | ||||
| -rw-r--r-- | src/guns.c | 13 | ||||
| -rw-r--r-- | src/objects.c | 3 | ||||
| -rw-r--r-- | src/pathfinding.c | 2 | ||||
| -rw-r--r-- | src/players.c | 4 | ||||
| -rw-r--r-- | src/wall_item.c | 49 |
8 files changed, 72 insertions, 4 deletions
diff --git a/src/asset_defs.c b/src/asset_defs.c index a51dfe8..d122b6b 100644 --- a/src/asset_defs.c +++ b/src/asset_defs.c @@ -5,4 +5,6 @@ void load_assets() { fnt_20 = assets_load_font(mono_ttf, mono_ttf+mono_ttf_len, 20); img_icon_bullets = assets_load_image_from_file("data/imgs/bullets.png"); + + img_icon_nova = assets_load_image_from_file("data/imgs/nova.png"); }
\ No newline at end of file diff --git a/src/drops.c b/src/drops.c index a03f7ca..e5e1d7b 100644 --- a/src/drops.c +++ b/src/drops.c @@ -15,7 +15,6 @@ void handle_drop_pickup(player* p, drop* d) { void update_drops() { #define MAX_HEIGHT_DIFF (0.3f) - #define FREQUENCY (0.15) for (int i = 0; i < MAX_DROPS; i++) { drop b = drops[i]; @@ -155,6 +155,7 @@ void update_server(platform_window* window) { update_spawners(); update_drops(); + update_wallitems(); update_bullets(window); update_players_server(); update_zombies_server(window); @@ -256,6 +257,7 @@ void update_game(platform_window* window) { take_player_input(window); draw_grid(window); + draw_wallitems(window); draw_drops(window); draw_bullets(window); draw_zombies(window); @@ -1,5 +1,18 @@ #include "../include/guns.h" +#include "../include/asset_defs.h" gun get_gun_by_type(gun_type type) { return guns[type]; +} + +image* get_image_of_gun(gun_type type) { + switch (type) + { + case GUN_NOVA: return img_icon_nova; break; + + default: + break; + } + + return 0; }
\ No newline at end of file diff --git a/src/objects.c b/src/objects.c index 23a57c6..a4d86e1 100644 --- a/src/objects.c +++ b/src/objects.c @@ -1,4 +1,5 @@ #include "../include/objects.h" +#include "../include/wall_item.h" box get_box_of_object(platform_window* window, object o) { return get_render_box_of_square(window, (vec3f){o.position.x, o.position.y, o.h}, o.size); @@ -79,4 +80,6 @@ void create_objects() { create_box(14, 10, 0); create_box(13, 10, 0); create_box(11, 10, 0); + + create_wallitem((vec3f){14, 1, 0}, WALLITEM_GUN, (wall_item_data){.gun = GUN_NOVA}); }
\ No newline at end of file diff --git a/src/pathfinding.c b/src/pathfinding.c index effca06..88bcd23 100644 --- a/src/pathfinding.c +++ b/src/pathfinding.c @@ -87,7 +87,7 @@ bool find_path_to(vec2f start_pos, vec2f end_pos, array *to_fill, pathfinding_re } if (to_fill) { - array_remove_at(to_fill, to_fill->length-1); + if (to_fill->length > 1) array_remove_at(to_fill, to_fill->length-1); //printf("PATHFINDING TOOK: %fms\n", (platform_get_time(TIME_PROCESS, TIME_MS)-timestamp)/1000.0f); } mutex_unlock(&request->mutex); diff --git a/src/players.c b/src/players.c index 5509067..7244cc4 100644 --- a/src/players.c +++ b/src/players.c @@ -180,8 +180,8 @@ void take_player_input(platform_window* window) { dirx /= length; diry /= length; - float gun_offset_x = (get_player_size_in_tile()/2) + dirx/2; - float gun_offset_y = (get_player_size_in_tile()/2) + diry/2; + float gun_offset_x = (get_player_size_in_tile()/2) + dirx; + float gun_offset_y = (get_player_size_in_tile()/2) + diry; p->gunx = p->playerx + gun_offset_x; p->guny = p->playery + gun_offset_y; diff --git a/src/wall_item.c b/src/wall_item.c new file mode 100644 index 0000000..a9f556c --- /dev/null +++ b/src/wall_item.c @@ -0,0 +1,49 @@ +#include "../include/wall_item.h" + +static image* get_wallitem_img(wall_item_type item, wall_item_data data) { + switch(item) { + case WALLITEM_GUN: return get_image_of_gun(data.gun); + } + + return 0; +} + +void create_wallitem(vec3f position, wall_item_type type, wall_item_data data) { + wall_item item; + item.active = true; + item.position = position; + item.item = type; + item.data = data; + item.start_h = position.z; + item.time_active = 0.0f; + item.img = get_wallitem_img(type, data); + + for (int i = 0; i < MAX_WALLITEMS; i++) { + wall_item ei = wallitems[i]; + if (ei.active) continue; + wallitems[i] = item; + return; + } +} + +void update_wallitems() { + #define MAX_HEIGHT_DIFF_FOR_WALLITEM (0.1f) + + for (int i = 0; i < MAX_WALLITEMS; i++) { + wall_item item = wallitems[i]; + if (!item.active) continue; + + wallitems[i].time_active += update_delta; + wallitems[i].position.z = MAX_HEIGHT_DIFF_FOR_WALLITEM * sin (2 * M_PI * 0.5f * (wallitems[i].time_active) + 0) + item.start_h; + } +} + +void draw_wallitems(platform_window* window) { + for (int i = 0; i < MAX_WALLITEMS; i++) { + wall_item item = wallitems[i]; + if (!item.active) continue; + + box box = get_render_box_of_square(window, item.position, (vec3f){1,1,2}); + renderer->render_image(item.img, box.tl_u.x, box.tl_u.y, box.tr_u.x - box.tl_u.x, box.br_u.y - box.tr_u.y); + } +}
\ No newline at end of file |
