WIP docs: commenting in codebase and README updates
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
# WrldBox Sandbox Simulator
|
||||
|
||||
## 🧊Introduction
|
||||
|
||||
**WrldBox** is a work-in-progress sandbox simulator made by Team wholeworldcoding. It is currently in an experimental stage.
|
||||
|
||||
It consists of two components:
|
||||
|
||||
- `text_physics.c`, a text-based 1-object physics simulation
|
||||
|
||||
- `ray.c`, rendering the simulation with raylib.
|
||||
|
||||
This project has a huge potential to become the next major `wholeworldcoding` project.
|
||||
|
||||
## 🛠️ Build and Compile
|
||||
|
||||
Clone the repository. Once you have navigated to the folder, you can run:
|
||||
|
||||
- `make text && ./text_physics.out` to compile and run `text_physics.c`
|
||||
|
||||
- `make visual && ./ray.out` to compile and run `ray.c`
|
||||
|
||||
## 🏅Credits
|
||||
|
||||
This project was impossible without the support of all three `wholeworldcoding` members.
|
||||
29
README.md
Normal file
29
README.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# WrldBox Sandbox Simulator
|
||||
|
||||
## 🧊Introduction
|
||||
|
||||
**WrldBox** is a work-in-progress sandbox simulator made by Team wholeworldcoding. It is currently in a pretty developed experimental stage.
|
||||
|
||||
It consists of several components:
|
||||
|
||||
- `src/main.c`, Main script. Takes all other src and actually renders the engine.
|
||||
- `src/physics.c`, All the science & math crap. Ugh. (physics.h: exposes UpdateEntities function)
|
||||
- `src/render.c`, Rendering of entities. Entities are currently limited to rectangles for... no particular reason. (render.h: exposes DrawEntities function)
|
||||
- `src/player.c`, Player control scripting. (player.h: exposes UpdatePlayerControls function)
|
||||
|
||||
|
||||
- More stuff in src. README in progress.
|
||||
|
||||
- OLD contains the original logic this came from.
|
||||
|
||||
This project *is* the next major `wholeworldcoding` project.
|
||||
|
||||
## 🛠️ Build and Compile
|
||||
|
||||
Clone the repository. Once you have navigated to the folder, you can run:
|
||||
|
||||
- `make`
|
||||
|
||||
## 🏅Credits
|
||||
|
||||
This project was impossible without the support of all three `wholeworldcoding` members.
|
||||
10
src/docprogress.txt
Normal file
10
src/docprogress.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
main.c - Done
|
||||
physics.c - Done, refine later
|
||||
physics.h - Done
|
||||
render.c - Done
|
||||
render.h - Done
|
||||
player.c - Done
|
||||
player.h - Done
|
||||
world.c
|
||||
world.h
|
||||
config.h
|
||||
16
src/main.c
16
src/main.c
@@ -1,7 +1,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
// add all the shit from the other shit
|
||||
#include "raylib.h"
|
||||
|
||||
#include "world.h"
|
||||
#include "physics.h"
|
||||
#include "player.h"
|
||||
@@ -10,6 +9,7 @@
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Let's make a window
|
||||
const int screenWidth = 1000;
|
||||
const int screenHeight = 600;
|
||||
|
||||
@@ -20,27 +20,33 @@ int main(void)
|
||||
|
||||
SetTargetFPS(60);
|
||||
|
||||
// Now we actually start the code
|
||||
InitWorld();
|
||||
|
||||
printf("WrldBox Sandbox Started\n");
|
||||
printf("WrldBox engine started\n");
|
||||
printf("Gravity = %.2f\n", g);
|
||||
|
||||
// until we close the window, expect inputs
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
float dt = GetFrameTime();
|
||||
|
||||
if (IsKeyPressed(KEY_P))
|
||||
{
|
||||
// If it's simulating, stop simulating. If it isn't simulating, start simulating.
|
||||
isSimulating = !isSimulating;
|
||||
}
|
||||
|
||||
if (IsKeyPressed(KEY_R))
|
||||
{
|
||||
// VERY complicated reset logic
|
||||
InitWorld();
|
||||
}
|
||||
|
||||
if (IsKeyPressed(KEY_Q))
|
||||
{
|
||||
// We're gonna have to rewrite the entity logic at some point. Because an actual game doesn't just contain a bunch of blocks. But whatever for now...
|
||||
// Q key pressed? -> Poof, box, random position, random size, random color.
|
||||
SpawnEntity(
|
||||
GetRandomValue(50, 950),
|
||||
GetRandomValue(20, 150),
|
||||
@@ -57,6 +63,7 @@ int main(void)
|
||||
|
||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
|
||||
{
|
||||
// Spawn cube where the mouse is when it clicks!
|
||||
Vector2 m = GetMousePosition();
|
||||
|
||||
SpawnEntity(
|
||||
@@ -69,12 +76,14 @@ int main(void)
|
||||
|
||||
if (isSimulating)
|
||||
{
|
||||
// allow player to be controlled, fit everything within the size of the screen
|
||||
UpdatePlayerControls();
|
||||
UpdateEntities(dt, screenWidth);
|
||||
|
||||
simTime += dt;
|
||||
}
|
||||
|
||||
// UI shenanigans
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
@@ -167,6 +176,7 @@ int main(void)
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
// When the window wants to close, close it. What a surprise.
|
||||
CloseWindow();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,20 +1,26 @@
|
||||
#include <math.h>
|
||||
|
||||
// better hope you were paying attention in physics class for this one
|
||||
#include "physics.h"
|
||||
#include "world.h"
|
||||
#include "config.h"
|
||||
|
||||
// Main physics update loop for all entities
|
||||
void UpdateEntities(float dt, int screenWidth)
|
||||
{
|
||||
// Iterate through all possible entities
|
||||
for (int i = 0; i < MAX_ENTITIES; i++)
|
||||
{
|
||||
Entity *e = &entities[i];
|
||||
|
||||
// Skip inactive entities
|
||||
if (!e->active)
|
||||
continue;
|
||||
|
||||
// Check if entity is currently touching the ground
|
||||
// YOU'RE GROUNDED!!! lol
|
||||
bool onGround = IsGrounded(e);
|
||||
|
||||
// Apply gravity force if enabled for this entity
|
||||
if (e->affectedByGravity)
|
||||
{
|
||||
ApplyForce(
|
||||
@@ -23,21 +29,25 @@ void UpdateEntities(float dt, int screenWidth)
|
||||
);
|
||||
}
|
||||
|
||||
// Compute acceleration from accumulated forces (F = ma)
|
||||
e->acceleration.x =
|
||||
e->force.x / e->mass;
|
||||
|
||||
e->acceleration.y =
|
||||
e->force.y / e->mass;
|
||||
|
||||
// Integrate velocity from acceleration
|
||||
e->velocity.x +=
|
||||
e->acceleration.x * dt;
|
||||
|
||||
e->velocity.y +=
|
||||
e->acceleration.y * dt;
|
||||
|
||||
// Apply air drag to slow movement over time
|
||||
e->velocity.x *= AIR_DRAG;
|
||||
e->velocity.y *= AIR_DRAG;
|
||||
|
||||
// Apply ground friction when on the ground
|
||||
if (onGround)
|
||||
{
|
||||
if (e->velocity.x > 0)
|
||||
@@ -58,6 +68,7 @@ void UpdateEntities(float dt, int screenWidth)
|
||||
}
|
||||
}
|
||||
|
||||
// Clamp player horizontal speed
|
||||
if (e->isPlayer)
|
||||
{
|
||||
if (e->velocity.x > MAX_PLAYER_SPEED)
|
||||
@@ -67,14 +78,17 @@ void UpdateEntities(float dt, int screenWidth)
|
||||
e->velocity.x = -MAX_PLAYER_SPEED;
|
||||
}
|
||||
|
||||
// Integrate position from velocity
|
||||
e->position.x +=
|
||||
e->velocity.x * dt;
|
||||
|
||||
e->position.y +=
|
||||
e->velocity.y * dt;
|
||||
|
||||
// Reset forces after integration step
|
||||
e->force = (Vector2){0, 0};
|
||||
|
||||
// Ground collision
|
||||
if (e->position.y +
|
||||
e->size * 0.5f >=
|
||||
ground_y)
|
||||
@@ -86,12 +100,14 @@ void UpdateEntities(float dt, int screenWidth)
|
||||
e->velocity.y *=
|
||||
-BOUNCE;
|
||||
|
||||
// Stop tiny bounces... or at least, attempt to.
|
||||
if (fabsf(e->velocity.y) < 15.0f)
|
||||
{
|
||||
e->velocity.y = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Left wall collision
|
||||
if (e->position.x -
|
||||
e->size * 0.5f < 0)
|
||||
{
|
||||
@@ -101,6 +117,7 @@ void UpdateEntities(float dt, int screenWidth)
|
||||
e->velocity.x *= -0.6f;
|
||||
}
|
||||
|
||||
// Right wall collision
|
||||
if (e->position.x +
|
||||
e->size * 0.5f >
|
||||
screenWidth)
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#ifndef PHYSICS_H
|
||||
#define PHYSICS_H
|
||||
|
||||
// FUNction declaration! yay!!!
|
||||
// used by main script to update entities as time goes on
|
||||
// i don't think it's used anywhere else, but double check me
|
||||
void UpdateEntities(float dt, int screenWidth);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,11 +5,15 @@
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
// let's a go!
|
||||
|
||||
void UpdatePlayerControls(void)
|
||||
{
|
||||
// if there isn't a player, you probably can't do much
|
||||
if (!player)
|
||||
return;
|
||||
|
||||
// if a key pressed, push player to the left
|
||||
if (IsKeyDown(KEY_A))
|
||||
{
|
||||
ApplyForce(
|
||||
@@ -17,7 +21,7 @@ void UpdatePlayerControls(void)
|
||||
(Vector2){-PLAYER_FORCE, 0}
|
||||
);
|
||||
}
|
||||
|
||||
// if d key pressed, push player to the right
|
||||
if (IsKeyDown(KEY_D))
|
||||
{
|
||||
ApplyForce(
|
||||
@@ -25,7 +29,7 @@ void UpdatePlayerControls(void)
|
||||
(Vector2){PLAYER_FORCE, 0}
|
||||
);
|
||||
}
|
||||
|
||||
// if sspace key pressed (and player isn't already jumping), push player upward
|
||||
if (IsGrounded(player) &&
|
||||
IsKeyPressed(KEY_SPACE))
|
||||
{
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef PLAYER_H
|
||||
#define PLAYER_H
|
||||
|
||||
// FUNction declaration! yay!!!
|
||||
// run by main.c constantly to allow player input.
|
||||
void UpdatePlayerControls(void);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "world.h"
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
// Take entities, put em on the screen. Basic rendering file. Our entities are just rectangles, which we should lowkey fix... but uh... that's a problem for LATER...
|
||||
void DrawEntities(void)
|
||||
{
|
||||
for (int i = 0; i < MAX_ENTITIES; i++)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef RENDER_H
|
||||
#define RENDER_H
|
||||
|
||||
// FUNction declaration! yay!!!
|
||||
// Make an entity! Once again, pretty sure this is must used in main.c
|
||||
void DrawEntities(void);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user