Skip to content

Commit

Permalink
Added weapon icon for each slot in HUD
Browse files Browse the repository at this point in the history
It marks the currently equiped weapon in yellow, leaving the rest of
the slots in white.
  • Loading branch information
iWas-Coder committed May 13, 2024
1 parent a88f8d5 commit 4c434c0
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 11 deletions.
Binary file added assets/images/7mm/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/akm/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions include/sk_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@

#define SK_PLAYER_WEAPON_SLOTS 2

enum {
SK_PLAYER_IDX_SIDE_WEAPON,
SK_PLAYER_IDX_MAIN_WEAPON
};

typedef enum {
SK_PLAYER_KIND_AGENT69
} sk_player_kind;
Expand Down
1 change: 1 addition & 0 deletions include/sk_weapon.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ typedef struct {

typedef struct {
sk_weapon_kind kind;
Texture2D icon;
Model model;
ModelAnimation *model_anims;
u8 model_anims_count;
Expand Down
13 changes: 4 additions & 9 deletions src/sk_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@
#define WALK_VELOCITY 14
#define MODEL_PATH_PLACEHOLDER "assets/models/%s.glb"

enum {
SIDE_WEAPON_IDX,
MAIN_WEAPON_IDX
};

sk_player sk_player_create(i8 lobby_id, i8 lobby_slot_idx, sk_player_kind kind, sk_config *config) {
assert(lobby_id != -1);
assert(lobby_slot_idx != -1);
Expand Down Expand Up @@ -67,9 +62,9 @@ void sk_player_destroy(sk_player *p) {

void sk_player_load(sk_player *p) {
p->model = LoadModel(TextFormat(MODEL_PATH_PLACEHOLDER, sk_player_kind2name[p->kind]));
p->weapon_slots[SIDE_WEAPON_IDX] = sk_weapon_create(SK_WEAPON_KIND_7MM);
p->weapon_slots[MAIN_WEAPON_IDX] = sk_weapon_create(SK_WEAPON_KIND_AKM);
p->weapon = &p->weapon_slots[SIDE_WEAPON_IDX];
p->weapon_slots[SK_PLAYER_IDX_SIDE_WEAPON] = sk_weapon_create(SK_WEAPON_KIND_7MM);
p->weapon_slots[SK_PLAYER_IDX_MAIN_WEAPON] = sk_weapon_create(SK_WEAPON_KIND_AKM);
p->weapon = &p->weapon_slots[SK_PLAYER_IDX_SIDE_WEAPON];
}

void sk_player_jump(sk_player *p, sk_config *config) {
Expand Down Expand Up @@ -119,7 +114,7 @@ void sk_player_move(sk_player *p, sk_config *config, f32 roll) {

void sk_player_rotate_weapon(sk_player *p) {
if (IsSoundPlaying(p->weapon->sound_equip) || IsSoundPlaying(p->weapon->sound_reload)) return;
static usz i = SIDE_WEAPON_IDX;
static usz i = SK_PLAYER_IDX_SIDE_WEAPON;
i = (i + 1) % SK_PLAYER_WEAPON_SLOTS;
p->weapon = &p->weapon_slots[i];
PlaySound(p->weapon->sound_equip);
Expand Down
10 changes: 8 additions & 2 deletions src/sk_scene_gameplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,20 @@ void sk_scene_gameplay_draw(sk_state *s) {
DrawText(TextFormat("N/A ms"), 10, 50, 20, LIME);
DrawText(TextFormat("(d) N/A bps | (u) N/A bps"), 10, 70, 20, LIME);
}
// START: HUD's Crosshair
DrawCircle(GetScreenWidth() / 2, GetScreenHeight() / 2, s->config.crosshair.radius, BLACK);
DrawCircle(GetScreenWidth() / 2, GetScreenHeight() / 2, s->config.crosshair.radius - 0.9f, RAYWHITE);
// END: HUD's Crosshair
DrawText(TextFormat("%u", s->player.hp), 100, GetScreenHeight() - 100, 25, RAYWHITE);
DrawText(TextFormat("%u | %u", s->player.weapon->ammo.magazine, s->player.weapon->ammo.reserve),
GetScreenWidth() - 100,
GetScreenHeight() - 100,
25,
RAYWHITE);
DrawTexture(s->player.weapon_slots[SK_PLAYER_IDX_SIDE_WEAPON].icon,
GetScreenWidth() - s->player.weapon_slots[SK_PLAYER_IDX_SIDE_WEAPON].icon.width - 30,
GetScreenHeight() - 260,
s->player.weapon == &s->player.weapon_slots[SK_PLAYER_IDX_SIDE_WEAPON] ? YELLOW : WHITE);
DrawTexture(s->player.weapon_slots[SK_PLAYER_IDX_MAIN_WEAPON].icon,
GetScreenWidth() - s->player.weapon_slots[SK_PLAYER_IDX_MAIN_WEAPON].icon.width - 30,
GetScreenHeight() - 200,
s->player.weapon == &s->player.weapon_slots[SK_PLAYER_IDX_MAIN_WEAPON] ? YELLOW : WHITE);
}
3 changes: 3 additions & 0 deletions src/sk_weapon.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <sk_weapon.h>
#include <raymath.h>

#define ICON_PATH_PLACEHOLDER "assets/images/%s/icon.png"
#define MODEL_PATH_PLACEHOLDER "assets/models/%s.glb"
#define SOUND_EQUIP_PATH_PLACEHOLDER "assets/sounds/%s/equip.wav"
#define SOUND_SHOOT_PATH_PLACEHOLDER "assets/sounds/%s/shoot.wav"
Expand All @@ -36,6 +37,7 @@ sk_weapon sk_weapon_create(sk_weapon_kind kind) {
const sk_weapon_ammo_spec ammo_spec = sk_weapon_kind2ammo[kind];
sk_weapon w = {
.kind = kind,
.icon = LoadTexture(TextFormat(ICON_PATH_PLACEHOLDER, name)),
.model = LoadModel(TextFormat(MODEL_PATH_PLACEHOLDER, name)),
.model_anims = LoadModelAnimations(TextFormat(MODEL_PATH_PLACEHOLDER, name), (int *) &w.model_anims_count),
.sound_equip = LoadSound(TextFormat(SOUND_EQUIP_PATH_PLACEHOLDER, name)),
Expand All @@ -59,6 +61,7 @@ void sk_weapon_destroy(sk_weapon *w) {
UnloadSound(w->sound_equip);
UnloadModelAnimations(w->model_anims, w->model_anims_count);
UnloadModel(w->model);
UnloadTexture(w->icon);
*w = (sk_weapon) {0};
w = 0;
}
Expand Down

0 comments on commit 4c434c0

Please sign in to comment.