-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFood.cpp
More file actions
47 lines (37 loc) · 917 Bytes
/
Food.cpp
File metadata and controls
47 lines (37 loc) · 917 Bytes
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
//
// Created by jan on 18.09.17.
//
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include "Food.h"
Food::Food(World& world) : world(world) {
this->size = (float) rand() / RAND_MAX * 1000;
this->pos_x = (float) rand() / RAND_MAX * world.get_size_x();
this->pos_y = (float) rand() / RAND_MAX * world.get_size_y();
radius = sqrt(size);
}
Food::Food(float size, float pos_x, float pos_y, World& world) : world(world) {
this->size = size;
this->pos_x = pos_x;
this->pos_y = pos_y;
radius = sqrt(size);
}
float Food::bite(float bite_size) {
float consumed = std::min(size, bite_size);
size -= consumed;
radius = sqrt(size);
return consumed;
}
float Food::get_size() const {
return size;
}
float Food::get_pos_x() const {
return pos_x;
}
float Food::get_pos_y() const {
return pos_y;
}
float Food::get_radius() const {
return radius;
}