blob: 4eec9e73e2cbab7155df354178d17fe9ec5716f2 (
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
#include <QGraphicsItem>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QPointF>
#include <QPushButton>
#include <QTime>
#include <QTimeLine>
class MazeScene;
class View : public QGraphicsView
{
Q_OBJECT
public:
View();
void resizeEvent(QResizeEvent *event);
};
class WallItem : public QGraphicsItem
{
public:
WallItem(MazeScene *scene, const QPointF &a, const QPointF &b, int type);
QPointF a() const { return m_a; }
QPointF b() const { return m_b; }
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
QGraphicsProxyWidget *childItem() const
{
return m_childItem;
}
int type() const { return m_type; }
void setDepths(qreal za, qreal zb);
void setAnimationTime(qreal time);
private:
QPointF m_a;
QPointF m_b;
QGraphicsProxyWidget *m_childItem;
QGraphicsRectItem *m_shadowItem;
int m_type;
QRectF m_targetRect;
};
class MazeScene : public QGraphicsScene
{
Q_OBJECT
public:
MazeScene(const char *map, int width, int height);
void addWall(const QPointF &a, const QPointF &b, int type);
void drawBackground(QPainter *painter, const QRectF &rect);
protected:
void keyPressEvent(QKeyEvent *event);
void keyReleaseEvent(QKeyEvent *event);
bool handleKey(int key, bool pressed);
public slots:
void move();
void toggleRenderer();
void toggleDoors();
private slots:
void moveDoors(qreal value);
private:
QVector<WallItem *> m_walls;
QVector<WallItem *> m_doors;
QVector<QGraphicsItem *> m_floorTiles;
QVector<QPushButton *> m_buttons;
QPointF m_cameraPos;
qreal m_cameraAngle;
qreal m_walkingVelocity;
qreal m_turningVelocity;
QTime m_time;
QTimeLine *m_doorAnimation;
long m_simulationTime;
long m_walkTime;
bool m_dirty;
int m_width;
int m_height;
};
|