-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathField.cpp
More file actions
51 lines (45 loc) · 1.12 KB
/
Field.cpp
File metadata and controls
51 lines (45 loc) · 1.12 KB
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
#include <SFML/Graphics.hpp>
#include "Field.h"
#include "Tile.h"
#include <fstream>
Field::Field(sf::Texture** texture)
{
std::ifstream mapFile;
mapFile.open("stringMap.txt");
mapFile >> height >> width;
height = 10;
width = 10;
int stringMap[10][10] = {
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 1, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 1, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 1, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
};
tileMap = new Tile** [height];
for (int y = 0; y < height; y++) {
tileMap[y] = new Tile* [width];
for (int x = 0; x < width; x++)
tileMap[y][x] = new Tile(texture[stringMap[y][x]], sf::Vector2f((float)x, (float)y), stringMap[y][x]);
}
}
Field::~Field()
{
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
delete tileMap[y][x];
delete tileMap[y];
}
}
void Field::draw(sf::RenderWindow& window)
{
for (int y = 0; y < height; y++)
for (int x = 0; x < width; x++)
tileMap[y][x]->draw(window);
}