handled collisions
authorPatrik Gornicz <Gornicz.P@gmail.com>
Thu, 17 Jul 2008 04:09:50 +0000 (00:09 -0400)
committerPatrik Gornicz <Gornicz.P@gmail.com>
Thu, 17 Jul 2008 04:09:50 +0000 (00:09 -0400)
22 files changed:
src/.gitignore [new file with mode: 0644]
src/Entities/Ball.cpp
src/Entities/Makefile [deleted file]
src/Entities/Polygon.cpp
src/Entities/depend.mk [deleted file]
src/GameStates/Makefile [deleted file]
src/GameStates/depend.mk [deleted file]
src/Makefile
src/TODO [new file with mode: 0644]
src/TODO.txt [deleted file]
src/Vector2.cpp
src/debug.h [new file with mode: 0644]
src/depend.mk [deleted file]
src/entityManager.cpp
src/graphics/colors.h [new file with mode: 0644]
src/graphics/graphics.cpp [moved from src/graphics.cpp with 65% similarity]
src/graphics/graphics.h [moved from src/graphics.h with 58% similarity]
src/input/inputManager.cpp [new file with mode: 0644]
src/input/inputManager.h [new file with mode: 0644]
src/main.cpp
src/mathw.cpp
src/mathw.h

diff --git a/src/.gitignore b/src/.gitignore
new file mode 100644 (file)
index 0000000..6142305
--- /dev/null
@@ -0,0 +1,2 @@
+*.o
+*.d
index 7c31364..ad24d8e 100644 (file)
@@ -1,5 +1,6 @@
 #include "Ball.h"
 #include "../Vector2.h"
+#include "../graphics/graphics.h"
 
 /// ***** Public Class Methods *****
 Ball::Ball(Vector2 pos, float radius)
@@ -15,4 +16,6 @@ Ball::~Ball()
 void Ball::draw() const
 {
     // TODO
+
+    glDrawCircle(radius, &position);
 }
diff --git a/src/Entities/Makefile b/src/Entities/Makefile
deleted file mode 100644 (file)
index a315853..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-
-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}
-
index 6b272bd..bd2a38d 100644 (file)
@@ -18,7 +18,7 @@ void Polygon::draw() const
 }
 
 /// ***** Private Class Methods *****
-void CreateBindingBox()
+void Polygon::CreateBindingBox()
 {
     // TODO
 }
diff --git a/src/Entities/depend.mk b/src/Entities/depend.mk
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/src/GameStates/Makefile b/src/GameStates/Makefile
deleted file mode 100644 (file)
index 8940e20..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-
-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}
-
diff --git a/src/GameStates/depend.mk b/src/GameStates/depend.mk
deleted file mode 100644 (file)
index e69de29..0000000
index 6de7bdb..885bc9e 100644 (file)
@@ -1,53 +1,90 @@
 
-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}
diff --git a/src/TODO b/src/TODO
new file mode 100644 (file)
index 0000000..7f2feba
--- /dev/null
+++ b/src/TODO
@@ -0,0 +1,26 @@
+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/
diff --git a/src/TODO.txt b/src/TODO.txt
deleted file mode 100644 (file)
index 5956f98..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-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
index 7985ef8..8028aa3 100644 (file)
@@ -29,7 +29,8 @@ void Vector2::unit()
 
 float Vector2::angle() const
 {
-  return atan2A(y,x);
+  //return atan2A(y,x);
+  return 0;
 }
 float Vector2::length() const
 {
diff --git a/src/debug.h b/src/debug.h
new file mode 100644 (file)
index 0000000..c8dfdb4
--- /dev/null
@@ -0,0 +1,12 @@
+#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
diff --git a/src/depend.mk b/src/depend.mk
deleted file mode 100644 (file)
index c1f7549..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-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
index f189c7d..351808a 100644 (file)
@@ -27,14 +27,14 @@ bool clearPhysics;
 
 /// ***** 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);
@@ -57,7 +57,7 @@ void addEntity(Entity* 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);
@@ -81,22 +81,22 @@ void deleteEntity(Entity* 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();
diff --git a/src/graphics/colors.h b/src/graphics/colors.h
new file mode 100644 (file)
index 0000000..e502735
--- /dev/null
@@ -0,0 +1,5 @@
+
+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};
similarity index 65%
rename from src/graphics.cpp
rename to src/graphics/graphics.cpp
index 42c2e6d..a719662 100644 (file)
@@ -5,15 +5,12 @@
 #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();
 
@@ -30,23 +27,35 @@ void graphicsCleanUp()
 
 }
 
-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)
@@ -74,7 +83,7 @@ void glInit()
     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();
similarity index 58%
rename from src/graphics.h
rename to src/graphics/graphics.h
index c3d5276..df3b5c2 100644 (file)
@@ -1,10 +1,12 @@
 #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
diff --git a/src/input/inputManager.cpp b/src/input/inputManager.cpp
new file mode 100644 (file)
index 0000000..e8b92c6
--- /dev/null
@@ -0,0 +1,64 @@
+
+#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;
+}
diff --git a/src/input/inputManager.h b/src/input/inputManager.h
new file mode 100644 (file)
index 0000000..411dcc2
--- /dev/null
@@ -0,0 +1,15 @@
+#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
index df9f490..629ca9b 100644 (file)
@@ -2,17 +2,16 @@
 #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 *****
@@ -74,11 +73,26 @@ void init()
     // 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()
@@ -95,11 +109,6 @@ void run()
     }
 }
 
-void cleanUp()
-{
-    gameClean();
-}
-
 void blockUpdate()
 {
     long int start = tickCountMicro();
@@ -140,17 +149,20 @@ void updateFPSCounters()
         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)
index c25df98..430a601 100644 (file)
@@ -13,21 +13,6 @@ 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)
index 0d9e3ab..d752838 100644 (file)
@@ -9,10 +9,6 @@
 
 int mod(int,int);
 
-float radsToA(float);
-float atanA(float);
-float atan2A(float, float);
-
 /// Vector2 Math
 
 //Vector2 vectorToLine(float, float, float, float) const;