Make it possible to scale the board by a factor
This commit is contained in:
parent
b50085c345
commit
31211538aa
3 changed files with 7 additions and 6 deletions
|
@ -5,7 +5,7 @@
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
Game::Game()
|
Game::Game()
|
||||||
: window(448*2, 496*2) {
|
: window(448, 496) {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Game::now() {
|
auto Game::now() {
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
GameWindow::GameWindow(int width, int height) {
|
GameWindow::GameWindow(int width, int height) {
|
||||||
initSDL();
|
initSDL();
|
||||||
initSDLImage();
|
initSDLImage();
|
||||||
auto sdl_window = createWindow(width, height);
|
auto sdl_window = createWindow(width*SCALE_FACTOR, height*SCALE_FACTOR);
|
||||||
auto sdl_renderer = createRenderer(sdl_window);
|
auto sdl_renderer = createRenderer(sdl_window);
|
||||||
createWindowSurface(sdl_window);
|
createWindowSurface(sdl_window);
|
||||||
setDrawColor(sdl_renderer);
|
setDrawColor(sdl_renderer);
|
||||||
|
@ -39,7 +39,7 @@ void GameWindow::renderSuperPellets(Board & board) const {
|
||||||
SDL_Rect sprite_rect = board.superPelletSprite();
|
SDL_Rect sprite_rect = board.superPelletSprite();
|
||||||
std::vector<SDL_Point> superPelletPositions = board.superPelletPositions();
|
std::vector<SDL_Point> superPelletPositions = board.superPelletPositions();
|
||||||
for (const auto & pos : 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);
|
renderTexture(sprite_texture.get(), &sprite_rect, &maze_rect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,20 +48,20 @@ void GameWindow::renderPellets(Board & board) const {
|
||||||
SDL_Rect sprite_rect = board.pelletSprite();
|
SDL_Rect sprite_rect = board.pelletSprite();
|
||||||
std::vector<SDL_Point> pelletPositions = board.pelletPositions();
|
std::vector<SDL_Point> pelletPositions = board.pelletPositions();
|
||||||
for (const auto & pos : 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);
|
renderTexture(sprite_texture.get(), &sprite_rect, &maze_rect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameWindow::renderPacMan(const PacMan & pac_man) const {
|
void GameWindow::renderPacMan(const PacMan & pac_man) const {
|
||||||
Position maze_position = pac_man.currentPosition();
|
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();
|
SDL_Rect sprite_rect = pac_man.currentSprite();
|
||||||
renderTexture(sprite_texture.get(), &sprite_rect, &maze_rect);
|
renderTexture(sprite_texture.get(), &sprite_rect, &maze_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Rect GameWindow::targetRect(const Position & position, int pixel_increase) {
|
SDL_Rect GameWindow::targetRect(const Position & position, int pixel_increase) {
|
||||||
int pixels = 32;
|
int pixels = 16*SCALE_FACTOR;
|
||||||
int displacement = pixel_increase / 2;
|
int displacement = pixel_increase / 2;
|
||||||
return {
|
return {
|
||||||
int(pixels * position.x) - displacement,
|
int(pixels * position.x) - displacement,
|
||||||
|
|
|
@ -39,6 +39,7 @@ public:
|
||||||
void update(const PacMan & pacMan, Board board);
|
void update(const PacMan & pacMan, Board board);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static const int16_t SCALE_FACTOR = 1;
|
||||||
std::unique_ptr<SDL_Window, SDL_Window_Deleter> window;
|
std::unique_ptr<SDL_Window, SDL_Window_Deleter> window;
|
||||||
std::unique_ptr<SDL_Renderer, SDL_Renderer_Deleter> renderer;
|
std::unique_ptr<SDL_Renderer, SDL_Renderer_Deleter> renderer;
|
||||||
std::unique_ptr<SDL_Surface, SDL_Surface_Deleter> window_surface;
|
std::unique_ptr<SDL_Surface, SDL_Surface_Deleter> window_surface;
|
||||||
|
|
Loading…
Reference in a new issue