Example #1
0
/**
 * \brief Calculate the new acceleration of the item.
 */
void bear::universe::physical_item::adjust_cinetic()
{
  speed_type s( get_speed() );

  if ( has_owner() )
    {
      const speed_type eps(get_owner().get_speed_epsilon());

      if ( (s.x < eps.x) && (s.x > -eps.x) )
        s.x = 0;
      if ( (s.y < eps.y) && (s.y > -eps.y) )
        s.y = 0;

      set_speed(s);

      if ( (get_angular_speed() < get_owner().get_angular_speed_epsilon()) &&
           (get_angular_speed() > -get_owner().get_angular_speed_epsilon()) )
        set_angular_speed(0);
    }
} // physical_item::adjust_cinetic()
Example #2
0
/**
 * \brief Call collision_check_and_bounce().
 * \param that The other item of the collision.
 * \param info Some informations about the collision.
 */
void rp::bonus::collision
( bear::engine::base_item& that, bear::universe::collision_info& info )
{
    if ( m_bonus_is_given )
        return;

    cart* c = dynamic_cast<cart*>(&that);

    if ( c != NULL )
        if ( c->get_current_action_name() != "dead" &&
                c->get_current_action_name() != "takeoff" )
        {
            m_bonus_is_given = true;
            give_bonus(c);
            set_angular_speed(-20);
            set_mass(1);
            m_cart = c;

            m_tweener_y_position.insert
            ( claw::tween::single_tweener
              ( 0.0, 300.0, 0.5,
                boost::bind( &rp::bonus::on_y_position_change, this, _1 ),
                &claw::tween::easing_quad::ease_out ) );
            m_tweener_y_position.insert
            ( claw::tween::single_tweener
              ( 300.0, 50.0, 0.5,
                boost::bind( &rp::bonus::on_y_position_change, this, _1 ),
                &claw::tween::easing_quad::ease_in ) );
            m_tweener_y_position.on_finished
            (boost::bind( &rp::bonus::kill, this ));

            m_tweener_x_position.insert
            ( claw::tween::single_tweener
              ( get_horizontal_middle() - m_cart->get_horizontal_middle(),
                0.0, 1.0,
                boost::bind( &rp::bonus::on_x_position_change, this, _1 ),
                &claw::tween::easing_quad::ease_out ) );
        }
} // bonus::collision()