-
Notifications
You must be signed in to change notification settings - Fork 0
/
play.cpp
222 lines (182 loc) · 3.94 KB
/
play.cpp
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
#include "play.hpp"
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <SFML/Graphics/Sprite.hpp>
#include "errcodes.hpp"
//#define DEBUG_GAME
Play* Play::singleton = 0;
Play::~Play()
{
delete finder;
}
Play* Play::getInstance()
{
if (singleton == 0)
{
singleton = new Play();
}
return singleton;
}
LineFinder* Play::getFinder()
{
return finder;
}
void Play::destroy()
{
if (singleton != 0)
{
delete singleton;
singleton = 0;
}
}
int Play::detect(float minLength,
float mGap,
int minVote,
int skelThreshold,
int cannyThreshold1,
int cannyThreshold2,
int cannyApertureSize,
bool l2Gradient
)
{
finder->setLineLengthAndGap(minLength, maxGap);
finder->setMinVote(minVote);
// creating a skeleton
finder->createSkeleton(skelThreshold);
// detecting the contours
cv::Canny(Play::getInstance()->getFinder()->getImage(), Play::getInstance()->getFinder()->getImage(), cannyThreshold1, cannyThreshold2, cannyApertureSize, l2Gradient);
std::vector<cv::Vec4i> lines = finder->findLines();
if (Play::getInstance()->getFinder()->getLines().size() == 0)
{
std::cerr << "There were no lines detected." << std::endl;
return -1;
}
// This closing operation fills holes between lines
// It has a very significant effect
cv::Mat tempDilated;
cv::Mat element = cv::getStructuringElement(cv::MORPH_CROSS, cv::Size(9,9));
cv::dilate(Play::getInstance()->getFinder()->getImage(), tempDilated, element);
cv::erode(tempDilated, Play::getInstance()->getFinder()->getImage(), element);
std::vector<std::vector<int> > levelFile = finder->saveToVec();
setLevelMap(levelFile);
return 0;
}
void Play::setLevelMap(std::vector<std::vector<int> > lm)
{
levelMap = lm;
}
std::vector<std::vector<int> > & Play::getLevelMap()
{
return levelMap;
}
int Play::buildLevel()
{
if(!m_TileMap.load(sf::Vector2u(5, 5), Play::getInstance()->getLevelMap(), levelMap[0].size(), levelMap.size()))
{
return -1;
}
return 0;
}
int Play::play()
{
//physicsMap(levelMap);
buildLevel();
Game game;
int success = game.run();
return success;
}
tileMap & Play::getTileMap()
{
return m_TileMap;
}
sf::Vector2u Play::getMapSize()
{
return mapSize;
}
void Play::setMapSize(int width, int height)
{
mapSize.x = width;
mapSize.y = height;
}
std::vector<std::vector<int> > & Play::getPhysicsMap()
{
return physicsMap;
}
void Play::setPhysicsMap(std::vector<std::vector<int> > newPhMap)
{
physicsMap = newPhMap;
}
void Play::setPlayerTexture(std::string newTex)
{
playerTextureToLoad = newTex;
}
std::string Play::getPlayerTexture()
{
return playerTextureToLoad;
}
float Play::getMinLength()
{
return minLength;
}
void Play::setMinLength(float mLength)
{
minLength = mLength;
}
float Play::getMaxGap()
{
return maxGap;
}
void Play::setMaxGap(float mGap)
{
maxGap = mGap;
}
int Play::getMinVote()
{
return minVote;
}
void Play::setMinVote(int mVote)
{
minVote = mVote;
}
int Play::getSkelThreshold()
{
return skelThreshold;
}
void Play::setSkelThreshold(int skThreshold)
{
skelThreshold = skThreshold;
}
int Play::getCannyThreshold1()
{
return cannyThreshold1;
}
void Play::setCannyThreshold1(int cThreshold1)
{
cannyThreshold1 = cThreshold1;
}
int Play::getCannyThreshold2()
{
return cannyThreshold2;
}
void Play::setCannyThreshold2(int cThreshold2)
{
cannyThreshold2 = cThreshold2;
}
int Play::getCannyApertureSize()
{
return cannyApertureSize;
}
void Play::setCannyApertureSize(int cASize)
{
cannyApertureSize = cASize;
}
bool Play::getL2Gradient()
{
return l2Gradient;
}
void Play::setL2Gradient(bool l2Grad)
{
l2Gradient = l2Grad;
}