aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzedarider <ymherklotz@gmail.com>2016-12-07 14:34:39 +0000
committerzedarider <ymherklotz@gmail.com>2016-12-07 14:34:39 +0000
commit1c8f5fa033cf11504b6368a71d05d1d4eb1e83fd (patch)
treed2efee0e533be65843f9605944dcf49983f7f695
parentf6f67ab84012fb08ca8bad0bc80a98977e0d3864 (diff)
downloadA-star-algorithm-1c8f5fa033cf11504b6368a71d05d1d4eb1e83fd.tar.gz
A-star-algorithm-1c8f5fa033cf11504b6368a71d05d1d4eb1e83fd.zip
added beautify
-rwxr-xr-xbin/mainbin272952 -> 272848 bytes
-rw-r--r--include/TileMap.hpp14
-rw-r--r--src/TileMap.cpp82
-rw-r--r--src/main.cpp12
4 files changed, 39 insertions, 69 deletions
diff --git a/bin/main b/bin/main
index ad9107a..2b73578 100755
--- a/bin/main
+++ b/bin/main
Binary files differ
diff --git a/include/TileMap.hpp b/include/TileMap.hpp
index 0eb53fe..e461c52 100644
--- a/include/TileMap.hpp
+++ b/include/TileMap.hpp
@@ -7,17 +7,15 @@
class TileMap : public sf::Drawable, public sf::Transformable {
public:
- TileMap();
- ~TileMap();
+ TileMap();
+ ~TileMap();
- bool load(const std::string& txt_file, const sf::Vector2f& txt_size,
- const sf::Vector2f& tile_size, const int* tiles,
- unsigned int width, unsigned int height);
+ bool load(const std::string& txt_file, const sf::Vector2f& txt_size, const sf::Vector2f& tile_size, const int *tiles, unsigned int width, unsigned int height);
private:
- virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
+ virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
- sf::VertexArray m_vertices;
- sf::Texture m_texture;
+ sf::VertexArray m_vertices;
+ sf::Texture m_texture;
};
#endif
diff --git a/src/TileMap.cpp b/src/TileMap.cpp
index daa45d4..f309b2f 100644
--- a/src/TileMap.cpp
+++ b/src/TileMap.cpp
@@ -1,64 +1,44 @@
#include "../include/TileMap.hpp"
TileMap::TileMap() {
-
}
TileMap::~TileMap() {
-
}
-bool TileMap::load(const std::string& txt_file, const sf::Vector2f& txt_size,
- const sf::Vector2f& tile_size, const int* tiles,
- unsigned int width, unsigned int height) {
-
- if(!m_texture.loadFromFile(txt_file)) {
- return false;
- }
-
- m_vertices.setPrimitiveType(sf::Quads);
- m_vertices.resize(width * height * 4);
-
- for(unsigned int i = 0; i < width; ++i)
- for(unsigned int j = 0; j < height; ++j) {
- // get the colour of the tile
- int tile_number = tiles[i + j * width];
-
- // get pointer to vertex of current quad
- sf::Vertex *quad = &m_vertices[(i + j * width) * 4];
-
- // define the quads
- quad[0].position = sf::Vector2f(i * tile_size.x,
- j * tile_size.y);
-
- quad[1].position = sf::Vector2f((i+1) * tile_size.x,
- j * tile_size.y);
-
- quad[2].position = sf::Vector2f((i+1) * tile_size.x,
- (j+1) * tile_size.y);
-
- quad[3].position = sf::Vector2f(i * tile_size.x,
- (j+1) * tile_size.y);
-
- // define texture
- quad[0].texCoords = sf::Vector2f(tile_number * txt_size.x,
- 0);
-
- quad[1].texCoords = sf::Vector2f((tile_number+1) * txt_size.x,
- 0);
-
- quad[2].texCoords = sf::Vector2f((tile_number+1) * txt_size.x,
- txt_size.y);
-
- quad[3].texCoords = sf::Vector2f(tile_number * txt_size.x,
- txt_size.y);
- }
- return true;
+bool TileMap::load(const std::string& txt_file, const sf::Vector2f& txt_size, const sf::Vector2f& tile_size, const int *tiles, unsigned int width, unsigned int height) {
+ if(!m_texture.loadFromFile(txt_file))
+ return false;
+
+ m_vertices.setPrimitiveType(sf::Quads);
+ m_vertices.resize(width * height * 4);
+
+ for(unsigned int i = 0; i < width; ++i)
+ for(unsigned int j = 0; j < height; ++j) {
+ // get the colour of the tile
+ int tile_number = tiles[i + j * width];
+
+ // get pointer to vertex of current quad
+ sf::Vertex *quad = &m_vertices[(i + j * width) * 4];
+
+ // define the quads
+ quad[0].position = sf::Vector2f(i * tile_size.x, j * tile_size.y);
+ quad[1].position = sf::Vector2f((i + 1) * tile_size.x, j * tile_size.y);
+ quad[2].position = sf::Vector2f((i + 1) * tile_size.x, (j + 1) * tile_size.y);
+ quad[3].position = sf::Vector2f(i * tile_size.x, (j + 1) * tile_size.y);
+
+ // define texture
+ quad[0].texCoords = sf::Vector2f(tile_number * txt_size.x, 0);
+ quad[1].texCoords = sf::Vector2f((tile_number + 1) * txt_size.x, 0);
+ quad[2].texCoords = sf::Vector2f((tile_number + 1) * txt_size.x, txt_size.y);
+ quad[3].texCoords = sf::Vector2f(tile_number * txt_size.x, txt_size.y);
+ }
+ return true;
}
void TileMap::draw(sf::RenderTarget& target, sf::RenderStates states) const {
- states.transform = getTransform();
- states.texture = &m_texture;
+ states.transform = getTransform();
+ states.texture = &m_texture;
- target.draw(m_vertices, states);
+ target.draw(m_vertices, states);
}
diff --git a/src/main.cpp b/src/main.cpp
index 11dad93..7ca4243 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -20,12 +20,9 @@ int main(int argc, char *argv[]) {
cout << "executing " << argv[0] << endl;
cout << "arguments given: " << argc - 1 << endl;
- srand(time(NULL));
-
sf::RenderWindow window(sf::VideoMode(800, 600), "A* Algorithm");
- cout << "window size: " << window.getSize().x << ", " << window.getSize().y
- << endl;
+ cout << "window size: " << window.getSize().x << ", " << window.getSize().y << endl;
const int tile_size = 21;
const int rows = 41;
@@ -49,20 +46,15 @@ int main(int argc, char *argv[]) {
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;
}
- //tiles[rand() % (rows*cols)] = rand() % 4;
-
- map.load("res/GridTileTexture3.png", sf::Vector2f(200, 200),
- sf::Vector2f(tile_size, tile_size), tiles, cols, rows);
+ 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);