diff options
author | BoredGuy <osome3717@gmail.com> | 2025-07-30 23:33:22 +0300 |
---|---|---|
committer | BoredGuy <osome3717@gmail.com> | 2025-07-30 23:33:22 +0300 |
commit | c05e188ef6a4b715848f9f0b401351a43c80168d (patch) | |
tree | dc1dd17a8623b26bac9bc6b959084babe556ee32 /src/game.c | |
parent | 815aec62f8ae3a403e913559d5fe6138c8825007 (diff) |
Small Refactor
Diffstat (limited to 'src/game.c')
-rw-r--r-- | src/game.c | 91 |
1 files changed, 4 insertions, 87 deletions
@@ -9,42 +9,12 @@ Game game; -static inline bool EntityAllocated(const Entity* e) { - return (e->flags & ENTITY_ALLOCATED); -} - -static inline bool PhysicsEnabled(const Entity* e) { - return EntityAllocated(e) && (e->flags & ENTITY_PHYSICS_ACTIVE); -} - static inline bool ShouldDrawEntity(const Entity* e, DrawLayer layerDrawing) { return EntityAllocated(e) && (e->flags & ENTITY_VISIBLE) && (layerDrawing == e->drawLayer); } -static inline bool SameEntity(const Entity* a, const Entity* b) { - return a->id == b->id; -} - -static inline bool IsColliding(const Rectangle* a, const Rectangle* b) { - bool collisionX = (a->x <= b->x && a->x + a->width > b->x) - || (b->x <= a->x && b->x + b->width > a->x); - - bool collisionY = (a->y <= b->y && a->y + a->height > b->y) - || (b->y <= a->y && b->y + b->height > a->y); - - return collisionX && collisionY; -} - -static inline Rectangle GetPhysicsColliderGlobal(const Entity* e) { - Rectangle physicsColliderGlobal = e->physicsCollider; - physicsColliderGlobal.x += e->position.x; - physicsColliderGlobal.y += e->position.y; - - return physicsColliderGlobal; -} - static inline Rectangle GetDrawDestinationRectGlobal(const Entity* e) { Rectangle destRectGlobal = e->destRect; @@ -54,47 +24,6 @@ static inline Rectangle GetDrawDestinationRectGlobal(const Entity* e) { return destRectGlobal; } -void MoveAndSlide(Entity* e, float deltaTime) { - Vector2 velocity = e->velocity; - Rectangle physicsCollider = GetPhysicsColliderGlobal(e); - - physicsCollider.x += e->velocity.x * deltaTime; - for (int i = 0; i < MAX_ENTITY_COUNT; i++) { - Entity* c = &game.entities[i]; - - if(!PhysicsEnabled(c) || SameEntity(c, e)) continue; - Rectangle otherCollider = GetPhysicsColliderGlobal(c); - - if(IsColliding(&physicsCollider, &otherCollider)) { - if (velocity.x > 0) { - physicsCollider.x = otherCollider.x - physicsCollider.width; - } else { - physicsCollider.x = otherCollider.x + otherCollider.width; - } - } - } - - physicsCollider.y += e->velocity.y * deltaTime; - for (int i = 0; i < MAX_ENTITY_COUNT; i++) { - Entity* c = &game.entities[i]; - - if(!PhysicsEnabled(c) || SameEntity(c, e)) continue; - Rectangle otherCollider = GetPhysicsColliderGlobal(c); - - if(IsColliding(&physicsCollider, &otherCollider)) { - if (velocity.y > 0) { - physicsCollider.y = otherCollider.y - physicsCollider.height; - } else { - physicsCollider.y = otherCollider.y + otherCollider.height; - } - } - } - - e->position.x = physicsCollider.x; - e->position.y = physicsCollider.y; -} - - void AddEntity(Entity* e) { static int nextId = 0; @@ -111,8 +40,10 @@ void AddEntity(Entity* e) { void InitGame() { game.paused = false; - LoadAssets(); - + #ifdef BEATEMUP_DEBUG + game.enableDebugOverlay = false; + #endif + memset(game.entities, 0, sizeof(game.entities)); } @@ -122,10 +53,6 @@ void UpdateEntity(Entity* e, float deltaTime) { UpdatePlayer(e, deltaTime); break; - case Background_Entity: - UpdateBackground(e, deltaTime); - break; - default: break; } @@ -146,16 +73,6 @@ void UpdateGame(float deltaTime) { } } -#ifdef BEATEMUP_DEBUG -void DebugHighlights(const Entity* e) { - if (!PhysicsEnabled(e)) - return; - - Rectangle dstRect = GetPhysicsColliderGlobal(e); - DrawRectangle(dstRect.x, dstRect.y, dstRect.width, dstRect.height, e->physicsColliderColor); -} -#endif - void DefaultDrawEntity(const Entity* e) { Rectangle srcRect = {0, 0, e->texture.width, e->texture.height}; Vector2 origin = {0.0f, 0.0f}; |