diff options
Diffstat (limited to 'src/game.c')
-rw-r--r-- | src/game.c | 32 |
1 files changed, 21 insertions, 11 deletions
@@ -7,17 +7,17 @@ #include "assets.h" #include "player.h" #include "background.h" +#include <math.h> Game game; static inline bool ShouldDrawEntity(const Entity* e, DrawLayer layerDrawing) { return EntityAllocated(e) - && (e->flags & ENTITY_VISIBLE) - && (layerDrawing == e->drawLayer); + && (e->flags & ENTITY_VISIBLE); } -static inline Rectangle GetDrawDestinationRectGlobal(const Entity* e) { - Rectangle destRectGlobal = e->destRect; +static inline Rectangle GetSpriteDrawDestinationRectGlobal(const Entity* e, int spriteIndex) { + Rectangle destRectGlobal = e->sprites[spriteIndex].destRect; destRectGlobal.x += e->position.x; destRectGlobal.y += e->position.y; @@ -78,20 +78,30 @@ void UpdateGame(float deltaTime) { } } -void DefaultDrawEntity(const Entity* e) { - Rectangle srcRect = {0, 0, e->texture.width, e->texture.height}; +void DrawEntitySprite(const Entity* e, int spriteIndex) { + const Sprite* drawnSprite = &e->sprites[spriteIndex]; + + Rectangle srcRect = + {0, 0, drawnSprite->texture.width, drawnSprite->texture.height}; Vector2 origin = {0.0f, 0.0f}; float rotation = 0.0f; - Rectangle destRect = GetDrawDestinationRectGlobal(e); + Rectangle destRect = GetSpriteDrawDestinationRectGlobal(e, spriteIndex); + + DrawTexturePro(drawnSprite->texture, srcRect, destRect, origin, rotation, WHITE); +} - DrawTexturePro(e->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) + DrawEntitySprite(e, i); + } } -void DrawEntity(const Entity* e) { +void DrawEntity(const Entity* e, DrawLayer toLayer) { switch (e->type) { default: - DefaultDrawEntity(e); + DefaultDrawEntity(e, toLayer); } } @@ -100,7 +110,7 @@ void DrawEntitiesInLayer(int layer) { Entity* currentEntity = &game.entities[i]; if (ShouldDrawEntity(currentEntity, layer)) - DrawEntity(currentEntity); + DrawEntity(currentEntity, layer); } } |