-
Notifications
You must be signed in to change notification settings - Fork 1
/
Object.h
66 lines (53 loc) · 1.81 KB
/
Object.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// Created by zr on 23-2-8.
//
#ifndef TANK_TROUBLE_OBJECT_H
#define TANK_TROUBLE_OBJECT_H
#include "util/Vec.h"
#include "defs.h"
#include <cairomm/context.h>
#include <vector>
#include <cfloat>
#define MOVING_STATIONARY 1
#define MOVING_FORWARD 2
#define MOVING_BACKWARD 4
#define ROTATING_CW 8
#define ROTATING_CCW 16
namespace TankTrouble
{
enum ObjMovingStep {TANK_MOVING_STEP = 1, SHELL_MOVING_STEP = 1};
enum ObjType {OBJ_TANK, OBJ_SHELL};
typedef uint8_t MovingStatus;
class Object {
public:
struct PosInfo
{
PosInfo(const util::Vec& p, double a): pos(p), angle(a){}
PosInfo& operator=(const PosInfo& info) = default;
bool operator==(const PosInfo& info) const {return (pos == info.pos && angle == info.angle);}
PosInfo(): PosInfo(util::Vec(0.0, 0.0), 0){}
static PosInfo invalid() {return PosInfo{util::Vec(DBL_MAX, DBL_MAX), DBL_MAX};}
[[nodiscard]] bool isValid() const
{return (pos.x() != DBL_MAX && pos.y() != DBL_MAX && angle != DBL_MAX);}
util::Vec pos;
double angle;
};
Object(const util::Vec& pos, double angle, Color c, int id);
virtual void draw(const Cairo::RefPtr<Cairo::Context>& cr) = 0;
virtual PosInfo getNextPosition(int movingStep, int rotationStep) = 0;
virtual void moveToNextPosition() = 0;
void resetNextPosition(const PosInfo& next);
PosInfo getCurrentPosition();
virtual ObjType type() = 0;
[[nodiscard]] int id() const;
[[nodiscard]] int getMovingStatus() const;
virtual ~Object() = default;
protected:
PosInfo posInfo;
PosInfo nextPos;
MovingStatus movingStatus;
Color color;
int _id;
};
}
#endif //TANK_TROUBLE_OBJECT_H