sdl_runtime_compiler git · main
SDL3 game for running and compiling code at runtime
C++ 72.3% C 26.2%git clone https://git.christianimmanuel.de/sdl-graphics/sdl_runtime_compiler.gitwget https://git.christianimmanuel.de/sdl-graphics/sdl_runtime_compiler/archive/sdl_runtime_compiler.tar.gzsrc/entities/player.cpp raw
#include "entities/player.hpp"
#include "utils/config.hpp"
namespace
Nimbin
{
Player::Player()
: pos {8.0, 0.0, 8.0},
vel {0.0, 0.0, 0.0},
radius(0.5f),
height(1.5f),
pitch (-0x08000000),
yaw (0x20000000)
{}
void
Player::apply_Collision(const PlayerCollision& col)
{
pos = col.pos;
vel = col.vel;
on_ground = col.hit_y;
}
void
Player::respawn(const Vec3& spawn_pos)
{
pos = spawn_pos;
vel = {0.0, 0.0, 0.0};
}
void
Player::add_Look(int dx, int dy)
{
int32_t delta = dx * 0x00080000;
int32_t y = static_cast<int32_t>(yaw) - delta;
yaw = static_cast<uint32_t>(y);
pitch = SDL_max(-0x40000000, SDL_min(0x40000000, pitch - dy * 0x00080000));
}
void
Player::compute_Movement(const FrameInput& input)
{
double rad = (double)yaw * Config::Physics::binrad;
double cos = SDL_cos(rad);
double sin = SDL_sin(rad);
double dir_x = (input.right ? 1.0 : 0.0) - (input.left ? 1.0 : 0.0);
double dir_z = (input.backward ? 1.0 : 0.0) - (input.forward ? 1.0 : 0.0);
double n = dir_x * dir_x + dir_z * dir_z;
_acc_x = 0;
_acc_z = 0;
if (n != 0) {
double inv = 1.0 / SDL_sqrt(n);
_acc_x = Config::Physics::player_move_accel * ( cos*dir_x + sin*dir_z) * inv;
_acc_z = Config::Physics::player_move_accel * (-sin*dir_x + cos*dir_z) * inv;
}
}
} // namespace Nimbin