summaryrefslogtreecommitdiff
path: root/src/game.h
blob: 022a7339ad52847f5de34b2710d4444c769a3807 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef GAME_H
#define GAME_H
#include "renderer.h"
#include "piece.h"
#include "point.h"
#include "texture.h"

class GameState{

    private:
        bool closed_;
        bool paused_;
        int timeAdvance_;
        int timeCounterAdvance_;
        int timeLevelUp_;
        int timeCounterLevelUp_;

        Renderer* renderer_;

        enum class Direction{
            NONE,
            LEFT,
            RIGHT
        };
        Direction xdirection_;
        int yspeed_;

        static const int SQUARE_SIZE = 16;
        static const int GRID_WIDTH  = 16;
        static const int GRID_HEIGHT = 32;


        int grid [GRID_HEIGHT][GRID_WIDTH];
        Piece piece_;

        float scale_;

        Texture blockTexture_;

    public:
        GameState(Renderer* renderer, float scale);
        void close();
        void resume();
        void pause();
        bool isClosed();
        bool isPaused();
        void update(unsigned int dt);
        void render();

        void newPiece();
        void clearLines();
        void finishGame();
        bool cellIsEmpty(Point* p);

        void pressRotate();
        void pressDown();
        void releaseDown();
        void pressLeft();
        void pressRight();
        void pressSpace();
};

#endif