diff --git a/game.c b/game.c index b0892a0..e390f03 100644 --- a/game.c +++ b/game.c @@ -67,6 +67,18 @@ void handle_input(Game *g) { } } +void process_bullet_collisions(Game *g, Entity *bullet) { + FOREACH_ENEMY { + INIT_ENEMY; + Rectangle bullet_rec = ((BulletProperties*)bullet->properties)->position; + Rectangle enemy_rec = ((EnemyProperties*)e->properties)->position; + if (CheckCollisionRecs(bullet_rec, enemy_rec)) { + remove_entity(g->bullets, bullet); + remove_entity(g->enemies, e); + } + } +} + void run_frame(Game *g) { handle_input(g); move_player(g->player); @@ -86,6 +98,7 @@ void run_frame(Game *g) { continue; } e->tick(e, GetFrameTime()); + process_bullet_collisions(g, e); } }