Better horizontal acceleration courtesy of Alex M.
This commit is contained in:
28
src/player.c
28
src/player.c
@@ -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))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user