From 5de933bbcbb361d422824012910f5d7583cada9a Mon Sep 17 00:00:00 2001 From: Christoph Sommer Date: Tue, 18 Jul 2006 16:34:09 +0000 Subject: [PATCH] Bonus block items' spawn direction depends on player position (again) SVN-Revision: 4043 --- src/object/block.cpp | 12 ++++++++---- src/object/growup.cpp | 4 ++-- src/object/growup.hpp | 3 ++- src/object/oneup.cpp | 4 ++-- src/object/oneup.hpp | 3 ++- src/object/star.cpp | 4 ++-- src/object/star.hpp | 3 ++- 7 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/object/block.cpp b/src/object/block.cpp index fb90272d7..17cb7ad0d 100644 --- a/src/object/block.cpp +++ b/src/object/block.cpp @@ -225,7 +225,11 @@ BonusBlock::try_open() } 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())); @@ -234,7 +238,7 @@ BonusBlock::try_open() 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( @@ -246,7 +250,7 @@ BonusBlock::try_open() case CONTENT_ICEGROW: 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( @@ -257,11 +261,11 @@ BonusBlock::try_open() 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: diff --git a/src/object/growup.cpp b/src/object/growup.cpp index 3a32bcfdf..6af5b5b3c 100644 --- a/src/object/growup.cpp +++ b/src/object/growup.cpp @@ -27,11 +27,11 @@ #include "player.hpp" #include "audio/sound_manager.hpp" -GrowUp::GrowUp() +GrowUp::GrowUp(Direction direction) : MovingSprite(Vector(0,0), "images/powerups/egg/egg.sprite", LAYER_OBJECTS, COLGROUP_MOVING) { physic.enable_gravity(true); - physic.set_velocity_x(100); + physic.set_velocity_x((direction == LEFT)?-100:100); sound_manager->preload("sounds/grow.wav"); } diff --git a/src/object/growup.hpp b/src/object/growup.hpp index cad747b32..df21d60f4 100644 --- a/src/object/growup.hpp +++ b/src/object/growup.hpp @@ -22,11 +22,12 @@ #include "object/moving_sprite.hpp" #include "physic.hpp" +#include "direction.hpp" class GrowUp : public MovingSprite { public: - GrowUp(); + GrowUp(Direction direction = RIGHT); virtual GrowUp* clone() const { return new GrowUp(*this); } virtual void update(float elapsed_time); diff --git a/src/object/oneup.cpp b/src/object/oneup.cpp index 3b45a63f3..3ce81fa84 100644 --- a/src/object/oneup.cpp +++ b/src/object/oneup.cpp @@ -26,10 +26,10 @@ #include "sector.hpp" #include "video/drawing_context.hpp" -OneUp::OneUp(const Vector& pos) +OneUp::OneUp(const Vector& pos, Direction direction) : MovingSprite(pos, "images/powerups/1up/1up.sprite", LAYER_FLOATINGOBJECTS, COLGROUP_TOUCHABLE) { - physic.set_velocity(100, -400); + physic.set_velocity((direction == LEFT)?-100:100, -400); } void diff --git a/src/object/oneup.hpp b/src/object/oneup.hpp index 7380be08d..415c61cfb 100644 --- a/src/object/oneup.hpp +++ b/src/object/oneup.hpp @@ -22,11 +22,12 @@ #include "object/moving_sprite.hpp" #include "physic.hpp" +#include "direction.hpp" class OneUp : public MovingSprite { public: - OneUp(const Vector& pos); + OneUp(const Vector& pos, Direction direction = RIGHT); virtual OneUp* clone() const { return new OneUp(*this); } virtual void update(float elapsed_time); diff --git a/src/object/star.cpp b/src/object/star.cpp index e6fff5d3f..617704c54 100644 --- a/src/object/star.cpp +++ b/src/object/star.cpp @@ -30,10 +30,10 @@ static const float INITIALJUMP = -400; static const float SPEED = 150; static const float JUMPSPEED = -300; -Star::Star(const Vector& pos) +Star::Star(const Vector& pos, Direction direction) : MovingSprite(pos, "images/powerups/star/star.sprite", LAYER_OBJECTS, COLGROUP_MOVING) { - physic.set_velocity(SPEED, INITIALJUMP); + physic.set_velocity((direction == LEFT) ? -SPEED : SPEED, INITIALJUMP); } void diff --git a/src/object/star.hpp b/src/object/star.hpp index fc01922b1..68b4fc949 100644 --- a/src/object/star.hpp +++ b/src/object/star.hpp @@ -22,11 +22,12 @@ #include "object/moving_sprite.hpp" #include "physic.hpp" +#include "direction.hpp" class Star : public MovingSprite { public: - Star(const Vector& pos); + Star(const Vector& pos, Direction direction = RIGHT); virtual Star* clone() const { return new Star(*this); } virtual void update(float elapsed_time); -- 2.11.0