{
bbox.set_size(32, 32.1);
set_group(COLGROUP_STATIC);
- flags |= FLAG_SOLID;
sound_manager->preload("sounds/upgrade.wav");
sound_manager->preload("sounds/brick.wav");
}
{
if(!bouncing)
return;
-
+
float offset = original_y - get_pos().y;
if(offset > BOUNCY_BRICK_MAX_OFFSET) {
bounce_dir = BOUNCY_BRICK_SPEED;
log_warning << "Invalid box contents" << std::endl;
contents = CONTENT_COIN;
break;
- }
+ }
}
BonusBlock::BonusBlock(const lisp::Lisp& lisp)
} else {
log_warning << "Invalid element '" << token << "' in bonusblock" << std::endl;
}
- }
+ }
}
if(contents == CONTENT_CUSTOM && object == 0)
throw std::runtime_error("Need to specify content object for custom block");
-
+
bbox.set_pos(pos);
}
BonusBlock::collision(GameObject& other, const CollisionHit& hit){
BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
if(badguy) {
- // if( badguy->can_break() && (hit.left||hit.right||hit.bottom) ){ //TODO: find out why hit contains no information and fix it
- if( badguy->can_break() && ( badguy->get_pos().y > get_pos().y ) ){
+ // hit contains no information for collisions with blocks.
+ // Badguy's bottom has to be below the top of the bonusblock
+ // +7 is required to slide over one tile gaps.
+ if( badguy->can_break() && ( badguy->get_bbox().get_bottom() > get_bbox().get_top() + 7.0) ){
try_open();
}
}
sound_manager->play("sounds/brick.wav");
return;
}
-
+
Sector* sector = Sector::current();
+ assert(sector);
+ assert(sector->player);
Player& player = *(sector->player);
+ Direction direction = (player.get_bbox().get_middle().x > get_bbox().get_middle().x) ? LEFT : RIGHT;
+
switch(contents) {
case CONTENT_COIN:
Sector::current()->add_object(new BouncyCoin(get_pos()));
case CONTENT_FIREGROW:
if(player.get_status()->bonus == NO_BONUS) {
- SpecialRiser* riser = new SpecialRiser(get_pos(), new GrowUp());
+ SpecialRiser* riser = new SpecialRiser(get_pos(), new GrowUp(direction));
sector->add_object(riser);
} else {
SpecialRiser* riser = new SpecialRiser(
case CONTENT_ICEGROW:
if(player.get_status()->bonus == NO_BONUS) {
- SpecialRiser* riser = new SpecialRiser(get_pos(), new GrowUp());
- sector->add_object(riser);
+ SpecialRiser* riser = new SpecialRiser(get_pos(), new GrowUp(direction));
+ sector->add_object(riser);
} else {
SpecialRiser* riser = new SpecialRiser(
get_pos(), new Flower(ICE_BONUS));
sector->add_object(riser);
- }
+ }
sound_manager->play("sounds/upgrade.wav");
break;
case CONTENT_STAR:
- sector->add_object(new Star(get_pos() + Vector(0, -32)));
+ sector->add_object(new Star(get_pos() + Vector(0, -32), direction));
break;
case CONTENT_1UP:
- sector->add_object(new OneUp(get_pos()));
+ sector->add_object(new OneUp(get_pos(), direction));
break;
case CONTENT_CUSTOM:
{
if(sprite->get_action() == "empty")
return;
-
+
try_break(true);
}
Brick::collision(GameObject& other, const CollisionHit& hit){
BadGuy* badguy = dynamic_cast<BadGuy*> (&other);
if(badguy) {
- // if( badguy->can_break() && (hit.left||hit.right||hit.bottom) ){ //TODO: find out why hit contains no information and fix it
- if( badguy->can_break() && ( badguy->get_pos().y > get_pos().y ) ){
+ // hit contains no information for collisions with blocks.
+ // Badguy's bottom has to be below the top of the brick
+ // +7 is required to slide over one tile gaps.
+ if( badguy->can_break() && ( badguy->get_bbox().get_bottom() > get_bbox().get_top() + 7.0 ) ){
try_break(false);
}
}
{
if(sprite->get_action() == "empty")
return;
-
+
sound_manager->play("sounds/brick.wav");
Sector* sector = Sector::current();
Player& player = *(sector->player);
}
//IMPLEMENT_FACTORY(Brick, "brick");
-