#include "Ball.h"
#include "../Vector2.h"
+#include "../graphics/graphics.h"
/// ***** Public Class Methods *****
Ball::Ball(Vector2 pos, float radius)
void Ball::draw() const
{
// TODO
+
+ glDrawCircle(radius, &position);
}
+++ /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}
-
}
/// ***** Private Class Methods *****
-void CreateBindingBox()
+void Polygon::CreateBindingBox()
{
// TODO
}
+++ /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 CreatingPolygon.cpp Paused.cpp Running.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}
-
-LIBALLG = `allegro-config --libs release`
-LIBGL = -lGL -lGLU
-LIBSDL = `sdl-config --libs`
-LIBS = ${LIBSDL} ${LIBGL}
+LIBGL := -lGL -lGLU
+LIBSDL := `sdl-config --libs`
+LIBS := ${LIBSDL} ${LIBGL}
-CXX = g++
-CXXFLAGS = -ggdb -Wall -pedantic
+OPTFLAGS := -O2
+DBGFLAGS := -ggdb
+PRFFLAGS := ${DBGFLAGS} -pg
-SRCS = Vector2.cpp ticks.cpp main.cpp game.cpp entityManager.cpp graphics.cpp
-OBJS = ${SRCS:.cpp=.o}
+#CXX := g++
+CXXFLAGS := -Wall -pedantic -ansi ${DBGFLAGS}
-TARGETS = ../run_physics
-DEPEND = depend.mk
-# set suffixes to look for ...
-.SUFFIXES: .cpp .o
+SRCS := entityManager.cpp
+SRCS += game.cpp
+SRCS += main.cpp
+SRCS += mathw.cpp
+SRCS += ticks.cpp
+SRCS += Vector2.cpp
-# set default action for a *.cc to create a *.o
-.cpp.o:
- g++ -c $< ${CXXFLAGS}
+SRCS += Entities/Ball.cpp
+SRCS += Entities/Entity.cpp
+SRCS += Entities/Line.cpp
+SRCS += Entities/Particle.cpp
+SRCS += Entities/PhysicsEntity.cpp
+SRCS += Entities/Point.cpp
+SRCS += Entities/Polygon.cpp
+SRCS += Entities/WindParticle.cpp
-all: ${TARGETS}
+SRCS += GameStates/CreatingPolygon.cpp
+SRCS += GameStates/GameState.cpp
+SRCS += GameStates/Paused.cpp
+SRCS += GameStates/Running.cpp
-depend:
- ${CXX} -MM ${SRCS} > ${DEPEND}
+SRCS += input/inputManager.cpp
-tags:
- ctags ${SRCS}
+SRCS += graphics/graphics.cpp
+OBJS := ${SRCS:.cpp=.o}
+
+
+TARGET := ../run_physics
+DEPENDS := ${SRCS:.cpp=.d}
+
+
+.PHONY: all
+all: ${TARGET}
+
+${TARGET}: ${OBJS}
+ ${CXX} ${CXXFLAGS} -o ${TARGET} $^ ${LIBS}
+ @echo ""
+
+# how to make a depend file from a source file
+%.d: %.cpp
+ @echo "DEP: $@"
+ @${CXX} -M ${CXXFLAGS} $< | sed 's,: , $@: ,' > $@
+
+#@${CXX} -M ${CXXFLAGS} $< | sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' > $@
+
+
+.PHONY: clean
clean:
- rm -f ${OBJS} ${TARGETS} *~
+ rm -f ${OBJS} ${TARGET}
+.PHONY: distclean
distclean: clean
- rm -f tags depend.mk
- touch depend.mk
+ rm -f ${DEPENDS} tags prof gmon.out
-# i need to find a nice way of ijnoring .svn folders for the below
-tar: clean
- cd ..; tar -cjf bluestar.tar.bz2 images/ source/
+tags: ${SRCS}
+ ctags $^
+tar: clean
+ cd ..; tar -cjf physics.tar.bz2 src/
-run: ../run_physics
- cd ..; ./run_physics
-../run_physics: ${OBJS}
- ${CXX} ${CXXFLAGS} -o ../run_physics ${OBJS} ${LIBS}
+.PHONY: run
+run: all
+ ${TARGET}
-Entities.d:
- cd Entities; make
+.PHONY: val
+val: all
+ valgrind ${TARGET}
-include ${DEPEND}
+.PHONY: prof
+prof: all
+ ${TARGET}
+ gprof -b ${TARGET} > prof
+ kprof -f prof
+-include ${DEPENDS}
--- /dev/null
+This file contains a TODO list for project Physics C++ using OpenGL.
+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 independent 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
+
+
++ Vector2 class
+ + take skeleton of my C# Vector2 class
+
+- game console needs to
+ - bind keys
+ - load / save state
+
+
+- LInKS !!
+http://www.gimp.org/tutorials/
+++ /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
float Vector2::angle() const
{
- return atan2A(y,x);
+ //return atan2A(y,x);
+ return 0;
}
float Vector2::length() const
{
--- /dev/null
+#ifndef DEBUG_H
+#define DEBUG_H
+
+// comment out when not debugging
+#define DEBUGGING
+
+#include <iostream>
+using std::cerr;
+using std::cout;
+using std::endl;
+
+#endif // DEBUG_H
+++ /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 GameStates/GameState.h GameStates/Running.h \
- GameStates/GameState.h GameStates/Paused.h GameStates/CreatingPolygon.h
-entityManager.o: entityManager.cpp entityManager.h Entities/Entity.h \
- Entities/../Vector2.h Entities/Particle.h Entities/Entity.h \
- Entities/PhysicsEntity.h
-graphics.o: graphics.cpp graphics.h
/// ***** Public Methods *****
-void entityMInit()
+void entityManager::init()
{
}
-void entityMClean()
+void entityManager::clean()
{
}
-void addEntity(Entity* e)
+void entityManager::add(Entity* e)
{
{
Particle* p = dynamic_cast<Particle*>(e);
std::cerr << "ENTITY TYPE NOT SUPPORTED BY addEntity()!!";
std::cerr << std::endl;
}
-void deleteEntity(Entity* e)
+void entityManager::remove(Entity* e)
{
{
Particle* p = dynamic_cast<Particle*>(e);
std::cerr << std::endl;
}
-void clear()
+void entityManager::clear()
{
clearParticles = true;
clearPhysics = true;
}
-void handleInput()
+void entityManager::handleInput()
{
// TODO
}
-void updateEntities(float time_step)
+void entityManager::update(float time_step)
{
updateParticles(time_step);
updatePhysics(time_step);
}
-void drawEntities()
+void entityManager::draw()
{
// update active Particle*s
for( setPart::iterator it = active_Particles.begin();
--- /dev/null
+
+static float const cRed[] = {1.0, 0.0, 0.0};
+static float const cGreen[] = {0.0, 1.0, 0.0};
+static float const cBlue[] = {0.0, 0.0, 1.0};
+static float const cYellow[] = {1.0, 1.0, 0.0};
#include <SDL/SDL.h>
#include <cmath>
-#include <iostream>
-using std::cerr;
-using std::cout;
-using std::endl;
-
+#include "../debug.h"
static const float PI = 3.1415926535897;
/// ***** Private Method Headers *****
+void drawCircle(int);
void sdlInit();
void glInit();
}
-void glDrawCircle()
+void glDrawCircle(float radius, const Vector2* vec, const float* color)
{
- int num = 32;
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(vec->x, vec->y, -1);
+ glScalef(radius, radius, radius);
+
+ if(color != NULL)
+ glColor3fv(color);
+
+ drawCircle(32);
+}
+
+/// ***** Private Methods *****
+void drawCircle(int pieces)
+{
glBegin(GL_POLYGON);
- for(int n = 0; n < num; n++)
+ for(int n = 0; n < pieces; n++)
{
- float angle = 2 * PI * n / num;
- float x = cos(angle);
- float y = sin(angle);
+ float angle = 2 * PI * n / pieces;
+ float ix = cos(angle);
+ float iy = sin(angle);
- glVertex3f(x, y, -1);
+ glVertex3f(ix, iy, 0);
}
glEnd();
}
-/// ***** Private Methods *****
void sdlInit()
{
if(SDL_Init(SDL_INIT_VIDEO) < 0)
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- glOrtho(-20.0, 20.0, -15.0, 15.0, -0.01, 1.01);
+ glOrtho(0, 800.0, 600.0, 0.0, -0.01, 1.01);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
#ifndef GRAPHICS_H
#define GRAPHICS_H
+#include "../Vector2.h"
+
/// ***** Header Methods *****
void graphicsInit();
void graphicsCleanUp();
-void glDrawCircle();
+void glDrawCircle(float radius, const Vector2*, const float* color = 0);
#endif // GRAPHICS_H
--- /dev/null
+
+#include "inputManager.h"
+#include "../debug.h"
+
+enum State
+{
+ isR,
+ wasP,
+ isP,
+ wasR
+};
+
+static const int keySize = 323;
+static State keyState[keySize];
+
+void inputInit()
+{
+ for(int i=0; i< keySize; i++)
+ keyState[i] = isR;
+}
+
+void inputUpdate()
+{
+ SDL_Event event;
+
+ for(int i=0; i< keySize; i++)
+ {
+ if(keyState[i] == wasR)
+ keyState[i] = isR;
+ else if(keyState[i] == wasP)
+ keyState[i] = isP;
+ }
+
+ while(SDL_PollEvent(&event))
+ {
+ switch(event.type)
+ {
+ case SDL_KEYUP:
+ keyState[event.key.keysym.sym] = wasR;
+ break;
+ case SDL_KEYDOWN:
+ keyState[event.key.keysym.sym] = wasP;
+ break;
+ }
+ }
+}
+
+bool isPressed(Uint8 key)
+{
+ return keyState[key] == isP || keyState[key] == wasP;
+}
+bool isReleased(Uint8 key)
+{
+ return keyState[key] == isR || keyState[key] == wasR;
+}
+
+bool wasPressed(Uint8 key)
+{
+ return keyState[key] == wasP;
+}
+bool wasReleased(Uint8 key)
+{
+ return keyState[key] == wasR;
+}
--- /dev/null
+#ifndef INPUT_H
+#define INPUT_H
+
+#include <SDL/SDL.h>
+
+/// ***** Header Methods *****
+void inputUpdate();
+
+bool isPressed(Uint8);
+bool isReleased(Uint8);
+
+bool wasPressed(Uint8);
+bool wasReleased(Uint8);
+
+#endif // INPUT_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 "debug.h"
+
#include "game.h"
#include "ticks.h"
-#include "graphics.h"
+
+#include "graphics/graphics.h"
+#include "input/inputManager.h"
/// ***** Private Method Headers *****
// TODO
// add a game state
+#ifdef DEBUGGING
cout << "Initialization Complete" << endl;
+#endif
// create starting entities
+#ifdef DEBUGGING
cout << "World Created" << endl;
+#endif
+}
+
+void cleanUp()
+{
+#ifdef DEBUGGING
+ cout << "Cleaning up" << endl;
+#endif
+
+ gameClean();
+
+ graphicsCleanUp();
}
void run()
}
}
-void cleanUp()
-{
- gameClean();
-}
-
void blockUpdate()
{
long int start = tickCountMicro();
draw_Count = 0;
last_Second = tickCountMicro();
+
+ //cout << "ups:\t" << ups << endl;
+ //cout << "fps:\t" << fps << endl;
}
}
void input()
{
+ inputUpdate();
+
gameInput();
- /*
- if(key[KEY_ESC])
+ if(wasReleased(SDLK_ESCAPE))
is_Running = false;
- */
}
void update(float time_step)
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)
int mod(int,int);
-float radsToA(float);
-float atanA(float);
-float atan2A(float, float);
-
/// Vector2 Math
//Vector2 vectorToLine(float, float, float, float) const;