/** * \brief The monster is injure. * \param attacker The monster attacking me. * \param side The side on which I am attacked. * \param duration The duration of injure state. */ void ptb::gorilla::injure ( const monster& attacker, bear::universe::zone::position side, double duration ) { if ( ( get_current_action_name() == "idle" ) || ( get_current_action_name() == "scan_left" ) || ( get_current_action_name() == "scan_right" ) || ( get_current_action_name() == "come_back" ) ) { m_scan_distance= 500; choose_angry_action(); const base_item* m = dynamic_cast<const base_item*>(&attacker); if ( m != NULL ) { if ( m->get_speed().x > 0 ) get_rendering_attributes().mirror(true); else get_rendering_attributes().mirror(false); } } super::injure(attacker, side, duration); } // ptb::gorilla::injure()
/** * \brief Progress in the state attack. */ void ptb::gorilla::progress_attack( bear::universe::time_type elapsed_time ) { if ( m_want_come_back ) start_model_action("come_back"); else if ( !scan(get_rendering_attributes().is_mirrored(), m_scan_distance) ) m_want_come_back = true; else if ( get_rendering_attributes().is_mirrored() ) add_internal_force( bear::universe::force_type(-250000, 0) ); else add_internal_force( bear::universe::force_type(250000, 0) ); } // gorilla::progress_attack()
/** * \brief Progress in the state scan_left. */ void ptb::gorilla::progress_scan_left( bear::universe::time_type elapsed_time ) { if ( m_want_scan ) { if ( listen() ) choose_angry_action(); else if ( scan( !get_rendering_attributes().is_mirrored(), m_scan_distance ) ) { choose_angry_action(); get_rendering_attributes().mirror (!get_rendering_attributes().is_mirrored()); } } } // gorilla::progress_scan_left()
/** * \brief Progress in the state scome_back. */ void ptb::gorilla::progress_come_back(bear::universe::time_type elapsed_time) { get_rendering_attributes().mirror(get_left() >= m_origin_position.x ); if ( scan(get_rendering_attributes().is_mirrored(), m_scan_distance) ) choose_angry_action(); else if ( std::abs(get_left() - m_origin_position.x) < 10 ) start_model_action("idle"); else if ( has_right_contact() || has_left_contact() ) start_model_action("idle"); else if ( get_rendering_attributes().is_mirrored() ) add_internal_force( bear::universe::force_type(-70000, 0) ); else add_internal_force( bear::universe::force_type(70000, 0) ); } // gorilla::progress_come_back()
/** * \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()
/** * \brief Initialize a slope. * \param slope A reference to the pointer of the slope. * \param s The steepness. * \param z The z position of the slope. */ void rp::switching::init_slope( bear::slope*& slope, double s, int z ) { if ( slope == NULL ) { slope = new bear::slope; if ( s < 0 ) slope->set_size( get_width(), get_height() / 2 ); else slope->set_size( get_size() ); const double effective_steepness = get_rendering_attributes().is_mirrored() ? -s : s; slope->set_bottom_left( get_bottom_left() ); slope->set_steepness( effective_steepness ); slope->set_top_friction( 0.95 ); slope->set_max_z_for_collision( z + 100 ); slope->set_z_position(z); slope->set_z_shift(100); slope->set_force_z_position(true); new_item(*slope); } else get_layer().add_item(*slope); } // rp::switching::init_slope()
/** * \brief Get a given offensive coefficient in the state "attack". * \param index The index of the attack. * \param other The other monster. * \param side The side of this through which the attack is done. */ unsigned int ptb::gorilla::get_offensive_coefficient_attack ( unsigned int index, const monster& other, bear::universe::zone::position side ) const { // The gorilla always attack on the front in attack_state. unsigned int result = super::get_offensive_coefficient(index, other, side); if ( ( index == indefensible_attack ) || ( index == normal_attack ) ) { unsigned int result_attack; if ( index == indefensible_attack ) result_attack = 1; else result_attack = 0; if ( side == bear::universe::zone::middle_zone ) { if ( m_is_injured ) result = 0; else result = result_attack; } else if ( get_rendering_attributes().is_mirrored() ) { if ( side == bear::universe::zone::middle_left_zone ) result = result_attack; } else if ( side == bear::universe::zone::middle_right_zone ) result = result_attack; } return result; } // gorilla::get_offensive_coefficient_attack()
/** * \brief Listen if there is a player in the accessive zone. */ bool ptb::gorilla::listen() { bool result = false; if ( scan(false, s_listen_distance) ) { result = true; get_rendering_attributes().mirror(false); } else if ( scan(true, s_listen_distance) ) { result = true; get_rendering_attributes().mirror(true); } return result; } // gorilla::listen()
/** * \brief Render the line on a screen. * \param scr The screen on which we render the line. */ void bear::visual::scene_line::render( base_screen& scr ) const { std::vector<position_type> p(m_points); for ( std::size_t i=0; i!=p.size(); ++i ) { p[i].x = get_position().x + p[i].x * get_scale_factor_x(); p[i].y = get_position().y + p[i].y * get_scale_factor_y(); } color_type c( m_color ); c.components.red *= get_rendering_attributes().get_red_intensity(); c.components.green *= get_rendering_attributes().get_green_intensity(); c.components.blue *= get_rendering_attributes().get_blue_intensity(); c.components.alpha *= get_rendering_attributes().get_opacity(); scr.draw_line(c, p, m_width); } // scene_line::render()
/** * \brief Get a given offensive coefficient on the state "come_back". * \param index The index of the attack. * \param other The other monster. * \param side The side of this through which the attack is done. */ unsigned int ptb::gorilla::get_offensive_coefficient_come_back ( unsigned int index, const monster& other, bear::universe::zone::position side ) const { // The gorilla attacks forward in come_back state. unsigned int result = super::get_offensive_coefficient(index, other, side); if ( ( index == indefensible_attack ) || ( index == normal_attack ) ) { if ( side == bear::universe::zone::middle_zone ) { if ( m_is_injured ) result = 0; else { const base_item* item = dynamic_cast<const base_item*>(&other); if ( ( item != NULL ) && get_rendering_attributes().is_mirrored() ) { if ( item->get_left() >= get_left() ) result = 0; } else if ( item->get_right() <= get_right() ) result = 0; } } else { const base_item* item = dynamic_cast<const base_item*>(&other); if ( ( item != NULL ) && get_rendering_attributes().is_mirrored() ) { if ( item->get_left() >= get_left() ) result = 0; } else if ( item->get_right() <= get_right() ) result = 0; } } return result; } // gorilla::get_offensive_coefficient_come_back()
/** * \brief Do post creation actions. */ void rp::zeppelin::on_enters_layer() { super::on_enters_layer(); if ( get_rendering_attributes().is_mirrored() ) { get_rendering_attributes().mirror(false); set_model_actor ( get_level_globals().get_model("model/zeppelin/zeppelin-mirror.cm") ); } else set_model_actor ( get_level_globals().get_model("model/zeppelin/zeppelin.cm") ); start_model_action("idle"); if ( m_item != NULL ) create_item(); create_interactive_item(*this, 1.5); } // rp::zeppelin::on_enters_layer()
/** * \brief Tell is the item has a defensive power. * \param index Index of the power. * \param attacker The attacker. * \param side The side on which the power is checked. */ bool ptb::gorilla::get_defensive_power_by_side ( unsigned int index, const monster& attacker, bear::universe::zone::position side ) const { bool result = super::get_defensive_power_by_side(index, attacker, side); if ( !result ) { if ( side == bear::universe::zone::middle_zone ) { if ( get_current_action_name() == "come_back" ) { const base_item* item = dynamic_cast<const base_item*>(&attacker); if ( ( item != NULL ) && get_rendering_attributes().is_mirrored() ) { if ( item->get_left() >= get_left() ) result = 0; } else if ( item->get_right() <= get_right() ) result = 0; } else result = true; } else if ( get_current_action_name() == "attack" ) { if ( get_rendering_attributes().is_mirrored() ) result = ( side == bear::universe::zone::middle_left_zone ); else result = ( side == bear::universe::zone::middle_right_zone ); } else if ( ( get_current_action_name() == "angry_1" ) || ( get_current_action_name() == "angry_2" ) || ( get_current_action_name() == "angry_3" ) ) result = true; } return result; } // gorilla::get_defensive_power_by_side()
/** * \brief Select passive opacity. */ void bear::hidden_block::select_passive_opacity() { double opacity = m_active_opacity + (m_passive_opacity-m_active_opacity) * m_last_modification / m_transition_duration; if ( opacity <= 0 ) opacity = 0; else if ( opacity >= 1 ) opacity = 1; get_rendering_attributes().set_opacity(opacity); } // hidden_block::select_passive_opacity()
/** * \brief Initialize the item. */ void ptb::honeypot::build() { super::build(); level_variables::set_object_count ( get_level(), "honeypot", level_variables::get_object_count( get_level(), "honeypot" ) + 1); m_id = level_variables::get_object_count( get_level(), "honeypot" ); std::ostringstream s; s << "honeypot " << m_id; std::string name(s.str()); create_level_bonus(name); level_variables::set_honeypot_found ( get_level(), m_id, game_variables::get_level_object_state (game_variables::get_main_level_name(), name )); game_variables::set_level_object_state (name, level_variables::get_honeypot_found(get_level(), m_id)); game_variables::set_level_object_filename (name, "gfx/ui/bonus-icons/bonus-icons.png"); game_variables::set_level_object_name(name, name); set_animation ( get_level_globals().get_animation("animation/shiny-honey-jar.canim") ); if ( level_variables::get_honeypot_found(get_level(), m_id) ) { get_rendering_attributes().set_intensity( 0.25, 0.25, 1 ); get_rendering_attributes().set_opacity( 0.5 ); } set_size( 64, 64 ); } // honeypot::build()
/** * \brief Constructor. */ ptb::gorilla::gorilla() : m_progress(NULL), m_want_come_back(false), m_scan_distance(320) { set_z_fixed(false); set_mass(100); set_density(2); m_monster_type = monster::enemy_monster; m_energy = 30; m_offensive_phase = true; m_offensive_force = s_gorilla_offensive_force; m_offensive_coefficients[normal_attack] = 1; get_rendering_attributes().mirror(false); set_category("gorilla"); } // gorilla::gorilla()
/** * \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()
/** * \brief Function called when the reppelin collides a tar. */ void rp::zeppelin::make_dirty() { get_rendering_attributes().set_intensity(0,0,0); } // zeppelin::make_dirty()