Exemplo n.º 1
0
void Crawler::move(Map *map)
{
    Monster::move(map);

    switch(m_action) {
        case Still:
            face_reference();
            set_action(Move);
            break;

        case Move:
            if (check_ahead(map)) {
                swap_move_dir();
            }
            check_ground(map);
            if (m_dir == Right) {
                set_vx(get_attribute("move_speed"));
            }
            else {
                set_vx(-get_attribute("move_speed"));
            }
            animate_move();
            break;

        default:
            break;
    }
}
Exemplo n.º 2
0
  void Roll::update(Spirit& spirit,
		    const stage::Zone& zone,
		    const enemy::EnemyVec& enemies,
		    const prop::PropVec& props)
  {
    if (spirit.orientation.h == common::Horizontal::LEFT) {
      spirit.force.add_x(-values[ctr.value()]);
      
    } else if (spirit.orientation.h == common::Horizontal::RIGHT) {
      spirit.force.add_x(values[ctr.value()]);
    }

    move_x(zone, props, spirit);

    move_y(zone, props, spirit);
  
    if (!check_ground(zone, props, spirit)) {
      if (spirit.orientation.h == common::Horizontal::LEFT) {
	spirit.force.set_vx(-speed);
	
      } else if (spirit.orientation.h == common::Horizontal::RIGHT) {
	spirit.force.set_vx(speed);
      }

      if (spirit.link != nullptr) {
	// Prevent stickiness when attached to a prop.
	spirit.mass.update_y(-1);
      }
      spirit.motion_flag.set(static_cast<int>(MotionState::FALL));
      
    } else if(spirit.controller->is_pressed(input::Glyph::A)) {
      spirit.force.reset();
      spirit.motion_flag.set(static_cast<int>(MotionState::JUMP));
      
    } else if (ctr.update()) {
      spirit.force.reset();
      
      if(spirit.controller->is_pressed(input::Glyph::A)) {
	spirit.motion_flag.set(static_cast<int>(MotionState::JUMP));
	
      } else if (spirit.controller->is_on(input::Glyph::LEFT) ||
		 spirit.controller->is_on(input::Glyph::RIGHT)) {
	spirit.motion_flag.set(static_cast<int>(MotionState::WALK));
	
      } else {
	spirit.motion_flag.set(static_cast<int>(MotionState::IDLE));
      }
    }
  }