-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathobstacles.h
253 lines (216 loc) · 6.72 KB
/
obstacles.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*
Copyright (C) 2002-2005, Jason Katz-Brown <jasonkb@mit.edu>
Copyright 2010 Stefan Majewsky <majewsky@gmx.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef KOLF_OBSTACLES_H
#define KOLF_OBSTACLES_H
//NOTE: Only refactored stuff goes into this header.
#include <config.h>
#include "canvasitem.h"
#include "overlay.h"
#include <QPen>
class QCheckBox;
class QGridLayout;
namespace Kolf
{
class LineShape;
class RectShape;
class Bumper : public EllipticalCanvasItem
{
Q_OBJECT
public:
Bumper(QGraphicsItem* parent, b2World* world);
bool collision(Ball* ball) override;
protected:
Kolf::Overlay* createOverlay() override;
public Q_SLOTS:
void turnBumperOff();
};
class Wall : public QGraphicsLineItem, public CanvasItem
{
public:
Wall(QGraphicsItem* parent, b2World* world);
void load(KConfigGroup* cfgGroup) override;
void save(KConfigGroup* cfgGroup) override;
void setVisible(bool visible);
virtual void setLine(const QLineF& line);
void moveBy(double dx, double dy) override;
QPointF getPosition() const override;
protected:
Kolf::Overlay* createOverlay() override;
private:
Kolf::LineShape* m_shape;
};
class WallOverlay : public Kolf::Overlay
{
Q_OBJECT
public:
explicit WallOverlay(Kolf::Wall* wall);
void update() override;
private Q_SLOTS:
//interface to handles
void moveHandle(const QPointF& handleScenePos);
private:
Kolf::OverlayHandle* m_handle1;
Kolf::OverlayHandle* m_handle2;
};
//WARNING: WallIndex and WallFlag have to stay in sync like they are now!
enum WallIndex {
TopWallIndex = 0,
LeftWallIndex = 1,
RightWallIndex = 2,
BottomWallIndex = 3,
RectangleWallCount = 4
};
class RectangleItem : public Tagaro::SpriteObjectItem, public CanvasItem
{
Q_OBJECT
public:
RectangleItem(const QString& type, QGraphicsItem* parent, b2World* world);
~RectangleItem() override;
bool hasWall(Kolf::WallIndex index) const;
bool isWallAllowed(Kolf::WallIndex index) const;
void setWall(Kolf::WallIndex index, bool hasWall);
void setWallAllowed(Kolf::WallIndex index, bool wallAllowed);
void setSize(const QSizeF& size) override;
QPointF getPosition() const override;
void moveBy(double dx, double dy) override;
void setWallColor(const QColor& color);
void applyWallStyle(Kolf::Wall* wall, bool adjustPainting = true);
void load(KConfigGroup* group) override;
void save(KConfigGroup* group) override;
Config* config(QWidget* parent) override;
Q_SIGNALS:
void wallChanged(Kolf::WallIndex index, bool hasWall, bool wallAllowed);
protected:
Kolf::Overlay* createOverlay() override;
virtual void updateWallPosition();
private:
QPen m_wallPen;
QVector<bool> m_wallAllowed;
QVector<Kolf::Wall*> m_walls;
Kolf::RectShape* m_shape;
};
class RectangleOverlay : public Kolf::Overlay
{
Q_OBJECT
public:
explicit RectangleOverlay(Kolf::RectangleItem* item);
void update() override;
private Q_SLOTS:
//interface to handles
void moveHandle(const QPointF& handleScenePos);
private:
QList<Kolf::OverlayHandle*> m_handles;
};
class RectangleConfig : public Config
{
Q_OBJECT
public:
RectangleConfig(Kolf::RectangleItem* item, QWidget* parent);
protected Q_SLOTS:
void setWall(bool hasWall);
void wallChanged(Kolf::WallIndex index, bool hasWall, bool wallAllowed);
protected:
QGridLayout* m_layout;
QVector<QCheckBox*> m_wallCheckBoxes;
Kolf::RectangleItem* const m_item;
};
class Bridge : public Kolf::RectangleItem
{
public:
Bridge(QGraphicsItem* parent, b2World* world);
bool collision(Ball* ball) override;
};
class Floater : public Kolf::RectangleItem
{
Q_OBJECT
public:
Floater(QGraphicsItem* parent, b2World* world);
void editModeChanged(bool changed) override;
void moveBy(double dx, double dy) override;
QLineF motionLine() const;
void setMotionLine(const QLineF& motionLine);
int speed() const;
void advance(int phase) override;
void load(KConfigGroup* group) override;
void save(KConfigGroup* group) override;
public Q_SLOTS:
void setSpeed(int speed);
protected:
Kolf::Overlay* createOverlay() override;
private:
void setMlPosition(qreal position);
QLineF m_motionLine;
int m_speed;
qreal m_velocity;
qreal m_position; //parameter on motion line (see QLineF::pointAt)
bool m_moveByMovesMotionLine, m_animated;
};
class FloaterOverlay : public Kolf::RectangleOverlay
{
Q_OBJECT
public:
explicit FloaterOverlay(Kolf::Floater* floater);
void update() override;
private Q_SLOTS:
//interface to handles
void moveMotionLineHandle(const QPointF& handleScenePos);
private:
Kolf::OverlayHandle* m_handle1;
Kolf::OverlayHandle* m_handle2;
QGraphicsLineItem* m_motionLineItem;
};
class Sign : public Kolf::RectangleItem
{
Q_OBJECT
public:
Sign(QGraphicsItem* parent, b2World* world);
QString text() const;
void setSize(const QSizeF& size) override;
void load(KConfigGroup* group) override;
void save(KConfigGroup* group) override;
public Q_SLOTS:
void setText(const QString& text);
private:
QString m_text;
QGraphicsTextItem* m_textItem;
};
class Windmill : public Kolf::RectangleItem
{
Q_OBJECT
public:
Windmill(QGraphicsItem* parent, b2World* world);
~Windmill() override;
bool guardAtTop() const;
int speed() const;
void advance(int phase) override;
void moveBy(double dx, double dy) override;
void load(KConfigGroup* group) override;
void save(KConfigGroup* group) override;
public Q_SLOTS:
void setGuardAtTop(bool guardAtTop);
void setSpeed(int speed);
protected:
void updateWallPosition() override;
private:
Kolf::Wall* m_leftWall;
Kolf::Wall* m_rightWall;
Kolf::Wall* m_guardWall;
bool m_guardAtTop;
int m_speed;
double m_velocity;
};
}
#endif // KOLF_OBSTACLES_H