From 0f25d9fb178e9fb32793331aa1ed724d9747702d Mon Sep 17 00:00:00 2001 From: BoredGuy Date: Sat, 23 Aug 2025 08:58:57 +0300 Subject: Animation System Complete --- src/game.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src/game.c') diff --git a/src/game.c b/src/game.c index 8659939..b15c85f 100644 --- a/src/game.c +++ b/src/game.c @@ -68,8 +68,21 @@ void UpdateGame(float deltaTime) { void DrawEntitySprite(const Entity* e, int spriteIndex) { const Sprite* drawnSprite = &e->sprites[spriteIndex]; - Rectangle srcRect = - {0, 0, drawnSprite->texture.width, drawnSprite->texture.height}; + Rectangle srcRect; + if (!IsAnimated(drawnSprite)) { + srcRect = (Rectangle) { + .x = 0, + .y = 0, + .width = drawnSprite->texture.width, + .height = drawnSprite->texture.height + }; + } else { + const Animation* currentAnimation = + &drawnSprite->animations[drawnSprite->currentAnimation]; + + srcRect = GetCurrentSourceRectangle(currentAnimation); + } + Vector2 origin = {0.0f, 0.0f}; float rotation = 0.0f; Rectangle destRect = GetSpriteDrawDestinationRectGlobal(e, spriteIndex); @@ -77,6 +90,7 @@ void DrawEntitySprite(const Entity* e, int spriteIndex) { DrawTexturePro(drawnSprite->texture, srcRect, destRect, origin, rotation, WHITE); } + void DefaultDrawEntity(const Entity* e, DrawLayer toLayer) { for (int i = 0; i < e->numSprites; i++) { if (e->sprites[i].layer == toLayer) @@ -163,7 +177,9 @@ void UpdateCurrentSpriteAnimation(Sprite* sprite, float dt) { if (currentAnimation->currentFrameTimer >= GetCurrentFrameTime(currentAnimation)) { currentAnimation->currentFrame++; - currentAnimation->currentFrameTimer = 0; + + currentAnimation->currentFrameTimer = + currentAnimation->currentFrameTimer - GetCurrentFrameTime(currentAnimation); } if (currentAnimation->currentFrame >= currentAnimation->numFrames) { -- cgit v1.2.3