File: obstacles.h

package info (click to toggle)
kolf 4:18.04.1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,972 kB
  • sloc: cpp: 19,333; xml: 243; makefile: 8; sh: 4
file content (252 lines) | stat: -rw-r--r-- 6,821 bytes parent folder | download
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
/*
    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) Q_DECL_OVERRIDE;
		protected:
			Kolf::Overlay* createOverlay() Q_DECL_OVERRIDE;
		public Q_SLOTS:
			void turnBumperOff();
	};

	class Wall : public QGraphicsLineItem, public CanvasItem
	{
		public:
			Wall(QGraphicsItem* parent, b2World* world);

			void load(KConfigGroup* cfgGroup) Q_DECL_OVERRIDE;
			void save(KConfigGroup* cfgGroup) Q_DECL_OVERRIDE;
			void setVisible(bool visible);

			virtual void setLine(const QLineF& line);
			void moveBy(double dx, double dy) Q_DECL_OVERRIDE;
			QPointF getPosition() const Q_DECL_OVERRIDE;
		protected:
			Kolf::Overlay* createOverlay() Q_DECL_OVERRIDE;
		private:
			Kolf::LineShape* m_shape;
	};

	class WallOverlay : public Kolf::Overlay
	{
		Q_OBJECT
		public:
			WallOverlay(Kolf::Wall* wall);
			void update() Q_DECL_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);
			virtual ~RectangleItem();

			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) Q_DECL_OVERRIDE;
			QPointF getPosition() const Q_DECL_OVERRIDE;
			void moveBy(double dx, double dy) Q_DECL_OVERRIDE;

			void setWallColor(const QColor& color);
			void applyWallStyle(Kolf::Wall* wall, bool adjustPainting = true);

			void load(KConfigGroup* group) Q_DECL_OVERRIDE;
			void save(KConfigGroup* group) Q_DECL_OVERRIDE;

			Config* config(QWidget* parent) Q_DECL_OVERRIDE;
		Q_SIGNALS:
			void wallChanged(Kolf::WallIndex index, bool hasWall, bool wallAllowed);
		protected:
			Kolf::Overlay* createOverlay() Q_DECL_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:
			RectangleOverlay(Kolf::RectangleItem* item);
			void update() Q_DECL_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) Q_DECL_OVERRIDE;
	};

	class Floater : public Kolf::RectangleItem
	{
		Q_OBJECT
		public:
			Floater(QGraphicsItem* parent, b2World* world);
			void editModeChanged(bool changed) Q_DECL_OVERRIDE;
			void moveBy(double dx, double dy) Q_DECL_OVERRIDE;

			QLineF motionLine() const;
			void setMotionLine(const QLineF& motionLine);
			int speed() const;
			void advance(int phase) Q_DECL_OVERRIDE;

			void load(KConfigGroup* group) Q_DECL_OVERRIDE;
			void save(KConfigGroup* group) Q_DECL_OVERRIDE;
		public Q_SLOTS:
			void setSpeed(int speed);
		protected:
			Kolf::Overlay* createOverlay() Q_DECL_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:
			FloaterOverlay(Kolf::Floater* floater);
			void update() Q_DECL_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) Q_DECL_OVERRIDE;

			void load(KConfigGroup* group) Q_DECL_OVERRIDE;
			void save(KConfigGroup* group) Q_DECL_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);
			virtual ~Windmill();

			bool guardAtTop() const;
			int speed() const;
			void advance(int phase) Q_DECL_OVERRIDE;
			void moveBy(double dx, double dy) Q_DECL_OVERRIDE;

			void load(KConfigGroup* group) Q_DECL_OVERRIDE;
			void save(KConfigGroup* group) Q_DECL_OVERRIDE;
		public Q_SLOTS:
			void setGuardAtTop(bool guardAtTop);
			void setSpeed(int speed);
		protected:
			void updateWallPosition() Q_DECL_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