Compare commits
42 Commits
1548f76c05
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fded40cbd9 | ||
| 40747ec508 | |||
| 9af9cef7ad | |||
| a3b5e6abee | |||
|
|
f112c37e9e | ||
| 257be0b3c5 | |||
| bdb6a0aca0 | |||
|
|
0dd35c52c0 | ||
|
|
47f73722b9 | ||
|
|
9dee043d95 | ||
|
|
c079ca620f | ||
|
|
c29f652cdc | ||
| 2917fd3152 | |||
|
|
466d62c023 | ||
|
|
78597f14c0 | ||
|
|
b7fef7bee3 | ||
|
|
3adef4de7b | ||
| e8a6af63af | |||
| 8163a4641e | |||
| 53c8a13578 | |||
| 43d8ddd0ec | |||
| bd0ffff93f | |||
| 013fab7c89 | |||
|
|
06d5ae6674 | ||
|
|
51b15daf2c | ||
|
|
21bd0c204e | ||
|
|
22377c6f1a | ||
| dff3a5d2c4 | |||
| f580ced394 | |||
| 3c5019bb46 | |||
| 7250e9c834 | |||
| b5b2142a62 | |||
| 37c8a5acfb | |||
| 028309c6ad | |||
| 74d23adaa5 | |||
| ddd90a47de | |||
| 4988964f22 | |||
| 1e597beeee | |||
| 944c6c8da4 | |||
| 81d0cbc673 | |||
| 11d7c736ae | |||
| 8507c2b754 |
87
.gitea/workflows/build.yaml
Normal file
87
.gitea/workflows/build.yaml
Normal file
@@ -0,0 +1,87 @@
|
||||
name: Build Project
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os:
|
||||
- ubuntu-latest
|
||||
# - windows-latest
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install Dependencies (Linux)
|
||||
if: runner.os == 'Linux'
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y \
|
||||
build-essential \
|
||||
gcc \
|
||||
g++ \
|
||||
make \
|
||||
git \
|
||||
cmake \
|
||||
libasound2-dev \
|
||||
mesa-common-dev \
|
||||
libx11-dev \
|
||||
libxrandr-dev \
|
||||
libxinerama-dev \
|
||||
libxcursor-dev \
|
||||
libxi-dev \
|
||||
libgl1-mesa-dev \
|
||||
libglu1-mesa-dev
|
||||
|
||||
- name: Build & Install Raylib (Linux)
|
||||
if: runner.os == 'Linux'
|
||||
run: |
|
||||
git clone --depth 1 https://github.com/raysan5/raylib.git
|
||||
cd raylib/src
|
||||
make PLATFORM=PLATFORM_DESKTOP
|
||||
sudo make install
|
||||
|
||||
# - name: Install MSYS2 and Raylib (Windows)
|
||||
# if: runner.os == 'Windows'
|
||||
# uses: msys2/setup-msys2@v2
|
||||
# with:
|
||||
# msystem: MINGW64
|
||||
# update: true
|
||||
# install: >
|
||||
# mingw-w64-x86_64-gcc
|
||||
# mingw-w64-x86_64-make
|
||||
# mingw-w64-x86_64-raylib
|
||||
|
||||
- name: Build (Linux)
|
||||
if: runner.os == 'Linux'
|
||||
run: make
|
||||
|
||||
# - name: Build (Windows)
|
||||
# if: runner.os == 'Windows'
|
||||
# shell: msys2 {0}
|
||||
# run: make
|
||||
|
||||
- name: Upload Linux Artifact
|
||||
if: runner.os == 'Linux'
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: wrldbox-linux
|
||||
path: wrldbox
|
||||
|
||||
# - name: Upload Windows Artifact
|
||||
# if: runner.os == 'Windows'
|
||||
# uses: actions/upload-artifact@v3
|
||||
# with:
|
||||
# name: wrldbox-windows
|
||||
# path: "*.exe"
|
||||
3
Makefile
3
Makefile
@@ -4,7 +4,8 @@ SRC=src/main.c \
|
||||
src/world.c \
|
||||
src/player.c \
|
||||
src/physics.c \
|
||||
src/render.c
|
||||
src/render.c \
|
||||
src/collision.c\
|
||||
|
||||
OUT=wrldbox
|
||||
|
||||
|
||||
5
MakefileMacOS
Normal file
5
MakefileMacOS
Normal file
@@ -0,0 +1,5 @@
|
||||
gcc src/*.c -o wrldboxMacOS \
|
||||
-I/opt/homebrew/include \
|
||||
-L/opt/homebrew/lib \
|
||||
-lraylib \
|
||||
-framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo
|
||||
13
README.md
13
README.md
@@ -1,7 +1,6 @@
|
||||
<<<<<<< HEAD
|
||||
# WrldBox Engine
|
||||
=======
|
||||
# WrldBox Sandbox Simulator
|
||||
|
||||
This project *is* the next major `wholeworldcoding` project.
|
||||
|
||||
## 🧊Introduction
|
||||
|
||||
@@ -10,13 +9,15 @@
|
||||
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:
|
||||
@@ -25,4 +26,4 @@ Clone the repository. Once you have navigated to the folder, you can run:
|
||||
|
||||
## 🏅Credits
|
||||
|
||||
This project was impossible without the support of all three `wholeworldcoding` members.
|
||||
This project was impossible without the support of all four `wholeworldcoding` members.
|
||||
|
||||
68
src/collision.c
Normal file
68
src/collision.c
Normal file
@@ -0,0 +1,68 @@
|
||||
#include "world.h"
|
||||
#include <math.h>
|
||||
#include "config.h"
|
||||
#include "collision.h"
|
||||
#include "player.h"
|
||||
#include <stdio.h>
|
||||
void checkCollision(){
|
||||
for(int u=0; u<=MAX_ENTITIES-1; u++){
|
||||
Entity *en1 = &entities[u];
|
||||
if(!en1->active){
|
||||
continue;
|
||||
}
|
||||
en1->headgrounded = false;
|
||||
for(int j=u+1; j<=MAX_ENTITIES-1; j++){
|
||||
if(u!=j){
|
||||
Entity *en2 = &entities[j];
|
||||
if(!en2->active){
|
||||
continue;
|
||||
}
|
||||
printf("%d\n", en1->headgrounded);
|
||||
|
||||
float half = (en1->size + en2->size) * 0.5f;
|
||||
float overlapX = half - fabsf(en1->position.x - en2->position.x);
|
||||
float overlapY = half - fabsf(en1->position.y - en2->position.y);
|
||||
|
||||
if (overlapX > 0 && overlapY > 0)
|
||||
{
|
||||
if (overlapY < overlapX && en1->position.y < en2->position.y)
|
||||
{
|
||||
// top collision
|
||||
en1->position.y = en2->position.y - half;
|
||||
en1->velocity.y = 0;
|
||||
en1->velocity.x *= en2->drag;
|
||||
en1->headgrounded = true;
|
||||
} else {
|
||||
en1->headgrounded = false;
|
||||
float forcex=fabsf(((en1->mass+en2->mass)/2)*((((en1->velocity.x)+(scale))+((en2->velocity.x)+(scale)))/2))*(scale*1.5);
|
||||
float forcey=fabsf(((en1->mass+en2->mass)/2)*((((en1->velocity.y)+(scale))+((en2->velocity.y)+(scale)))/2))*(scale/4);
|
||||
if(en1->position.x < en2->position.x){
|
||||
en1->velocity.x=0;
|
||||
en2->velocity.x=0;
|
||||
ApplyForce(
|
||||
en1,
|
||||
(Vector2){-forcex, 0}
|
||||
);
|
||||
ApplyForce(
|
||||
en2,
|
||||
(Vector2){forcex, 0}
|
||||
);
|
||||
}
|
||||
else{
|
||||
en1->velocity.x=0;
|
||||
en2->velocity.x=0;
|
||||
ApplyForce(
|
||||
en1,
|
||||
(Vector2){forcex, 0}
|
||||
);
|
||||
ApplyForce(
|
||||
en2,
|
||||
(Vector2){-forcex, 0}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
8
src/collision.h
Normal file
8
src/collision.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef COLLISION_H
|
||||
#define COLLISION_H
|
||||
|
||||
// FUNction declaration! yay!!!
|
||||
// run by main.c constantly to allow player input.
|
||||
void checkCollision();
|
||||
|
||||
#endif
|
||||
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
|
||||
@@ -10,6 +10,7 @@ typedef struct Entity
|
||||
|
||||
bool isPlayer;
|
||||
bool affectedByGravity;
|
||||
bool headgrounded;
|
||||
|
||||
float mass;
|
||||
float size;
|
||||
@@ -20,6 +21,7 @@ typedef struct Entity
|
||||
Vector2 force;
|
||||
|
||||
Color color;
|
||||
float drag;
|
||||
|
||||
} Entity;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "player.h"
|
||||
#include "render.h"
|
||||
#include "config.h"
|
||||
#include "collision.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
@@ -58,7 +59,8 @@ int main(void)
|
||||
GetRandomValue(50,255),
|
||||
GetRandomValue(50,255),
|
||||
255
|
||||
});
|
||||
},
|
||||
GetRandomValue(0, 1) + 0.1f);
|
||||
}
|
||||
|
||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
|
||||
@@ -71,13 +73,15 @@ int main(void)
|
||||
m.y,
|
||||
25,
|
||||
1.0f,
|
||||
ORANGE);
|
||||
ORANGE,
|
||||
0.1f);
|
||||
}
|
||||
|
||||
if (isSimulating)
|
||||
{
|
||||
// allow player to be controlled, fit everything within the size of the screen
|
||||
UpdatePlayerControls();
|
||||
checkCollision();
|
||||
UpdateEntities(dt, screenWidth);
|
||||
|
||||
simTime += dt;
|
||||
|
||||
@@ -1,21 +1,27 @@
|
||||
#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);
|
||||
|
||||
if (e->affectedByGravity)
|
||||
// Apply gravity force if enabled for this entity
|
||||
if (e->affectedByGravity && !onGround)
|
||||
{
|
||||
ApplyForce(
|
||||
e,
|
||||
@@ -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
|
||||
|
||||
35
src/player.c
35
src/player.c
@@ -5,27 +5,46 @@
|
||||
|
||||
#include "raylib.h"
|
||||
|
||||
// let's a go!
|
||||
float curhorvel=0.0f; //current horizonatal velocity
|
||||
bool dir=0;
|
||||
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=65.5f*scale;
|
||||
}
|
||||
// if a key pressed, push player to the left
|
||||
if (IsKeyDown(KEY_A))
|
||||
{
|
||||
dir=1;
|
||||
if(curhorvel<MAX_PLAYER_SPEED){
|
||||
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))
|
||||
{
|
||||
dir=0;
|
||||
if(curhorvel<=MAX_PLAYER_SPEED){
|
||||
curhorvel=curhorvel*PLAYER_SPEED_FACTOR;
|
||||
}
|
||||
ApplyForce(
|
||||
player,
|
||||
(Vector2){PLAYER_FORCE, 0}
|
||||
);
|
||||
(Vector2){curhorvel, 0}
|
||||
);
|
||||
}
|
||||
|
||||
else{
|
||||
curhorvel=65.5f*scale;
|
||||
}
|
||||
// if sspace key pressed (and player isn't already jumping), push player
|
||||
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
|
||||
|
||||
40
src/world.c
40
src/world.c
@@ -1,16 +1,19 @@
|
||||
#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_FORCE = 3500.0f;
|
||||
const float JUMP_FORCE = 22000.0f;
|
||||
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 = 1200.0f;
|
||||
const float MAX_PLAYER_SPEED = 300.0f;
|
||||
const float GROUND_FRICTION = 27.432f*scale;
|
||||
const float MAX_PLAYER_SPEED = 10.0f*scale;
|
||||
|
||||
const float BOUNCE = 0.45f;
|
||||
|
||||
@@ -37,12 +40,12 @@ bool IsGrounded(Entity *e)
|
||||
{
|
||||
if (!e)
|
||||
return false;
|
||||
|
||||
return (
|
||||
e->position.y +
|
||||
e->size * 0.5f >=
|
||||
ground_y - 2.0f
|
||||
);
|
||||
if(e->position.y +e->size * 0.5f >=ground_y - 2.0f || e->headgrounded){
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Entity *SpawnEntity(
|
||||
@@ -50,7 +53,8 @@ Entity *SpawnEntity(
|
||||
float y,
|
||||
float size,
|
||||
float mass,
|
||||
Color color)
|
||||
Color color,
|
||||
float drag)
|
||||
{
|
||||
for (int i = 0; i < MAX_ENTITIES; i++)
|
||||
{
|
||||
@@ -65,6 +69,7 @@ Entity *SpawnEntity(
|
||||
|
||||
e->mass = mass;
|
||||
e->size = size;
|
||||
e->drag = drag;
|
||||
|
||||
e->position = (Vector2){x, y};
|
||||
e->velocity = (Vector2){0, 0};
|
||||
@@ -72,6 +77,7 @@ Entity *SpawnEntity(
|
||||
e->force = (Vector2){0, 0};
|
||||
|
||||
e->color = color;
|
||||
e->headgrounded = false;
|
||||
|
||||
return e;
|
||||
}
|
||||
@@ -79,7 +85,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 +98,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();
|
||||
@@ -99,7 +108,8 @@ void InitWorld(void)
|
||||
120,
|
||||
40,
|
||||
1.0f,
|
||||
BLUE);
|
||||
BLUE,
|
||||
0.1f);
|
||||
|
||||
if (player)
|
||||
{
|
||||
@@ -113,12 +123,14 @@ void InitWorld(void)
|
||||
50,
|
||||
25,
|
||||
1.0f,
|
||||
RED);
|
||||
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;
|
||||
|
||||
10
src/world.h
10
src/world.h
@@ -12,6 +12,13 @@ extern bool isSimulating;
|
||||
|
||||
extern float simTime;
|
||||
|
||||
extern const float scale;
|
||||
|
||||
extern const float MAX_PLAYER_SPEED;
|
||||
|
||||
extern const float PLAYER_SPEED_FACTOR;
|
||||
|
||||
|
||||
void ApplyForce(Entity *e, Vector2 force);
|
||||
bool IsGrounded(Entity *e);
|
||||
|
||||
@@ -20,7 +27,8 @@ Entity *SpawnEntity(
|
||||
float y,
|
||||
float size,
|
||||
float mass,
|
||||
Color color);
|
||||
Color color,
|
||||
float drag);
|
||||
|
||||
void ClearWorld(void);
|
||||
void InitWorld(void);
|
||||
|
||||
BIN
wrldboxMacOS
Executable file
BIN
wrldboxMacOS
Executable file
Binary file not shown.
Reference in New Issue
Block a user