From 4eb407d28670c260af5fe22345bccbca746aad2d Mon Sep 17 00:00:00 2001 From: huaqo-games Date: Sun, 23 Mar 2025 21:11:09 +0100 Subject: [PATCH] new anim state in animation struct --- src/engine/animation.h | 3 ++- src/game/bee.h | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/engine/animation.h b/src/engine/animation.h index 99c8abf..b2a85a9 100644 --- a/src/engine/animation.h +++ b/src/engine/animation.h @@ -1,7 +1,8 @@ #ifndef ANIMATION_H #define ANIMATION_H -typedef struct { +typedef struct { + int state; int currentFrame; int maxFrame; int framesCounter; diff --git a/src/game/bee.h b/src/game/bee.h index 728d9da..e90c0c7 100644 --- a/src/game/bee.h +++ b/src/game/bee.h @@ -5,6 +5,9 @@ #include "../engine/physics.h" #include "../engine/object.h" +typedef enum { + FLYING +} BeeAnimationState; typedef struct { Sprite sprite; @@ -15,7 +18,7 @@ typedef struct { int flowerCount; } Bee; -Bee CreateBee(Texture2D texture, float frameWidth, int maxFrame, int framesSpeed, Vector2 position, float speed, ObjectArray* target, Object* base){ +Bee CreateBee(BeeAnimationState animState, Texture2D texture, float frameWidth, int maxFrame, int framesSpeed, Vector2 position, float speed, ObjectArray* target, Object* base){ return (Bee){ .sprite = { .texture = texture, @@ -27,6 +30,7 @@ Bee CreateBee(Texture2D texture, float frameWidth, int maxFrame, int framesSpeed .color = WHITE }, .animation = { + .state = animState, .currentFrame = 0, .maxFrame = maxFrame, .framesCounter = 0, @@ -66,7 +70,7 @@ void UpdateBee(Bee* bee, ObjectArray* flowers, Object* hive){ UpdateSpriteRotation(&bee->sprite, &bee->physics.direction); UpdateSpriteDestRec(&bee->sprite, &bee->physics.position); UpdateAnimation(&bee->animation, GetFrameTime()); - UpdateSpriteSourceRec(&bee->sprite, &(Vector2){bee->sprite.frameSize.x, bee->sprite.frameSize.x * bee->animation.currentFrame}); + UpdateSpriteSourceRec(&bee->sprite, &(Vector2){bee->sprite.frameSize.x * bee->animation.state, bee->sprite.frameSize.x * bee->animation.currentFrame}); } #endif // BEE_H