thelandofwildblocs/CPP/player.cpp
thatscringebro 9dfd911bff Init
2023-02-16 09:26:40 -05:00

90 lines
2.2 KiB
C++
Executable File

#include "../H/player.h"
Player::Player(const Vector3f & position, float rotx, float roty) : m_rotx(rotx), m_roty(roty), m_pos(position){
m_health = 100.f;
std::cout << "Constructor" << std::endl;
}
Vector3f Player::Position(){
return m_pos;
}
void Player::TurnCamera(float x, float y){
x *= 0.01;
y *= 0.01;
if(m_rotx + y >= -70 && m_rotx + y <= 70)
m_rotx += y;
m_roty += x;
}
void Player::SetPosition (Vector3f delta){
m_pos.x = delta.x;
m_pos.y = delta.y;
m_pos.z = delta.z;
}
Vector3f Player::SimulateMove ( bool front , bool back , bool left , bool right , bool run, float elapsedTime ){
Vector3f delta(0, 0, 0);
double speed = 0.1;
if(run)
speed = 0.2;
if (front){
float yrotrad = (m_roty / 180 * 3.141592654f);
delta.x += float(sin(yrotrad)) * speed;
delta.z -= float(cos(yrotrad)) * speed;
}
if (back){
float yrotrad = (m_roty / 180 * 3.141592654f);
delta.x -= float(sin(yrotrad)) * speed;
delta.z += float(cos(yrotrad)) * speed;
}
if (left){
float yrotrad = (m_roty / 180 * 3.141592654f);
delta.x -= float(cos(yrotrad)) * speed;
delta.z -= float(sin(yrotrad)) * speed;
}
if(right){
float yrotrad = (m_roty / 180 * 3.141592654f);
delta.x += float(cos(yrotrad)) * speed;
delta.z += float(sin(yrotrad)) * speed;
}
return delta;
}
float Player::SimulateJump(bool jump, bool& InJump, float& deltay, bool OnGround, float& jumpsize){
if(jump){
if (OnGround)
{
InJump = true;
}
}
if(InJump){
deltay += 0.2;
if (jumpsize > 1.5)
{
InJump = false;
return -1.5;
}
return 0.1;
}
return 0;
}
void Player::ApplyTransformation ( Transformation & transformation ) const{
transformation.ApplyRotation(-m_rotx, 1.f, 0, 0);
transformation.ApplyRotation(-m_roty, 0, 1.f, 0);
transformation.ApplyTranslation(-m_pos);
}
void Player::Damage(Mob& mob){
mob.setHealth(mob.Health() - m_damage);
}
float Player::Health(){
return m_health;
}
void Player::setHealth(float health){
m_health = health;
}