2020-11-27 13:10:09 +00:00
|
|
|
#ifndef PACMAN_GAMEWINDOW_H
|
|
|
|
#define PACMAN_GAMEWINDOW_H
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
|
|
|
|
struct SDL_Window_Deleter {
|
|
|
|
void operator()(SDL_Window * window) {
|
|
|
|
SDL_DestroyWindow(window);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SDL_Renderer_Deleter {
|
|
|
|
void operator()(SDL_Renderer * renderer) {
|
|
|
|
SDL_DestroyRenderer(renderer);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SDL_Surface_Deleter {
|
|
|
|
void operator()(SDL_Surface * surface) {
|
|
|
|
SDL_FreeSurface(surface);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SDL_Texture_Deleter {
|
|
|
|
void operator()(SDL_Texture * texture) {
|
|
|
|
SDL_DestroyTexture(texture);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class PacMan;
|
2020-11-28 13:10:25 +00:00
|
|
|
class Pellets;
|
|
|
|
class Position;
|
|
|
|
class SuperPellets;
|
2020-11-27 13:10:09 +00:00
|
|
|
|
|
|
|
class GameWindow {
|
|
|
|
public:
|
|
|
|
explicit GameWindow(int width, int height);
|
2020-11-27 16:16:42 +00:00
|
|
|
|
2020-11-28 13:10:25 +00:00
|
|
|
void update(const PacMan & pacMan, const Pellets & pellets, const SuperPellets & superPellets);
|
2020-11-27 13:10:09 +00:00
|
|
|
|
|
|
|
private:
|
2020-11-27 15:44:06 +00:00
|
|
|
static const int16_t SCALE_FACTOR = 1;
|
2020-11-27 13:10:09 +00:00
|
|
|
std::unique_ptr<SDL_Window, SDL_Window_Deleter> window;
|
|
|
|
std::unique_ptr<SDL_Renderer, SDL_Renderer_Deleter> renderer;
|
|
|
|
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;
|
2020-11-27 16:16:42 +00:00
|
|
|
|
2020-11-27 13:10:09 +00:00
|
|
|
SDL_Window * createWindow(int width, int height);
|
2020-11-27 16:16:42 +00:00
|
|
|
|
2020-11-27 13:10:09 +00:00
|
|
|
SDL_Renderer * createRenderer(SDL_Window * window);
|
2020-11-27 16:16:42 +00:00
|
|
|
|
2020-11-27 13:10:09 +00:00
|
|
|
void createWindowSurface(SDL_Window * sdl_window);
|
2020-11-27 16:16:42 +00:00
|
|
|
|
2020-11-27 13:10:09 +00:00
|
|
|
static void initSDL();
|
2020-11-27 16:16:42 +00:00
|
|
|
|
2020-11-27 13:10:09 +00:00
|
|
|
static void initSDLImage();
|
2020-11-27 16:16:42 +00:00
|
|
|
|
2020-11-27 13:10:09 +00:00
|
|
|
static void setDrawColor(SDL_Renderer * sdl_renderer);
|
2020-11-27 16:16:42 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2020-11-27 13:10:09 +00:00
|
|
|
void renderMaze() const;
|
2020-11-27 16:16:42 +00:00
|
|
|
|
2020-11-27 13:10:09 +00:00
|
|
|
void renderPacMan(const PacMan & pac_man) const;
|
2020-11-27 16:16:42 +00:00
|
|
|
|
2020-11-28 13:10:25 +00:00
|
|
|
void renderPellets(const Pellets & pellets) const;
|
2020-11-27 16:16:42 +00:00
|
|
|
|
2020-11-28 13:10:25 +00:00
|
|
|
void renderSuperPellets(const SuperPellets & superPellets) const;
|
2020-11-27 16:16:42 +00:00
|
|
|
|
2020-11-27 13:10:09 +00:00
|
|
|
static SDL_Rect targetRect(const Position & position, int pixel_increase);
|
2020-11-27 16:16:42 +00:00
|
|
|
|
2020-11-27 13:10:09 +00:00
|
|
|
void renderTexture(SDL_Texture * texture, SDL_Rect * texture_rect, SDL_Rect * target_rect) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif //PACMAN_GAMEWINDOW_H
|