This repository was archived by the owner on Dec 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageProcessing.cpp
83 lines (68 loc) · 1.75 KB
/
ImageProcessing.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
#include "ImageProcessing.h"
ImageProcessing::ImageProcessing(void)
{
}
ImageProcessing::~ImageProcessing(void)
{
}
void ImageProcessing::ImageProcess(int data[800][500], sf::Sprite *BackGround)
{
sf::Image BackGroundImage = BackGround->getTexture()->copyToImage();
sf::Vector2u size = BackGround->getTexture()->getSize();
for (int x = 0; x < size.x; x++)
{
for (int y = 0; y < size.y; y++)
{
if (BackGroundImage.getPixel(x,y) == sf::Color(240,240,240))
{
FillPixels(data, x, y, C_PATH);
//data[x][y] = C_PATH;
}
else if (BackGroundImage.getPixel(x,y) == sf::Color::Black)
{
FillPixels(data, x, y, C_CASTLE);
//data[x][y] = C_CASTLE;
}
else
{
FillPixels(data, x, y, C_MAP);
//data[x][y] = C_MAP;
}
}
}
}
void ImageProcessing::FillPixels(int data[800][500], int X, int Y, int number)
{
X = MAPSCALE*X;
Y = MAPSCALE*Y;
for (int x = X; x < X+MAPSCALE; x++)
{
for (int y = Y; y < Y+MAPSCALE; y++)
{
data[x][y] = number;
}
}
}
sf::Vector2i ImageProcessing::FindStart(int ImageMap[800][500])
{
for (int x = 0; x< 800; x++)
if (ImageMap[x][0] == C_PATH) return sf::Vector2i(x, 0);
for (int x = 0; x< 800; x++)
if (ImageMap[x][499] == C_PATH) return sf::Vector2i(x, 499);
for (int y = 0; y< 500; y++)
if (ImageMap[0][y] == C_PATH) return sf::Vector2i(0, y);
for (int y = 0; y< 500; y++)
if (ImageMap[799][y] == C_PATH) return sf::Vector2i(799, y);
return sf::Vector2i(0,0);
}
sf::Vector2i ImageProcessing::FindCastle(int ImageMap[800][500])
{
for (int x = 0; x< 800; x++)
{
for (int y=0; y < 500; y++)
{
if (ImageMap[x][y] == C_CASTLE) return sf::Vector2i(x, y);
}
}
return sf::Vector2i(0,0);
}