Better horizontal acceleration courtesy of Alex M.

This commit is contained in:
2026-06-16 14:35:32 -04:00
parent 1e597beeee
commit 4988964f22
4 changed files with 34 additions and 11 deletions

View File

@@ -6,30 +6,42 @@
#include "raylib.h"
// let's a go!
float curhorvel=0.0f; //current horizonatal velocity
void UpdatePlayerControls(void)
{
// if there isn't a player, you probably can't do much
if (!player)
if (!player){
return;
}
if(curhorvel==0.0f){
curhorvel=10.0f*scale;
}
// if a key pressed, push player to the left
if (IsKeyDown(KEY_A))
{
if(curhorvel<PMV){
curhorvel=curhorvel*PLAYER_SPEED_FACTOR;
}
ApplyForce(
player,
(Vector2){-PLAYER_FORCE, 0}
(Vector2){-curhorvel, 0}
);
}
// if d key pressed, push player to the right
if (IsKeyDown(KEY_D))
else if (IsKeyDown(KEY_D))
{
if(curhorvel<=PMV){
curhorvel=curhorvel*PLAYER_SPEED_FACTOR;
}
ApplyForce(
player,
(Vector2){PLAYER_FORCE, 0}
);
(Vector2){curhorvel, 0}
);
}
// if sspace key pressed (and player isn't already jumping), push player upward
else{
curhorvel=10.0f*scale;
}
// if sspace key pressed (and player isn't already jumping), push player
if (IsGrounded(player) &&
IsKeyPressed(KEY_SPACE))
{