-
Notifications
You must be signed in to change notification settings - Fork 0
/
FoodSource.h
51 lines (41 loc) · 1.28 KB
/
FoodSource.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*==================\\
|| FoodSource Class ||
\\==================*/
#ifndef FOODSOURCE_H
#define FOODSOURCE_H
#include <string>
#include "Bacterium.h"
#include "utils.h"
class Bacterium;
class FoodSource {
public:
int x; // x-position (integer)
int y; // y-position (integer)
double radius; // Radius of food source (can be a real)
double radius2; // Squared radius
unsigned int rations; // Food "rations" left in source
std::vector<Bacterium*> bacteriaHere; // Bacteria currently at this food source
// Constructor
FoodSource (int p_x, int p_y, double p_radius, int p_rations) {
x = p_x;
y = p_y;
radius = p_radius;
radius2 = radius*radius;
rations = p_rations;
bacteriaHere.reserve(10);
}
// Returns whether the point (x,y) is "inside" the food source or not
bool contains(int x1, int y1) {
return ((x-x1)*(x-x1) + (y-y1)*(y-y1) <= radius2);
}
// Clears the list of bacteria at this food source
void clearBacteriaHere() {
bacteriaHere.clear();
bacteriaHere.reserve(64); // for faster future use
}
// Returns a string representation of the food source in the provided char*
void repr(char* retbuf) {
sprintf(retbuf, "Food source at (%i,%i)", x, y);
}
};
#endif // FOODSOURCE_H