summaryrefslogtreecommitdiff
path: root/src/game.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/game.c')
-rw-r--r--src/game.c22
1 files changed, 19 insertions, 3 deletions
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) {