[Fix] Scrolling is now done.

This commit is contained in:
Tamir Atias 2012-04-12 04:09:03 +03:00
parent 06ee0fbdda
commit c783228588
4 changed files with 26 additions and 2 deletions

View File

@ -40,3 +40,6 @@ void Player::ProcessEvents(void) {
_player->SetX(x);
}
}
int Player::GetWidth() { return _player->GetWidth(); }
int Player::GetHeight() { return _player->GetWidth(); }

View File

@ -18,6 +18,8 @@ public:
int GetX() { return x; }
int GetY() { return y; }
int GetWidth();
int GetHeight();
private:
float x;

View File

@ -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;

View File

@ -2,10 +2,13 @@
#include <windows.h>
#endif
#include <algorithm>
#include <GL/gl.h>
#include <GL/glu.h>
#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();