/**
 * \brief Create a splinter item.
 * \param splinter_index Index of animation in splinter_animations list.
 * \param pos Position of item to create.
 */
void bear::explosion_effect_item::create_splinter_item
(unsigned int splinter_index, bear::universe::position_type pos)
{
  bear::decorative_item* item = new bear::decorative_item;

  item->set_animation(m_splinter_animations[splinter_index]);
  item->set_kill_when_leaving(true);
  item->set_kill_when_finished(false);
  item->set_mass(1);
  item->set_z_position(get_z_position());
  item->set_density(0.002);

  universe::force_type force;
  double angle = ( 6.283 * rand() ) / RAND_MAX;
  double factor = (double)rand() / RAND_MAX / 2.0 + 0.5;
  force.x = cos(angle) * m_force * factor;
  force.y = sin(angle) * m_force * factor;
  item->set_external_force(force);

  item->set_system_angle(angle);
  item->set_system_angle_as_visual_angle(true);

  new_item( *item );

  item->set_center_of_mass(pos);

  CLAW_ASSERT
    ( item->is_valid(),
      "A decorative item created by exposion_effect_item isn't correctly "
      "initialized" );

} // explosion_effect_item::create_splinter_item()
Example #2
0
/**
 * \brief Create the item representing a new power.
 * \param fill_color The color inside the effect.
 * \param border_color The color of the border of the effect.
 */
void ptb::power_effect::show_change_effect
( const bear::visual::color& fill_color,
  const bear::visual::color& border_color )
{
  bear::star* new_decoration =
    new bear::star( 16, 1, border_color, 2, fill_color );

  new_decoration->set_z_position(get_z_position() - 10);
  new_decoration->set_size( 160, 160 );
  new_item( *new_decoration );
  new_decoration->set_center_of_mass(get_center_of_mass());

  const bear::universe::time_type d(0.5);
  bear::universe::forced_tracking mvt(d);
  mvt.set_reference_point_on_center( *this );
  new_decoration->set_forced_movement(mvt);

  bear::decorative_effect* decoration_effect = new bear::decorative_effect;

  decoration_effect->set_duration(d);
  bear::visual::color init_color, end_color;
  init_color.set(1,1,1,1);
  end_color.set(1,1,1,0);
  decoration_effect->set_color( init_color, end_color );
  decoration_effect->set_item(new_decoration, true);

  new_item( *decoration_effect );
} // power_effect::show_change_effect()
Example #3
0
/**
 * \brief Function called when the explosition starts.
 */
void rp::zeppelin::explose()
{ 
  set_transportability(false);
  kill_interactive_item();
  drop();
  m_hit = true;
  util::create_floating_score(*this,750);

  bear::universe::position_type pos = get_center_of_mass();
  pos.x -= get_width()/4;

  for ( unsigned int i = 0; i != 3; ++i )
    {
      explosion* item = new explosion(15,20,0.6);
      item->set_z_position(get_z_position() + 1000);
      item->set_combo_value(get_combo_value());
      item->set_center_of_mass(pos);
      new_item( *item );
      CLAW_ASSERT( item->is_valid(),
                   "The explosion of bomb isn't correctly initialized" );
      
      bear::universe::forced_tracking m;
      m.set_reference_point_on_center(*this);
      item->set_forced_movement(m);
      pos.x += get_width()/4;
    }

  start_model_action("explose");
} // zeppelin::explose()
Example #4
0
/**
 * \brief Create an explosion.
 * \param nb_explosions Number of explosions to display.
 * \param radius The radius of the explosion.
 */
void rp::tnt::create_explosion
(unsigned int nb_explosions, bear::universe::coordinate_type radius)
{ 
  explosion* item = new explosion(nb_explosions,radius, 0.6);
      
  item->set_z_position(get_z_position() + 10);
  item->set_combo_value(get_combo_value());
  item->set_center_of_mass(get_center_of_mass());
  new_item( *item );
  CLAW_ASSERT( item->is_valid(),
               "The explosion of tnt isn't correctly initialized" );
} // tnt::create_explosion()
Example #5
0
/**
 * \brief create bonus.
 */
void rp::level_generator::create_bonus(bear::universe::position_type& pos)
{
  add_straight_slope(pos);

  bonus* new_bonus = new bonus();
  new_bonus->set_center_of_mass
    ( pos + bear::universe::position_type(0,100));
  
  new_bonus->set_z_position(get_z_position()+11000);
  
  new_item( *new_bonus );

  add_straight_slope(pos);
} // level_generator::create_bonus()
Example #6
0
/**
 * \brief Progress in the state dead.
 */
void ptb::gorilla::progress_dead( bear::universe::time_type elapsed_time )
{
  if (  has_bottom_contact() )
    {
      bear::visual::animation soul_anim
        ( get_level_globals().get_animation
          ("animation/forest/gorilla/gorilla_soul.canim") );
      create_headstone( get_bottom_middle(), soul_anim, s_soul_energy,
                        get_z_position() - 2 );
      kill();
    }
  else
    get_rendering_attributes().set_angle
      ( get_rendering_attributes().get_angle() - 0.1 );
} // gorilla::progress_dead()
Example #7
0
/**
 * \brief Add a slope.
 */
