Ejemplo n.º 1
0
HitResponse
Block::collision(GameObject& other, const CollisionHit& )
{
  Player* player = dynamic_cast<Player*> (&other);
  if(player) {
    if(player->get_bbox().get_top() > get_bbox().get_bottom() - 7.0) {
      hit(*player);
    }
  }

  // only interact with other objects if...
  //   1) we are bouncing
  // and
  //   2) the object is not portable (either never or not currently)
  Portable* portable = dynamic_cast<Portable*> (&other);
  if(bouncing && (portable == 0 || (!portable->is_portable()))) {

    // Badguys get killed
    BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
    if(badguy) {
      badguy->kill_fall();
    }

    // Coins get collected
    Coin* coin = dynamic_cast<Coin*> (&other);
    if(coin) {
      coin->collect();
    }

  }

  return SOLID;
}
Ejemplo n.º 2
0
HitResponse
Block::collision(GameObject& other, const CollisionHit& )
{
  Player* player = dynamic_cast<Player*> (&other);
  if(player) {
    if(player->get_bbox().get_top() > get_bbox().get_bottom() - SHIFT_DELTA) {
      hit(*player);
    }
  }

  // only interact with other objects if...
  //   1) we are bouncing
  //   2) the object is not portable (either never or not currently)
  //   3) the object is being hit from below (baguys don't get killed for activating boxes)
  Portable* portable = dynamic_cast<Portable*> (&other);
  MovingObject* moving_object = dynamic_cast<MovingObject*> (&other);
  bool is_portable = ((portable != 0) && portable->is_portable());
  bool hit_mo_from_below = ((moving_object == 0) || (moving_object->get_bbox().get_bottom() < (get_bbox().get_top() + SHIFT_DELTA)));
  if(bouncing && !is_portable && hit_mo_from_below) {

    // Badguys get killed
    BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
    if(badguy) {
      badguy->kill_fall();
    }

    // Coins get collected
    Coin* coin = dynamic_cast<Coin*> (&other);
    if(coin) {
      coin->collect();
    }

    //Eggs get jumped
    GrowUp* growup = dynamic_cast<GrowUp*> (&other);
    if(growup) {
      growup->do_jump();
    }

  }

  return FORCE_MOVE;
}
Ejemplo n.º 3
0
HitResponse
Block::collision(GameObject& other, const CollisionHit& )
{
  Player* player = dynamic_cast<Player*> (&other);
  if(player) {
    if(player->get_bbox().get_top() > get_bbox().get_bottom() - 7.0) {
      hit(*player);
    }
  }

  if(bouncing) {
    BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
    if(badguy) {
      badguy->kill_fall();
    }
    Coin* coin = dynamic_cast<Coin*> (&other);
    if(coin) {
      coin->collect();
    }
  }

  return SOLID;
}