2021-06-16 10:52:04 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-09-06 13:38:40 +00:00
|
|
|
#include <SFML/Graphics.hpp>
|
|
|
|
|
2021-07-08 14:57:18 +00:00
|
|
|
#include "GameState.hpp"
|
2021-06-20 16:52:34 +00:00
|
|
|
#include "Position.hpp"
|
2021-06-24 08:32:54 +00:00
|
|
|
#include "Score.hpp"
|
2021-06-20 16:52:34 +00:00
|
|
|
#include <optional>
|
2021-06-16 10:52:04 +00:00
|
|
|
|
2021-07-05 12:10:01 +00:00
|
|
|
namespace pacman {
|
|
|
|
|
2021-09-06 13:38:40 +00:00
|
|
|
using Rect = sf::Rect<int>;
|
|
|
|
using Sprite = sf::Sprite;
|
|
|
|
|
2021-06-16 10:52:04 +00:00
|
|
|
class Canvas {
|
|
|
|
public:
|
|
|
|
Canvas();
|
2021-07-08 14:57:18 +00:00
|
|
|
void update(const GameState & gameState, const Score & score);
|
2021-06-20 16:52:34 +00:00
|
|
|
std::optional<sf::Event> pollEvent();
|
2021-06-16 10:52:04 +00:00
|
|
|
|
|
|
|
private:
|
2021-07-06 20:16:11 +00:00
|
|
|
static constexpr uint16_t LEFT_MARGIN = 40 * 2;
|
2021-07-08 14:57:18 +00:00
|
|
|
static constexpr uint16_t TOP_MARGIN = 40 * 2;
|
2021-07-06 20:16:11 +00:00
|
|
|
static constexpr uint16_t BOTTOM_MARGIN = 40 * 2;
|
2021-07-07 09:33:22 +00:00
|
|
|
static constexpr uint16_t MAZE_WIDTH = 448;
|
|
|
|
static constexpr uint16_t MAZE_HEIGHT = 496;
|
|
|
|
static constexpr uint16_t MAZE_SCALE_UP = 2;
|
2021-07-08 14:57:18 +00:00
|
|
|
static constexpr uint16_t TARGET_MAZE_WIDTH = 448 * MAZE_SCALE_UP;
|
2021-07-07 09:33:22 +00:00
|
|
|
static constexpr uint16_t TARGET_MAZE_HEIGHT = 496 * MAZE_SCALE_UP;
|
2021-07-06 20:16:11 +00:00
|
|
|
static constexpr uint16_t SCORE_WIDTH = 200 * 2;
|
2021-07-07 09:33:22 +00:00
|
|
|
static constexpr uint16_t SPRITE_WIDTH = 32;
|
|
|
|
static constexpr uint16_t SPRITE_HEIGHT = 32;
|
2021-06-16 10:52:04 +00:00
|
|
|
|
2021-06-20 16:52:34 +00:00
|
|
|
void clear();
|
|
|
|
void render();
|
|
|
|
void renderMaze();
|
|
|
|
void renderPacMan(const PacMan & pac_man);
|
2021-06-24 11:32:52 +00:00
|
|
|
void renderGhost(const Ghost & ghost);
|
2021-06-20 16:52:34 +00:00
|
|
|
void renderPellets(const Pellets & pellets);
|
|
|
|
void renderSuperPellets(const SuperPellets & superPellets);
|
2021-06-22 10:00:29 +00:00
|
|
|
void renderSprite(Sprite sprite, Position pos);
|
2021-06-20 16:52:34 +00:00
|
|
|
|
2021-06-16 13:18:00 +00:00
|
|
|
void renderScore(int score);
|
2021-06-24 08:44:13 +00:00
|
|
|
void renderLives(int lives);
|
2021-06-16 10:52:04 +00:00
|
|
|
|
2021-07-07 09:33:22 +00:00
|
|
|
static Rect viewDimensions();
|
2021-06-22 10:52:02 +00:00
|
|
|
static sf::Texture loadTexture(std::string_view path);
|
|
|
|
static sf::Font loadFont(std::string_view path);
|
2021-06-20 16:52:34 +00:00
|
|
|
|
2021-07-05 09:46:49 +00:00
|
|
|
Sprite getSprite(GridPosition rect) const;
|
2021-06-20 16:52:34 +00:00
|
|
|
|
|
|
|
sf::RenderWindow window;
|
2021-07-07 09:33:22 +00:00
|
|
|
sf::View view;
|
2021-06-20 16:52:34 +00:00
|
|
|
sf::Texture maze_texture;
|
|
|
|
sf::Texture sprites_texture;
|
|
|
|
sf::Font game_font;
|
2021-06-16 10:52:04 +00:00
|
|
|
};
|
2021-07-05 12:10:01 +00:00
|
|
|
|
|
|
|
} // namespace pacman
|