gravity well now follows the mouse v0.05
authorPatrik Gornicz <Gornicz.P@gmail.com>
Thu, 21 Aug 2008 20:58:24 +0000 (16:58 -0400)
committerPatrik Gornicz <Gornicz.P@gmail.com>
Thu, 21 Aug 2008 20:58:24 +0000 (16:58 -0400)
src/Effects/GravityWell.cpp
src/Effects/GravityWell.h
src/Effects/Screen.cpp
src/effectManager.cpp
src/effectManager.h
src/entityManager.cpp
src/input/inputManager.cpp
src/input/inputManager.h

index 4fcd446..68afa27 100644 (file)
@@ -48,3 +48,8 @@ Vector2 GravityWell::forceDelta(const PhysicsEntity* e, float) const
 
     return acc;
 }
+
+void GravityWell::setPosition(const Vector2& pos)
+{
+    position = pos;
+}
index 36b9dec..d6165d3 100644 (file)
 class GravityWell: public Effect
 {
   public:
-    GravityWell(const Vector2& pos);
+    GravityWell(const Vector2&);
     ~GravityWell();
 
     Vector2 forceDelta(const PhysicsEntity*, float) const;
 
+    void setPosition(const Vector2&);
+
   private:
     Vector2 position;
 };
index 61108c4..f7bf80e 100644 (file)
@@ -37,7 +37,6 @@ Screen::~Screen()
 Vector2 Screen::positionDelta(const PhysicsEntity* e, float time_step) const
 {
     const Vector2& pos = e->positionRaw();
-    const Vector2& velo = e->velocityRaw();
 
     Vector2 acc(0,0);
 
index 6ebffdd..2e50c65 100644 (file)
 #include "Effects/Screen.h"
 
 #include "Vector2.h"
+#include "input/inputManager.h"
 
 /// ***** Private Variables *****
 
 Effect** effects;
 int numEffects;
 
+GravityWell* mouseWell;
+
 /// ***** Initializers/Cleaners *****
 
 void effect::init()
@@ -36,8 +39,10 @@ void effect::init()
     numEffects = 3;
     effects = new Effect*[numEffects]();
 
-    effects[0] = new Gravity();
-    effects[1] = new GravityWell(Vector2(400,400));
+    mouseWell = new GravityWell(input::mousePosition());
+
+    effects[0] = mouseWell;
+    effects[1] = new Gravity();
     effects[2] = new Screen();
 }
 void effect::clean()
@@ -52,6 +57,15 @@ void effect::clean()
 
 /// ***** Public Methods *****
 
+void effect::update(float)
+{
+
+}
+void effect::handleInput()
+{
+    mouseWell->setPosition(input::mousePosition());
+}
+
 Vector2 effect::positionDelta(const PhysicsEntity* e, float time_step)
 {
     Vector2 acc(0,0);
index 089c12a..f77e191 100644 (file)
@@ -27,6 +27,9 @@ namespace effect
     void init();
     void clean();
 
+    void update(float);
+    void handleInput();
+
     Vector2 positionDelta(const PhysicsEntity*, float);
     Vector2 velocityDelta(const PhysicsEntity*, float);
     Vector2 forceDelta(const PhysicsEntity*, float);
index c7fc78b..c78a7ce 100644 (file)
@@ -25,6 +25,7 @@
 #include "Entities/PhysicsEntity.h"
 
 #include "collisionHandler.h"
+#include "effectManager.h"
 
 /// ***** Private Method Headers *****
 
@@ -107,10 +108,12 @@ void manager::remove(Entity* e)
 
 void manager::handleInput()
 {
-    // TODO
+    effect::handleInput();
 }
 void manager::update(float time_step)
 {
+    effect::update(time_step);
+
     updateParticles(time_step);
     updatePhysics(time_step);
 }
index a8491b1..0df4baa 100644 (file)
@@ -72,6 +72,16 @@ void input::update()
     }
 }
 
+Vector2 input::mousePosition()
+{
+    int x;
+    int y;
+
+    SDL_GetMouseState(&x, &y);
+
+    return Vector2(x,y);
+}
+
 bool input::isPressed(Uint8 key)
 {
     return keyState[key] == isP || keyState[key] == wasP;
index a117324..3e0e45d 100644 (file)
@@ -19,6 +19,7 @@
 #define INPUT_H
 
 #include <SDL/SDL.h>
+#include "../Vector2.h"
 
 
 /// ***** Header Methods *****
@@ -30,6 +31,8 @@ namespace input
 
     void update();
 
+    Vector2 mousePosition();
+
     bool isPressed(Uint8);
     bool isReleased(Uint8);