implement colony

This commit is contained in:
churl
2021-04-08 03:17:23 +02:00
parent 39a90e2b3f
commit be1ca36ecb
2 changed files with 35 additions and 0 deletions

15
src/colony.cpp Normal file
View File

@ -0,0 +1,15 @@
#include "colony.hpp"
#include "ant.hpp"
Colony::Colony(double x, double y)
: x(x), y(y) {
appearance = sf::CircleShape(25);
appearance.setFillColor(sf::Color::Red);
appearance.setPosition(x - appearance.getRadius(), y - appearance.getRadius());
}
// TODO: don't use appearance for this, add radius field
bool Colony::antIsHome(const Ant& ant) const {
return ant.x > x - appearance.getRadius() && ant.x < x + appearance.getRadius()
&& ant.y > y - appearance.getRadius() && ant.y < y + appearance.getRadius();
}

20
src/colony.hpp Normal file
View File

@ -0,0 +1,20 @@
#ifndef __COLONY_H_
#define __COLONY_H_
#include <SFML/Graphics.hpp>
class Ant; // Colony and Ant can't include eachother so forward-declare
class Colony {
double x, y;
public:
sf::CircleShape appearance;
public:
Colony(double x, double y);
bool antIsHome(const Ant& ant) const;
};
#endif // __COLONY_H_