[Add] Initial map scrolling.
This commit is contained in:
parent
2de0088860
commit
deb832f7e2
@ -124,6 +124,7 @@
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\Actor\Player.cpp" />
|
||||
<ClCompile Include="..\..\src\Collision\AABB.cpp" />
|
||||
<ClCompile Include="..\..\src\Global\Constants.cpp" />
|
||||
<ClCompile Include="..\..\src\Global\Globals.cpp" />
|
||||
<ClCompile Include="..\..\src\IO\Input.cpp" />
|
||||
<ClCompile Include="..\..\src\Level\Layer.cpp" />
|
||||
|
@ -236,5 +236,8 @@
|
||||
<ClCompile Include="..\..\src\Level\Tileset.cpp">
|
||||
<Filter>Level</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Global\Constants.cpp">
|
||||
<Filter>Global</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -46,6 +46,7 @@ HEADERS += ../src/Actor/Player.h \
|
||||
../src/TMXParser/TmxUtil.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 \
|
||||
|
@ -16,6 +16,9 @@ public:
|
||||
void Render(void);
|
||||
void ProcessEvents(void);
|
||||
|
||||
int GetX() { return x; }
|
||||
int GetY() { return y; }
|
||||
|
||||
private:
|
||||
float x;
|
||||
float y;
|
||||
|
10
src/Global/Constants.cpp
Normal file
10
src/Global/Constants.cpp
Normal file
@ -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;
|
@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
#include <SDL/SDL.h>
|
||||
|
||||
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;
|
||||
|
@ -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);
|
||||
|
@ -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; }
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
#include "Level.h"
|
||||
#include "Layer.h"
|
||||
#include "Tileset.h"
|
||||
@ -78,8 +79,8 @@ bool Level::Load(const std::string& filename) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void Level::Draw() {
|
||||
void Level::Draw(int xOffset, int yOffset) {
|
||||
for(std::list<Layer*>::iterator i = _layers.begin(); i != _layers.end(); ++i) {
|
||||
(*i)->Draw();
|
||||
(*i)->Draw(xOffset, yOffset);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ public:
|
||||
bool Load(const std::string& filename);
|
||||
|
||||
void Update(float dt);
|
||||
void Draw();
|
||||
void Draw(int xOffset, int yOffset);
|
||||
|
||||
int GetWidth() const { return _width; }
|
||||
int GetHeight() const { return _height; }
|
||||
|
@ -52,9 +52,13 @@ void Game::Render(void) {
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
glTranslatef(-(_player->GetX() - 256), -(_player->GetY() - 128), 0.0f);
|
||||
|
||||
// Render our shit..
|
||||
_level->Draw();
|
||||
_level->Draw(_player->GetX() - 256, _player->GetY() - 128);
|
||||
_player->Render();
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void Game::Shutdown(void) {
|
||||
|
Loading…
Reference in New Issue
Block a user