-
Notifications
You must be signed in to change notification settings - Fork 0
/
MapDrawer.cpp
73 lines (68 loc) · 1.29 KB
/
MapDrawer.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
#include "MapDrawer.h"
MapDrawer::MapDrawer()
{
}
void MapDrawer::InitMapTexture(sf::RenderWindow* screen, Tile mapToDraw[], int mapHeight, int mapWidth)
{
texture.create(mapWidth, mapHeight);
sf::Uint8* pixels = new sf::Uint8[mapWidth*mapHeight*4];
int currentCell = 0;
int index = 0;
for (int y = 0; y < mapHeight; y++)
{
for (int x = 0; x < mapWidth; x++)
{
for (int i = 0; i < 4; i++)
{
switch (mapToDraw[currentCell].checkSymbol())
{
case 'G':
case '.': //walkable terrain, draw nothing
{
pixels[index] = 0;
}
break;
case '@': //impassable terrain
case 'O':
case 'T':
case 'W':
{
switch (i)
{
case 0:
//r
pixels[index] = 0;
break;
case 1:
//g
pixels[index] = 0;
break;
case 2:
//b
pixels[index] = 255;
break;
case 3:
//a
pixels[index] = 255;
break;
}
}
break;
default:
break;
}
index++;
}
currentCell++;
}
}
texture.update(pixels);
texture.setSmooth(true);
texture.copyToImage().saveToFile("map.png");
mapSprite.setTexture(texture);
mapSprite.setPosition(0, 0);
}
void MapDrawer::DrawMap(sf::RenderWindow* screen)
{
screen->draw(mapSprite);
}