-
Notifications
You must be signed in to change notification settings - Fork 1
/
Block.h
45 lines (40 loc) · 1.2 KB
/
Block.h
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
//
// Created by zr on 23-2-17.
//
#ifndef TANK_TROUBLE_BLOCK_H
#define TANK_TROUBLE_BLOCK_H
#include "util/Vec.h"
#include <utility>
#include <cairomm/context.h>
namespace TankTrouble
{
class Block
{
public:
Block() = default;
Block(int id, const util::Vec& start, const util::Vec& end);
Block(bool isHorizon, const util::Vec& center);
void draw(const Cairo::RefPtr<Cairo::Context>& cr);
[[nodiscard]] bool isHorizon() const;
[[nodiscard]] util::Vec center() const;
[[nodiscard]] int height() const;
[[nodiscard]] int width() const;
[[nodiscard]] int id() const;
[[nodiscard]] util::Vec start() const;
[[nodiscard]] util::Vec end() const;
[[nodiscard]] std::pair<util::Vec, util::Vec> border(int n) const;
const static int BLOCK_WIDTH = 4;
private:
void calculate();
int _id;
util::Vec _center;
util::Vec tl, tr, bl, br;
bool horizon;
util::Vec _start, _end;
int _height;
int _width;
//计算碰撞位置的包围盒(顺序上下左右)
std::pair<util::Vec, util::Vec> _border[4];
};
}
#endif //TANK_TROUBLE_BLOCK_H