#include <igel.hpp>
Inherits WalkingBadguy.
Public Member Functions | |
Igel (const Reader &reader) | |
Igel (const Vector &pos, Direction d) | |
HitResponse | collision_bullet (Bullet &bullet, const CollisionHit &hit) |
Called when the badguy collided with a bullet. | |
void | active_update (float elapsed_time) |
called each frame when the badguy is activated. | |
Protected Member Functions | |
bool | collision_squished (GameObject &object) |
Called when the player hit the badguy from above. | |
void | be_normal () |
switch to state STATE_NORMAL | |
void | turn_around () |
reverse direction, assumes we are in STATE_NORMAL | |
bool | can_see (const MovingObject &o) |
check if we can see o | |
Private Attributes | |
Timer | turn_recover_timer |
wait time until we will turn around again when shot at |
Definition at line 25 of file igel.hpp.
Igel::Igel | ( | const Reader & | reader | ) |
Definition at line 31 of file igel.cpp.
References IGEL_SPEED, WalkingBadguy::max_drop_height, and WalkingBadguy::walk_speed.
00031 : 00032 WalkingBadguy(reader, "images/creatures/igel/igel.sprite", "walking-left", "walking-right"), 00033 turn_recover_timer() 00034 { 00035 walk_speed = IGEL_SPEED; 00036 max_drop_height = 16; 00037 }
Definition at line 39 of file igel.cpp.
References IGEL_SPEED, WalkingBadguy::max_drop_height, and WalkingBadguy::walk_speed.
00039 : 00040 WalkingBadguy(pos, d, "images/creatures/igel/igel.sprite", "walking-left", "walking-right"), 00041 turn_recover_timer() 00042 { 00043 walk_speed = IGEL_SPEED; 00044 max_drop_height = 16; 00045 }
HitResponse Igel::collision_bullet | ( | Bullet & | bullet, | |
const CollisionHit & | hit | |||
) | [virtual] |
Called when the badguy collided with a bullet.
Reimplemented from BadGuy.
Definition at line 100 of file igel.cpp.
References BadGuy::collision_bullet(), BadGuy::dir, FORCE_MOVE, CollisionHit::left, LEFT, Bullet::ricochet(), CollisionHit::right, and RIGHT.
00101 { 00102 // default reaction if hit on front side 00103 if (((dir == LEFT) && hit.left) || ((dir == RIGHT) && hit.right)) { 00104 return BadGuy::collision_bullet(bullet, hit); 00105 } 00106 00107 // else make bullet ricochet and ignore the hit 00108 bullet.ricochet(*this, hit); 00109 return FORCE_MOVE; 00110 }
void Igel::active_update | ( | float | elapsed_time | ) | [virtual] |
called each frame when the badguy is activated.
Reimplemented from WalkingBadguy.
Definition at line 75 of file igel.cpp.
References WalkingBadguy::active_update(), BadGuy::active_update(), can_see(), Sector::current(), FIRE_BONUS, Sector::gameobjects, Timer::started(), turn_around(), and turn_recover_timer.
00076 { 00077 bool wants_to_flee = false; 00078 00079 // check if we see a fire bullet 00080 Sector* sector = Sector::current(); 00081 for (Sector::GameObjects::iterator i = sector->gameobjects.begin(); i != sector->gameobjects.end(); ++i) { 00082 Bullet* bullet = dynamic_cast<Bullet*>(*i); 00083 if (!bullet) continue; 00084 if (bullet->get_type() != FIRE_BONUS) continue; 00085 if (can_see(*bullet)) wants_to_flee = true; 00086 } 00087 00088 // if we flee, handle this ourselves 00089 if (wants_to_flee && (!turn_recover_timer.started())) { 00090 turn_around(); 00091 BadGuy::active_update(elapsed_time); 00092 return; 00093 } 00094 00095 // else adhere to default behaviour 00096 WalkingBadguy::active_update(elapsed_time); 00097 }
bool Igel::collision_squished | ( | GameObject & | object | ) | [protected, virtual] |
void Igel::be_normal | ( | ) | [protected] |
switch to state STATE_NORMAL
Definition at line 48 of file igel.cpp.
References WalkingBadguy::initialize().
00049 { 00050 initialize(); 00051 }
void Igel::turn_around | ( | ) | [protected] |
reverse direction, assumes we are in STATE_NORMAL
Reimplemented from WalkingBadguy.
Definition at line 54 of file igel.cpp.
References Timer::start(), WalkingBadguy::turn_around(), TURN_RECOVER_TIME, and turn_recover_timer.
Referenced by active_update().
00055 { 00056 WalkingBadguy::turn_around(); 00057 turn_recover_timer.start(TURN_RECOVER_TIME); 00058 }
bool Igel::can_see | ( | const MovingObject & | o | ) | [protected] |
check if we can see o
Definition at line 61 of file igel.cpp.
References BadGuy::dir, MovingObject::get_bbox(), LEFT, Rectf::p1, Rectf::p2, RANGE_OF_VISION, RIGHT, Vector::x, and Vector::y.
Referenced by active_update().
00062 { 00063 Rectf mb = get_bbox(); 00064 Rectf ob = o.get_bbox(); 00065 00066 bool inReach_left = ((ob.p2.x < mb.p1.x) && (ob.p2.x >= mb.p1.x-((dir == LEFT) ? RANGE_OF_VISION : 0))); 00067 bool inReach_right = ((ob.p1.x > mb.p2.x) && (ob.p1.x <= mb.p2.x+((dir == RIGHT) ? RANGE_OF_VISION : 0))); 00068 bool inReach_top = (ob.p2.y >= mb.p1.y); 00069 bool inReach_bottom = (ob.p1.y <= mb.p2.y); 00070 00071 return ((inReach_left || inReach_right) && inReach_top && inReach_bottom); 00072 }
Timer Igel::turn_recover_timer [private] |
wait time until we will turn around again when shot at
Definition at line 42 of file igel.hpp.
Referenced by active_update(), and turn_around().