From 251be1ac2d808dfd0fca5c0eb37398357ca7bb20 Mon Sep 17 00:00:00 2001 From: BoredGuy Date: Thu, 7 Aug 2025 10:10:18 +0300 Subject: Huge Commit - Added (static)sprites - Removed variable fps (removes wierd camera jitter) Also I'm becoming increasingly more anti-VSync --- src/game.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'src/game.c') diff --git a/src/game.c b/src/game.c index 66fd8e4..55b65c2 100644 --- a/src/game.c +++ b/src/game.c @@ -7,17 +7,17 @@ #include "assets.h" #include "player.h" #include "background.h" +#include 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); } } -- cgit v1.2.3