-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBacteria.cpp
72 lines (58 loc) · 1.75 KB
/
Bacteria.cpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
Authors: Andrew Yoder, Thomas Stryjski, Zachary O'Brien
Date: 12/5/18
Class: EEEE-346-01
Assignment: Project 3
Purpose: Executes functions declared in Bacteria.h
*/
#include "Bacteria.h"
#include "Miscellaneous.h"
#include <cmath>
//constructors
Bacteria::Bacteria(double x, double y, double z) {
consumption_amount = 0;
consumption_time = 0;
reproduction_amount = 2;
reproduction_time = 3;
reproduction_counter = reproduction_time;
consumption_food_counter = consumption_amount;
consumption_time_counter = consumption_time;
age = 0;
movement = 2;
spawn_distance = 4;
visibility = 1;
setLocation(x, y, z);
}
//getters
double Bacteria::get_fertility() {
return fertility;
}
//setters
void Bacteria::set_sunlight(double x) {
sunlight = x;
}
void Bacteria::set_chemical(double x) {
chemical = x;
}
void Bacteria::set_fertility() {
double temper = exp((-1/200) * pow((temperature - 75), 2));
fertility = (1 - temper) + (1 + sunlight) * (1 +chemical);
}
//other
void Bacteria::reproduce(Bacteria *O, double x_max, double y_max, double z_max) {
double theta, phi, x, y, z;
do {
theta = fRand(0, 2 * 3.14159265);
phi = fRand(0, 2 * 3.14159265);
x = spawn_distance * cos(phi) * cos(theta);
y = spawn_distance * cos(phi) * sin(theta);
z = spawn_distance * sin(phi);
} while ((x > x_max) || (x < -(x_max)) || (y > y_max) || (y < -(y_max)) || (z > z_max) || (z < -(z_max)));
O->setLocation(x, y, z);
}
void Bacteria::aged() {
age++;
movement = movement - (age/20); //decereases movement the older the cell is, although this is scaled by the constant 10. Accumulates
spawn_distance = 4 - (age / 100);//decreases spawn distance as the cell gets older, scaled by the constant 100. Acculmulates
}