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))
{

View File

@@ -1,11 +1,14 @@
#include <stddef.h>
#include "world.h"
// the beeg one. hooooooooooooooooh boy
const float scale = 43.7445319335f;
const float g = 9.81f * scale;
const float PLAYER_FORCE = 3500.0f;
const float JUMP_FORCE = 22000.0f;
const float PMV = 10000.0*scale; //Player Max Velocity
const float PLAYER_SPEED_FACTOR =1.3f;
const float JUMP_FORCE = 300.0f*scale;
const float AIR_DRAG = 0.999f;
@@ -79,7 +82,9 @@ Entity *SpawnEntity(
return NULL;
}
// say bye bye to EVERYTHINGGGG AHAHAHAHAHAAH
// im a little mad with power
// this is literally just a helper function to clear the entities and player
void ClearWorld(void)
{
for (int i = 0; i < MAX_ENTITIES; i++)
@@ -90,6 +95,7 @@ void ClearWorld(void)
player = NULL;
}
// used in main.c to start the actual engine behaviors. spawns the player, and a few other boxes for funsies.
void InitWorld(void)
{
ClearWorld();
@@ -119,6 +125,7 @@ void InitWorld(void)
simTime = 0.0f;
}
// helper function: count number of entities. Something somewhere uses this. I think it's probably for entity counting. Don't quote me on that.
int CountEntities(void)
{
int count = 0;

View File

@@ -12,6 +12,10 @@ extern bool isSimulating;
extern float simTime;
extern const float PMV;
extern const float PLAYER_SPEED_FACTOR;
void ApplyForce(Entity *e, Vector2 force);
bool IsGrounded(Entity *e);

BIN
wrldbox

Binary file not shown.