Compare commits
18 Commits
cube_game
...
1548f76c05
| Author | SHA1 | Date | |
|---|---|---|---|
| 1548f76c05 | |||
| 5fe4f6dd91 | |||
| ac24f566e0 | |||
| 7a53bde1d1 | |||
| baa5a6935f | |||
| e8d29b7f6b | |||
| 123063b3c5 | |||
| d40cc9b484 | |||
| 5a4cd2eb83 | |||
| 0927a0a531 | |||
| 20706dc060 | |||
| 1ccdba57a5 | |||
| 3298638725 | |||
| 15b2066ea2 | |||
| a79815eb7b | |||
| c24535ad67 | |||
| 7e48cd8496 | |||
| 0b357330a6 |
11
README.md
11
README.md
@@ -1,3 +1,6 @@
|
|||||||
|
<<<<<<< HEAD
|
||||||
|
# WrldBox Engine
|
||||||
|
=======
|
||||||
# WrldBox Sandbox Simulator
|
# WrldBox Sandbox Simulator
|
||||||
|
|
||||||
## 🧊Introduction
|
## 🧊Introduction
|
||||||
@@ -7,10 +10,6 @@
|
|||||||
It consists of several components:
|
It consists of several components:
|
||||||
|
|
||||||
- `src/main.c`, Main script. Takes all other src and actually renders the engine.
|
- `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.
|
- More stuff in src. README in progress.
|
||||||
|
|
||||||
@@ -24,10 +23,6 @@ Clone the repository. Once you have navigated to the folder, you can run:
|
|||||||
|
|
||||||
- `make`
|
- `make`
|
||||||
|
|
||||||
## 🌳 This Branch
|
|
||||||
|
|
||||||
This is the branch for the cube-based RPG.
|
|
||||||
|
|
||||||
## 🏅Credits
|
## 🏅Credits
|
||||||
|
|
||||||
This project was impossible without the support of all three `wholeworldcoding` members.
|
This project was impossible without the support of all three `wholeworldcoding` members.
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
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
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
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
|
|
||||||
23
src/main.c
23
src/main.c
@@ -20,20 +20,20 @@ int main(void)
|
|||||||
|
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
|
||||||
InitWorld(); // from world.h
|
// Now we actually start the code
|
||||||
|
InitWorld();
|
||||||
|
|
||||||
printf("WrldBox engine started\n");
|
printf("WrldBox engine started\n");
|
||||||
printf("Gravity = %.2f\n", g);
|
printf("Gravity = %.2f\n", g);
|
||||||
|
|
||||||
|
// until we close the window, expect inputs
|
||||||
while (!WindowShouldClose())
|
while (!WindowShouldClose())
|
||||||
{
|
{
|
||||||
|
|
||||||
// Calculate delta time for consistent performace across different FPSes
|
|
||||||
float dt = GetFrameTime();
|
float dt = GetFrameTime();
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_P))
|
if (IsKeyPressed(KEY_P))
|
||||||
{
|
{
|
||||||
// Toggle simulation
|
// If it's simulating, stop simulating. If it isn't simulating, start simulating.
|
||||||
isSimulating = !isSimulating;
|
isSimulating = !isSimulating;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +45,8 @@ int main(void)
|
|||||||
|
|
||||||
if (IsKeyPressed(KEY_Q))
|
if (IsKeyPressed(KEY_Q))
|
||||||
{
|
{
|
||||||
// Test feature: spawn random cube
|
// 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(
|
SpawnEntity(
|
||||||
GetRandomValue(50, 950),
|
GetRandomValue(50, 950),
|
||||||
GetRandomValue(20, 150),
|
GetRandomValue(20, 150),
|
||||||
@@ -87,7 +88,6 @@ int main(void)
|
|||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
// Ground line
|
|
||||||
DrawLine(
|
DrawLine(
|
||||||
0,
|
0,
|
||||||
(int)ground_y,
|
(int)ground_y,
|
||||||
@@ -95,7 +95,6 @@ int main(void)
|
|||||||
(int)ground_y,
|
(int)ground_y,
|
||||||
DARKGRAY);
|
DARKGRAY);
|
||||||
|
|
||||||
// Ground Text
|
|
||||||
DrawText(
|
DrawText(
|
||||||
"GROUND",
|
"GROUND",
|
||||||
10,
|
10,
|
||||||
@@ -103,9 +102,9 @@ int main(void)
|
|||||||
20,
|
20,
|
||||||
DARKGRAY);
|
DARKGRAY);
|
||||||
|
|
||||||
DrawEntities(); // from render.c
|
DrawEntities();
|
||||||
|
|
||||||
DrawRectangle( // title box
|
DrawRectangle(
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
screenWidth,
|
screenWidth,
|
||||||
@@ -134,8 +133,6 @@ int main(void)
|
|||||||
20,
|
20,
|
||||||
BLACK);
|
BLACK);
|
||||||
|
|
||||||
|
|
||||||
// if player exists, draw position and velocity
|
|
||||||
if (player)
|
if (player)
|
||||||
{
|
{
|
||||||
DrawText(
|
DrawText(
|
||||||
@@ -176,10 +173,10 @@ int main(void)
|
|||||||
DrawText("Q = Random Cube", 700, 105, 18, BLACK);
|
DrawText("Q = Random Cube", 700, 105, 18, BLACK);
|
||||||
DrawText("P = Pause | R = Reset", 700, 125, 18, BLACK);
|
DrawText("P = Pause | R = Reset", 700, 125, 18, BLACK);
|
||||||
|
|
||||||
EndDrawing(); // end the current draw loop
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
// At this point the window was closed
|
// When the window wants to close, close it. What a surprise.
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,20 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
// better hope you were paying attention in physics class for this one
|
|
||||||
#include "physics.h"
|
#include "physics.h"
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
// Main physics update loop for all entities
|
|
||||||
void UpdateEntities(float dt, int screenWidth)
|
void UpdateEntities(float dt, int screenWidth)
|
||||||
{
|
{
|
||||||
// Iterate through all possible entities
|
|
||||||
for (int i = 0; i < MAX_ENTITIES; i++)
|
for (int i = 0; i < MAX_ENTITIES; i++)
|
||||||
{
|
{
|
||||||
Entity *e = &entities[i];
|
Entity *e = &entities[i];
|
||||||
|
|
||||||
// Skip inactive entities
|
|
||||||
if (!e->active)
|
if (!e->active)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Check if entity is currently touching the ground
|
|
||||||
// YOU'RE GROUNDED!!! lol
|
|
||||||
bool onGround = IsGrounded(e);
|
bool onGround = IsGrounded(e);
|
||||||
|
|
||||||
// Apply gravity force if enabled for this entity
|
|
||||||
if (e->affectedByGravity)
|
if (e->affectedByGravity)
|
||||||
{
|
{
|
||||||
ApplyForce(
|
ApplyForce(
|
||||||
@@ -29,25 +23,21 @@ void UpdateEntities(float dt, int screenWidth)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute acceleration from accumulated forces (F = ma)
|
|
||||||
e->acceleration.x =
|
e->acceleration.x =
|
||||||
e->force.x / e->mass;
|
e->force.x / e->mass;
|
||||||
|
|
||||||
e->acceleration.y =
|
e->acceleration.y =
|
||||||
e->force.y / e->mass;
|
e->force.y / e->mass;
|
||||||
|
|
||||||
// Integrate velocity from acceleration
|
|
||||||
e->velocity.x +=
|
e->velocity.x +=
|
||||||
e->acceleration.x * dt;
|
e->acceleration.x * dt;
|
||||||
|
|
||||||
e->velocity.y +=
|
e->velocity.y +=
|
||||||
e->acceleration.y * dt;
|
e->acceleration.y * dt;
|
||||||
|
|
||||||
// Apply air drag to slow movement over time
|
|
||||||
e->velocity.x *= AIR_DRAG;
|
e->velocity.x *= AIR_DRAG;
|
||||||
e->velocity.y *= AIR_DRAG;
|
e->velocity.y *= AIR_DRAG;
|
||||||
|
|
||||||
// Apply ground friction when on the ground
|
|
||||||
if (onGround)
|
if (onGround)
|
||||||
{
|
{
|
||||||
if (e->velocity.x > 0)
|
if (e->velocity.x > 0)
|
||||||
@@ -68,7 +58,6 @@ void UpdateEntities(float dt, int screenWidth)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clamp player horizontal speed
|
|
||||||
if (e->isPlayer)
|
if (e->isPlayer)
|
||||||
{
|
{
|
||||||
if (e->velocity.x > MAX_PLAYER_SPEED)
|
if (e->velocity.x > MAX_PLAYER_SPEED)
|
||||||
@@ -78,17 +67,14 @@ void UpdateEntities(float dt, int screenWidth)
|
|||||||
e->velocity.x = -MAX_PLAYER_SPEED;
|
e->velocity.x = -MAX_PLAYER_SPEED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Integrate position from velocity
|
|
||||||
e->position.x +=
|
e->position.x +=
|
||||||
e->velocity.x * dt;
|
e->velocity.x * dt;
|
||||||
|
|
||||||
e->position.y +=
|
e->position.y +=
|
||||||
e->velocity.y * dt;
|
e->velocity.y * dt;
|
||||||
|
|
||||||
// Reset forces after integration step
|
|
||||||
e->force = (Vector2){0, 0};
|
e->force = (Vector2){0, 0};
|
||||||
|
|
||||||
// Ground collision
|
|
||||||
if (e->position.y +
|
if (e->position.y +
|
||||||
e->size * 0.5f >=
|
e->size * 0.5f >=
|
||||||
ground_y)
|
ground_y)
|
||||||
@@ -100,14 +86,12 @@ void UpdateEntities(float dt, int screenWidth)
|
|||||||
e->velocity.y *=
|
e->velocity.y *=
|
||||||
-BOUNCE;
|
-BOUNCE;
|
||||||
|
|
||||||
// Stop tiny bounces... or at least, attempt to.
|
|
||||||
if (fabsf(e->velocity.y) < 15.0f)
|
if (fabsf(e->velocity.y) < 15.0f)
|
||||||
{
|
{
|
||||||
e->velocity.y = 0;
|
e->velocity.y = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Left wall collision
|
|
||||||
if (e->position.x -
|
if (e->position.x -
|
||||||
e->size * 0.5f < 0)
|
e->size * 0.5f < 0)
|
||||||
{
|
{
|
||||||
@@ -117,7 +101,6 @@ void UpdateEntities(float dt, int screenWidth)
|
|||||||
e->velocity.x *= -0.6f;
|
e->velocity.x *= -0.6f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Right wall collision
|
|
||||||
if (e->position.x +
|
if (e->position.x +
|
||||||
e->size * 0.5f >
|
e->size * 0.5f >
|
||||||
screenWidth)
|
screenWidth)
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
#ifndef PHYSICS_H
|
#ifndef PHYSICS_H
|
||||||
#define 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);
|
void UpdateEntities(float dt, int screenWidth);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
32
src/player.c
32
src/player.c
@@ -5,43 +5,27 @@
|
|||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
// 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 (!player)
|
||||||
if (!player){
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
if(curhorvel==0.0f){
|
|
||||||
curhorvel=10.0f*scale;
|
|
||||||
}
|
|
||||||
// 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){-curhorvel, 0}
|
(Vector2){-PLAYER_FORCE, 0}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// if d key pressed, push player to the right
|
|
||||||
else if (IsKeyDown(KEY_D))
|
if (IsKeyDown(KEY_D))
|
||||||
{
|
{
|
||||||
if(curhorvel<=PMV){
|
|
||||||
curhorvel=curhorvel*PLAYER_SPEED_FACTOR;
|
|
||||||
}
|
|
||||||
ApplyForce(
|
ApplyForce(
|
||||||
player,
|
player,
|
||||||
(Vector2){curhorvel, 0}
|
(Vector2){PLAYER_FORCE, 0}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
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))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
#ifndef PLAYER_H
|
#ifndef PLAYER_H
|
||||||
#define PLAYER_H
|
#define PLAYER_H
|
||||||
|
|
||||||
// FUNction declaration! yay!!!
|
|
||||||
// run by main.c constantly to allow player input.
|
|
||||||
void UpdatePlayerControls(void);
|
void UpdatePlayerControls(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include "world.h"
|
#include "world.h"
|
||||||
|
|
||||||
#include "raylib.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)
|
void DrawEntities(void)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < MAX_ENTITIES; i++)
|
for (int i = 0; i < MAX_ENTITIES; i++)
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#ifndef RENDER_H
|
#ifndef RENDER_H
|
||||||
#define 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);
|
void DrawEntities(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
13
src/world.c
13
src/world.c
@@ -1,14 +1,11 @@
|
|||||||
#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 PMV = 10000.0*scale; //Player Max Velocity
|
const float PLAYER_FORCE = 3500.0f;
|
||||||
const float PLAYER_SPEED_FACTOR =1.3f;
|
const float JUMP_FORCE = 22000.0f;
|
||||||
const float JUMP_FORCE = 300.0f*scale;
|
|
||||||
|
|
||||||
const float AIR_DRAG = 0.999f;
|
const float AIR_DRAG = 0.999f;
|
||||||
|
|
||||||
@@ -82,9 +79,7 @@ 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++)
|
||||||
@@ -95,7 +90,6 @@ 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();
|
||||||
@@ -125,7 +119,6 @@ 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,10 +12,6 @@ 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