#include <brick.hpp>
Inherits Block.
Public Member Functions | |
Brick (const Vector &pos, int data) | |
void | try_break (Player *player=false) |
HitResponse | collision (GameObject &other, const CollisionHit &hit) |
this function is called when the object collided with any other object | |
Protected Member Functions | |
virtual void | hit (Player &player) |
Private Attributes | |
bool | breakable |
int | coin_counter |
Definition at line 22 of file brick.hpp.
Brick::Brick | ( | const Vector & | pos, | |
int | data | |||
) |
Definition at line 29 of file brick.cpp.
References MovingObject::bbox, breakable, coin_counter, and Rectf::set_pos().
00030 : Block(sprite_manager->create("images/objects/bonus_block/brick.sprite")), breakable(false), 00031 coin_counter(0) 00032 { 00033 bbox.set_pos(pos); 00034 if(data == 1) 00035 coin_counter = 5; 00036 else 00037 breakable = true; 00038 }
void Brick::try_break | ( | Player * | player = false |
) |
Definition at line 77 of file brick.cpp.
References PlayerStatus::add_coins(), Sector::add_object(), Block::break_me(), breakable, coin_counter, Sector::current(), MovingObject::get_pos(), Player::get_status(), SoundManager::play(), Sector::player, sound_manager, Block::sprite, Block::start_bounce(), and Block::start_break().
Referenced by collision(), and hit().
00078 { 00079 if(sprite->get_action() == "empty") 00080 return; 00081 00082 sound_manager->play("sounds/brick.wav"); 00083 Sector* sector = Sector::current(); 00084 Player& player_one = *(sector->player); 00085 if(coin_counter > 0) { 00086 sector->add_object(new BouncyCoin(get_pos(),true)); 00087 coin_counter--; 00088 player_one.get_status()->add_coins(1); 00089 if(coin_counter == 0) 00090 sprite->set_action("empty"); 00091 start_bounce(player); 00092 } else if(breakable) { 00093 if(player){ 00094 if(player->is_big()){ 00095 start_break(player); 00096 return; 00097 } else { 00098 start_bounce(player); 00099 return; 00100 } 00101 } 00102 break_me(); 00103 } 00104 }
HitResponse Brick::collision | ( | GameObject & | other, | |
const CollisionHit & | hit | |||
) | [virtual] |
this function is called when the object collided with any other object
Reimplemented from Block.
Definition at line 50 of file brick.cpp.
References BadGuy::can_break(), Block::collision(), Player::does_buttjump, MovingObject::get_bbox(), Rectf::get_bottom(), Rectf::get_top(), hit(), SHIFT_DELTA, and try_break().
00050 { 00051 00052 Player* player = dynamic_cast<Player*> (&other); 00053 if (player) { 00054 if (player->does_buttjump) try_break(); 00055 } 00056 00057 BadGuy* badguy = dynamic_cast<BadGuy*> (&other); 00058 if(badguy) { 00059 // hit contains no information for collisions with blocks. 00060 // Badguy's bottom has to be below the top of the brick 00061 // SHIFT_DELTA is required to slide over one tile gaps. 00062 if( badguy->can_break() && ( badguy->get_bbox().get_bottom() > get_bbox().get_top() + SHIFT_DELTA ) ){ 00063 try_break(); 00064 } 00065 } 00066 Portable* portable = dynamic_cast<Portable*> (&other); 00067 if(portable) { 00068 MovingObject* moving = dynamic_cast<MovingObject*> (&other); 00069 if(moving->get_bbox().get_top() > get_bbox().get_bottom() - SHIFT_DELTA) { 00070 try_break(); 00071 } 00072 } 00073 return Block::collision(other, hit); 00074 }
void Brick::hit | ( | Player & | player | ) | [protected, virtual] |
Implements Block.
Definition at line 41 of file brick.cpp.
References Block::sprite, and try_break().
Referenced by collision().
00042 { 00043 if(sprite->get_action() == "empty") 00044 return; 00045 00046 try_break(&player); 00047 }
bool Brick::breakable [private] |
int Brick::coin_counter [private] |