-
Notifications
You must be signed in to change notification settings - Fork 0
/
rabbit.cpp
114 lines (101 loc) · 3.45 KB
/
rabbit.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <iostream>
#include <cmath>
#include "rabbit.h"
#include "application.h"
#include "constants.h"
using namespace std;
Rabbit::Rabbit()
{
rabbit_id = 0;
truex = -100;
truey = -100;
distance_to_user = 9999;
distance_complement = 0.0;
angle_to_user = 0.0;
activated = false;
is_fox = false;
is_rabbit = false;
}
Rabbit::~Rabbit(){}
// MODIFICATION MEMBER FUNCTIONS
void Rabbit::setRabbitId(int a){
rabbit_id = a;
}
void Rabbit::setFox(bool a){
is_fox = a;
}
void Rabbit::setTrueX(int x){
truex = x;
}
void Rabbit::setTrueY(int y){
truey = y;
}
void Rabbit::setTrueXandTrueY(int x, int y){
setTrueX(x);
setTrueY(y);
}
void Rabbit::initRabbit(int a, bool b, bool c, int x, int y, int userx, int usery){
setTrueXandTrueY(x,y);
calcDistanceToUser(userx, usery);
rabbit_id = a;
is_fox = b;
is_rabbit = c;
}
void Rabbit::calcDistanceToUser(int userx, int usery){
distance_to_user = abs(sqrt(pow(userx - truex, 2) + pow(usery - truey, 2))); // this is an integer, not a double. we are rounding.
distance_complement = pow((((float)1) - ((distance_to_user/(SCREENDIAGONAL(SCREENW,SCREENH))))),2); // complement distance to amplitude
}
void Rabbit::calcAngleToUser(int userx, int usery){
angle_to_user = DEGTORAD(acos((userx - truex)/distance_to_user)); // get our adjacent and hypotenuse
if(usery < truey) angle_to_user = (angle_to_user*-1)+360; // reflection & offset to get an increasing value after cos 1/2
angle_to_user -= 90; // 0 deg is to the left, we will make it to the up
if(angle_to_user < 0) angle_to_user += 360; // ^ will give us some negatives, which are decreasing at a convenient rate...
if(distance_to_user == 0) angle_to_user = 0; // todo activate all speakers or earcon or something
}
void Rabbit::calcDistanceToCenter(int userx, int usery){
distance_to_center = abs(sqrt(pow(CENTERX - truex, 2) + pow(CENTERY - truey, 2)));
}
void Rabbit::calcAngleToCenter(int userx, int usery){
angle_to_center = DEGTORAD(acos((CENTERX - truex)/distance_to_center)); // get our adjacent and hypotenuse
if(CENTERY < truey) angle_to_center = (angle_to_center*-1)+360; // reflection & offset to get an increasing value after cos 1/2
angle_to_center -= 90; // 0 deg is to the left, we will make it to the up
if(angle_to_center < 0) angle_to_center += 360; // ^ will give us some negatives, which are decreasing at a convenient rate...
if(distance_to_center == 0) angle_to_center = 0; // todo activate all speakers or earcon or something
}
void Rabbit::activate(bool flag){
activated = flag;
}
// CONSTANT MEMBER FUNCTIONS
int Rabbit::getTrueX(){
return truex;
}
int Rabbit::getTrueY(){
return truey;
}
int Rabbit::getRabbitId(){
return rabbit_id;
}
float Rabbit::getAngleToUser(){
return angle_to_user;
}
float Rabbit::getDistanceToUser(){
return distance_to_user;
}
float Rabbit::getAngleToCenter(){
return angle_to_center;
}
float Rabbit::getDistanceToCenter(){
return distance_to_center;
}
float Rabbit::getDistanceComplement(){
return distance_complement;
}
bool Rabbit::isActivated(){
return activated;
}
bool Rabbit::isFox(){
return is_fox;
}
Rabbit& Rabbit::getRabbit(){
return *this;
}