implement food

This commit is contained in:
churl
2021-04-08 03:17:29 +02:00
parent be1ca36ecb
commit f81fbda652
2 changed files with 34 additions and 0 deletions

14
src/food.cpp Normal file
View File

@ -0,0 +1,14 @@
#include "food.hpp"
#include "ant.hpp"
Food::Food(double x, double y)
: x(x), y(y) {
appearance = sf::CircleShape(15);
appearance.setFillColor(sf::Color::Green);
appearance.setPosition(x - appearance.getRadius(), y - appearance.getRadius());
}
bool Food::antHasFood(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/food.hpp Normal file
View File

@ -0,0 +1,20 @@
#ifndef __FOOD_H_
#define __FOOD_H_
#include <SFML/Graphics.hpp>
class Ant;
class Food {
double x, y;
public:
sf::CircleShape appearance;
public:
Food(double x, double y);
bool antHasFood(const Ant& ant) const;
};
#endif // __FOOD_H_