Ejemplo n.º 1
0
/**
 * \brief Get the position of the level name.
 * \param camera_rect The rectangle of the camera. 
 */
bear::universe::position_type rp::util::get_level_name_position
( const bear::universe::rectangle_type & camera_rect)
{
  return 
    bear::universe::position_type
    ( camera_rect.left() + camera_rect.size().x / 2,
      camera_rect.bottom() + 0.9 * camera_rect.size().y );
} // get_level_name_position()
Ejemplo n.º 2
0
/**
 * \brief Get the position of the medal.
 * \param camera_rect The rectangle of the camera. 
 */
bear::universe::position_type rp::util::get_medal_position
( const bear::universe::rectangle_type & camera_rect)
{
  return 
#if 0
    // at right
    bear::universe::position_type
    ( camera_rect.left() + 0.85 * camera_rect.size().x,
      camera_rect.bottom() + 0.19 * camera_rect.size().y );
#else
  // at left
  bear::universe::position_type
    ( camera_rect.left() + 0.15 * camera_rect.size().x,
      camera_rect.bottom() + 0.19 * camera_rect.size().y );
#endif

} // get_medal_position()
Ejemplo n.º 3
0
/**
 * \brief Update the content of the box.
 * \param camera_box The box of the camera in the level.
 * \param layer_size The size of the layer.
 */
void bear::item_information_layer::info_box::update
( const bear::universe::rectangle_type& camera_box,
  const claw::math::coordinate_2d<unsigned int>& layer_size)
{
  claw::math::coordinate_2d<double> ratio
    ( camera_box.size().x / layer_size.x,
      camera_box.size().y / layer_size.y );

  if ( m_item != NULL )
    {
      bear::universe::position_type pos;
      pos.x = (m_item->get_right() - camera_box.left())/ratio.x + m_delta.x;
      pos.y = (m_item->get_top() - camera_box.bottom())/ratio.y + m_delta.y;
      m_text.set_position( pos );
    }
  else
    m_text.set_text("Invalid handle.");
} // item_information_layer::info_box::update()
/**
 * \brief Adjust the distance between the player and the arrow.
 * \param glob The level globals in which we load the media.
 * \param visible_area The visible part of the layer.
 */
void ptb::player_arrows_layer::player_data::adjust_distance
( bear::engine::level_globals& glob,
  const bear::universe::rectangle_type& visible_area )
{
  claw::math::coordinate_2d<double> ratio
    ( visible_area.size().x / m_screen_size.x,
      visible_area.size().y / m_screen_size.y );

  bear::universe::position_type relative_position;
  relative_position.x = visible_area.left() +
    ( m_position.x + m_arrow.width() / 2 ) * ratio.x;

  relative_position.y = visible_area.bottom() +
    ( m_screen_size.y - m_position.y - m_arrow.height() / 2 ) * ratio.y;

  bear::universe::speed_type vect
    (m_player.get_center_of_mass(), relative_position);
  unsigned int dist = (unsigned int)vect.length() / 100;

  const bear::universe::rectangle_type box = m_player.get_bounding_box();
  bear::visual::font f = glob.get_font("font/Fava-black.ttf", 30);
  if ( box.intersects( visible_area ) )
    m_distance.create(f, "");
  else
    {
      std::ostringstream oss;
      oss << dist+1;
      m_distance.create(f, oss.str());
      m_distance->set_intensity(1, 0.8, 0);
    }

  m_distance_text_position = m_position;

  bear::universe::position_type gap;
  gap.x = cos(m_arrow.get_angle()) * 50;
  gap.y = sin(m_arrow.get_angle()) * 50;

  m_distance_text_position.x +=
    m_arrow.width() / 2 - gap.x - m_distance.get_width() / 2;
  m_distance_text_position.y +=
    m_arrow.height() / 2 - gap.y - m_distance.get_height() / 2;
} // player_arrows_layer::player_data::adjust_distance()
Ejemplo n.º 5
0
/**
 * \brief Show the informations of an item, given a position.
 * \param pos The position where the item is searched.
 * \param camera_box The box of the camera in the level.
 */
bool bear::item_information_layer::show_item
( const bear::universe::position_type& pos,
  const bear::universe::rectangle_type& camera_box )
{
  claw::math::coordinate_2d<double> ratio
    ( camera_box.size().x / get_size().x,
      camera_box.size().y / get_size().y );

  bear::universe::position_type r_pos;
  r_pos.x = pos.x*ratio.x + camera_box.left();
  r_pos.y = pos.y*ratio.y + camera_box.bottom();

  bear::universe::physical_item* item = find_item(r_pos);

  if (item != NULL)
    {
      m_info_box.push_front
      ( new info_box
        (*item, get_level_globals().get_font("font/fixed_white-7x12.fnt",12)) );
    }
  return item != NULL;
} // item_information_layer::show_item()
/**
 * \brief Set the position and the angle of the arrow.
 * \param glob The level globals in which we load the media.
 * \param visible_area The visible part of the level.
 */
void ptb::player_arrows_layer::player_data::adjust_arrow
( bear::engine::level_globals& glob,
  const bear::universe::rectangle_type& visible_area )
{
  m_visible = false;

  if ( (m_player != NULL) && !m_player.is_a_marionette() )
    {
      const bear::universe::position_type center =
        m_player.get_center_of_mass();

      if( ( center.x < visible_area.left() ) ||
          ( center.x > visible_area.left() + visible_area.size().x ) ||
          ( center.y < visible_area.bottom() ) ||
          ( center.y > visible_area.bottom() + visible_area.size().y ) )
        {
          adjust_position( visible_area );
          adjust_angle( visible_area );
          adjust_distance(glob, visible_area );

          m_visible = true;
        }
    }
} // player_arrows_layer::player_data::adjust_arrow()
/**
 * \brief Adjust the angle of the arrow.
 * \param visible_area The visible part of the layer.
 */
void ptb::player_arrows_layer::player_data::adjust_angle
( const bear::universe::rectangle_type& visible_area )
{
  claw::math::coordinate_2d<double> ratio
    ( visible_area.size().x / m_screen_size.x,
      visible_area.size().y / m_screen_size.y );

  bear::universe::position_type relative_position;
  relative_position.x = visible_area.left() +
    ( m_position.x + m_arrow.width() / 2 ) * ratio.x;

  relative_position.y = visible_area.bottom() +
    ( m_position.y + m_arrow.height() / 2 ) * ratio.y;

  bear::universe::speed_type v =
    m_player.get_center_of_mass() - relative_position;

  v.normalize();

  if ( v.y <= 0 )
    m_arrow.set_angle( -acos(v.x) );
  else
    m_arrow.set_angle( acos(v.x) );
} // player_arrows_layer::player_data::adjust_angle()