#include <block.hpp>
Inherits MovingObject.
Inherited by BonusBlock, Brick, InfoBlock, and InvisibleBlock.
Public Member Functions | |
Block (SpritePtr sprite) | |
~Block () | |
virtual HitResponse | collision (GameObject &other, const CollisionHit &hit) |
this function is called when the object collided with any other object | |
virtual void | update (float elapsed_time) |
This function is called once per frame and allows the object to update it's state. | |
virtual void | draw (DrawingContext &context) |
The GameObject should draw itself onto the provided DrawingContext if this function is called. | |
Protected Member Functions | |
virtual void | hit (Player &player)=0 |
void | start_bounce (GameObject *hitter) |
void | start_break (GameObject *hitter) |
void | break_me () |
Protected Attributes | |
SpritePtr | sprite |
bool | bouncing |
bool | breaking |
float | bounce_dir |
float | bounce_offset |
float | original_y |
Private Member Functions | |
Block (const Block &) | |
Block & | operator= (const Block &) |
Friends | |
class | FlipLevelTransformer |
Definition at line 28 of file block.hpp.
Block::Block | ( | SpritePtr | sprite | ) |
Definition at line 33 of file block.cpp.
References MovingObject::bbox, COLGROUP_STATIC, SoundManager::preload(), MovingObject::set_group(), Rectf::set_size(), and sound_manager.
00033 : 00034 sprite(newsprite), 00035 bouncing(false), 00036 breaking(false), 00037 bounce_dir(0), 00038 bounce_offset(0), 00039 original_y(-1) 00040 { 00041 bbox.set_size(32, 32.1f); 00042 set_group(COLGROUP_STATIC); 00043 sound_manager->preload("sounds/upgrade.wav"); 00044 sound_manager->preload("sounds/brick.wav"); 00045 }
Block::Block | ( | const Block & | ) | [private] |
HitResponse Block::collision | ( | GameObject & | other, | |
const CollisionHit & | hit | |||
) | [virtual] |
this function is called when the object collided with any other object
Implements MovingObject.
Reimplemented in BonusBlock, Brick, and InvisibleBlock.
Definition at line 52 of file block.cpp.
References bouncing, Coin::collect(), GrowUp::do_jump(), FORCE_MOVE, MovingObject::get_bbox(), Rectf::get_bottom(), Rectf::get_top(), hit(), Portable::is_portable(), BadGuy::kill_fall(), and SHIFT_DELTA.
Referenced by InvisibleBlock::collision(), Brick::collision(), and BonusBlock::collision().
00053 { 00054 Player* player = dynamic_cast<Player*> (&other); 00055 if(player) { 00056 if(player->get_bbox().get_top() > get_bbox().get_bottom() - SHIFT_DELTA) { 00057 hit(*player); 00058 } 00059 } 00060 00061 // only interact with other objects if... 00062 // 1) we are bouncing 00063 // 2) the object is not portable (either never or not currently) 00064 // 3) the object is being hit from below (baguys don't get killed for activating boxes) 00065 Portable* portable = dynamic_cast<Portable*> (&other); 00066 MovingObject* moving_object = dynamic_cast<MovingObject*> (&other); 00067 bool is_portable = ((portable != 0) && portable->is_portable()); 00068 bool hit_mo_from_below = ((moving_object == 0) || (moving_object->get_bbox().get_bottom() < (get_bbox().get_top() + SHIFT_DELTA))); 00069 if(bouncing && !is_portable && hit_mo_from_below) { 00070 00071 // Badguys get killed 00072 BadGuy* badguy = dynamic_cast<BadGuy*> (&other); 00073 if(badguy) { 00074 badguy->kill_fall(); 00075 } 00076 00077 // Coins get collected 00078 Coin* coin = dynamic_cast<Coin*> (&other); 00079 if(coin) { 00080 coin->collect(); 00081 } 00082 00083 //Eggs get jumped 00084 GrowUp* growup = dynamic_cast<GrowUp*> (&other); 00085 if(growup) { 00086 growup->do_jump(); 00087 } 00088 00089 } 00090 00091 return FORCE_MOVE; 00092 }
void Block::update | ( | float | elapsed_time | ) | [virtual] |
This function is called once per frame and allows the object to update it's state.
The elapsed_time is the time since the last frame in seconds and should be the base for all timed calculations (don't use SDL_GetTicks directly as this will fail in pause mode)
Implements GameObject.
Reimplemented in InfoBlock.
Definition at line 95 of file block.cpp.
References bounce_dir, bouncing, BOUNCY_BRICK_MAX_OFFSET, BOUNCY_BRICK_SPEED, break_me(), breaking, MovingObject::get_pos(), MovingObject::movement, original_y, sprite, and Vector::y.
Referenced by InfoBlock::update().
00096 { 00097 if(!bouncing) 00098 return; 00099 00100 float offset = original_y - get_pos().y; 00101 if(offset > BOUNCY_BRICK_MAX_OFFSET) { 00102 bounce_dir = BOUNCY_BRICK_SPEED; 00103 movement = Vector(0, bounce_dir * elapsed_time); 00104 if(breaking){ 00105 break_me(); 00106 } 00107 } else if(offset < BOUNCY_BRICK_SPEED * elapsed_time && bounce_dir > 0) { 00108 movement = Vector(0, offset); 00109 bounce_dir = 0; 00110 bouncing = false; 00111 sprite->set_angle(0); 00112 } else { 00113 movement = Vector(0, bounce_dir * elapsed_time); 00114 } 00115 }
void Block::draw | ( | DrawingContext & | context | ) | [virtual] |
The GameObject should draw itself onto the provided DrawingContext if this function is called.
Implements GameObject.
Reimplemented in InfoBlock, and InvisibleBlock.
Definition at line 118 of file block.cpp.
References MovingObject::get_pos(), LAYER_OBJECTS, and sprite.
Referenced by InfoBlock::draw().
00119 { 00120 sprite->draw(context, get_pos(), LAYER_OBJECTS+1); 00121 }
virtual void Block::hit | ( | Player & | player | ) | [protected, pure virtual] |
void Block::start_bounce | ( | GameObject * | hitter | ) | [protected] |
Definition at line 124 of file block.cpp.
References MovingObject::bbox, bounce_dir, bounce_offset, bouncing, BOUNCY_BRICK_SPEED, BUMP_ROTATION_ANGLE, MovingObject::get_bbox(), Rectf::get_middle(), Rectf::get_width(), original_y, Rectf::p1, sprite, Vector::x, and Vector::y.
Referenced by InvisibleBlock::hit(), InfoBlock::hit(), start_break(), Brick::try_break(), and BonusBlock::try_open().
00125 { 00126 if(original_y == -1){ 00127 original_y = bbox.p1.y; 00128 } 00129 bouncing = true; 00130 bounce_dir = -BOUNCY_BRICK_SPEED; 00131 bounce_offset = 0; 00132 00133 MovingObject* hitter_mo = dynamic_cast<MovingObject*>(hitter); 00134 if (hitter_mo) { 00135 float center_of_hitter = hitter_mo->get_bbox().get_middle().x; 00136 float offset = (get_bbox().get_middle().x - center_of_hitter)*2 / get_bbox().get_width(); 00137 sprite->set_angle(BUMP_ROTATION_ANGLE*offset); 00138 } 00139 }
void Block::start_break | ( | GameObject * | hitter | ) | [protected] |
Definition at line 142 of file block.cpp.
References breaking, and start_bounce().
Referenced by Brick::try_break().
00143 { 00144 start_bounce(hitter); 00145 breaking = true; 00146 }
void Block::break_me | ( | ) | [protected] |
Definition at line 221 of file bonus_block.cpp.
References Sector::add_object(), Sector::current(), MovingObject::get_pos(), GameObject::remove_me(), and sprite.
Referenced by Brick::try_break(), and update().
00222 { 00223 Sector* sector = Sector::current(); 00224 sector->add_object( 00225 new BrokenBrick(sprite->clone(), get_pos(), Vector(-100, -400))); 00226 sector->add_object( 00227 new BrokenBrick(sprite->clone(), get_pos() + Vector(0, 16), 00228 Vector(-150, -300))); 00229 sector->add_object( 00230 new BrokenBrick(sprite->clone(), get_pos() + Vector(16, 0), 00231 Vector(100, -400))); 00232 sector->add_object( 00233 new BrokenBrick(sprite->clone(), get_pos() + Vector(16, 16), 00234 Vector(150, -300))); 00235 remove_me(); 00236 }
friend class FlipLevelTransformer [friend] |
SpritePtr Block::sprite [protected] |
Definition at line 46 of file block.hpp.
Referenced by BonusBlock::BonusBlock(), break_me(), InvisibleBlock::draw(), draw(), InvisibleBlock::hit(), Brick::hit(), start_bounce(), Brick::try_break(), BonusBlock::try_open(), and update().
bool Block::bouncing [protected] |
bool Block::breaking [protected] |
float Block::bounce_dir [protected] |
float Block::bounce_offset [protected] |
float Block::original_y [protected] |
Definition at line 51 of file block.hpp.
Referenced by InfoBlock::draw(), start_bounce(), FlipLevelTransformer::transform_block(), and update().