Bonus block items' spawn direction depends on player position (again)
authorChristoph Sommer <mail@christoph-sommer.de>
Tue, 18 Jul 2006 16:34:09 +0000 (16:34 +0000)
committerChristoph Sommer <mail@christoph-sommer.de>
Tue, 18 Jul 2006 16:34:09 +0000 (16:34 +0000)
SVN-Revision: 4043

src/object/block.cpp
src/object/growup.cpp
src/object/growup.hpp
src/object/oneup.cpp
src/object/oneup.hpp
src/object/star.cpp
src/object/star.hpp

index fb90272..17cb7ad 100644 (file)
@@ -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:
index 3a32bcf..6af5b5b 100644 (file)
 #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");
 }
 
index cad747b..df21d60 100644 (file)
 
 #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);
index 3b45a63..3ce81fa 100644 (file)
 #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
index 7380be0..415c61c 100644 (file)
 
 #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);
index e6fff5d..617704c 100644 (file)
@@ -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
index fc01922..68b4fc9 100644 (file)
 
 #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);