aboutsummaryrefslogtreecommitdiff
path: root/src/games/tetris/Tetromino.hpp
blob: 86821b95b85570c7ce6dca7c9257d90a0fae421e (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
64
#pragma once

#include <common/defs.hpp>
#include <common/math.hpp>
#include <games/tetris/Board.hpp>


class Tetromino {
public:
    enum Id : uint8_t {
        o_piece,
        s_piece,
        z_piece,
        t_piece,
        l_piece,
        j_piece,
        i_piece,
        id_count,
        id_none,
    };

    enum Rotation {
        rotate_clockwise = 1,
        rotate_counter_clockwise = 3
    };

    enum Direction {
        left = -1,
        right = 1
    };


public:
    explicit Tetromino(uint16_t* board_bitmap);
    void Reset(Id id);

    Id GetId();
    BoardPos GetPos();
    int32_t GetOri();
    void GetBitmap(uint16_t* bitmap);

    bool IsCollisionWithBoard();
    bool MaybeMoveDown();
    void MaybeMoveHorizontally(Direction direction);
    void MaybeRotate(Rotation rotation);

    void Draw();


public:
    static Id GenerateRandomId();
    static bool IsCollisionWithBoard(Id id, BoardPos pos, int32_t ori, uint16_t *board_bitmap);
    static void GetBitmap(Id id, BoardPos pos, int32_t ori, uint16_t *bitmap);
    static Color GetColor(Id id);
    static void Draw(Id id, int32_t ori, V2F32 pos, float scale);


private:
    Id m_id;
    BoardPos m_pos;
    int32_t m_ori;
    uint16_t* m_board_bitmap;
};