diff options
Diffstat (limited to 'collision_system.c')
-rw-r--r-- | collision_system.c | 38 |
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 |