SRCS += GameStates/Paused.cpp
SRCS += GameStates/Running.cpp
+SRCS += input/inputManager.cpp
+
OBJS = ${SRCS:.cpp=.o}
TARGET = ../run_physics
--- /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
#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, float x, float y, const float* color)
{
- int num = 32;
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ glTranslatef(x, 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();
void graphicsInit();
void graphicsCleanUp();
-void glDrawCircle();
+void glDrawCircle(float radius, float x, float y, 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 "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 run()
void input()
{
+ inputUpdate();
+
gameInput();
- /*
- if(key[KEY_ESC])
+ if(isPressed(SDLK_ESCAPE))
is_Running = false;
- */
}
void update(float time_step)