camera controller
This commit is contained in:
parent
a1f8e26d9a
commit
83e312894b
|
@ -18,5 +18,4 @@ public:
|
||||||
private:
|
private:
|
||||||
bool mb_isOpen = false;
|
bool mb_isOpen = false;
|
||||||
Map m_currentMap;
|
Map m_currentMap;
|
||||||
SDL_Rect m_viewport;
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
struct GlobalState {
|
struct GlobalState {
|
||||||
SDL_Window *window;
|
SDL_Window *window;
|
||||||
SDL_Renderer *renderer;
|
SDL_Renderer *renderer;
|
||||||
|
SDL_Rect camera;
|
||||||
PPlayer player;
|
PPlayer player;
|
||||||
PhoenixAssets assets;
|
PhoenixAssets assets;
|
||||||
int scale = 20;
|
int scale = 20;
|
||||||
|
|
|
@ -2,7 +2,7 @@ MAPNAME DMSCALE
|
||||||
MAPVERS 1
|
MAPVERS 1
|
||||||
MAPAUTH Interfiber
|
MAPAUTH Interfiber
|
||||||
MAPSIZE 10x10
|
MAPSIZE 10x10
|
||||||
MAPSCAL 5x5
|
MAPSCAL 2x2
|
||||||
MAP
|
MAP
|
||||||
TILE WALL
|
TILE WALL
|
||||||
TILE FLOOR
|
TILE FLOOR
|
||||||
|
|
|
@ -34,13 +34,14 @@ PhoenixGame::PhoenixGame() {
|
||||||
PRunBoostrap();
|
PRunBoostrap();
|
||||||
|
|
||||||
m_currentMap = PLoadMapFromFile("maps/dm_scale.map");
|
m_currentMap = PLoadMapFromFile("maps/dm_scale.map");
|
||||||
m_viewport = {0, 0, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2};
|
|
||||||
|
state.camera.x = 0;
|
||||||
|
state.camera.y = 0;
|
||||||
|
state.camera.w = SCREEN_WIDTH;
|
||||||
|
state.camera.h = SCREEN_HEIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhoenixGame::present() {
|
void PhoenixGame::present() { SDL_RenderPresent(state.renderer); }
|
||||||
SDL_RenderSetViewport(state.renderer, &m_viewport);
|
|
||||||
SDL_RenderPresent(state.renderer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PhoenixGame::render() {
|
void PhoenixGame::render() {
|
||||||
|
|
||||||
|
@ -90,6 +91,11 @@ void PhoenixGame::run() {
|
||||||
state.player.x += 5;
|
state.player.x += 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
state.camera.x =
|
||||||
|
state.player.x - ((SCREEN_WIDTH / m_currentMap.mapScaleX) / 2);
|
||||||
|
state.camera.y =
|
||||||
|
state.player.y - ((SCREEN_HEIGHT / m_currentMap.mapScaleY) / 2);
|
||||||
|
|
||||||
// Rendering code
|
// Rendering code
|
||||||
|
|
||||||
render();
|
render();
|
||||||
|
|
|
@ -25,8 +25,8 @@ void PDestroyTexture(PhoenixTexture *texture) {
|
||||||
|
|
||||||
void PRenderTexture(PhoenixTexture *texture, int x, int y) {
|
void PRenderTexture(PhoenixTexture *texture, int x, int y) {
|
||||||
SDL_Rect dstRect{};
|
SDL_Rect dstRect{};
|
||||||
dstRect.x = x;
|
dstRect.x = x - state.camera.x;
|
||||||
dstRect.y = y;
|
dstRect.y = y - state.camera.y;
|
||||||
dstRect.w = TEXTURE_WIDTH;
|
dstRect.w = TEXTURE_WIDTH;
|
||||||
dstRect.h = TEXTURE_HEIGHT;
|
dstRect.h = TEXTURE_HEIGHT;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue