}
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());
+ SpecialRiser* riser = new SpecialRiser(get_pos(), new GrowUp(direction));
sector->add_object(riser);
} else {
SpecialRiser* riser = new SpecialRiser(
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:
#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");
}
#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);
#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
#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);
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
#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);