diff --git a/src/Actor/Player.cpp b/src/Actor/Player.cpp index d3550ab..f8b5808 100644 --- a/src/Actor/Player.cpp +++ b/src/Actor/Player.cpp @@ -40,3 +40,6 @@ void Player::ProcessEvents(void) { _player->SetX(x); } } + +int Player::GetWidth() { return _player->GetWidth(); } +int Player::GetHeight() { return _player->GetWidth(); } \ No newline at end of file diff --git a/src/Actor/Player.h b/src/Actor/Player.h index 184e67d..482a85e 100644 --- a/src/Actor/Player.h +++ b/src/Actor/Player.h @@ -18,6 +18,8 @@ public: int GetX() { return x; } int GetY() { return y; } + int GetWidth(); + int GetHeight(); private: float x; diff --git a/src/Level/Level.h b/src/Level/Level.h index fe9d4e2..33070be 100644 --- a/src/Level/Level.h +++ b/src/Level/Level.h @@ -18,6 +18,8 @@ public: int GetWidth() const { return _width; } int GetHeight() const { return _height; } + int GetTileWidth() const { return _tileWidth; } + int GetTileHeight() const { return _tileHeight; } private: int _width; diff --git a/src/Main/Game.cpp b/src/Main/Game.cpp index d0180ba..4457730 100644 --- a/src/Main/Game.cpp +++ b/src/Main/Game.cpp @@ -2,10 +2,13 @@ #include #endif +#include + #include #include #include "../Global/Globals.h" +#include "../Global/Constants.h" #include "../System/Debug.h" #include "../Sprite/Sprite.h" #include "../Texture/Texture.h" @@ -52,10 +55,24 @@ void Game::Render(void) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - glTranslatef(-(_player->GetX() - 256), -(_player->GetY() - 128), 0.0f); + float windowCenterX = ((float)WINDOW_WIDTH / 2.0f) - ((float)_player->GetWidth() / 2.0f); + float windowCenterY = ((float)WINDOW_HEIGHT / 2.0f) - ((float)_player->GetHeight() / 2.0f); + + float xOffset = _player->GetX() - windowCenterX; + float yOffset = _player->GetY() - windowCenterY; + + float maxXOffset = (_level->GetWidth() * _level->GetTileWidth()) - (float)WINDOW_WIDTH; + float maxYOffset = (_level->GetHeight() * _level->GetTileHeight()) - (float)WINDOW_HEIGHT; + + if(xOffset < 0.0f) xOffset = 0.0f; + if(yOffset < 0.0f) yOffset = 0.0f; + if(xOffset > maxXOffset) xOffset = maxXOffset; + if(yOffset > maxYOffset) yOffset = maxYOffset; + + glTranslatef(-xOffset, -yOffset, 0.0f); // Render our shit.. - _level->Draw(_player->GetX() - 256, _player->GetY() - 128); + _level->Draw(xOffset, yOffset); _player->Render(); glPopMatrix();