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