Reformat most
This commit is contained in:
parent
e572f2a93a
commit
c34a2b730d
10 changed files with 132 additions and 84 deletions
16
.clang-format
Normal file
16
.clang-format
Normal file
|
@ -0,0 +1,16 @@
|
|||
---
|
||||
BasedOnStyle: Mozilla
|
||||
AllowAllConstructorInitializersOnNextLine: false
|
||||
AllowShortFunctionsOnASingleLine: Inline
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
BreakBeforeBraces: Custom
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakInheritanceList: BeforeColon
|
||||
ColumnLimit: '0'
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
NamespaceIndentation: All
|
||||
PenaltyReturnTypeOnItsOwnLine: '10000'
|
||||
PointerAlignment: Middle
|
||||
|
||||
...
|
|
@ -1,7 +1,7 @@
|
|||
from conans import ConanFile, CMake
|
||||
|
||||
class ConanDependencies(ConanFile):
|
||||
|
||||
class ConanDependencies(ConanFile):
|
||||
settings = "os", "compiler", "build_type", "arch"
|
||||
generators = "cmake", "cmake_find_package"
|
||||
default_options = {
|
||||
|
|
|
@ -67,7 +67,8 @@ bool Board::isWalkable(Position point, float_t position_delta, Direction directi
|
|||
case Direction::DOWN:
|
||||
return board_state[int(point.y) + 1][int(point.x)] != 0;
|
||||
case Direction::NONE:
|
||||
default: return true;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ public:
|
|||
std::vector<SDL_Point> superPelletPositions();
|
||||
|
||||
private:
|
||||
uint8_t board_state[ROWS][COLUMNS];
|
||||
uint8_t board_state[ROWS][COLUMNS]{};
|
||||
const SDL_Rect super_pellet = {0 * 32, 9 * 32, 32, 32};
|
||||
const SDL_Rect pellet = {1 * 32, 9 * 32, 32, 32};
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
class Game {
|
||||
public:
|
||||
Game();
|
||||
|
||||
void run();
|
||||
|
||||
private:
|
||||
|
@ -17,7 +18,9 @@ private:
|
|||
Board board;
|
||||
|
||||
static void processEvents(InputState & inputState);
|
||||
|
||||
static void keyToggle(const SDL_Event & event, InputState & inputState, bool on);
|
||||
|
||||
[[nodiscard]] static auto now();
|
||||
};
|
||||
|
||||
|
|
|
@ -125,12 +125,14 @@ void GameWindow::setDrawColor(SDL_Renderer * sdl_renderer) {
|
|||
exitFailure("Failed to set renderer color");
|
||||
}
|
||||
|
||||
std::unique_ptr<SDL_Texture, SDL_Texture_Deleter> GameWindow::loadTexture(SDL_Renderer * sdl_renderer, const std::string& path) {
|
||||
std::unique_ptr<SDL_Texture, SDL_Texture_Deleter>
|
||||
GameWindow::loadTexture(SDL_Renderer * sdl_renderer, const std::string & path) {
|
||||
auto surface = std::unique_ptr<SDL_Surface, SDL_Surface_Deleter>(IMG_Load(path.c_str()));
|
||||
if (!surface)
|
||||
exitImgFailure("Failed to load image");
|
||||
|
||||
auto texture = std::unique_ptr<SDL_Texture, SDL_Texture_Deleter>(SDL_CreateTextureFromSurface(sdl_renderer, surface.get()));
|
||||
auto texture = std::unique_ptr<SDL_Texture, SDL_Texture_Deleter>(
|
||||
SDL_CreateTextureFromSurface(sdl_renderer, surface.get()));
|
||||
if (!texture)
|
||||
exitFailure("Failed to create texture from surface");
|
||||
return texture;
|
||||
|
|
|
@ -36,6 +36,7 @@ class PacMan;
|
|||
class GameWindow {
|
||||
public:
|
||||
explicit GameWindow(int width, int height);
|
||||
|
||||
void update(const PacMan & pacMan, Board board);
|
||||
|
||||
private:
|
||||
|
@ -45,21 +46,38 @@ private:
|
|||
std::unique_ptr<SDL_Surface, SDL_Surface_Deleter> window_surface;
|
||||
std::unique_ptr<SDL_Texture, SDL_Texture_Deleter> maze_texture;
|
||||
std::unique_ptr<SDL_Texture, SDL_Texture_Deleter> sprite_texture;
|
||||
|
||||
SDL_Window * createWindow(int width, int height);
|
||||
|
||||
SDL_Renderer * createRenderer(SDL_Window * window);
|
||||
|
||||
void createWindowSurface(SDL_Window * sdl_window);
|
||||
|
||||
static void initSDL();
|
||||
|
||||
static void initSDLImage();
|
||||
|
||||
static void setDrawColor(SDL_Renderer * sdl_renderer);
|
||||
|
||||
static void exitFailure(const std::string & message);
|
||||
|
||||
static void exitImgFailure(const std::string & message);
|
||||
static std::unique_ptr<SDL_Texture, SDL_Texture_Deleter> loadTexture(SDL_Renderer * sdl_renderer, const std::string& path);
|
||||
|
||||
static std::unique_ptr<SDL_Texture, SDL_Texture_Deleter>
|
||||
loadTexture(SDL_Renderer * sdl_renderer, const std::string & path);
|
||||
|
||||
void renderMaze() const;
|
||||
|
||||
void renderPacMan(const PacMan & pac_man) const;
|
||||
|
||||
void renderBoard(Board board);
|
||||
|
||||
void renderPellets(Board & board) const;
|
||||
|
||||
void renderSuperPellets(Board & board) const;
|
||||
|
||||
static SDL_Rect targetRect(const Position & position, int pixel_increase);
|
||||
|
||||
void renderTexture(SDL_Texture * texture, SDL_Rect * texture_rect, SDL_Rect * target_rect) const;
|
||||
};
|
||||
|
||||
|
|
|
@ -9,11 +9,16 @@ PacMan::PacMan() :
|
|||
|
||||
SDL_Rect PacMan::currentSprite() const {
|
||||
switch (direction) {
|
||||
case Direction::NONE: return closed;
|
||||
case Direction::LEFT: return left_animation[animation_position];
|
||||
case Direction::RIGHT: return right_animation[animation_position];
|
||||
case Direction::UP: return up_animation[animation_position];
|
||||
case Direction::DOWN: return down_animation[animation_position];
|
||||
case Direction::NONE:
|
||||
return closed;
|
||||
case Direction::LEFT:
|
||||
return left_animation[animation_position];
|
||||
case Direction::RIGHT:
|
||||
return right_animation[animation_position];
|
||||
case Direction::UP:
|
||||
return up_animation[animation_position];
|
||||
case Direction::DOWN:
|
||||
return down_animation[animation_position];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,5 +78,4 @@ void PacMan::updateMazePosition(std::chrono::milliseconds time_delta, const Boar
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,7 +12,9 @@
|
|||
class PacMan {
|
||||
public:
|
||||
PacMan();
|
||||
|
||||
[[nodiscard]] SDL_Rect currentSprite() const;
|
||||
|
||||
[[nodiscard]] Position currentPosition() const;
|
||||
|
||||
void update(std::chrono::milliseconds time_delta, InputState state, const Board & board);
|
||||
|
@ -39,7 +41,9 @@ private:
|
|||
float_t animation_position_delta = 0.0;
|
||||
|
||||
void setDirection(const InputState & state);
|
||||
|
||||
void updateAnimationPosition(std::chrono::milliseconds time_delta);
|
||||
|
||||
void updateMazePosition(std::chrono::milliseconds time_delta, const Board & board);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue