Fix laser beam blocked by own tile, consolidate enemy-type checks
Beam raycast now skips the tile the turret is mounted on, so wall-embedded laser turrets can shoot outward. Extract entity_is_enemy() into engine/entity.c as single source of truth for enemy-type checks. Replaces triplicated type lists in level.c, drone.c, and projectile.c that caused the collision bug when new enemy types were added.
This commit is contained in:
@@ -233,12 +233,6 @@ static void damage_player(Entity *player, int damage, Entity *source) {
|
||||
}
|
||||
}
|
||||
|
||||
static bool is_enemy(const Entity *e) {
|
||||
return e->type == ENT_ENEMY_GRUNT || e->type == ENT_ENEMY_FLYER ||
|
||||
e->type == ENT_TURRET || e->type == ENT_ENEMY_CHARGER ||
|
||||
e->type == ENT_SPAWNER || e->type == ENT_LASER_TURRET;
|
||||
}
|
||||
|
||||
static void handle_collisions(EntityManager *em) {
|
||||
/* Find the player */
|
||||
Entity *player = NULL;
|
||||
@@ -267,7 +261,7 @@ static void handle_collisions(EntityManager *em) {
|
||||
bool hit = false;
|
||||
|
||||
/* Player bullet hits enemies */
|
||||
if (from_player && is_enemy(b)) {
|
||||
if (from_player && entity_is_enemy(b)) {
|
||||
if (physics_overlap(&a->body, &b->body)) {
|
||||
damage_entity(b, a->damage);
|
||||
hit = true;
|
||||
@@ -293,7 +287,7 @@ static void handle_collisions(EntityManager *em) {
|
||||
|
||||
/* ── Enemy contact damage to player ──── */
|
||||
if (player && !(player->flags & ENTITY_INVINCIBLE) &&
|
||||
is_enemy(a) && !(a->flags & ENTITY_DEAD)) {
|
||||
entity_is_enemy(a) && !(a->flags & ENTITY_DEAD)) {
|
||||
if (physics_overlap(&a->body, &player->body)) {
|
||||
/* Check if player is stomping (falling onto enemy from above) */
|
||||
bool stomping = (player->body.vel.y > 0) &&
|
||||
|
||||
Reference in New Issue
Block a user