Files
WrldBox/src/player.c
2026-06-22 01:46:21 -04:00

59 lines
1.2 KiB
C

#include "player.h"
#include "world.h"
#include "config.h"
#include "raylib.h"
// let's a go!
float curhorvel=0.0f; //current horizonatal velocity
bool dir=0;
void UpdatePlayerControls(void)
{
// if there isn't a player, you probably can't do much
if (!player){
return;
}
if(curhorvel==0.0f){
curhorvel=65.5f*scale;
}
// if a key pressed, push player to the left
if (IsKeyDown(KEY_A))
{
dir=1;
if(curhorvel<MAX_PLAYER_SPEED){
curhorvel=curhorvel*PLAYER_SPEED_FACTOR;
}
ApplyForce(
player,
(Vector2){-curhorvel, 0}
);
}
// if d key pressed, push player to the right
else if (IsKeyDown(KEY_D))
{
dir=0;
if(curhorvel<=MAX_PLAYER_SPEED){
curhorvel=curhorvel*PLAYER_SPEED_FACTOR;
}
ApplyForce(
player,
(Vector2){curhorvel, 0}
);
}
else{
curhorvel=65.5f*scale;
}
// if sspace key pressed (and player isn't already jumping), push player
if (IsGrounded(player) &&
IsKeyPressed(KEY_SPACE))
{
player->velocity.y = 0;
ApplyForce(
player,
(Vector2){0, -JUMP_FORCE}
);
}
}