--- /dev/null
+#include "Ball.h"
+#include "../Vector2.h"
+
+/// ***** Public Class Methods *****
+Ball::Ball(Vector2 pos, float radius)
+ : PhysicsEntity(pos), radius(radius)
+{
+
+}
+Ball::~Ball()
+{
+
+}
+
+void Ball::draw() const
+{
+ // TODO
+}
--- /dev/null
+#ifndef BALL_H
+#define BALL_H
+
+#include "PhysicsEntity.h"
+#include "../Vector2.h"
+
+/// ***** Header Class *****
+class Ball: public PhysicsEntity
+{
+ public:
+ Ball(Vector2, float);
+ virtual ~Ball();
+
+ virtual void draw() const;
+
+ protected:
+ float radius;
+ // color;
+};
+
+#endif // BALL_H
--- /dev/null
+#include "Entity.h"
+#include "../Vector2.h"
+
+#include <iostream>
+
+/// ***** Public Class Methods *****
+
+Entity::Entity(Vector2 pos)
+ : position(pos), velocity(0,0)
+{
+
+}
+Entity::~Entity()
+{
+
+}
--- /dev/null
+#ifndef ENTITY_H
+#define ENTITY_H
+
+#include "../Vector2.h"
+
+/// ***** Header Class *****
+class Entity
+{
+ protected:
+ Entity(Vector2);
+
+ public:
+ virtual ~Entity();
+
+ virtual void update(float) = 0;
+ virtual void draw() const = 0;
+
+ protected:
+ Vector2 position;
+ Vector2 velocity;
+};
+
+#endif // ENTITY_H
--- /dev/null
+#include "Line.h"
+#include "../Vector2.h"
+
+/// ***** Public Class Methods *****
+Line::Line(Vector2 org, Vector2 dest, bool canDie)
+ : Particle(org, canDie), dest(dest)
+{
+
+}
+Line::Line(Vector2 org, Vector2 dest, float life_time)
+ : Particle(org, life_time), dest(dest)
+{
+
+}
+Line::~Line()
+{
+
+}
+
+void Line::draw()
+{
+ // TODO
+}
--- /dev/null
+#ifndef LINE_H
+#define LINE_H
+
+#include "Particle.h"
+#include "../Vector2.h"
+
+/// NOTE to SELF
+// a Particle should be drawn for at least the next frame
+// ie. creating a particle using ParticleE(Vector2),
+// should draw the particle once THEN kill it
+
+/// ***** Header Class *****
+class Line: public Particle
+{
+ public:
+ Line(Vector2, Vector2, bool=true);
+ Line(Vector2, Vector2, float);
+ virtual ~Line();
+
+ virtual void draw();
+
+ protected:
+ Vector2 dest;
+
+ // triangle stuffs
+ // color
+};
+
+#endif // LINE_H
--- /dev/null
+
+LIBALLG = `allegro-config --libs release`
+LIBGL = -lGL -lGLU
+LIBSDL = `sdl-config --libs`
+LIBS = ${LIBSDL} ${LIBGL}
+
+CXX = g++
+CXXFLAGS = -ggdb -Wall -pedantic
+
+LDFLAGS = -lc
+
+SRCS = Ball.cpp Entity.cpp Line.cpp Particle.cpp PhysicsEntity.cpp \
+ Point.cpp Polygon.cpp WindParticle.cpp
+OBJS = ${SRCS:.cpp=.o}
+
+TARGETS = Entity.ld
+DEPEND = depend.mk
+
+# set suffixes to look for ...
+.SUFFIXES: .cpp .o
+
+# set default action for a *.cc to create a *.o
+.cpp.o:
+ g++ -c $< ${CXXFLAGS}
+
+all: ${TARGETS}
+
+depend:
+ ${CXX} -MM ${SRCS} > ${DEPEND}
+
+tags:
+ ctags ${SRCS}
+
+clean:
+ rm -f ${OBJS} ${TARGETS} *~
+
+distclean: clean
+ rm -f tags depend.mk
+ touch depend.mk
+
+Entity.ld: ${OBJS}
+# ld -o Entity.ld ${LDFLAGS} ${OBJS}
+
+include ${DEPEND}
+
--- /dev/null
+#include "Particle.h"
+#include "../Vector2.h"
+
+/// ***** Public Class Methods *****
+Particle::Particle(Vector2 pos, bool canDie)
+ : Entity(pos), canDie(canDie)
+{
+
+}
+Particle::Particle(Vector2 pos, float lifeTime)
+ : Entity(pos), lifeTime(lifeTime)
+{
+
+}
+Particle::~Particle()
+{
+
+}
+
+void Particle::update(float time_step)
+{
+ if(isDead)
+ return;
+
+ if (canDie)
+ {
+ lifeTime -= time_step;
+ isDead = lifeTime <= 0;
+ }
+ position += velocity * time_step;
+}
--- /dev/null
+#ifndef PARTICLE_H
+#define PARTICLE_H
+
+#include "Entity.h"
+#include "../Vector2.h"
+
+/// NOTE to SELF
+// a Particle should be drawn for at least the next frame
+// ie. creating a particle using ParticleE(Vector2),
+// should draw the particle once THEN kill it
+
+/// ***** Header Class *****
+class Particle: public Entity
+{
+ protected:
+ Particle(Vector2, bool=true);
+ Particle(Vector2, float);
+
+ public:
+ virtual ~Particle();
+
+ virtual void update(float);
+
+ protected:
+ float lifeTime;
+
+ bool isDead;
+ bool canDie;
+};
+
+#endif // PARTICLE_H
--- /dev/null
+#include "PhysicsEntity.h"
+#include "../Vector2.h"
+
+/// ***** Public Class Methods *****
+PhysicsEntity::PhysicsEntity(Vector2 pos)
+ : Entity(pos)
+{
+
+}
+PhysicsEntity::~PhysicsEntity()
+{
+
+}
+
+void PhysicsEntity::update(float time_step)
+{
+ position = positionAt(time_step);
+ velocity = velocityAt(time_step);
+
+ force *= 0;
+}
+
+Vector2 PhysicsEntity::positionAt(float time_step) const
+{
+ return force/mass / 2 * time_step * time_step + velocity * time_step + position;
+}
+
+Vector2 PhysicsEntity::velocityAt(float time_step) const
+{
+ return force/mass / 2 * time_step + velocity;
+}
+
+void PhysicsEntity::applyForce(const Vector2& force)
+{
+ this->force += force;
+}
+
+void PhysicsEntity::applyImpulse(const Vector2& impluse)
+{
+ velocity += impluse;
+}
--- /dev/null
+#ifndef PHYSICS_H
+#define PHYSICS_H
+
+#include "Entity.h"
+#include "../Vector2.h"
+
+/// ***** Header Class *****
+class PhysicsEntity: public Entity
+{
+ protected:
+ PhysicsEntity(Vector2);
+
+ public:
+ virtual ~PhysicsEntity();
+
+ virtual void update(float);
+
+ virtual Vector2 positionAt(float) const;
+ virtual Vector2 velocityAt(float) const;
+
+ virtual void applyForce(const Vector2&);
+ virtual void applyImpulse(const Vector2&);
+
+ protected:
+ Vector2 force;
+
+ float mass;
+
+ // Coefficient of Restitution
+ float CoR;
+};
+
+#endif // PHYSICS_H
--- /dev/null
+#include "Point.h"
+#include "../Vector2.h"
+
+/// ***** Public Class Methods *****
+Point::Point(Vector2 org, bool canDie)
+ : Particle(org, canDie), radius(2)
+{
+
+}
+Point::Point(Vector2 org, float life_time)
+ : Particle(org, life_time), radius(2)
+{
+
+}
+Point::~Point()
+{
+
+}
+
+void Point::draw()
+{
+ // TODO
+}
--- /dev/null
+#ifndef POINT_H
+#define POINT_H
+
+#include "Particle.h"
+#include "../Vector2.h"
+
+/// NOTE to SELF
+// a Particle should be drawn for at least the next frame
+// ie. creating a particle using ParticleE(Vector2),
+// should draw the particle once THEN kill it
+
+/// ***** Header Class *****
+class Point: public Particle
+{
+ public:
+ Point(Vector2, bool=true);
+ Point(Vector2, float);
+ virtual ~Point();
+
+ virtual void draw();
+
+ protected:
+ float radius;
+ // color
+};
+
+#endif // POINT_H
--- /dev/null
+#include "Polygon.h"
+#include "../Vector2.h"
+
+/// ***** Public Class Methods *****
+Polygon::Polygon(Vector2 pos, vector<Vector2> points)
+ : PhysicsEntity(pos), points(points)
+{
+ CreateBindingBox();
+}
+Polygon::~Polygon()
+{
+
+}
+
+void Polygon::draw() const
+{
+ // TODO
+}
+
+/// ***** Private Class Methods *****
+void CreateBindingBox()
+{
+ // TODO
+}
--- /dev/null
+#ifndef POLYGON_H
+#define POLYGON_H
+
+#include "PhysicsEntity.h"
+#include "../Vector2.h"
+
+#include <vector>
+using std::vector;
+
+/// ***** Header Class *****
+class Polygon: public PhysicsEntity
+{
+ public:
+ Polygon(Vector2, vector<Vector2>);
+ virtual ~Polygon();
+
+ virtual void draw() const;
+
+ protected:
+ Vector2 maxP; // stores the max bounding box point
+ Vector2 minP; // stores the min bounding box point
+
+ vector<Vector2> points;
+
+ // color;
+ private:
+ void CreateBindingBox();
+};
+
+#endif // POLYGON_H
--- /dev/null
+#include "WindParticle.h"
+#include "../Vector2.h"
+
+/// ***** Public Class Methods *****
+WindParticle::WindParticle(Vector2 org, float life_time)
+ : Point(org, life_time)
+{
+
+}
+WindParticle::~WindParticle()
+{
+
+}
+
+void WindParticle::update(float time_step)
+{
+ Point::update(time_step);
+ // TODO, insure particle is in the screen by moding
+}
--- /dev/null
+#ifndef WINDPARTICLE_H
+#define WINDPARTICLE_H
+
+#include "Point.h"
+#include "../Vector2.h"
+
+/// ***** Header Class *****
+class WindParticle: public Point
+{
+ public:
+ WindParticle(Vector2, float);
+ virtual ~WindParticle();
+
+ virtual void update(float);
+
+ protected:
+ float radius;
+ // color
+};
+
+#endif // POINT_H
--- /dev/null
+#include "CreatingPolygon.h"
+
+/// ***** Constructors/Destructors *****
+CreatingPolygon::CreatingPolygon()
+{
+
+}
+CreatingPolygon::~CreatingPolygon()
+{
+
+}
+
+/// ***** Public Class Methods *****
+void CreatingPolygon::handleInput(bool on_top) const
+{
+ // TODO
+}
+void CreatingPolygon::update(float time_step, bool on_top) const
+{
+
+}
+void CreatingPolygon::draw(bool on_top) const
+{
+ // TODO
+}
--- /dev/null
+#ifndef CREATINGPOLYGON_H
+#define CREATINGPOLYGON_H
+
+#include "GameState.h"
+
+/// ***** Header Class *****
+class CreatingPolygon : public GameState
+{
+ public:
+ CreatingPolygon();
+ virtual ~CreatingPolygon();
+
+ virtual void handleInput(bool=false) const;
+ virtual void update(float, bool=false) const;
+ virtual void draw(bool=false) const;
+};
+
+#endif // CREATINGPOLYGON_H
--- /dev/null
+#include "GameState.h"
+
+/// ***** Constructors/Destructors *****
+GameState::GameState()
+{
+
+}
+GameState::~GameState()
+{
+
+}
--- /dev/null
+#ifndef GAMESTATE_H
+#define GAMESTATE_H
+
+/// ***** Header Class *****
+class GameState
+{
+ protected:
+ GameState();
+
+ public:
+ virtual ~GameState();
+
+ virtual void handleInput(bool=false) const = 0;
+ virtual void update(float, bool=false) const = 0;
+ virtual void draw(bool=false) const = 0;
+};
+
+#endif // GAMESTATE_H
--- /dev/null
+
+LIBALLG = `allegro-config --libs release`
+LIBGL = -lGL -lGLU
+LIBSDL = `sdl-config --libs`
+LIBS = ${LIBSDL} ${LIBGL}
+
+CXX = g++
+CXXFLAGS = -ggdb -Wall -pedantic
+
+LDFLAGS = -lc
+
+SRCS = GameState.cpp
+OBJS = ${SRCS:.cpp=.o}
+
+TARGETS = GameStates.ld
+DEPEND = depend.mk
+
+# set suffixes to look for ...
+.SUFFIXES: .cpp .o
+
+# set default action for a *.cc to create a *.o
+.cpp.o:
+ g++ -c $< ${CXXFLAGS}
+
+all: ${TARGETS}
+
+depend:
+ ${CXX} -MM ${SRCS} > ${DEPEND}
+
+tags:
+ ctags ${SRCS}
+
+clean:
+ rm -f ${OBJS} ${TARGETS} *~
+
+distclean: clean
+ rm -f tags depend.mk
+ touch depend.mk
+
+GameStates.ld: ${OBJS}
+# ld -o Entity.ld ${LDFLAGS} ${OBJS}
+
+include ${DEPEND}
+
--- /dev/null
+#include "Paused.h"
+
+/// ***** Constructors/Destructors *****
+Paused::Paused()
+{
+
+}
+Paused::~Paused()
+{
+
+}
+
+/// ***** Public Class Methods *****
+void Paused::handleInput(bool on_top) const
+{
+ // TODO
+}
+void Paused::update(float time_step, bool on_top) const
+{
+
+}
+void Paused::draw(bool on_top) const
+{
+ // TODO
+}
--- /dev/null
+#ifndef PAUSED_H
+#define PAUSED_H
+
+#include "GameState.h"
+
+/// ***** Header Class *****
+class Paused : public GameState
+{
+ public:
+ Paused();
+ virtual ~Paused();
+
+ virtual void handleInput(bool=false) const;
+ virtual void update(float, bool=false) const;
+ virtual void draw(bool=false) const;
+};
+
+#endif // PAUSED_H
--- /dev/null
+#include "Running.h"
+#include "../entityManager.h"
+
+/// ***** Constructors/Destructors *****
+Running::Running()
+{
+ entityManager::init();
+}
+Running::~Running()
+{
+ entityManager::clean();
+}
+
+/// ***** Public Class Methods *****
+void Running::handleInput(bool on_top) const
+{
+ if( on_top )
+ {
+ entityManager::handleInput();
+ }
+}
+void Running::update(float time_step, bool on_top) const
+{
+ if( on_top )
+ {
+ entityManager::update(time_step);
+ }
+}
+void Running::draw(bool on_top) const
+{
+ entityManager::draw();
+}
--- /dev/null
+#ifndef RUNNING_H
+#define RUNNING_H
+
+#include "GameState.h"
+
+/// ***** Header Class *****
+class Running : public GameState
+{
+ public:
+ Running();
+ virtual ~Running();
+
+ virtual void handleInput(bool=false) const;
+ virtual void update(float, bool=false) const;
+ virtual void draw(bool=false) const;
+};
+
+#endif // RUNNING_H
--- /dev/null
+
+LIBALLG = `allegro-config --libs release`
+LIBGL = -lGL -lGLU
+LIBSDL = `sdl-config --libs`
+LIBS = ${LIBSDL} ${LIBGL}
+
+CXX = g++
+CXXFLAGS = -ggdb -Wall -pedantic
+
+SRCS = Vector2.cpp ticks.cpp main.cpp game.cpp entityManager.cpp gldraw.cpp graphics.cpp
+OBJS = ${SRCS:.cpp=.o}
+
+TARGETS = ../run_physics
+DEPEND = depend.mk
+
+# set suffixes to look for ...
+.SUFFIXES: .cpp .o
+
+# set default action for a *.cc to create a *.o
+.cpp.o:
+ g++ -c $< ${CXXFLAGS}
+
+all: ${TARGETS}
+
+depend:
+ ${CXX} -MM ${SRCS} > ${DEPEND}
+
+tags:
+ ctags ${SRCS}
+
+clean:
+ rm -f ${OBJS} ${TARGETS} *~
+
+distclean: clean
+ rm -f tags depend.mk
+ touch depend.mk
+
+# i need to find a nice way of ijnoring .svn folders for the below
+tar: clean
+ cd ..; tar -cjf bluestar.tar.bz2 images/ source/
+
+
+run: ../run_physics
+ cd ..; ./run_physics
+
+../run_physics: ${OBJS}
+ ${CXX} ${CXXFLAGS} -o ../run_physics ${OBJS} ${LIBS}
+
+Entities.d:
+ cd Entities; make
+
+include ${DEPEND}
+
--- /dev/null
+This file contains a TODO list for project Blue Star in C++ with allegro.
+a - entry is something to do,
+a ~ entry has been started,
+a + entry is something that was done,
+and a * entry is something to remember when working in this area of the project.
+*******************************************************************************
+
+- make the tickCount file independ of platform. UNIX/Windows
+ - do a preprocessor if that changes the file based on OS
+
++ investigate the make system, get it to build my project
+ * http://www.eng.hawaii.edu/Tutor/Make/
+ * http://www.opussoftware.com/tutorial/TutMakefile.htm
+ * http://www.sethi.org/classes/cet375/lab_notes/lab_04_makefile_and_compilation.html
+
+- Ship class
+ - isFriendly
+ - hp
+ + position
+ + velocity
+ + force
+ + mass
+ + BITMAP
+ + drawing
+ + rotating
+
++ Vector2 class
+ + take skeleton of my C# Vector2 class
+
+- map system
+ - should have a notion of speed and direction
+ - ex. side scrolling should be possible
+ - diagonal scrolling should also be possible
+ - rotational defense / final offensive scrolling
+ - scrolling map background
+ - static pieces are drawn into the background on loading
+ - dynamic map pieces are stored and only displayed when on the screen
+
+ - game console needs to
+ - bind keys
+ - load / save game
+ - free play mode commands
+ - switch levels
+ - invincible
+ - free money
+
+- collision system
+ - boxes can be out-boxes as well as in-boxes
+ - boxes can be relative to
+ - map background
+ - map objects
+ - player
+ - enemies
+ - collision types include
+ - object pickup
+ - repulsion
+ - character effects
+ - slow down, map scrolling
+ - speed up, map scrolling
+ - gain health
+ - lose health
+
+
+- random list of allegro things to read
+ - create_video_bitmap()
+ - int show_video_bitmap(BITMAP *bitmap); for my double buffering?
+ - int request_video_bitmap(BITMAP *bitmap); for possible triple buffering
+ - GFX_CAN_TRIPLE_BUFFER
+ - int enable_triple_buffer();
+
+
+- LInKS !!
+http://www.gimp.org/tutorials/
\ No newline at end of file
--- /dev/null
+#include "Vector2.h"
+#include "mathw.h"
+
+Vector2::Vector2()
+ : x(0), y(0)
+{
+}
+Vector2::Vector2(float x, float y)
+ : x(x), y(y)
+{
+}
+Vector2::Vector2(const Vector2& vec)
+ : x(vec.x), y(vec.y)
+{
+}
+
+void Vector2::zero()
+{
+ x = 0;
+ y = 0;
+}
+void Vector2::unit()
+{
+ float len = length();
+
+ x /= len;
+ y /= len;
+}
+
+float Vector2::angle() const
+{
+ return atan2A(y,x);
+}
+float Vector2::length() const
+{
+ return sqrt(x*x + y*y);
+}
+
+
+string Vector2::toString() const
+{
+ char* strX = new char[50]; // long just to be safe
+ char* strY = new char[50]; // long just to be safe
+ sprintf(strX, "%f", x);
+ sprintf(strY, "%f", y);
+
+ string val = (string)"Vector2 x: " + strX + ", y: " + strY;
+ delete []strX; // deletes the memory allocated, not just what is used by sprintf
+ delete []strY; // deletes the memory allocated, not just what is used by sprintf
+
+ return val;
+}
+void Vector2::print() const
+{
+ printf("%s\n",toString().c_str());
+}
+
+
+Vector2 Vector2::add(const Vector2& vec) const
+{
+ return Vector2(x+vec.x, y+vec.y);
+}
+Vector2 Vector2::subtract(const Vector2& vec) const
+{
+ return Vector2(x-vec.x, y-vec.y);
+}
+Vector2 Vector2::multiply(float c) const
+{
+ return Vector2(x*c, y*c);
+}
+Vector2 Vector2::divide(float c) const
+{
+ return Vector2(x/c, y/c);
+}
+
+
+Vector2 operator+(const Vector2& vec1, const Vector2& vec2)
+{
+ return vec1.add(vec2);
+}
+Vector2 operator-(const Vector2& vec1, const Vector2& vec2)
+{
+ return vec1.subtract(vec2);
+}
+Vector2 operator*(float c, const Vector2& vec)
+{
+ return vec.multiply(c);
+}
+Vector2 operator*(const Vector2& vec, float c)
+{
+ return vec.multiply(c);
+}
+Vector2 operator/(const Vector2& vec, float c)
+{
+ return vec.divide(c);
+}
+
+
+void operator+=(Vector2& vec1, const Vector2& vec2)
+{
+ vec1.x += vec2.x;
+ vec1.y += vec2.y;
+}
+void operator-=(Vector2& vec1, const Vector2& vec2)
+{
+ vec1.x -= vec2.x;
+ vec1.y -= vec2.y;
+}
+void operator*=(Vector2& vec, float c)
+{
+ vec.x *= c;
+ vec.y *= c;
+}
+void operator/=(Vector2& vec, float c)
+{
+ vec.x /= c;
+ vec.y /= c;
+}
--- /dev/null
+#ifndef VECTOR2_H
+#define VECTOR2_H
+
+#include <string>
+
+using std::string;
+
+/// ***** Header Class *****
+class Vector2
+{
+ public:
+ float x;
+ float y;
+
+ Vector2();
+ Vector2(float, float);
+ Vector2(const Vector2&);
+
+ void zero();
+ void unit();
+
+ float angle() const;
+ float length() const;
+
+ Vector2 add(const Vector2&) const;
+ Vector2 subtract(const Vector2&) const;
+ Vector2 divide(float) const;
+ Vector2 multiply(float) const;
+
+ string toString() const;
+ void print() const;
+};
+
+/// ***** Header Methods *****
+// definitions of the operators are external
+// because (float, Vector2) would fail inside class
+Vector2 operator+(const Vector2&, const Vector2&);
+Vector2 operator-(const Vector2&, const Vector2&);
+Vector2 operator*(float, const Vector2&);
+Vector2 operator*(const Vector2&, float);
+Vector2 operator/(const Vector2&, float);
+
+void operator+=(Vector2&, const Vector2&);
+void operator-=(Vector2&, const Vector2&);
+void operator*=(Vector2&, float);
+void operator/=(Vector2&, float);
+
+#endif // VECTOR2_H
--- /dev/null
+These are a few style guidelines of my own that I try to adhere to.
+This is in a very short form as it's mostly for myself.
+
+- FileNameWithClass
+- ClassName
+ - Public_Class_Variable
+ - protected_Class_Variable
+ - private_Class_Variable
+
+- fileNameWithMethods
+ - variable_Local_To_File
+- methodName, class or file
+ - method_parameter
+ - method_variable
+
+- prefix consts with c, camel -> cName, under -> c_Name
+
+
+- sections of a file should be commented with the following where appropriate
+ - they should appear in this order
+ - they should have two newlines before star lines, excluding the first
+
+/// ***** Private Method Headers *****
+/// ***** Private Variables *****
+
+/// ***** Constructors/Destructors *****
+
+/// ***** Public Methods *****
+/// ***** Private Methods *****
+
+/// ***** Public Class Methods *****
+/// ***** Protected Class Methods *****
+/// ***** Private Class Methods *****
+
+
+/// ***** Header Class *****
+/// ***** Header Methods *****
--- /dev/null
+Vector2.o: Vector2.cpp Vector2.h mathw.h
+ticks.o: ticks.cpp ticks.h
+main.o: main.cpp game.h ticks.h graphics.h
+game.o: game.cpp game.h
+entityManager.o: entityManager.cpp entityManager.h Entities/Entity.h \
+ Entities/../Vector2.h Entities/Particle.h Entities/Entity.h \
+ Entities/PhysicsEntity.h
+gldraw.o: gldraw.cpp
+graphics.o: graphics.cpp
--- /dev/null
+#include "entityManager.h"
+#include "Entities/Entity.h"
+#include "Entities/Particle.h"
+#include "Entities/PhysicsEntity.h"
+
+#include <set>
+using std::set;
+
+#include <iostream>
+
+/// ***** Private Method Headers *****
+void updateParticles(float);
+void updatePhysics(float);
+
+/// ***** Private Variables *****
+typedef set<Particle*> setPart;
+setPart particles_To_Add;
+setPart active_Particles;
+setPart particles_To_Remove;
+bool clearParticles;
+
+typedef set<PhysicsEntity*> setPhys;
+setPhys physics_To_Add;
+setPhys active_Physics;
+setPhys physics_To_Remove;
+bool clearPhysics;
+
+/// ***** Public Methods *****
+
+void entityMInit()
+{
+}
+void entityMClean()
+{
+}
+
+void addEntity(Entity* e)
+{
+ {
+ Particle* p = dynamic_cast<Particle*>(e);
+ if( p != 0 )
+ {
+ particles_To_Add.insert(p);
+ return;
+ }
+ }
+
+ {
+ PhysicsEntity* p = dynamic_cast<PhysicsEntity*>(e);
+ if( p != 0 )
+ {
+ physics_To_Add.insert(p);
+ return;
+ }
+ }
+
+ std::cerr << "ENTITY TYPE NOT SUPPORTED BY addEntity()!!";
+ std::cerr << std::endl;
+}
+void deleteEntity(Entity* e)
+{
+ {
+ Particle* p = dynamic_cast<Particle*>(e);
+ if( p != 0 )
+ {
+ particles_To_Remove.insert(p);
+ return;
+ }
+ }
+
+ {
+ PhysicsEntity* p = dynamic_cast<PhysicsEntity*>(e);
+ if( p != 0 )
+ {
+ physics_To_Remove.insert(p);
+ return;
+ }
+ }
+
+ std::cerr << "ENTITY TYPE NOT SUPPORTED BY deleteEntity()!!";
+ std::cerr << std::endl;
+}
+
+void clear()
+{
+ clearParticles = true;
+ clearPhysics = true;
+}
+
+void handleInput()
+{
+ // TODO
+}
+void updateEntities(float time_step)
+{
+ updateParticles(time_step);
+ updatePhysics(time_step);
+}
+void drawEntities()
+{
+ // update active Particle*s
+ for( setPart::iterator it = active_Particles.begin();
+ it != active_Particles.end();
+ it++ )
+ {
+ (*it)->draw();
+ }
+
+ // update active PhysicsEntity*s
+ for( setPhys::iterator it = active_Physics.begin();
+ it != active_Physics.end();
+ it++ )
+ {
+ (*it)->draw();
+ }
+}
+
+/// ***** Private Methods *****
+void updateParticles(float time_step)
+{
+ // add new Particle*s to Active
+ for( setPart::iterator it = particles_To_Add.begin();
+ it != particles_To_Add.end();
+ it++ )
+ {
+ active_Particles.insert(*it);
+ }
+ particles_To_Add.clear();
+
+ // remove dead Particle*s from Active
+ for( setPart::iterator it = particles_To_Remove.begin();
+ it != particles_To_Remove.end();
+ it++ )
+ {
+ active_Particles.erase(*it);
+ }
+ particles_To_Remove.clear();
+
+ // update active Particle*s
+ for( setPart::iterator it = active_Particles.begin();
+ it != active_Particles.end();
+ it++ )
+ {
+ (*it)->update(time_step);
+ }
+}
+void updatePhysics(float time_step)
+{
+ // add new PhysicsEntity*s to Active
+ for( setPhys::iterator it = physics_To_Add.begin();
+ it != physics_To_Add.end();
+ it++ )
+ {
+ active_Physics.insert(*it);
+ }
+ physics_To_Add.clear();
+
+ // remove dead PhysicsEntity*s from Active
+ for( setPhys::iterator it = physics_To_Remove.begin();
+ it != physics_To_Remove.end();
+ it++ )
+ {
+ active_Physics.erase(*it);
+ }
+ physics_To_Remove.clear();
+
+ // update active PhysicsEntity*s
+ for( setPhys::iterator it = active_Physics.begin();
+ it != active_Physics.end();
+ it++ )
+ {
+ (*it)->update(time_step);
+ }
+}
--- /dev/null
+#ifndef ENTITYMANAGER_H
+#define ENTITYMANAGER_H
+
+#include "Entities/Entity.h"
+
+/// ***** Header Methods *****
+namespace entityManager
+{
+ void init();
+ void clean();
+
+ // does not new or delete Entities
+ void add(Entity*);
+ void remove(Entity*);
+ void clear();
+
+ void update(float);
+ void draw();
+ void handleInput();
+}
+#endif // ENTITYMANAGER_H
--- /dev/null
+#include "game.h"
+
+#include "GameStates/GameState.h"
+#include "GameStates/Running.h"
+#include "GameStates/Paused.h"
+#include "GameStates/CreatingPolygon.h"
+
+#include <vector>
+using std::vector;
+
+
+/// ***** Private Variables *****
+
+// The stack of active game states
+vector<GameState*> active_States;
+
+// Pointers to each possible game state
+// inserted and removed from the active_States
+Running* running;
+Paused* paused;
+CreatingPolygon* creating_Polygon;
+
+
+/// ***** Public Methods *****
+void gameInit()
+{
+ running = new Running();
+ paused = new Paused();
+ creating_Polygon = new CreatingPolygon();
+}
+
+void gameClean()
+{
+ delete creating_Polygon;
+ delete paused;
+ delete running;
+}
+
+void gameInput()
+{
+ int size = active_States.size();
+ for( int i = 0;
+ i < size;
+ i++ )
+ {
+ if( i-1 == size )
+ active_States[i]->handleInput(true);
+ else
+ active_States[i]->handleInput(false);
+ }
+
+}
+
+void gameUpdate(float time_step)
+{
+ int size = active_States.size();
+ for( int i = 0;
+ i < size;
+ i++ )
+ {
+ if( i-1 == size )
+ active_States[i]->update(time_step, true);
+ else
+ active_States[i]->update(time_step, false);
+ }
+}
+
+void gameDraw()
+{
+ int size = active_States.size();
+ for( int i = 0;
+ i < size;
+ i++ )
+ {
+ if( i-1 == size )
+ active_States[i]->draw(true);
+ else
+ active_States[i]->draw(false);
+ }
+}
--- /dev/null
+#ifndef GAME_H
+#define GAME_H
+
+/// ***** Header Methods *****
+void gameInit();
+void gameClean();
+
+void gameInput();
+void gameUpdate(float);
+void gameDraw();
+
+#endif // GAME_H
--- /dev/null
+#include "graphics.h"
+
+#include <GL/gl.h>
+#include <GL/glu.h>
+#include <SDL/SDL.h>
+#include <cmath>
+
+#include <iostream>
+using std::cerr;
+using std::cout;
+using std::endl;
+
+
+static const float PI = 3.1415926535897;
+
+/// ***** Private Method Headers *****
+void sdlInit();
+void glInit();
+
+/// ***** Public Methods *****
+
+void graphicsInit()
+{
+ sdlInit();
+ glInit();
+}
+
+void graphicsCleanUp()
+{
+
+}
+
+void glDrawCircle()
+{
+ int num = 32;
+
+ glBegin(GL_POLYGON);
+ for(int n = 0; n < num; n++)
+ {
+ float angle = 2 * PI * n / num;
+ float x = cos(angle);
+ float y = sin(angle);
+
+ glVertex3f(x, y, -1);
+ }
+ glEnd();
+}
+
+/// ***** Private Methods *****
+void sdlInit()
+{
+ if(SDL_Init(SDL_INIT_VIDEO) < 0)
+ {
+ cerr << "SDL_Init failed: " << SDL_GetError() << endl;
+ exit(1);
+ }
+
+ // In order to use SDL_OPENGLBLIT we have to
+ // set GL attributes first
+ SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+
+ if(SDL_SetVideoMode(800, 600, 16, SDL_OPENGL) < 0)
+ {
+ cerr << "SDL_SetVideoMode failed: " << SDL_GetError() << endl;
+ exit(1);
+ }
+}
+
+void glInit()
+{
+ glClearColor(0.0, 0.0, 0.0, 0.0);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+
+ glOrtho(-20.0, 20.0, -15.0, 15.0, -0.01, 1.01);
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+
+ glEnable(GL_DEPTH_TEST);
+}
--- /dev/null
+#ifndef GRAPHICS_H
+#define GRAPHICS_H
+
+/// ***** Header Methods *****
+void graphicsInit();
+void graphicsCleanUp();
+
+void glDrawCircle();
+
+#endif // GRAPHICS_H
--- /dev/null
+#ifndef INIT_H
+#define INIT_H
+
+/// ***** Header Methods *****
+void initGraphics();
+int initMouse();
+void initKeyboard();
+
+void cleanGraphics();
+void cleanMouse();
+void cleanKeyboard();
+
+#endif // INIT_H
--- /dev/null
+#include <GL/gl.h>
+#include <GL/glu.h>
+#include <SDL/SDL.h>
+
+#include <iostream>
+using std::cerr;
+using std::cout;
+using std::endl;
+
+#include <vector>
+using std::vector;
+
+#include "game.h"
+#include "ticks.h"
+#include "graphics.h"
+
+
+/// ***** Private Method Headers *****
+void init();
+
+void run();
+void cleanUp();
+
+void blockUpdate();
+void updateFPSCounters();
+
+void input();
+void update(float);
+void draw();
+
+
+/// ***** MAIN Method *****
+int main()
+{
+ init();
+ run();
+ cleanUp();
+ return 0;
+}
+
+
+/// ***** Private Variables *****
+
+// variable used to determine if it is time to shutdown
+bool is_Running;
+
+/* Values for the main game loop
+ * target_UPS := the amount of updates that is wanted in one second
+ * last_Update := stores the time of the last update
+ * update_Sum := used to determine the updates needs for this run
+
+ * ups := updates per second for the last second
+ * fps := frames per second for the last second
+ * update_Count := counts this seconds updates
+ * draw_Count := counts this seconds draws
+ * last_Second := stores the time of the last second, used for ups and fps
+ */
+int target_UPS = 250;
+long int last_Block_Update;
+float update_Sum = 0;
+
+int ups, fps;
+int update_Count, draw_Count;
+long int last_Second;
+
+
+/// ***** Private Methods *****
+void init()
+{
+ graphicsInit();
+
+ gameInit();
+
+ // TODO
+ // add a game state
+
+ cout << "Initialization Complete" << endl;
+
+ // create starting entities
+
+ cout << "World Created" << endl;
+}
+
+void run()
+{
+ is_Running = true;
+ last_Block_Update = tickCountMicro();
+ last_Second = tickCountMicro();
+
+ while(is_Running)
+ {
+ blockUpdate();
+ updateFPSCounters();
+ draw();
+ }
+}
+
+void cleanUp()
+{
+ gameClean();
+}
+
+void blockUpdate()
+{
+ long int start = tickCountMicro();
+
+ // Calculate the updates that should be run for the next draw
+ update_Sum += (start - last_Block_Update) / (1000000 / (float)target_UPS);
+
+ // insures the float to int cast is done once.
+ int iupdate_sum = (int)update_Sum;
+
+ // TODO the main run loop needs to be tested and pruned
+ if (iupdate_sum > 0)
+ {
+ // Calculate a time step that spreads the updates out as much as possible
+ // used because really quick updates are nearly wasted
+ float time_step = ((float)(start - last_Block_Update)) / iupdate_sum;
+
+ // run the updates
+ for (int i = 1; i <= iupdate_sum; i++)
+ {
+ input();
+ update(time_step*i / 1000);
+ }
+ // remove the updates that where run from the sum
+ update_Sum -= iupdate_sum;
+ last_Block_Update = tickCountMicro();
+ }
+}
+
+void updateFPSCounters()
+{
+ // Check if a second has passed to recalculate UPS and FPS
+ if (tickCountMicro() - last_Second >= 1000000)
+ {
+ ups = update_Count;
+ fps = draw_Count;
+ update_Count = 0;
+ draw_Count = 0;
+
+ last_Second = tickCountMicro();
+ }
+}
+
+void input()
+{
+ gameInput();
+
+ /*
+ if(key[KEY_ESC])
+ is_Running = false;
+ */
+}
+
+void update(float time_step)
+{
+ update_Count++;
+
+ gameUpdate(time_step);
+}
+
+void draw()
+{
+ draw_Count++;
+
+ gameDraw();
+
+ SDL_GL_SwapBuffers();
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+}
--- /dev/null
+#include "mathw.h"
+
+
+/// ***** Private Varibles *****
+
+const float PI = 3.141592653;
+
+
+/// ***** Public Methods *****
+
+int mod(int x, int y)
+{
+ return x % y + (x < 0 ? y : 0);
+}
+
+float radsToA(float rads)
+{
+ return ftofix(rads * 128/PI);
+}
+
+float atanA(float c)
+{
+ return radsToA(atan(c)) + itofix(64);
+}
+
+float atan2A(float y, float x)
+{
+ return radsToA(atan2(y,x)) + itofix(64);
+}
+
+/// Vector2 Math
+
+Vector2 perp(const Vector2& vec)
+{
+ return Vector2(-vec.y, vec.x);
+}
+
+float dot(const Vector2& vec1, const Vector2& vec2)
+{
+ return vec1.x * vec2.x + vec1.y * vec2.y;
+}
+
+//TODO float Vector2::projectionCoeff(const Vector2* vec) const;
+//TODO Vector2* Vector2::projection(const Vector2* vec) const;
+
--- /dev/null
+#ifndef MATHW_H
+#define MATHW_H
+
+#include <math.h>
+#include "Vector2.h"
+
+
+/// ***** Header Methods *****
+
+int mod(int,int);
+
+float radsToA(float);
+float atanA(float);
+float atan2A(float, float);
+
+/// Vector2 Math
+
+//Vector2 vectorToLine(float, float, float, float) const;
+//Vector2 lineIntersection(Vector2&, Vector2&, Vector2&, Vector2&) const;
+
+//void Rotate(float rads);
+
+float dot(const Vector2&, const Vector2&);
+Vector2 perp(const Vector2&);
+
+//TODO float projectionCoeff(const Vector2&, const Vector2&) const;
+//TODO void projection(const Vector2&, const Vector2&);
+
+#endif // MATHW_H
--- /dev/null
+#include <sys/time.h>
+#include "ticks.h"
+
+/* this file is specific to a UNIX system */
+
+/// ***** Public Methods *****
+
+// returns the current microseconds from unix time
+long int tickCountMicro()
+{
+ struct timeval tv;
+ gettimeofday(&tv, 0);
+
+ return (long int)tv.tv_sec * 1000000 + tv.tv_usec;
+}
+
+// returns the current milliseconds from unix time
+long int tickCountMilli()
+{
+ return tickCountMicro() / 1000;
+}
+
+// returns the current seconds from unix time
+long int tickCountSec()
+{
+ return tickCountMicro() / 1000000;
+}
+
+// return after num milliseconds
+void wait(int num)
+{
+ long int start;
+ int numMicro = num * 1000;
+
+ start = tickCountMicro();
+ while(tickCountMicro() - start < numMicro);
+}
+
--- /dev/null
+#ifndef TICKS_H
+#define TICKS_H
+
+/// ***** Public Methods *****
+
+// returns the current seconds from program start
+long int tickCountSec();
+
+// returns the current milliseconds from program start
+long int tickCountMilli();
+
+// returns the current microseconds from program start
+long int tickCountMicro();
+
+void wait(int);
+
+#endif // TICKS_H