HitResponse BadGuy::collision(GameObject& other, const CollisionHit& hit) { if (!is_active()) return ABORT_MOVE; auto badguy = dynamic_cast<BadGuy*> (&other); if (badguy && badguy->is_active() && badguy->m_col.get_group() == COLGROUP_MOVING) { /* Badguys don't let badguys squish other badguys. It's bad. */ #if 0 // hit from above? if (badguy->get_bbox().get_bottom() < (bbox.get_top() + 16)) { if (collision_squished(*badguy)) { return ABORT_MOVE; } } #endif return collision_badguy(*badguy, hit); } auto player = dynamic_cast<Player*> (&other); if (player) { // hit from above? if (player->get_bbox().get_bottom() < (m_col.m_bbox.get_top() + 16)) { if (player->is_stone()) { kill_fall(); return FORCE_MOVE; } if (collision_squished(*player)) { return FORCE_MOVE; } } if (player->is_stone()) { collision_solid(hit); return FORCE_MOVE; } return collision_player(*player, hit); } auto bullet = dynamic_cast<Bullet*> (&other); if (bullet) return collision_bullet(*bullet, hit); return FORCE_MOVE; }
static bool prendre_action(t_player *p, char *obj) { e_stone stone; if ((stone = is_stone(obj)) != NONE) { if (!set_box_delstone(p->x, p->y, stone, 1) || !set_player_addstone(p, stone, 1)) return (false); } else if (!strcasecmp(obj, "nourriture")) { if (!set_box_delfood(p->x, p->y, 1) || !set_player_addfood(p->id, 1)) return (false); } else return (false); return (true); }