summaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
authorLuke Bratch <l_bratch@yahoo.co.uk>2010-11-24 19:57:03 +0000
committerLuke Bratch <l_bratch@yahoo.co.uk>2010-11-24 19:57:03 +0000
commit3383e8be9001826bf0d09f1fb73ad5013cc8627e (patch)
tree27be0f78ab8672a7187d517c73b4ee22817369cc /main.cpp
Initial commit
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/main.cpp b/main.cpp
new file mode 100644
index 0000000..c2b91fe
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,63 @@
+#include <iostream>
+
+#include "intensemarcus.h"
+#include "Level.h"
+#include "SDL/SDL.h"
+#include "SDL/SDL_image.h"
+
+int main(int argc, char* args[]) {
+
+ // Main SDL event structure
+ SDL_Event event;
+ // Ggame window
+ SDL_Surface *screen;
+ // Current level number
+ int levelNo = 1;
+ // Main loop continues while true
+ bool loop = true;
+ // Timer start
+ Uint32 startTicks = 0;
+
+ // Initialise SDL
+ if (SDL_Init(SDL_INIT_EVERYTHING) == -1)
+ return 1;
+
+ // Turn on the main screen
+ if (!(screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE)))
+ return 1;
+
+ // Set window title
+ SDL_WM_SetCaption("Intense Marcus", NULL);
+
+ Level level;
+ level.changeLevel(levelNo);
+
+ // Main loop
+ while (loop) {
+ // Start FPS timer
+ startTicks = SDL_GetTicks();
+
+ // Get input
+ while (SDL_PollEvent(&event)) {
+ //std::cout << "Got event.\n";
+
+ // Handle the user trying to close the window
+ if (event.type == SDL_QUIT || event.key.keysym.sym == SDLK_ESCAPE)
+ loop = false;
+ }
+
+ // Do movement
+ level.move();
+
+ // Draw level
+ level.draw(screen);
+
+ // Update screen
+ if (SDL_Flip(screen) == -1)
+ return 1;
+
+ // Set FPS cap to 30
+ if ((SDL_GetTicks() - startTicks) < 1000 / FPS)
+ SDL_Delay((1000 / FPS) - (SDL_GetTicks() - startTicks));
+ }
+}