diff --git a/src/pheromones.cpp b/src/pheromone_map.cpp similarity index 54% rename from src/pheromones.cpp rename to src/pheromone_map.cpp index fba2ffd..9032325 100644 --- a/src/pheromones.cpp +++ b/src/pheromone_map.cpp @@ -1,9 +1,9 @@ -#include "pheromones.hpp" +#include "pheromone_map.hpp" extern const unsigned short WIDTH; extern const unsigned short HEIGHT; -Pheromones::Pheromones() { +PheromoneMap::PheromoneMap() { for (unsigned short y = 0; y < HEIGHT; ++y) { for (unsigned short x = 0; x < WIDTH; ++x) { map[y * WIDTH + x].position.x = x; @@ -13,15 +13,22 @@ Pheromones::Pheromones() { } } -void Pheromones::place(unsigned short x, unsigned short y, sf::Color col) { +void PheromoneMap::place(unsigned short x, unsigned short y, sf::Color col) { map[y * WIDTH + x].color = col; - map[(y + 1) * WIDTH + x].color = col; - map[(y - 1) * WIDTH + x].color = col; - map[y * WIDTH + (x + 1)].color = col; - map[y * WIDTH + (x - 1)].color = col; + + // Have to check for off-limit-pixels + map[std::min(WIDTH * HEIGHT - 1, (y + 1) * WIDTH + x)].color = col; + map[std::max(0, (y - 1) * WIDTH + x)].color = col; + map[std::min(WIDTH * HEIGHT - 1, y * WIDTH + (x + 1))].color = col; + map[std::max(0, y * WIDTH + (x - 1))].color = col; } -void Pheromones::update() { +sf::Color PheromoneMap::get(unsigned short x, unsigned short y) const { + // TODO: range-checks + return map[y * WIDTH + x].color; +} + +void PheromoneMap::update() { for (int i = 0; i < WIDTH * HEIGHT; ++i) { map[i].color -= sf::Color(decay, decay, decay, decay); } diff --git a/src/pheromones.hpp b/src/pheromone_map.hpp similarity index 64% rename from src/pheromones.hpp rename to src/pheromone_map.hpp index 7e33cc8..60f818d 100644 --- a/src/pheromones.hpp +++ b/src/pheromone_map.hpp @@ -1,22 +1,25 @@ #ifndef __PHEROMONES_H_ #define __PHEROMONES_H_ +#include #include +#include "pheromone.hpp" extern const unsigned short WIDTH; extern const unsigned short HEIGHT; const unsigned short decay = 1; -class Pheromones +class PheromoneMap { public: - sf::VertexArray map = sf::VertexArray(sf::PrimitiveType::Points, WIDTH * HEIGHT); + std::vector