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