Compare commits

..

6 Commits

13 changed files with 108 additions and 25 deletions

View File

@@ -1,4 +1,3 @@
# WrldBox Engine
# WrldBox Sandbox Simulator
## 🧊Introduction
@@ -8,6 +7,10 @@
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.
@@ -21,6 +24,10 @@ Clone the repository. Once you have navigated to the folder, you can run:
- `make`
## 🌳 This Branch
This is the branch for the cube-based RPG.
## 🏅Credits
This project was impossible without the support of all three `wholeworldcoding` members.

13
home/p7mj/idea.txt Normal file
View File

@@ -0,0 +1,13 @@
Develop a particular branch of this game into a RPG with a storyline and characters as cubes.
So the storyline I can think of now is:
You are a cube (pick name w/o numbers or symbols, and color)
You are in school
You like another cube, but the cube likes someone else
they get together and u get angry, first few missions is sabotage daily life of the other cube's xxxfriend
then it evolves into all out war

10
src/docprogress.txt Normal file
View 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

View File

@@ -20,20 +20,20 @@ int main(void)
SetTargetFPS(60);
// Now we actually start the code
InitWorld();
InitWorld(); // from world.h
printf("WrldBox engine started\n");
printf("Gravity = %.2f\n", g);
// until we close the window, expect inputs
while (!WindowShouldClose())
{
// Calculate delta time for consistent performace across different FPSes
float dt = GetFrameTime();
if (IsKeyPressed(KEY_P))
{
// If it's simulating, stop simulating. If it isn't simulating, start simulating.
// Toggle simulation
isSimulating = !isSimulating;
}
@@ -45,8 +45,7 @@ int main(void)
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.
// Test feature: spawn random cube
SpawnEntity(
GetRandomValue(50, 950),
GetRandomValue(20, 150),
@@ -88,6 +87,7 @@ int main(void)
ClearBackground(RAYWHITE);
// Ground line
DrawLine(
0,
(int)ground_y,
@@ -95,6 +95,7 @@ int main(void)
(int)ground_y,
DARKGRAY);
// Ground Text
DrawText(
"GROUND",
10,
@@ -102,9 +103,9 @@ int main(void)
20,
DARKGRAY);
DrawEntities();
DrawEntities(); // from render.c
DrawRectangle(
DrawRectangle( // title box
0,
0,
screenWidth,
@@ -133,6 +134,8 @@ int main(void)
20,
BLACK);
// if player exists, draw position and velocity
if (player)
{
DrawText(
@@ -173,10 +176,10 @@ int main(void)
DrawText("Q = Random Cube", 700, 105, 18, BLACK);
DrawText("P = Pause | R = Reset", 700, 125, 18, BLACK);
EndDrawing();
EndDrawing(); // end the current draw loop
}
// When the window wants to close, close it. What a surprise.
// At this point the window was closed
CloseWindow();
return 0;
}

View File

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

View File

@@ -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

View File

@@ -5,27 +5,43 @@
#include "raylib.h"
// let's a go!
float curhorvel=0.0f; //current horizonatal velocity
void UpdatePlayerControls(void)
{
if (!player)
// if there isn't a player, you probably can't do much
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 (IsKeyDown(KEY_D))
// if d key pressed, push player to the right
else if (IsKeyDown(KEY_D))
{
if(curhorvel<=PMV){
curhorvel=curhorvel*PLAYER_SPEED_FACTOR;
}
ApplyForce(
player,
(Vector2){PLAYER_FORCE, 0}
);
(Vector2){curhorvel, 0}
);
}
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,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

View File

@@ -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++)

View File

@@ -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

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.