#include <owl.hpp>
Inherits BadGuy.
Public Member Functions | |
Owl (const Reader &reader) | |
Owl (const Vector &pos, Direction d) | |
void | initialize () |
called immediately before the first call to initialize | |
void | collision_solid (const CollisionHit &hit) |
Called when the badguy collided with solid ground. | |
Protected Member Functions | |
bool | is_above_player (void) |
void | active_update (float elapsed_time) |
called each frame when the badguy is activated. | |
bool | collision_squished (GameObject &object) |
Called when the player hit the badguy from above. | |
Protected Attributes | |
std::string | carried_obj_name |
Portable * | carried_object |
Private Member Functions | |
Owl (const Owl &) | |
Owl & | operator= (const Owl &) |
Definition at line 24 of file owl.hpp.
Owl::Owl | ( | const Reader & | reader | ) |
Definition at line 32 of file owl.cpp.
References carried_obj_name, BadGuy::dir, lisp::Lisp::get(), LEFT, and MovingSprite::set_action().
00032 : 00033 BadGuy(reader, "images/creatures/owl/owl.sprite", LAYER_OBJECTS + 1), 00034 carried_obj_name("skydive"), 00035 carried_object(NULL) 00036 { 00037 reader.get("carry", carried_obj_name); 00038 set_action (dir == LEFT ? "left" : "right", /* loops = */ -1); 00039 }
Definition at line 41 of file owl.cpp.
References BadGuy::dir, LEFT, and MovingSprite::set_action().
00041 : 00042 BadGuy(pos, d, "images/creatures/owl/owl.sprite", LAYER_OBJECTS + 1), 00043 carried_obj_name("skydive"), 00044 carried_object(NULL) 00045 { 00046 set_action (dir == LEFT ? "left" : "right", /* loops = */ -1); 00047 }
Owl::Owl | ( | const Owl & | ) | [private] |
void Owl::initialize | ( | ) | [virtual] |
called immediately before the first call to initialize
Reimplemented from BadGuy.
Definition at line 50 of file owl.cpp.
References Sector::add_object(), carried_obj_name, carried_object, ObjectFactory::create(), Sector::current(), BadGuy::dir, Physic::enable_gravity(), FLYING_SPEED, MovingObject::get_pos(), ObjectFactory::instance(), LEFT, log_fatal, log_warning, BadGuy::physic, Physic::set_velocity_x(), and MovingSprite::sprite.
00051 { 00052 GameObject *game_object; 00053 00054 physic.set_velocity_x(dir == LEFT ? -FLYING_SPEED : FLYING_SPEED); 00055 physic.enable_gravity(false); 00056 sprite->set_action(dir == LEFT ? "left" : "right"); 00057 00058 game_object = ObjectFactory::instance().create(carried_obj_name, get_pos(), dir); 00059 if (game_object == NULL) { 00060 log_fatal << "Creating \"" << carried_obj_name << "\" object failed." << std::endl; 00061 return; 00062 } 00063 00064 carried_object = dynamic_cast<Portable *> (game_object); 00065 if (carried_object == NULL) { 00066 log_warning << "Object is not portable: " << carried_obj_name << std::endl; 00067 delete game_object; 00068 return; 00069 } 00070 00071 Sector::current ()->add_object (game_object); 00072 } /* void initialize */
void Owl::collision_solid | ( | const CollisionHit & | hit | ) | [virtual] |
Called when the badguy collided with solid ground.
Reimplemented from BadGuy.
Definition at line 133 of file owl.cpp.
References CollisionHit::bottom, BadGuy::dir, FLYING_SPEED, LEFT, CollisionHit::left, BadGuy::physic, RIGHT, CollisionHit::right, MovingSprite::set_action(), Physic::set_velocity_x(), Physic::set_velocity_y(), and CollisionHit::top.
00134 { 00135 if(hit.top || hit.bottom) { 00136 physic.set_velocity_y(0); 00137 } else if(hit.left || hit.right) { 00138 if (dir == LEFT) { 00139 set_action ("right", /* loops = */ -1); 00140 dir = RIGHT; 00141 physic.set_velocity_x (FLYING_SPEED); 00142 } 00143 else { 00144 set_action ("left", /* loops = */ -1); 00145 dir = LEFT; 00146 physic.set_velocity_x (-FLYING_SPEED); 00147 } 00148 } 00149 } /* void Owl::collision_solid */
bool Owl::is_above_player | ( | void | ) | [protected] |
Definition at line 75 of file owl.cpp.
References ACTIVATION_DISTANCE, Sector::current(), BadGuy::dir, MovingObject::get_bbox(), Sector::get_nearest_player(), LEFT, Rectf::p1, Rectf::p2, Vector::x, and Vector::y.
Referenced by active_update().
00076 { 00077 Player* player = Sector::current()->get_nearest_player (this->get_bbox ()); 00078 if (!player) 00079 return false; 00080 00081 /* Let go of carried objects a short while *before* Tux is below us. This 00082 * makes it more likely that we'll hit him. */ 00083 float x_offset = (dir == LEFT) ? ACTIVATION_DISTANCE : -ACTIVATION_DISTANCE; 00084 00085 const Rectf& player_bbox = player->get_bbox(); 00086 const Rectf& owl_bbox = get_bbox(); 00087 00088 if ((player_bbox.p1.y >= owl_bbox.p2.y) /* player is below us */ 00089 && ((player_bbox.p2.x + x_offset) > owl_bbox.p1.x) 00090 && ((player_bbox.p1.x + x_offset) < owl_bbox.p2.x)) 00091 return true; 00092 else 00093 return false; 00094 }
void Owl::active_update | ( | float | elapsed_time | ) | [protected, virtual] |
called each frame when the badguy is activated.
Reimplemented from BadGuy.
Definition at line 97 of file owl.cpp.
References BadGuy::active_update(), ANCHOR_BOTTOM, MovingObject::bbox, carried_object, BadGuy::dir, get_anchor_pos(), Portable::grab(), is_above_player(), Portable::ungrab(), Vector::x, and Vector::y.
00098 { 00099 BadGuy::active_update (elapsed_time); 00100 00101 if (carried_object != NULL) { 00102 if (!is_above_player ()) { 00103 Vector obj_pos = get_anchor_pos (bbox, ANCHOR_BOTTOM); 00104 obj_pos.x -= 16.0; /* FIXME: Actually do use the half width of the carried object here. */ 00105 obj_pos.y += 3.0; /* Move a little away from the hitbox (the body). Looks nicer. */ 00106 00107 carried_object->grab (*this, obj_pos, dir); 00108 } 00109 else { /* if (is_above_player) */ 00110 carried_object->ungrab (*this, dir); 00111 carried_object = NULL; 00112 } 00113 } 00114 }
bool Owl::collision_squished | ( | GameObject & | object | ) | [protected, virtual] |
Called when the player hit the badguy from above.
You should return true if the badguy was squished, false if squishing wasn't possible
Reimplemented from BadGuy.
Definition at line 117 of file owl.cpp.
References Player::bounce(), carried_object, Sector::current(), BadGuy::dir, Sector::get_nearest_player(), BadGuy::kill_fall(), and Portable::ungrab().
00118 { 00119 Player* player = Sector::current()->get_nearest_player (this->get_bbox ()); 00120 if (player) 00121 player->bounce (*this); 00122 00123 if (carried_object != NULL) { 00124 carried_object->ungrab (*this, dir); 00125 carried_object = NULL; 00126 } 00127 00128 kill_fall (); 00129 return true; 00130 }
std::string Owl::carried_obj_name [protected] |
Portable* Owl::carried_object [protected] |
Definition at line 39 of file owl.hpp.
Referenced by active_update(), collision_squished(), and initialize().