implement pheromone type
This commit is contained in:
39
src/pheromone.cpp
Normal file
39
src/pheromone.cpp
Normal 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
25
src/pheromone.hpp
Normal 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
|
Reference in New Issue
Block a user