morault/ProjectMorault/Morault_Player.cpp
2025-06-01 16:26:04 -04:00

73 lines
2.2 KiB
C++

#include "Morault_Player.h"
#include <raymath.h>
Morault::Gameplay::Player::Player()
{
}
Morault::Gameplay::Player::Player(PlayerData a, PlayerController b)
{
data = a; controller = b; // self explanatory <3
}
Morault::Gameplay::Player::~Player()
{
}
Morault::Gameplay::PlayerController::PlayerController()
{
camera = { 0 };
camera.fovy = 90;
camera.position = { -10,5,0 };
camera.target = { 0,5,0 };
camera.up = { 0,1,0 };
camera.projection = CAMERA_PERSPECTIVE;
rotation = { 10,0,0 };
}
Morault::Gameplay::PlayerController::PlayerController(Vector3 position)
{
camera = { 0 };
camera.fovy = 90;
camera.position = position;
camera.target = { 0, position.y,0 };
camera.up = { 0,1,0 };
camera.projection = CAMERA_PERSPECTIVE;
rotation = { 1,0,0 };
}
int collfloor = 5;
float gravity = 0;
void Morault::Gameplay::PlayerController::UpdatePlayerController(bool focus)
{
if (focus) {
rotation = Vector3RotateByAxisAngle(rotation, { 0,1,0 }, -GetMouseDelta().x * 0.05 * sensitivityMultiplier);
rotation.y = Clamp(rotation.y - GetMouseDelta().y * 0.3 * sensitivityMultiplier, -15, 15);
camera.target = Vector3Add(camera.position, rotation);
if (IsKeyDown(KEY_W)) camera.position = Vector3Add(camera.position, Vector3Multiply({rotation.x, 0, rotation.z}, {GetFrameTime(), GetFrameTime(), GetFrameTime()}));
if (IsKeyDown(KEY_S)) camera.position = Vector3Subtract(camera.position, Vector3Multiply({ rotation.x, 0, rotation.z }, { GetFrameTime(), GetFrameTime(), GetFrameTime() }));
if (IsKeyDown(KEY_A)) camera.position = Vector3Add(camera.position, Vector3Multiply(Vector3RotateByAxisAngle({ rotation.x, 0, rotation.z }, {0,1,0}, DEG2RAD*90), {GetFrameTime(), GetFrameTime(), GetFrameTime()}));
if (IsKeyDown(KEY_D)) camera.position = Vector3Add(camera.position, Vector3Multiply(Vector3RotateByAxisAngle({ rotation.x, 0, rotation.z }, { 0,1,0 }, DEG2RAD * -90), { GetFrameTime(), GetFrameTime(), GetFrameTime() }));
if (IsKeyPressed(KEY_SPACE)) {
gravity -= 5;
}
}
camera.position.y -= gravity*GetFrameTime();
gravity += 10*GetFrameTime();
if (camera.position.y < collfloor) {
camera.position.y = collfloor;
gravity = 0;
}
}
Morault::Gameplay::PlayerController::~PlayerController()
{
camera = { 0 };
}