From c162e010ae85c636131ff59e8d810be4e9960caa Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Sat, 4 Nov 2023 16:48:51 +0100 Subject: throwables ui --- build/data/imgs/icons/grenade.png | Bin 0 -> 3336 bytes build/data/imgs/icons/molotov.png | Bin 0 -> 2109 bytes build/zombies.exe | Bin 1997811 -> 1999947 bytes data/imgs/icons/grenade.png | Bin 0 -> 3336 bytes data/imgs/icons/molotov.png | Bin 0 -> 2109 bytes include/asset_defs.h | 3 +++ include/players.h | 4 ++++ include/throwables.h | 1 + main.c | 1 + src/asset_defs.c | 3 +++ src/game.c | 2 -- src/guns.c | 1 + src/overlay.c | 39 +++++++++++++++++++++++++++++++------- src/players.c | 2 ++ 14 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 build/data/imgs/icons/grenade.png create mode 100644 build/data/imgs/icons/molotov.png create mode 100644 data/imgs/icons/grenade.png create mode 100644 data/imgs/icons/molotov.png diff --git a/build/data/imgs/icons/grenade.png b/build/data/imgs/icons/grenade.png new file mode 100644 index 0000000..3253924 Binary files /dev/null and b/build/data/imgs/icons/grenade.png differ diff --git a/build/data/imgs/icons/molotov.png b/build/data/imgs/icons/molotov.png new file mode 100644 index 0000000..9f94000 Binary files /dev/null and b/build/data/imgs/icons/molotov.png differ diff --git a/build/zombies.exe b/build/zombies.exe index af07907..b5f879c 100644 Binary files a/build/zombies.exe and b/build/zombies.exe differ diff --git a/data/imgs/icons/grenade.png b/data/imgs/icons/grenade.png new file mode 100644 index 0000000..3253924 Binary files /dev/null and b/data/imgs/icons/grenade.png differ diff --git a/data/imgs/icons/molotov.png b/data/imgs/icons/molotov.png new file mode 100644 index 0000000..9f94000 Binary files /dev/null and b/data/imgs/icons/molotov.png differ diff --git a/include/asset_defs.h b/include/asset_defs.h index 0fc0f92..cdf9614 100644 --- a/include/asset_defs.h +++ b/include/asset_defs.h @@ -3,6 +3,7 @@ #include +font* fnt_32; font* fnt_24; font* fnt_20; @@ -17,6 +18,8 @@ image* img_3d; image* img_tiles; image* img_sunny; image* img_disconnected; +image* img_icon_grenade; +image* img_icon_molotov; // Objects image* img_spawner; diff --git a/include/players.h b/include/players.h index 0c7433e..d34f83a 100644 --- a/include/players.h +++ b/include/players.h @@ -51,6 +51,10 @@ typedef struct t_player { sprite sprite; vec3f velocity; network_state connection_state; + struct { + int grenades; + int molotovs; + } throwables; } player; #include "protocol.h" diff --git a/include/throwables.h b/include/throwables.h index 5e49c16..4053826 100644 --- a/include/throwables.h +++ b/include/throwables.h @@ -12,6 +12,7 @@ typedef enum t_throwable_type { THROWABLE_NONE = 0, THROWABLE_GRENADE, + THROWABLE_MOLOTOV, } throwable_type; typedef enum t_throwable_state diff --git a/main.c b/main.c index 9616392..6288233 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,6 @@ #define ASSET_IMAGE_COUNT 50 #define ASSET_QUEUE_COUNT 50 +#define ASSET_FONT_COUNT 10 #include diff --git a/src/asset_defs.c b/src/asset_defs.c index c4e229f..15a948a 100644 --- a/src/asset_defs.c +++ b/src/asset_defs.c @@ -1,6 +1,7 @@ #include "../include/asset_defs.h" void load_assets() { + fnt_32 = assets_load_font(noto_regular_ttf, noto_regular_ttf+noto_regular_ttf_len, 32); fnt_24 = assets_load_font(noto_regular_ttf, noto_regular_ttf+noto_regular_ttf_len, 24); fnt_20 = assets_load_font(noto_regular_ttf, noto_regular_ttf+noto_regular_ttf_len, 20); @@ -15,6 +16,8 @@ void load_assets() { img_tiles = assets_load_image_from_file("data/imgs/icons/tiles.png"); img_sunny = assets_load_image_from_file("data/imgs/icons/sunny.png"); img_disconnected = assets_load_image_from_file("data/imgs/icons/disconnected.png"); + img_icon_grenade = assets_load_image_from_file("data/imgs/icons/grenade.png"); + img_icon_molotov = assets_load_image_from_file("data/imgs/icons/molotov.png"); // Throwables img_grenade = assets_load_image_from_file("data/imgs/throwables/grenade.png"); diff --git a/src/game.c b/src/game.c index 2222b86..3a39f76 100644 --- a/src/game.c +++ b/src/game.c @@ -358,8 +358,6 @@ static void move_camera(platform_window* window) { _camera_buffer.y += diry*speedy; _global_camera.x = (int)_camera_buffer.x; _global_camera.y = (int)_camera_buffer.y; - //_global_camera.x = _next_camera_pos.x; - //_global_camera.y = _next_camera_pos.y; } void update_game(platform_window* window) { diff --git a/src/guns.c b/src/guns.c index 8741fa6..7fa4f7e 100644 --- a/src/guns.c +++ b/src/guns.c @@ -9,6 +9,7 @@ image* get_image_of_gun(gun_type type) { switch (type) { case GUN_NOVA: return img_icon_nova; break; + case GUN_MP5: return img_icon_nova; break; default: break; diff --git a/src/overlay.c b/src/overlay.c index 6388d5b..485373b 100644 --- a/src/overlay.c +++ b/src/overlay.c @@ -11,16 +11,41 @@ static void draw_gun_info(platform_window* window) { gun g = get_gun_by_type(p->guntype); - - int y = window->height - fnt_24->px_h - EDGE_PADDING; + int y = window->height - fnt_32->px_h - EDGE_PADDING; int x = EDGE_PADDING; + int icon_h = 26; + + { // Ammo + char ammo_txt[50]; + sprintf(ammo_txt, "%d/%d", p->ammo_in_mag, p->total_ammo); + renderer->render_text(fnt_32, _global_camera.x + x+1, _global_camera.y + y+1, ammo_txt, rgba(0,0,0,120)); + renderer->render_text(fnt_32, _global_camera.x + x, _global_camera.y + y, ammo_txt, rgb(255,255,255)); + } - renderer->render_text(fnt_24, (int)_global_camera.x + x, (int)_global_camera.y + y, g.name, rgb(255,255,255)); - y -= fnt_24->px_h; + y -= icon_h + 5; + + { // Throwables + int offset_x = 0; + for (int i = 0; i < p->throwables.grenades; i++) + { + renderer->render_image_tint(img_icon_grenade, _global_camera.x + x-1 + offset_x, _global_camera.y + y-1, icon_h, icon_h, rgba(0,0,0,100)); + renderer->render_image(img_icon_grenade, _global_camera.x + x + offset_x, _global_camera.y + y, icon_h, icon_h); + + offset_x += icon_h/3; + } + + y -= icon_h + 5; + + offset_x = 0; + for (int i = 0; i < p->throwables.molotovs; i++) + { + renderer->render_image_tint(img_icon_molotov, _global_camera.x + x-1 + offset_x, _global_camera.y + y-1, icon_h, icon_h, rgba(0,0,0,100)); + renderer->render_image(img_icon_molotov, _global_camera.x + x + offset_x, _global_camera.y + y, icon_h, icon_h); + + offset_x += icon_h/3; + } + } - char ammo_txt[50]; - sprintf(ammo_txt, "%d / %d", p->ammo_in_mag, p->total_ammo); - renderer->render_text(fnt_20, (int)_global_camera.x + x, (int)_global_camera.y + y, ammo_txt, rgb(255,255,255)); } static void draw_leaderboard_entry(int x, int y, int w, int h, char* name, char* kills, char* deaths, char* ping, bool highlighted, bool disconnected) { diff --git a/src/players.c b/src/players.c index f62f53e..3e657a0 100644 --- a/src/players.c +++ b/src/players.c @@ -61,6 +61,8 @@ void spawn_player(u32 id, network_client client) { players[i].sprite = create_sprite(img_player_running, 22, 108, 136, 0.02f); players[i].direction = DIRECTION_DOWN; players[i].connection_state = CONNECTED; + players[i].throwables.grenades = 3; + players[i].throwables.molotovs = 1; gun g = get_gun_by_type(players[i].guntype); players[i].total_ammo = g.max_ammunition; -- cgit v1.2.3-70-g09d2