From: Patrik Gornicz Date: Sat, 2 Aug 2008 01:08:37 +0000 (-0400) Subject: added screen collisions using an Effect X-Git-Tag: physics-premerge~176 X-Git-Url: http://gitweb.pgornicz.com/gitweb.cgi?a=commitdiff_plain;h=2c18685d7e87c72562bdbeb01b7372748d9927a3;p=libbear.git added screen collisions using an Effect --- diff --git a/src/Effects/Gravity.h b/src/Effects/Gravity.h index dc04726..ac20d49 100644 --- a/src/Effects/Gravity.h +++ b/src/Effects/Gravity.h @@ -9,7 +9,7 @@ class Gravity: public Effect { public: Gravity(); - virtual ~Gravity(); + ~Gravity(); Vector2 positionDelta(const PhysicsEntity*, float) const; Vector2 velocityDelta(const PhysicsEntity*, float) const; diff --git a/src/Effects/Screen.cpp b/src/Effects/Screen.cpp new file mode 100644 index 0000000..bbae5bb --- /dev/null +++ b/src/Effects/Screen.cpp @@ -0,0 +1,53 @@ +#include "Screen.h" +#include "../debug.h" + +#include "../Entities/PhysicsEntity.h" + +Screen::Screen() +{ + +} +Screen::~Screen() +{ + +} + +Vector2 Screen::positionDelta(const PhysicsEntity*, float) const +{ + return Vector2(0,0); +} + +Vector2 Screen::velocityDelta(const PhysicsEntity* e, float time_step) const +{ + const Vector2& pos = e->positionRaw(); + const Vector2& velo = e->velocityRaw(); + + Vector2 acc(0,0); + + if(pos.y > 600 && velo.y > 0) + { + acc.y += velo.y * -2; + } + + if(pos.y < 0 && velo.y < 0) + { + acc.y += velo.y * -2; + } + + if(pos.x > 800 && velo.x > 0) + { + acc.x += velo.x * -2; + } + + if(pos.x < 0 && velo.x < 0) + { + acc.x += velo.x * -2; + } + + return acc; +} + +Vector2 Screen::forceDelta(const PhysicsEntity*, float) const +{ + return Vector2(0,0); +} diff --git a/src/Effects/Screen.h b/src/Effects/Screen.h new file mode 100644 index 0000000..9403687 --- /dev/null +++ b/src/Effects/Screen.h @@ -0,0 +1,19 @@ +#ifndef SCREEN_H +#define SCREEN_H + +#include "../Vector2.h" +#include "Effect.h" + +/// ***** Header Class ***** +class Screen: public Effect +{ + public: + Screen(); + ~Screen(); + + Vector2 positionDelta(const PhysicsEntity*, float) const; + Vector2 velocityDelta(const PhysicsEntity*, float) const; + Vector2 forceDelta(const PhysicsEntity*, float) const; +}; + +#endif // SCREEN_H diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 462fcd0..5365bcc 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -5,6 +5,15 @@ /// ***** Public Class Methods ***** +const Vector2& Entity::positionRaw() const +{ + return position; +} +const Vector2& Entity::velocityRaw() const +{ + return velocity; +} + Entity::Entity(const Vector2& pos) : position(pos), velocity(0,0) { diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 65fe632..b5b268d 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -15,6 +15,9 @@ class Entity virtual void update(float) = 0; virtual void draw() const = 0; + const Vector2& positionRaw() const; + const Vector2& velocityRaw() const; + protected: Vector2 position; Vector2 velocity; diff --git a/src/Makefile b/src/Makefile index b399061..6168eb3 100644 --- a/src/Makefile +++ b/src/Makefile @@ -39,6 +39,7 @@ SRCS += GameStates/Running.cpp SRCS += Effects/Effect.cpp SRCS += Effects/Gravity.cpp +SRCS += Effects/Screen.cpp SRCS += input/inputManager.cpp diff --git a/src/effectManager.cpp b/src/effectManager.cpp index b661f51..cc3eb73 100644 --- a/src/effectManager.cpp +++ b/src/effectManager.cpp @@ -2,6 +2,7 @@ #include "Effects/Effect.h" #include "Effects/Gravity.h" +#include "Effects/Screen.h" /// ***** Private Variables ***** Effect** effects; @@ -11,10 +12,11 @@ int numEffects; void effect::init() { - numEffects = 1; + numEffects = 2; effects = new Effect*[numEffects](); effects[0] = new Gravity(); + effects[1] = new Screen(); } void effect::clean() { diff --git a/src/entityManager.cpp b/src/entityManager.cpp index 850f70f..5fe9878 100644 --- a/src/entityManager.cpp +++ b/src/entityManager.cpp @@ -29,9 +29,11 @@ bool clearPhysics; void manager::init() { + } void manager::clean() { + } void manager::add(Entity* e)