void rp::level_generator::create_target(bear::universe::position_type& pos)
{
  target* new_target = new target();

  new_target->set_center_of_mass
    ( pos + 
      bear::universe::position_type
      ( (rand() % 600) - 200,
	(rand() % 400) - 200) );
  new_target->set_z_position(get_z_position()+10000);
  
  if ( ( (double)rand() / RAND_MAX ) < 0.5 ) 
    new_target->set_color("yellow");
  else
    new_target->set_color("red");

  new_item( *new_target );
} // level_generator::create_target()
Example #8
0
/**
 * \brief Add bridge visual on a line.
 * \param visuals (out) The visuals.
 * \param left_pos Left position.
 * \param right_pos Right position.
 */
void bear::bridge::add_bridge_visual
( std::list<engine::scene_visual>& visuals,
  const universe::position_type& left_pos,
  const universe::position_type& right_pos ) const
{
  visual::sprite s(get_sprite());
      
  visual::position_type p
    ( ( left_pos + right_pos - s.get_size() ) / 2 + get_gap() );
  
  claw::math::line_2d<universe::coordinate_type> line
    ( left_pos, right_pos - left_pos );
  
  double angle = std::atan(line.direction.y / line.direction.x);
  s.set_angle(angle);
  
  visuals.push_front
    ( engine::scene_visual( p, s, get_z_position() ) );
} // bridge::add_bridge_visual()
Example #9
0
/**
 * \brief Create a decoration.
 */
void ptb::honeypot::create_decoration()
{
  bear::decorative_item* item = new bear::decorative_item;

  item->set_animation
    (get_level_globals().get_animation
     ("animation/corrupting-bonus-disapearing.canim"));
  item->get_rendering_attributes().set_angle(get_visual_angle());
  item->set_kill_when_finished(true);
  item->set_z_position(get_z_position()-1);

  new_item( *item );

  item->set_center_of_mass(get_center_of_mass());

  CLAW_ASSERT( item->is_valid(),
               "The decoration of corrupting_bonus isn't correctly "
               "initialized" );
} // honeypot::create_decoration()
Example #10
0
/**
 * \brief Create item.
 */
void rp::zeppelin::create_item()
{
  base_item* const item = m_item->clone();
  
  item->set_top_middle( get_mark_world_position("anchor") );
  item->set_global( is_global() );

  entity* e = dynamic_cast<entity*>( m_item );
  if ( e != NULL )
    item->set_z_position(get_z_position() + 1);
  new_item( *item );

  m_drop_item = handle_type(item);

  bear::universe::forced_tracking mvt
    ( item->get_center_of_mass() - get_center_of_mass() );
  mvt.set_reference_point_on_center( *this );
  mvt.set_auto_remove(true);
  item->set_forced_movement( mvt );
} // zeppelin::create_item()
Example #11
0
/**
 * \brief Create a dust item.
 * \param dust_index Index of animation in dust_animations list.
 * \param pos Position of item to create.
 */
void bear::explosion_effect_item::create_dust_item
(unsigned int dust_index, bear::universe::position_type pos)
{
  bear::decorative_item* item = new bear::decorative_item;

  item->set_animation(m_dust_animations[dust_index]);
  item->set_kill_when_finished(true);
  item->set_kill_when_leaving(true);
  item->set_z_position(get_z_position()-1);
  double angle = ( 6.283 * rand() ) / RAND_MAX;
  item->set_system_angle(angle);
  item->set_system_angle_as_visual_angle(true);

  new_item( *item );

  item->set_center_of_mass(pos);

  CLAW_ASSERT
    ( item->is_valid(),
      "A decorative item created by exposion_effect_item isn't correctly "
      "initialized" );
} // explosion_effect_item::create_dust_item()
Example #12
0
/**
 * \brief Gets the scene elements to use to render this item.
 * \param visuals (out) The scene elements.
 */
void bear::decorative_item::get_visual
( std::list<engine::scene_visual>& visuals ) const
{
  if ( (m_shadow_x == 0) || (m_shadow_y == 0) )
    super::get_visual( visuals );
  else
    {
      typedef std::list<engine::scene_visual> visual_list;

      visual_list parent_visuals;

      super::get_visual( parent_visuals );
      parent_visuals.sort( engine::scene_visual::z_position_compare() );

      visual::scene_element_sequence result;
      result.set_shadow( m_shadow_x, m_shadow_y );

      for ( visual_list::iterator it=parent_visuals.begin();
            it!=parent_visuals.end(); ++it )
        result.push_back( it->scene_element );

      visuals.push_back( engine::scene_visual( result, get_z_position() ) );
    }
} // decorative_item::get_visual()
Example #13
0
/**
 * \brief Get the sprites representing the item.
 * \param visuals (out) The sprites of the item, and their positions.
 */
void bear::reflecting_decoration::get_visual
( std::list<engine::scene_visual>& visuals ) const
{
  items_list::const_iterator it;
  items_list item_list(m_items_list);

  item_list.sort( reflecting_decoration::z_item_position_compare() );

  for ( it = item_list.begin(); it != item_list.end(); ++it )
    if ( it->get_item() != NULL )
      {
        std::list<engine::scene_visual> scenes;
        (*it)->get_visual(scenes);

        scenes.sort(engine::scene_visual::z_position_compare());

        if ( !scenes.empty() )
          {
            visual::scene_element_sequence e;
            visual::position_type origin
              ( scenes.front().scene_element.get_position() );
            e.set_position( origin + get_gap() );

            for ( ; !scenes.empty() ; scenes.pop_front() )
              {
                visual::scene_element elem( scenes.front().scene_element );
                elem.set_position( elem.get_position() - origin );
                e.push_back( elem );
              }

            e.get_rendering_attributes().combine( get_rendering_attributes() );

            visuals.push_back( engine::scene_visual(e, get_z_position()) );
          }
      }
} // reflecting_decoration::get_visual()