summaryrefslogtreecommitdiff
path: root/src/physics.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/physics.c')
-rw-r--r--src/physics.c27
1 files changed, 9 insertions, 18 deletions
diff --git a/src/physics.c b/src/physics.c
index 6567dc4..048d65d 100644
--- a/src/physics.c
+++ b/src/physics.c
@@ -7,16 +7,6 @@ static inline bool PhysicsEnabled(const Entity* e) {
return EntityAllocated(e) && (e->flags & ENTITY_PHYSICS_ACTIVE);
}
-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;
@@ -31,12 +21,12 @@ void MoveAndSlide(Entity* e, float deltaTime) {
physicsCollider.x += e->velocity.x * deltaTime;
for (int i = 0; i < MAX_ENTITY_COUNT; i++) {
- Entity* c = &game.entities[i];
+ Entity* other = &game.entities[i];
- if(!PhysicsEnabled(c) || SameEntity(c, e)) continue;
- Rectangle otherCollider = GetPhysicsColliderGlobal(c);
+ if(!PhysicsEnabled(other) || SameEntity(other, e)) continue;
+ Rectangle otherCollider = GetPhysicsColliderGlobal(other);
- if(IsColliding(&physicsCollider, &otherCollider)) {
+ if(CheckCollisionRecs(physicsCollider, otherCollider)) {
if (velocity.x > 0) {
physicsCollider.x = otherCollider.x - physicsCollider.width;
} else {
@@ -47,12 +37,13 @@ void MoveAndSlide(Entity* e, float deltaTime) {
physicsCollider.y += e->velocity.y * deltaTime;
for (int i = 0; i < MAX_ENTITY_COUNT; i++) {
- Entity* c = &game.entities[i];
+ Entity* other = &game.entities[i];
+
+ if(!PhysicsEnabled(other) || SameEntity(other, e)) continue;
- if(!PhysicsEnabled(c) || SameEntity(c, e)) continue;
- Rectangle otherCollider = GetPhysicsColliderGlobal(c);
+ Rectangle otherCollider = GetPhysicsColliderGlobal(other);
- if(IsColliding(&physicsCollider, &otherCollider)) {
+ if(CheckCollisionRecs(physicsCollider, otherCollider)) {
if (velocity.y > 0) {
physicsCollider.y = otherCollider.y - physicsCollider.height;
} else {