All checks were successful
Build Project / build (ubuntu-latest) (push) Successful in 17m55s
146 lines
2.7 KiB
C
146 lines
2.7 KiB
C
#include <stddef.h>
|
|
#include "world.h"
|
|
#include "collision.h"
|
|
|
|
// the beeg one. hooooooooooooooooh boy
|
|
|
|
const float scale = 43.7445319335f;
|
|
const float g = 9.81f * scale;
|
|
|
|
const float PLAYER_SPEED_FACTOR =1.1f; //1.1 is good
|
|
const float JUMP_FORCE = 450.0f*scale;
|
|
|
|
const float AIR_DRAG = 0.999f;
|
|
|
|
const float GROUND_FRICTION = 27.432f*scale;
|
|
const float MAX_PLAYER_SPEED = 10.0f*scale;
|
|
|
|
const float BOUNCE = 0.45f;
|
|
|
|
const float ground_y = 550.0f;
|
|
|
|
Entity entities[MAX_ENTITIES];
|
|
|
|
Entity *player = NULL;
|
|
|
|
bool isSimulating = true;
|
|
|
|
float simTime = 0.0f;
|
|
|
|
void ApplyForce(Entity *e, Vector2 force)
|
|
{
|
|
if (!e || !e->active)
|
|
return;
|
|
|
|
e->force.x += force.x;
|
|
e->force.y += force.y;
|
|
}
|
|
|
|
bool IsGrounded(Entity *e)
|
|
{
|
|
if (!e)
|
|
return false;
|
|
if(e->position.y +e->size * 0.5f >=ground_y - 2.0f || e->headgrounded){
|
|
return true;
|
|
}
|
|
else{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
Entity *SpawnEntity(
|
|
float x,
|
|
float y,
|
|
float size,
|
|
float mass,
|
|
Color color,
|
|
float drag)
|
|
{
|
|
for (int i = 0; i < MAX_ENTITIES; i++)
|
|
{
|
|
if (!entities[i].active)
|
|
{
|
|
Entity *e = &entities[i];
|
|
|
|
e->active = true;
|
|
|
|
e->isPlayer = false;
|
|
e->affectedByGravity = true;
|
|
|
|
e->mass = mass;
|
|
e->size = size;
|
|
e->drag = drag;
|
|
|
|
e->position = (Vector2){x, y};
|
|
e->velocity = (Vector2){0, 0};
|
|
e->acceleration = (Vector2){0, 0};
|
|
e->force = (Vector2){0, 0};
|
|
|
|
e->color = color;
|
|
e->headgrounded = false;
|
|
|
|
return e;
|
|
}
|
|
}
|
|
|
|
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++)
|
|
{
|
|
entities[i].active = false;
|
|
}
|
|
|
|
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();
|
|
|
|
player = SpawnEntity(
|
|
120,
|
|
120,
|
|
40,
|
|
1.0f,
|
|
BLUE,
|
|
0.1f);
|
|
|
|
if (player)
|
|
{
|
|
player->isPlayer = true;
|
|
}
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
{
|
|
SpawnEntity(
|
|
300 + i * 50,
|
|
50,
|
|
25,
|
|
1.0f,
|
|
RED,
|
|
0.9f);
|
|
}
|
|
|
|
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;
|
|
|
|
for (int i = 0; i < MAX_ENTITIES; i++)
|
|
{
|
|
if (entities[i].active)
|
|
count++;
|
|
}
|
|
|
|
return count;
|
|
}
|