diff options
author | BoredGuy <osome3717@gmail.com> | 2025-08-07 10:10:18 +0300 |
---|---|---|
committer | BoredGuy <osome3717@gmail.com> | 2025-08-07 10:10:18 +0300 |
commit | 251be1ac2d808dfd0fca5c0eb37398357ca7bb20 (patch) | |
tree | 4bc7ccdaee4773b1ef55ce734a40c528384d4efe /src/game.c | |
parent | 2b95f565e8b88841d20f79205ac600cc14e28458 (diff) |
Huge Commit
- Added (static)sprites
- Removed variable fps (removes wierd camera jitter)
Also I'm becoming increasingly more anti-VSync
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); } } |