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"
|
#include "raylib.h"
|
||||||
|
|
||||||
// let's a go!
|
// let's a go!
|
||||||
|
float curhorvel=0.0f; //current horizonatal velocity
|
||||||
void UpdatePlayerControls(void)
|
void UpdatePlayerControls(void)
|
||||||
{
|
{
|
||||||
// if there isn't a player, you probably can't do much
|
// if there isn't a player, you probably can't do much
|
||||||
if (!player)
|
if (!player){
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
if(curhorvel==0.0f){
|
||||||
|
curhorvel=10.0f*scale;
|
||||||
|
}
|
||||||
// if a key pressed, push player to the left
|
// if a key pressed, push player to the left
|
||||||
if (IsKeyDown(KEY_A))
|
if (IsKeyDown(KEY_A))
|
||||||
{
|
{
|
||||||
|
if(curhorvel<PMV){
|
||||||
|
curhorvel=curhorvel*PLAYER_SPEED_FACTOR;
|
||||||
|
}
|
||||||
ApplyForce(
|
ApplyForce(
|
||||||
player,
|
player,
|
||||||
(Vector2){-PLAYER_FORCE, 0}
|
(Vector2){-curhorvel, 0}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// if d key pressed, push player to the right
|
// 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(
|
ApplyForce(
|
||||||
player,
|
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) &&
|
if (IsGrounded(player) &&
|
||||||
IsKeyPressed(KEY_SPACE))
|
IsKeyPressed(KEY_SPACE))
|
||||||
{
|
{
|
||||||
|
|||||||
13
src/world.c
13
src/world.c
@@ -1,11 +1,14 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
|
|
||||||
|
// the beeg one. hooooooooooooooooh boy
|
||||||
|
|
||||||
const float scale = 43.7445319335f;
|
const float scale = 43.7445319335f;
|
||||||
const float g = 9.81f * scale;
|
const float g = 9.81f * scale;
|
||||||
|
|
||||||
const float PLAYER_FORCE = 3500.0f;
|
const float PMV = 10000.0*scale; //Player Max Velocity
|
||||||
const float JUMP_FORCE = 22000.0f;
|
const float PLAYER_SPEED_FACTOR =1.3f;
|
||||||
|
const float JUMP_FORCE = 300.0f*scale;
|
||||||
|
|
||||||
const float AIR_DRAG = 0.999f;
|
const float AIR_DRAG = 0.999f;
|
||||||
|
|
||||||
@@ -79,7 +82,9 @@ Entity *SpawnEntity(
|
|||||||
|
|
||||||
return NULL;
|
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)
|
void ClearWorld(void)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < MAX_ENTITIES; i++)
|
for (int i = 0; i < MAX_ENTITIES; i++)
|
||||||
@@ -90,6 +95,7 @@ void ClearWorld(void)
|
|||||||
player = NULL;
|
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)
|
void InitWorld(void)
|
||||||
{
|
{
|
||||||
ClearWorld();
|
ClearWorld();
|
||||||
@@ -119,6 +125,7 @@ void InitWorld(void)
|
|||||||
simTime = 0.0f;
|
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 CountEntities(void)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ extern bool isSimulating;
|
|||||||
|
|
||||||
extern float simTime;
|
extern float simTime;
|
||||||
|
|
||||||
|
extern const float PMV;
|
||||||
|
|
||||||
|
extern const float PLAYER_SPEED_FACTOR;
|
||||||
|
|
||||||
void ApplyForce(Entity *e, Vector2 force);
|
void ApplyForce(Entity *e, Vector2 force);
|
||||||
bool IsGrounded(Entity *e);
|
bool IsGrounded(Entity *e);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user