implement colony
This commit is contained in:
15
src/colony.cpp
Normal file
15
src/colony.cpp
Normal 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
20
src/colony.hpp
Normal 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_
|
Reference in New Issue
Block a user