summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Level.cpp2
-rw-r--r--Level.h5
-rw-r--r--Screen.cpp26
-rw-r--r--Screen.h21
-rw-r--r--intensemarcus.h5
-rw-r--r--main.cpp17
6 files changed, 60 insertions, 16 deletions
diff --git a/Level.cpp b/Level.cpp
index a6cab97..27a77be 100644
--- a/Level.cpp
+++ b/Level.cpp
@@ -31,6 +31,6 @@ void Level::move() {
//std::cout << "Level::move(): Moving level items.\n";
}
-void Level::draw(SDL_Surface *screen) {
+void Level::draw(Screen *screen) {
//std::cout << "Level::draw(): Drawing into the screen.\n";
}
diff --git a/Level.h b/Level.h
index c2334b0..a56b734 100644
--- a/Level.h
+++ b/Level.h
@@ -2,8 +2,7 @@
#define LEVEL_H
#include "Player.h"
-#include "SDL/SDL.h"
-#include "SDL/SDL_image.h"
+#include "Screen.h"
class Level {
public:
@@ -16,7 +15,7 @@ class Level {
void move();
// Draw the current scene on the screen
- void draw(SDL_Surface *screen);
+ void draw(Screen *screen);
// The human player
Player player;
diff --git a/Screen.cpp b/Screen.cpp
new file mode 100644
index 0000000..5a0b157
--- /dev/null
+++ b/Screen.cpp
@@ -0,0 +1,26 @@
+#include <iostream>
+#include "Screen.h"
+
+Screen::Screen() {
+ // Turn on the main screen
+ if (!(screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE)))
+ std::cout << "Error setting video mode.\n";
+
+ // Set window title
+ SDL_WM_SetCaption("Intense Marcus", NULL);
+}
+
+void Screen::blit(int x, int y, SDL_Surface* src, SDL_Surface* dst, SDL_Rect* clip) {
+ // Destination position
+ SDL_Rect pos;
+
+ pos.x = x;
+ pos.y = y;
+
+ SDL_BlitSurface(src, clip, dst, &pos);
+}
+
+void Screen::flip() {
+ if (SDL_Flip(screen) == -1)
+ std::cout << "Error flipping screen.\n";
+}
diff --git a/Screen.h b/Screen.h
new file mode 100644
index 0000000..c5672b5
--- /dev/null
+++ b/Screen.h
@@ -0,0 +1,21 @@
+#ifndef SCREEN_H
+#define SCREEN_H
+
+#include "intensemarcus.h"
+#include "SDL/SDL.h"
+
+class Screen {
+ public:
+ Screen();
+
+ /* blits src onto dst, at position x, y */
+ void blit(int x, int y, SDL_Surface* src, SDL_Surface* dst, SDL_Rect* clip = NULL);
+ /* Swap screen buffers */
+ void flip();
+
+ private:
+ // Game window
+ SDL_Surface *screen;
+};
+
+#endif
diff --git a/intensemarcus.h b/intensemarcus.h
index 7c3a330..3f7d5bf 100644
--- a/intensemarcus.h
+++ b/intensemarcus.h
@@ -1,4 +1,9 @@
+#ifndef INTENSEMARCUS_H
+#define INTENSEMARCUS_H
+
const int SCREEN_WIDTH = 800;
const int SCREEN_HEIGHT = 600;
const int SCREEN_BPP = 32;
const int FPS = 30;
+
+#endif
diff --git a/main.cpp b/main.cpp
index c2b91fe..55db293 100644
--- a/main.cpp
+++ b/main.cpp
@@ -9,8 +9,6 @@ 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
@@ -18,17 +16,13 @@ int main(int argc, char* args[]) {
// Timer start
Uint32 startTicks = 0;
+ // Game window
+ Screen screen;
+
// 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);
@@ -50,11 +44,10 @@ int main(int argc, char* args[]) {
level.move();
// Draw level
- level.draw(screen);
+ level.draw(&screen);
// Update screen
- if (SDL_Flip(screen) == -1)
- return 1;
+ screen.flip();
// Set FPS cap to 30
if ((SDL_GetTicks() - startTicks) < 1000 / FPS)