-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbass.cpp
More file actions
40 lines (36 loc) · 1.51 KB
/
bass.cpp
File metadata and controls
40 lines (36 loc) · 1.51 KB
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
#include "bass.h"
#include <memory>
#include <vector>
#include <raymath.h>
Bass::Bass(const std::vector<std::unique_ptr<Fish>>* allFish,const float width_limit, const float height_limit) : Fish(width_limit, height_limit) {
allFishPointer = allFish;
energy = -1;
target = -1;
chase = false;
}
// Hunt shrimp and follow player
void Bass::GatherInstructions() {
if (energy < 0) { // Hunts down the nearest shrimp at the time
if (!chase) { // Finds nearest target and sets acceleration
float minDistance = std::numeric_limits<float>::max();
for (int i = 0; i < 100; i++) {
float distanceFromShrimp = std::abs(Vector2Length(position - (*allFishPointer)[i]->position));
if (distanceFromShrimp < minDistance) {
minDistance = distanceFromShrimp;
target = i;
}
}
acceleration = Vector2Normalize((*allFishPointer)[target]->position - position);
chase = true;
} else if (std::abs(Vector2Length(position - (*allFishPointer)[target]->position)) < 100) { // Stops when target is caught and respawned
(*allFishPointer)[target]->Respawn(width_limit, height_limit);
chase = false;
energy = GetRandomValue(700, 2000);
acceleration = { 0, 0 };
} else {
acceleration = Vector2Normalize((*allFishPointer)[target]->position - position) * 3.0f;
}
} else { // When not hunting
energy--;
}
}