#include "flower.h"
#include "oneup.h"
#include "star.h"
+#include "badguy/badguy.h"
+#include "coin.h"
+#include "object_factory.h"
static const float BOUNCY_BRICK_MAX_OFFSET=8;
static const float BOUNCY_BRICK_SPEED=90;
HitResponse
Block::collision(GameObject& other, const CollisionHit& hitdata)
{
- // TODO kill badguys when bumping them...
-
Player* player = dynamic_cast<Player*> (&other);
if(player) {
// collided from below?
}
}
+ if(bouncing) {
+ BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
+ if(badguy) {
+ badguy->kill_fall();
+ }
+ Coin* coin = dynamic_cast<Coin*> (&other);
+ if(coin) {
+ coin->collect();
+ }
+ }
+
return FORCE_MOVE;
}
}
void
-BonusBlock::hit(Player& player)
+BonusBlock::hit(Player& )
+{
+ try_open();
+}
+
+void
+BonusBlock::try_open()
{
if(sprite->get_action_name() == "empty") {
SoundManager::get()->play_sound(IDToSound(SND_BRICK));
}
Sector* sector = Sector::current();
+ Player& player = *(sector->player);
switch(data) {
case 1: // coin
Sector::current()->add_object(new BouncyCoin(get_pos()));
sprite->set_action("empty");
}
+//IMPLEMENT_FACTORY(BonusBlock, "bonusblock")
+
//---------------------------------------------------------------------------
Brick::Brick(const Vector& pos, int data)
}
void
-Brick::hit(Player& player)
+Brick::hit(Player& )
+{
+ if(sprite->get_action_name() == "empty")
+ return;
+
+ try_break(true);
+}
+
+void
+Brick::try_break(bool playerhit)
{
if(sprite->get_action_name() == "empty")
return;
SoundManager::get()->play_sound(IDToSound(SND_BRICK));
Sector* sector = Sector::current();
+ Player& player = *(sector->player);
if(coin_counter > 0) {
sector->add_object(new BouncyCoin(get_pos()));
coin_counter--;
sprite->set_action("empty");
start_bounce();
} else if(breakable) {
- if(player.size == SMALL) {
+ if(playerhit && player.size == SMALL) {
start_bounce();
return;
}
}
}
+//IMPLEMENT_FACTORY(Brick, "brick")