-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlandscape.h
164 lines (139 loc) · 4.13 KB
/
landscape.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
/*
Copyright (C) 2002-2005, Jason Katz-Brown <[email protected]>
Copyright 2010 Stefan Majewsky <[email protected]>
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_LANDSCAPE_H
#define KOLF_LANDSCAPE_H
//NOTE: Only refactored stuff goes into this header.
#include "canvasitem.h"
#include <config.h>
#include "overlay.h"
namespace Kolf
{
class LandscapeItem : public EllipticalCanvasItem
{
Q_OBJECT
public:
LandscapeItem(const QString& type, QGraphicsItem* parent, b2World* world);
bool isBlinkEnabled() const;
int blinkInterval() const;
void advance(int phase) override;
void load(KConfigGroup* group) override;
void save(KConfigGroup* group) override;
Config* config(QWidget* parent) override;
public Q_SLOTS:
void setBlinkEnabled(bool blinkEnabled);
void setBlinkInterval(int blinkInterval);
protected:
Kolf::Overlay* createOverlay() override;
private:
bool m_blinkEnabled;
int m_blinkInterval, m_blinkFrame;
};
class LandscapeOverlay : public Kolf::Overlay
{
Q_OBJECT
public:
explicit LandscapeOverlay(Kolf::LandscapeItem* item);
void update() override;
private Q_SLOTS:
//interface to handles
void moveHandle(const QPointF& handleScenePos);
private:
QList<Kolf::OverlayHandle*> m_handles;
};
class LandscapeConfig : public Config
{
Q_OBJECT
public:
LandscapeConfig(Kolf::LandscapeItem* item, QWidget* parent);
Q_SIGNALS:
void blinkIntervalChanged(int blinkInterval);
public Q_SLOTS:
void setBlinkInterval(int sliderValue);
};
class Puddle : public Kolf::LandscapeItem
{
public:
Puddle(QGraphicsItem* parent, b2World* world);
bool collision(Ball* ball) override;
};
class Sand : public Kolf::LandscapeItem
{
public:
Sand(QGraphicsItem* parent, b2World* world);
bool collision(Ball* ball) override;
};
enum SlopeType
{
VerticalSlope = 0,
HorizontalSlope,
DiagonalSlope,
CrossDiagonalSlope,
EllipticSlope
};
class Slope : public Tagaro::SpriteObjectItem, public CanvasItem
{
Q_OBJECT
public:
Slope(QGraphicsItem* parent, b2World* world);
double grade() const;
bool isReversed() const;
Kolf::SlopeType slopeType() const;
bool isStuckOnGround() const;
QPainterPath shape() const override;
void setSize(const QSizeF& size) override;
QPointF getPosition() const override;
void moveBy(double dx, double dy) override;
void load(KConfigGroup* group) override;
void save(KConfigGroup* group) override;
bool collision(Ball* ball) override;
bool terrainCollisions() const override;
QList<QGraphicsItem*> infoItems() const override;
Config* config(QWidget* parent) override;
public Q_SLOTS:
void setGrade(double grade);
void setReversed(bool reversed);
void setSlopeType(int type);
void setStuckOnGround(bool stuckOnGround);
protected:
Kolf::Overlay* createOverlay() override;
private:
void updateAppearance();
void updateInfo();
double m_grade;
bool m_reversed, m_stuckOnGround;
Kolf::SlopeType m_type;
QGraphicsSimpleTextItem* m_gradeItem;
QList<ArrowItem*> m_arrows;
};
class SlopeConfig : public Config
{
public:
SlopeConfig(Kolf::Slope* slope, QWidget* parent);
};
class SlopeOverlay : public Kolf::Overlay
{
Q_OBJECT
public:
explicit SlopeOverlay(Kolf::Slope* slope);
void update() override;
private Q_SLOTS:
//interface to handles
void moveHandle(const QPointF& handleScenePos);
private:
QList<Kolf::OverlayHandle*> m_handles;
};
}
#endif // KOLF_LANDSCAPE_H