diff --git a/Bin/VC10/VC10.vcxproj b/Bin/VC10/VC10.vcxproj
index c0ff780..a73715e 100644
--- a/Bin/VC10/VC10.vcxproj
+++ b/Bin/VC10/VC10.vcxproj
@@ -124,6 +124,7 @@
+
diff --git a/Bin/VC10/VC10.vcxproj.filters b/Bin/VC10/VC10.vcxproj.filters
index 88db6ab..df0868d 100644
--- a/Bin/VC10/VC10.vcxproj.filters
+++ b/Bin/VC10/VC10.vcxproj.filters
@@ -236,5 +236,8 @@
Level
+
+ Global
+
\ No newline at end of file
diff --git a/LibDQt/LibDQt.pro b/LibDQt/LibDQt.pro
index 2a1a82f..24b0550 100644
--- a/LibDQt/LibDQt.pro
+++ b/LibDQt/LibDQt.pro
@@ -46,6 +46,7 @@ HEADERS += ../src/Actor/Player.h \
../src/Level/Layer.h \
SOURCES += ../src/Actor/Player.cpp \
../src/Global/Globals.cpp \
+ ../src/Global/Constants.cpp \
../src/IO/Input.cpp \
../src/Main/main.cpp \
../src/Main/LGLXWindow.cpp \
diff --git a/src/Actor/Player.h b/src/Actor/Player.h
index 2205162..a3feb29 100644
--- a/src/Actor/Player.h
+++ b/src/Actor/Player.h
@@ -30,6 +30,9 @@ public:
void ProcessEvents(void);
+ int GetX() { return x; }
+ int GetY() { return y; }
+
private:
float x;
float y;
diff --git a/src/Global/Constants.cpp b/src/Global/Constants.cpp
new file mode 100644
index 0000000..fe1d368
--- /dev/null
+++ b/src/Global/Constants.cpp
@@ -0,0 +1,10 @@
+#include "Constants.h"
+
+const int WINDOW_WIDTH = 800;
+const int WINDOW_HEIGHT = 600;
+const int WINDOW_BPP = 16;
+const int WINDOW_FULLSCREEN = 0;
+
+const SDL_VideoInfo* info = NULL;
+
+int flags = 0;
diff --git a/src/Global/Constants.h b/src/Global/Constants.h
index e0d1ac1..55130f2 100644
--- a/src/Global/Constants.h
+++ b/src/Global/Constants.h
@@ -1,11 +1,11 @@
#pragma once
#include
-const int WINDOW_WIDTH = 800;
-const int WINDOW_HEIGHT = 600;
-const int WINDOW_BPP = 16;
-const int WINDOW_FULLSCREEN = false;
+extern const int WINDOW_WIDTH;
+extern const int WINDOW_HEIGHT;
+extern const int WINDOW_BPP;
+extern const int WINDOW_FULLSCREEN;
-const SDL_VideoInfo* info = NULL;
+extern const SDL_VideoInfo* info;
-int flags = 0;
+extern int flags;
diff --git a/src/Level/Layer.cpp b/src/Level/Layer.cpp
index 30eaa9d..fba8462 100644
--- a/src/Level/Layer.cpp
+++ b/src/Level/Layer.cpp
@@ -1,5 +1,6 @@
#include "Layer.h"
#include "Tileset.h"
+#include "../Global/Constants.h"
Layer::Layer(int width, int height, int tileWidth, int tileHeight) {
_width = width;
@@ -20,7 +21,15 @@ void Layer::Update(float dt) {
}
}
-void Layer::Draw() {
+void Layer::Draw(int xOffset, int yOffset) {
+ int xOffsetTiles = xOffset / _width;
+ int yOffsetTiles = yOffset / _height;
+
+ int minX = std::max(0, xOffsetTiles - 1);
+ int maxX = std::min(_width, xOffsetTiles + (WINDOW_WIDTH / (int)_tileWidth) + 1);
+ int minY = std::max(0, yOffsetTiles - 1);
+ int maxY = std::min(_height, yOffsetTiles + (WINDOW_HEIGHT / (int)_tileHeight) + 1);
+
for(int x = 0; x < _width; x++) {
for(int y = 0; y < _height; y++) {
MapTile& tile = GetTile(x, y);
diff --git a/src/Level/Layer.h b/src/Level/Layer.h
index 1b13508..96b9417 100644
--- a/src/Level/Layer.h
+++ b/src/Level/Layer.h
@@ -8,7 +8,7 @@ public:
~Layer();
void Update(float dt);
- void Draw();
+ void Draw(int xOffset, int yOffset);
int GetWidth() const { return _width; }
int GetHeight() const { return _height; }
diff --git a/src/Level/Level.cpp b/src/Level/Level.cpp
index fc72fec..057cb2f 100644
--- a/src/Level/Level.cpp
+++ b/src/Level/Level.cpp
@@ -1,4 +1,5 @@
#include