#include <mrbomb.hpp>
Inherits WalkingBadguy, and Portable.
Public Member Functions | |
MrBomb (const Reader &reader) | |
MrBomb (const Vector &pos, Direction d) | |
void | kill_fall () |
Set the badguy to kill/falling state, which makes him falling of the screen (his sprite is turned upside-down). | |
HitResponse | collision (GameObject &object, const CollisionHit &hit) |
Called when a collision with another object occurred. | |
HitResponse | collision_player (Player &player, const CollisionHit &hit) |
Called when the badguy collided with a player. | |
void | active_update (float elapsed_time) |
called each frame when the badguy is activated. | |
void | grab (MovingObject &object, const Vector &pos, Direction dir) |
called each frame when the object has been grabbed. | |
void | ungrab (MovingObject &object, Direction dir) |
bool | is_portable () const |
void | freeze () |
Called when hit by an ice bullet, and is_freezable() returns true. | |
bool | is_freezable () const |
Protected Member Functions | |
bool | collision_squished (GameObject &object) |
Called when the player hit the badguy from above. | |
Private Attributes | |
bool | grabbed |
Definition at line 22 of file mrbomb.hpp.
MrBomb::MrBomb | ( | const Reader & | reader | ) |
Definition at line 28 of file mrbomb.cpp.
References SpriteManager::create(), lisp::Lisp::get(), grabbed, WalkingBadguy::max_drop_height, SoundManager::preload(), sound_manager, MovingSprite::sprite, sprite_manager, MovingSprite::sprite_name, and WalkingBadguy::walk_speed.
00028 : 00029 WalkingBadguy(reader, "images/creatures/mr_bomb/mr_bomb.sprite", "left", "right"), 00030 grabbed() 00031 { 00032 walk_speed = 80; 00033 max_drop_height = 16; 00034 grabbed = false; 00035 00036 //Prevent stutter when Tux jumps on Mr Bomb 00037 sound_manager->preload("sounds/explosion.wav"); 00038 00039 //Check if we need another sprite 00040 if( !reader.get( "sprite", sprite_name ) ){ 00041 return; 00042 } 00043 if( sprite_name == "" ){ 00044 sprite_name = "images/creatures/mr_bomb/mr_bomb.sprite"; 00045 return; 00046 } 00047 //Replace sprite 00048 sprite = sprite_manager->create( sprite_name ); 00049 }
Definition at line 52 of file mrbomb.cpp.
References grabbed, WalkingBadguy::max_drop_height, SoundManager::preload(), sound_manager, and WalkingBadguy::walk_speed.
00052 : 00053 WalkingBadguy(pos, d, "images/creatures/mr_bomb/mr_bomb.sprite", "left", "right"), 00054 grabbed() 00055 { 00056 walk_speed = 80; 00057 max_drop_height = 16; 00058 grabbed = false; 00059 sound_manager->preload("sounds/explosion.wav"); 00060 }
void MrBomb::kill_fall | ( | ) | [virtual] |
Set the badguy to kill/falling state, which makes him falling of the screen (his sprite is turned upside-down).
Reimplemented from BadGuy.
Definition at line 104 of file mrbomb.cpp.
References Sector::add_object(), Sector::current(), MovingObject::get_bbox(), GameObject::is_valid(), GameObject::remove_me(), and BadGuy::run_dead_script().
Referenced by collision_squished().
00105 { 00106 if(is_valid()) { 00107 remove_me(); 00108 Explosion* explosion = new Explosion(get_bbox().get_middle()); 00109 Sector::current()->add_object(explosion); 00110 } 00111 00112 run_dead_script(); 00113 }
HitResponse MrBomb::collision | ( | GameObject & | object, | |
const CollisionHit & | hit | |||
) | [virtual] |
Called when a collision with another object occurred.
The default implementation calls collision_player, collision_solid, collision_badguy and collision_squished
Reimplemented from BadGuy.
Definition at line 63 of file mrbomb.cpp.
References BadGuy::collision(), FORCE_MOVE, and grabbed.
00064 { 00065 if(grabbed) 00066 return FORCE_MOVE; 00067 return WalkingBadguy::collision(object, hit); 00068 }
HitResponse MrBomb::collision_player | ( | Player & | player, | |
const CollisionHit & | hit | |||
) | [virtual] |
Called when the badguy collided with a player.
Reimplemented from BadGuy.
Definition at line 71 of file mrbomb.cpp.
References BadGuy::collision_player(), FORCE_MOVE, and grabbed.
00072 { 00073 if(grabbed) 00074 return FORCE_MOVE; 00075 return WalkingBadguy::collision_player(player, hit); 00076 }
void MrBomb::active_update | ( | float | elapsed_time | ) | [virtual] |
called each frame when the badguy is activated.
Reimplemented from WalkingBadguy.
Definition at line 96 of file mrbomb.cpp.
References WalkingBadguy::active_update(), and grabbed.
00097 { 00098 if(grabbed) 00099 return; 00100 WalkingBadguy::active_update(elapsed_time); 00101 }
void MrBomb::grab | ( | MovingObject & | object, | |
const Vector & | pos, | |||
Direction | dir | |||
) | [virtual] |
called each frame when the object has been grabbed.
Implements Portable.
Definition at line 116 of file mrbomb.cpp.
References COLGROUP_DISABLED, BadGuy::frozen, MovingObject::get_pos(), grabbed, LEFT, MovingObject::movement, BadGuy::set_colgroup_active(), and MovingSprite::sprite.
00117 { 00118 assert(frozen); 00119 movement = pos - get_pos(); 00120 this->dir = dir; 00121 sprite->set_action(dir == LEFT ? "iced-left" : "iced-right"); 00122 set_colgroup_active(COLGROUP_DISABLED); 00123 grabbed = true; 00124 }
void MrBomb::ungrab | ( | MovingObject & | object, | |
Direction | dir | |||
) | [virtual] |
Reimplemented from Portable.
Definition at line 127 of file mrbomb.cpp.
References COLGROUP_MOVING, grabbed, and BadGuy::set_colgroup_active().
00128 { 00129 this->dir = dir; 00130 set_colgroup_active(COLGROUP_MOVING); 00131 grabbed = false; 00132 }
bool MrBomb::is_portable | ( | ) | const [virtual] |
Reimplemented from Portable.
Definition at line 148 of file mrbomb.cpp.
References BadGuy::frozen.
00149 { 00150 return frozen; 00151 }
void MrBomb::freeze | ( | ) | [virtual] |
Called when hit by an ice bullet, and is_freezable() returns true.
Reimplemented from WalkingBadguy.
Definition at line 135 of file mrbomb.cpp.
References BadGuy::dir, WalkingBadguy::freeze(), LEFT, and MovingSprite::sprite.
00136 { 00137 WalkingBadguy::freeze(); 00138 sprite->set_action(dir == LEFT ? "iced-left" : "iced-right"); 00139 }
bool MrBomb::is_freezable | ( | ) | const [virtual] |
bool MrBomb::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 79 of file mrbomb.cpp.
References Sector::add_object(), Player::bounce(), Sector::current(), BadGuy::dir, MovingObject::get_pos(), Player::is_invincible(), GameObject::is_valid(), kill_fall(), BadGuy::kill_squished(), GameObject::remove_me(), and MovingSprite::sprite_name.
00080 { 00081 Player* player = dynamic_cast<Player*>(&object); 00082 if(player && player->is_invincible()) { 00083 player->bounce(*this); 00084 kill_fall(); 00085 return true; 00086 } 00087 if(is_valid()) { 00088 remove_me(); 00089 Sector::current()->add_object(new Bomb(get_pos(), dir, sprite_name )); 00090 } 00091 kill_squished(object); 00092 return true; 00093 }
bool MrBomb::grabbed [private] |
Definition at line 46 of file mrbomb.hpp.
Referenced by active_update(), collision(), collision_player(), grab(), MrBomb(), and ungrab().