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
|
#include <SFML/Graphics.hpp>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
std::string line;
int counter = 0;
char Positions[255][15];
void explode(string str, string separator, vector<string>* results){
int found;
found = str.find_first_of(separator);
while(found != string::npos){
if(found > 0){
results->push_back(str.substr(0,found));
}
str = str.substr(found+1);
found = str.find_first_of(separator);
}
if(str.length() > 0){
results->push_back(str);
}
}
void ReadMap(){
cout << "Readmap (Test)" << endl;
std::ifstream file( "test.txt" ) ;
cout << "ReadPositions from Map (Test)" << endl;
counter = 0;
while( std::getline( file, line ) )
{
std::vector<string> ThisLine;
explode(line, ":", &ThisLine);
if(ThisLine[0] == "obj"){
counter = counter + 1;
cout << "[Obj: " << counter;
cout << " X1: " << ThisLine[1];
cout << " X2: " << ThisLine[3];
cout << " X3: " << ThisLine[5];
cout << " Y1: " << ThisLine[2];
cout << " Y2: " << ThisLine[4];
cout << " Y3: " << ThisLine[6] << "]" << endl;
Positions[counter][1] = atoi(ThisLine[1].c_str());
Positions[counter][2] = atoi(ThisLine[2].c_str());
Positions[counter][3] = atoi(ThisLine[3].c_str());
Positions[counter][4] = atoi(ThisLine[4].c_str());
Positions[counter][5] = atoi(ThisLine[5].c_str());
Positions[counter][6] = atoi(ThisLine[6].c_str());
}
}
}
int main()
{
int Y = 0;
cout << "Display Window" << endl;
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Soldier Map");
sf::View Camera;
ReadMap();
while (App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
if ((Event.Type == sf::Event::Closed) ||
((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape)))
{
App.Close();
break;
}
if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::F2)){
ReadMap();
}
if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::F3)){
App.SetView(App.GetDefaultView());
}
}
if(Y == 10){
sf::Vector2f MousePos = App.ConvertCoords(App.GetInput().GetMouseX(), App.GetInput().GetMouseY());
Camera.SetCenter(MousePos);
App.SetView(Camera);
Y = 0;
}else{ Y++; }
App.Clear();
for(int i = 0; i <= counter; i++){
sf::Shape Polygon;
Polygon.AddPoint(Positions[i][1], Positions[i][2], sf::Color(0, 128, 128), sf::Color(0, 128, 128));
Polygon.AddPoint(Positions[i][3], Positions[i][4], sf::Color(0, 128, 128), sf::Color(0, 128, 128));
Polygon.AddPoint(Positions[i][5], Positions[i][6], sf::Color(0, 128, 128), sf::Color(0, 128, 128));
Polygon.EnableFill(true);
Polygon.EnableOutline(false);
Polygon.SetOutlineWidth(0);
App.Draw(Polygon);
}
App.Display();
}
return EXIT_SUCCESS;
}
|