aboutsummaryrefslogtreecommitdiff
path: root/include/graphics.hpp
blob: 5f274a31cd3f6d800b47c2d007fd8f9d8b725e81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef GRAPHICS_HPP
# define GRAPHICS_HPP

#include <iostream>
#include <string>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "game.hpp"

class Graphics
{
public:
    Graphics(Game &game, std::string title, int width, int height);
    ~Graphics();

    void update();
    bool isRunning() const;

private:
    bool         m_running;
    Game         &m_game;
    std::string  m_title;
    int          m_width;
    int          m_height;
    SDL_Renderer *m_renderer;
    SDL_Window   *m_window;
    SDL_Texture  *m_wallTex;
    SDL_Texture  *m_crateTex;
    SDL_Texture  *m_crateSolvedTex;
    SDL_Texture  *m_payloadTex;
    SDL_Texture  *m_playerUpTex;
    SDL_Texture  *m_playerDownTex;
    SDL_Texture  *m_playerLeftTex;
    SDL_Texture  *m_playerRightTex;

    void        drawGame();
    void        drawCell(Game::Cell cell, int y, int x);
    void        drawPlayer();
    void        handleEvent();
    SDL_Texture *loadImage(std::string filename);
    void        putImage(SDL_Texture *tex, SDL_Rect *destRect);
    void        error() const;
};

#endif