aboutsummaryrefslogtreecommitdiff
path: root/collision_system.c
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2023-05-07 12:53:46 +1000
committerquou <quou@disroot.org>2023-05-07 12:54:06 +1000
commit5f341eacdf0d75a4b334969a2d8a4701d61e4d9e (patch)
treeee3a4c44b92e975530e1e6fed18c8852a6f70a93 /collision_system.c
parent5ef6a71e935e2c3d1e5f9828e8cdbd78403a06a0 (diff)
Add waves and stuff.
Diffstat (limited to 'collision_system.c')
-rw-r--r--collision_system.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/collision_system.c b/collision_system.c
index 2bb8cdb..a5342d2 100644
--- a/collision_system.c
+++ b/collision_system.c
@@ -175,12 +175,13 @@ static void handle(
}
void collision_system(World* world) {
- int i, j, k, s, s2, p0x, p0y, r, l, t, b;
+ int i, j, k, s, s2, p0x, p0y, r, l, t, b, dx, dy, d;
int ax, ay, aw, ah, bx, by, bw, bh;
int overlap[4];
unsigned bits;
- const CPosition* pos0, * pos1;
+ CPosition* pos0, * pos1;
const CCollider* col0, * col1;
+ const CEnemy* e0, * e1;
Collision_Side side;
for (i = 0; i < world->entity_count; i++) {
@@ -254,6 +255,39 @@ void collision_system(World* world) {
}
}
}
+
+ for (i = 0; i < world->entity_count; i++) {
+ bits = world->bitmask[i];
+ if (
+ !(bits & ctype_enemy) ||
+ !(bits & ctype_position)
+ ) { continue; }
+
+ pos0 = &world->positions[i];
+ e0 = &world->enemies[i];
+
+ for (j = i + 1; j < world->entity_count; j++) {
+ bits = world->bitmask[j];
+ if (
+ !(bits & ctype_enemy) ||
+ !(bits & ctype_position)
+ ) { continue; }
+
+ pos1 = &world->positions[j];
+ e1 = &world->enemies[j];
+
+ dx = (pos0->x - pos1->x) >> 4;
+ dy = (pos0->y - pos1->y) >> 4;
+ d = ((dx * dx) + (dy * dy)) >> fbits;
+
+ if (d < enemy_min_distance) {
+ pos0->x += dx;
+ pos1->x -= dx;
+ pos0->y += dy;
+ pos1->y -= dy;
+ }
+ }
+ }
}
#endif