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
|
/*
*
* description:
*
* author: Yann Herklotz <ymherklotz@gmail.com>
* date created: DD-MM-YYYY
*
*/
#include "../include/TileMap.hpp"
#include <SFML/Graphics.hpp>
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char *argv[]) {
cout << "executing " << argv[0] << endl;
cout << "arguments given: " << argc - 1 << endl;
sf::RenderWindow window(sf::VideoMode(800, 600), "A* Algorithm");
cout << "window size: " << window.getSize().x << ", " << window.getSize().y << endl;
const int tile_size = 21;
const int rows = 41;
const int cols = 34;
cout << "tile size: " << tile_size << "px, rows: " << rows << ", cols: " <<
cols << endl;
int tiles[cols * rows];
for(int i = 0; i < cols * rows; ++i)
tiles[i] = 0;
TileMap map;
while(window.isOpen()) {
sf::Event event;
while(window.pollEvent(event))
if(event.type == sf::Event::Closed)
window.close();
if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
sf::Vector2i mouse = sf::Mouse::getPosition(window);
tiles[(int)(mouse.x / tile_size) +
cols * (int)(mouse.y / tile_size)] = 1;
} else if(sf::Mouse::isButtonPressed(sf::Mouse::Right)) {
sf::Vector2i mouse = sf::Mouse::getPosition(window);
tiles[(int)(mouse.x / tile_size) +
cols * (int)(mouse.y / tile_size)] = 2;
}
map.load("res/GridTileTexture3.png", sf::Vector2f(200, 200), sf::Vector2f(tile_size, tile_size), tiles, cols, rows);
window.clear(sf::Color(47, 47, 47));
window.draw(map);
window.display();
}
return 0;
}
|