-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.cpp
175 lines (145 loc) · 3.68 KB
/
Player.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include <zenilib.h>
#include "Player.h"
using namespace Zeni;
using namespace Zeni::Collision;
namespace Crate {
Player::Player(const Camera &camera_,
const Vector3f &end_point_b_,
const float radius_)
: m_camera(camera_),
m_end_point_b(end_point_b_),
m_radius(radius_),
m_is_on_ground(false),
fuel(200.0f),
health(200.0f)
{
m_camera.fov_rad = Zeni::Global::pi / 3.0f;
create_body();
}
// Level 2
void Player::set_position(const Point3f &position) {
m_camera.position = position;
create_body();
}
void Player::adjust_pitch(const float &phi) {
const Quaternion backup = m_camera.orientation;
const Vector3f backup_up = m_camera.get_up();
m_camera.adjust_pitch(phi);
if(m_camera.get_up().k < 0.0f && backup_up.k >= 0.0f)
m_camera.orientation = backup;
}
void Player::turn_left_xy(const float &theta) {
m_camera.turn_left_xy(theta);
}
void Player::set_on_ground(const bool &is_on_ground_) {
m_is_on_ground = is_on_ground_;
if(m_is_on_ground)
m_velocity.k = 0.0f;
}
void Player::jump() {
if(m_is_on_ground) {
m_velocity.k += 150.0f;
m_is_on_ground = false;
}
}
std::pair <Zeni::Point3f, Zeni::Vector3f> Player::shoot(){
return std::make_pair (Zeni::Point3f(m_camera.position), 350.0f*(Zeni::Vector3f(m_camera.get_forward())).normalized());
}
//jetpack implementation
void Player::fly()
{
no_move.stop();
if(!fly_timer.is_running())
{
fly_timer.set(0);
fly_timer.start();
}
else
{
rest_timer.stop();
fly_timer.start();
in_air_time = fly_timer.seconds();
if(fuel > 0.0f)
{
fuel -= 1.5f * in_air_time;
}
m_velocity.k += 5.0f;
}
}
//lost health when being atacked
void Player::attacked()
{
//take away some health
if(health >=5.0f)health -= 20.0f;
//get bumped
m_camera.position.z = 55.0f;
//m_velocity.k = 260.0f;
}
void Player::port(const Zeni::Point3f &location_)
{
m_camera.position = location_ + Zeni::Vector3f(0.0f, 0.0f, 50.0f);
create_body();
}
void Player::fall()
{
if(fly_timer.is_running())
{
fly_timer.set(0);
fly_timer.stop();
}
//no_move.stop();
}
bool Player::can_fly()
{
if(fuel > 0.0f) return true;
else return false;
}
void Player::fuel_up()
{
if(!rest_timer.is_running())
{
rest_timer.set(0);
rest_timer.start();
}
else
{
rest_timer.start();
rest_time = rest_timer.seconds();
if(fuel < 200)
{
fuel += rest_time * 2.0f;
}
}
}
float Player::get_time()
{
return fuel;
}
float Player::get_health()
{
return health;
}
bool Player::resting()
{
bool result = false;
if(!no_move.is_running())
{
no_move.set(0);
no_move.start();
}
return no_move.seconds() > 0.5f;
}
void Player::step(const float &time_step) {
m_camera.position += time_step * m_velocity;
create_body();
}
void Player::create_body() {
Sound &sr = get_Sound();
m_body = Capsule(m_camera.position,
m_camera.position + m_end_point_b,
m_radius);
sr.set_listener_position(m_camera.position);
sr.set_listener_forward_and_up(m_camera.get_forward(), m_camera.get_up());
sr.set_listener_velocity(m_velocity);
}
}