From 31211538aad1211b66f62363e61d8512068dfb1e Mon Sep 17 00:00:00 2001 From: Patricia Aas Date: Fri, 27 Nov 2020 16:44:06 +0100 Subject: [PATCH] Make it possible to scale the board by a factor --- pacman/src/Game.cpp | 2 +- pacman/src/GameWindow.cpp | 10 +++++----- pacman/src/GameWindow.h | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pacman/src/Game.cpp b/pacman/src/Game.cpp index eb01f99..d98368d 100644 --- a/pacman/src/Game.cpp +++ b/pacman/src/Game.cpp @@ -5,7 +5,7 @@ #include Game::Game() - : window(448*2, 496*2) { + : window(448, 496) { } auto Game::now() { diff --git a/pacman/src/GameWindow.cpp b/pacman/src/GameWindow.cpp index 62f339a..d025758 100644 --- a/pacman/src/GameWindow.cpp +++ b/pacman/src/GameWindow.cpp @@ -8,7 +8,7 @@ GameWindow::GameWindow(int width, int height) { initSDL(); initSDLImage(); - auto sdl_window = createWindow(width, height); + auto sdl_window = createWindow(width*SCALE_FACTOR, height*SCALE_FACTOR); auto sdl_renderer = createRenderer(sdl_window); createWindowSurface(sdl_window); setDrawColor(sdl_renderer); @@ -39,7 +39,7 @@ void GameWindow::renderSuperPellets(Board & board) const { SDL_Rect sprite_rect = board.superPelletSprite(); std::vector superPelletPositions = board.superPelletPositions(); for (const auto & pos : superPelletPositions) { - SDL_Rect maze_rect = targetRect({ float_t(pos.x), float_t(pos.y) }, 16); + SDL_Rect maze_rect = targetRect({ float_t(pos.x), float_t(pos.y) }, 8*SCALE_FACTOR); renderTexture(sprite_texture.get(), &sprite_rect, &maze_rect); } } @@ -48,20 +48,20 @@ void GameWindow::renderPellets(Board & board) const { SDL_Rect sprite_rect = board.pelletSprite(); std::vector pelletPositions = board.pelletPositions(); for (const auto & pos : pelletPositions) { - SDL_Rect maze_rect = targetRect({ float_t(pos.x), float_t(pos.y) }, 16); + SDL_Rect maze_rect = targetRect({ float_t(pos.x), float_t(pos.y) }, 8*SCALE_FACTOR); renderTexture(sprite_texture.get(), &sprite_rect, &maze_rect); } } void GameWindow::renderPacMan(const PacMan & pac_man) const { Position maze_position = pac_man.currentPosition(); - SDL_Rect maze_rect = targetRect(maze_position, 16); + SDL_Rect maze_rect = targetRect(maze_position, 8*SCALE_FACTOR); SDL_Rect sprite_rect = pac_man.currentSprite(); renderTexture(sprite_texture.get(), &sprite_rect, &maze_rect); } SDL_Rect GameWindow::targetRect(const Position & position, int pixel_increase) { - int pixels = 32; + int pixels = 16*SCALE_FACTOR; int displacement = pixel_increase / 2; return { int(pixels * position.x) - displacement, diff --git a/pacman/src/GameWindow.h b/pacman/src/GameWindow.h index 65bc730..b747466 100644 --- a/pacman/src/GameWindow.h +++ b/pacman/src/GameWindow.h @@ -39,6 +39,7 @@ public: void update(const PacMan & pacMan, Board board); private: + static const int16_t SCALE_FACTOR = 1; std::unique_ptr window; std::unique_ptr renderer; std::unique_ptr window_surface;