#include "physics.h" #include "game.h" #include "utils.h" #include "constants.h" extern Game game; void MoveWithoutPhysics(Entity* e, float dt) { e->position.x += e->velocity.x * dt; e->position.y += e->velocity.y * dt; } void MoveAndStop(Entity* e, float deltaTime) { Vector2 velocity = e->velocity; Rectangle physicsCollider = GetPhysicsColliderGlobal(e); Rectangle pastCollider = physicsCollider; physicsCollider.x += e->velocity.x * deltaTime; for (int i = 0; i < MAX_ENTITY_COUNT; i++) { Entity* other = &game.entities[i]; if(!PhysicsEnabled(other) || SameEntity(other, e)) continue; Rectangle otherCollider = GetPhysicsColliderGlobal(other); if(CheckCollisionRecs(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* other = &game.entities[i]; if(!PhysicsEnabled(other) || SameEntity(other, e)) continue; Rectangle otherCollider = GetPhysicsColliderGlobal(other); if(CheckCollisionRecs(physicsCollider, otherCollider)) { if (velocity.y > 0) { physicsCollider.y = otherCollider.y - physicsCollider.height; } else { physicsCollider.y = otherCollider.y + otherCollider.height; } } } e->position.x += (physicsCollider.x - pastCollider.x); e->position.y += (physicsCollider.y - pastCollider.y); } #ifdef BEATEMUP_DEBUG void DebugHighlights(const Entity* e) { if (!PhysicsEnabled(e)) return; Rectangle dstRect = GetPhysicsColliderGlobal(e); Color colliderDrawColor = e->physicsColliderColor; colliderDrawColor.a = COLLIDER_ALPHA; DrawRectangleRec(dstRect, colliderDrawColor); for (int i = 0; i < e->numHitBoxes; i++) { Color hitboxDrawColor = e->hitboxColors[i]; hitboxDrawColor.a = COLLIDER_ALPHA; Rectangle dstRect = GetEntityHitboxGlobal(e, i); DrawRectangleRec(dstRect, hitboxDrawColor); } for (int i = 0; i < e->numHurtBoxes; i++) { Color hurtboxDrawColor = e->hurtboxColors[i]; hurtboxDrawColor.a = COLLIDER_ALPHA; Rectangle dstRect = GetEntityHurtboxGlobal(e, i); DrawRectangleRec(dstRect, hurtboxDrawColor); } } #endif