コード例 #1
0
void
Totem::activate()
{
  if (!carried_by) {
    physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
    sprite->set_action(dir == LEFT ? "walking-left" : "walking-right");
    return;
  } else {
    synchronize_with(carried_by);
    sprite->set_action(dir == LEFT ? "stacked-left" : "stacked-right");
    return;
  }
}
コード例 #2
0
ファイル: totem.cpp プロジェクト: leyyin/supertux
void
Totem::initialize()
{
  if (!carried_by) {
static const float WALKSPEED = 100;
    physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
    sprite->set_action(dir == LEFT ? "walking-left" : "walking-right");
    return;
  } else {
    synchronize_with(carried_by);
    sprite->set_action(dir == LEFT ? "stacked-left" : "stacked-right");
    return;
  }
}
コード例 #3
0
ファイル: totem.cpp プロジェクト: HybridDog/supertux
void
Totem::active_update(float dt_sec)
{
  BadGuy::active_update(dt_sec);

  if (!carried_by) {
    if (on_ground() && might_fall())
    {
      m_dir = (m_dir == Direction::LEFT ? Direction::RIGHT : Direction::LEFT);
      initialize();
    }

    // jump a bit if we find a suitable totem
    for (auto& obj : Sector::get().get_objects_by_type<MovingObject>()) {
      auto t = dynamic_cast<Totem*>(&obj);
      if (!t) continue;

      // skip if we are not approaching each other
      if (!((m_dir == Direction::LEFT) && (t->m_dir == Direction::RIGHT))) continue;

      Vector p1 = m_col.m_bbox.p1();
      Vector p2 = t->get_pos();

      // skip if not on same height
      float dy = (p1.y - p2.y);
      if (fabsf(dy - 0) > 2) continue;

      // skip if too far away
      float dx = (p1.x - p2.x);
      if (fabsf(dx - 128) > 2) continue;

      m_physic.set_velocity_y(JUMP_ON_SPEED_Y);
      p1.y -= 1;
      set_pos(p1);
      break;
    }
  }

  if (carried_by) {
    synchronize_with(carried_by);
  }

  if (carrying) {
    carrying->synchronize_with(this);
  }

}
コード例 #4
0
ファイル: totem.cpp プロジェクト: HybridDog/supertux
void
Totem::jump_on(Totem* target)
{
  if (target->carrying) {
    log_warning << "target is already carrying someone" << std::endl;
    return;
  }

  target->carrying = this;

  carried_by = target;
  initialize();
  m_col.m_bbox.set_size(m_sprite->get_current_hitbox_width(), m_sprite->get_current_hitbox_height());

  SoundManager::current()->play( LAND_ON_TOTEM_SOUND , get_pos());

  synchronize_with(target);
}