diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/background.c | 16 | ||||
-rw-r--r-- | src/game.c | 22 |
2 files changed, 29 insertions, 9 deletions
diff --git a/src/background.c b/src/background.c index c9ed1fb..d3647cf 100644 --- a/src/background.c +++ b/src/background.c @@ -7,8 +7,8 @@ void AddBackground(const char* backgroundTextureName) { Entity e = {0}; - e.type = Background_Entity; + e.type = Background_Entity; e.flags |= ENTITY_VISIBLE; e.position = (Vector2) {0.0f, 0.0f}; @@ -32,11 +32,15 @@ void AddBackground(const char* backgroundTextureName) { Vector2 backgroundBounds = Vector2Scale((Vector2) {backgroundTexture.width, backgroundTexture.height}, backgroundSizeScale); - AddSpriteToEntity(&e, (Sprite){ - .texture = backgroundTexture, - .layer = Background_Layer, - .destRect = {NO_OFFSET, NO_OFFSET, backgroundBounds.x, backgroundBounds.y} - }); + Sprite backgroundSprite = (Sprite) { + .texture = backgroundTexture, + .layer = Background_Layer, + .numAnimations = 0, + + .destRect = {NO_OFFSET, NO_OFFSET, backgroundBounds.x, backgroundBounds.y} + }; + + AddSpriteToEntity(&e, backgroundSprite); AddEntity(&e); } @@ -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) { |