implement pheromone type

This commit is contained in:
churl
2021-04-12 01:35:21 +02:00
parent d8f148ff34
commit 8b34a8c604
2 changed files with 64 additions and 0 deletions

39
src/pheromone.cpp Normal file
View File

@ -0,0 +1,39 @@
//
// Created by christoph on 11.04.21.
//
#include <SFML/Graphics.hpp>
#include "world_object.hpp"
#include "pheromone.hpp"
Pheromone::Pheromone(double x, double y, PheroType type)
: WorldObject(x, y, 2, sf::Color::Transparent) {
if (type == HOME) {
appearance.setFillColor(sf::Color::Red);
} else if (type == FOOD) {
appearance.setFillColor(sf::Color::Green);
} else {
appearance.setFillColor(sf::Color::Transparent);
}
}
PheroType Pheromone::getPheromoneType() const {
if (appearance.getFillColor() == sf::Color::Red) {
return HOME;
}
if (appearance.getFillColor() == sf::Color::Green) {
return FOOD;
}
return NONE;
}
void Pheromone::update() {
intensity = std::max(0, intensity - decay);
appearance.setFillColor(sf::Color(
appearance.getFillColor().r,
appearance.getFillColor().g,
appearance.getFillColor().b,
intensity
));
}

25
src/pheromone.hpp Normal file
View File

@ -0,0 +1,25 @@
//
// Created by christoph on 11.04.21.
//
#ifndef ANTSIMULATOR_PHEROMONE_HPP
#define ANTSIMULATOR_PHEROMONE_HPP
#include <SFML/Graphics.hpp>
#include "world_object.hpp"
const unsigned short decay = 1;
class Pheromone : public WorldObject
{
public:
unsigned short intensity = 255;
public:
Pheromone(double x, double y, PheroType type);
PheroType getPheromoneType() const override;
void update() override;
};
#endif //ANTSIMULATOR_PHEROMONE_HPP