diff --git a/include/sparky_gametypes.h b/include/sparky_gametypes.h index 1afc9c7..7865912 100644 --- a/include/sparky_gametypes.h +++ b/include/sparky_gametypes.h @@ -34,6 +34,9 @@ typedef struct { typedef struct { Model model; + ModelAnimation *model_anims; + u8 model_anims_count; + u8 model_anim_frame_count; Sound sound_shoot; } Weapon; diff --git a/src/sparky_client.c b/src/sparky_client.c index 1366a67..66f777c 100644 --- a/src/sparky_client.c +++ b/src/sparky_client.c @@ -47,6 +47,7 @@ static void __init(void) { static u8 __shutdown(void) { UnloadSound(state.player.weapon.sound_shoot); + UnloadModelAnimations(state.player.weapon.model_anims, state.player.weapon.model_anims_count); UnloadModel(state.player.weapon.model); UnloadModel(state.player.model); CloseAudioDevice(); diff --git a/src/sparky_client_renderer_update.c b/src/sparky_client_renderer_update.c index 9c873b1..8c273c1 100644 --- a/src/sparky_client_renderer_update.c +++ b/src/sparky_client_renderer_update.c @@ -24,10 +24,22 @@ #include #include -static void __load_player(State *s) { - s->player.model = LoadModel("assets/models/jett/scene.gltf"); - s->player.weapon.model = LoadModel("assets/models/7mm/scene.gltf"); - s->player.weapon.sound_shoot = LoadSound("assets/sounds/7mm/shoot.wav"); +#define MODEL_PLAYER_JETT "assets/models/jett/scene.gltf" +#define MODEL_WEAPON_7MM "assets/models/7mm.glb" +#define MODEL_WEAPON_7MM_SOUND_SHOOT "assets/sounds/7mm/shoot.wav" + +static inline void __load_weapon(State *s) { + s->player.weapon.model = LoadModel(MODEL_WEAPON_7MM); + s->player.weapon.model_anims = LoadModelAnimations(MODEL_WEAPON_7MM, (int *) &s->player.weapon.model_anims_count); + assert(s->player.weapon.model_anims_count == 1); + assert(IsModelAnimationValid(s->player.weapon.model, s->player.weapon.model_anims[0])); + s->player.weapon.model_anim_frame_count = 0; + s->player.weapon.sound_shoot = LoadSound(MODEL_WEAPON_7MM_SOUND_SHOOT); +} + +static inline void __load_player(State *s) { + s->player.model = LoadModel(MODEL_PLAYER_JETT); + __load_weapon(s); } static void __update_main_menu(State *s) { @@ -53,6 +65,11 @@ static void __update_gameplay_jump(State *s) { static void __update_gameplay_shoot(State *s) { if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) { + ++s->player.weapon.model_anim_frame_count; + UpdateModelAnimation(s->player.weapon.model, s->player.weapon.model_anims[0], s->player.weapon.model_anim_frame_count); + if (s->player.weapon.model_anim_frame_count >= s->player.weapon.model_anims[0].frameCount) { + s->player.weapon.model_anim_frame_count = 0; + } PlaySound(s->player.weapon.sound_shoot); } }