Compare commits
35 Commits
cube_game
...
21bd0c204e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
21bd0c204e | ||
|
|
22377c6f1a | ||
| dff3a5d2c4 | |||
| f580ced394 | |||
| 3c5019bb46 | |||
| 7250e9c834 | |||
| b5b2142a62 | |||
| 37c8a5acfb | |||
| 028309c6ad | |||
| 74d23adaa5 | |||
| ddd90a47de | |||
| 4988964f22 | |||
| 1e597beeee | |||
| 944c6c8da4 | |||
| 81d0cbc673 | |||
| 11d7c736ae | |||
| 8507c2b754 | |||
| 1548f76c05 | |||
| 5fe4f6dd91 | |||
| ac24f566e0 | |||
| 7a53bde1d1 | |||
| baa5a6935f | |||
| e8d29b7f6b | |||
| 123063b3c5 | |||
| d40cc9b484 | |||
| 5a4cd2eb83 | |||
| 0927a0a531 | |||
| 20706dc060 | |||
| 1ccdba57a5 | |||
| 3298638725 | |||
| 15b2066ea2 | |||
| a79815eb7b | |||
| c24535ad67 | |||
| 7e48cd8496 | |||
| 0b357330a6 |
3
Makefile
3
Makefile
@@ -4,7 +4,8 @@ SRC=src/main.c \
|
|||||||
src/world.c \
|
src/world.c \
|
||||||
src/player.c \
|
src/player.c \
|
||||||
src/physics.c \
|
src/physics.c \
|
||||||
src/render.c
|
src/render.c \
|
||||||
|
src/collision.c\
|
||||||
|
|
||||||
OUT=wrldbox
|
OUT=wrldbox
|
||||||
|
|
||||||
|
|||||||
11
README.md
11
README.md
@@ -1,4 +1,6 @@
|
|||||||
# WrldBox Sandbox Simulator
|
# WrldBox Engine
|
||||||
|
|
||||||
|
This project *is* the next major `wholeworldcoding` project.
|
||||||
|
|
||||||
## 🧊Introduction
|
## 🧊Introduction
|
||||||
|
|
||||||
@@ -16,18 +18,13 @@ It consists of several components:
|
|||||||
|
|
||||||
- OLD contains the original logic this came from.
|
- OLD contains the original logic this came from.
|
||||||
|
|
||||||
This project *is* the next major `wholeworldcoding` project.
|
|
||||||
|
|
||||||
## 🛠️ Build and Compile
|
## 🛠️ Build and Compile
|
||||||
|
|
||||||
Clone the repository. Once you have navigated to the folder, you can run:
|
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.
|
||||||
|
and Alex
|
||||||
|
|||||||
@@ -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
|
|
||||||
60
src/collision.c
Normal file
60
src/collision.c
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
#include "world.h"
|
||||||
|
#include <math.h>
|
||||||
|
#include "config.h"
|
||||||
|
#include "collision.h"
|
||||||
|
<<<<<<< HEAD
|
||||||
|
#include "player.h"
|
||||||
|
=======
|
||||||
|
>>>>>>> dff3a5d2c4b8cd3d6d86ab9792e394cd0d27a619
|
||||||
|
|
||||||
|
void checkCollision(){
|
||||||
|
float playerx=0.0;
|
||||||
|
float playery=0.0;
|
||||||
|
float plrsize=0.0;
|
||||||
|
for (int i = 0; i < MAX_ENTITIES; i++){
|
||||||
|
Entity *e = &entities[i];
|
||||||
|
|
||||||
|
if (!e->active)
|
||||||
|
continue;
|
||||||
|
if(e->isPlayer == false){
|
||||||
|
float objposx=e->position.x;
|
||||||
|
//float objposy=e->position.y;
|
||||||
|
float objsize=e->size;
|
||||||
|
|
||||||
|
if(playerx-(plrsize/2)<objposx+(objsize/2) && playerx-(plrsize/2)>objposx-(objsize/2)){
|
||||||
|
ApplyForce(
|
||||||
|
e,
|
||||||
|
<<<<<<< HEAD
|
||||||
|
(Vector2){10000, 1000}
|
||||||
|
);
|
||||||
|
if(dir){
|
||||||
|
ApplyForce(
|
||||||
|
player,
|
||||||
|
(Vector2){(curhorvel*3), 1000}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
ApplyForce(
|
||||||
|
player,
|
||||||
|
(Vector2){-(curhorvel*3), 1000}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
=======
|
||||||
|
(Vector2){1000, 1000}
|
||||||
|
);
|
||||||
|
ApplyForce(
|
||||||
|
player,
|
||||||
|
(Vector2){-1000, 1000}
|
||||||
|
);
|
||||||
|
>>>>>>> dff3a5d2c4b8cd3d6d86ab9792e394cd0d27a619
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
playerx=e->position.x;
|
||||||
|
playery=e->position.y;
|
||||||
|
if(playery==playery)
|
||||||
|
|
||||||
|
plrsize=e->size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
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
|
||||||
25
src/main.c
25
src/main.c
@@ -6,6 +6,7 @@
|
|||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "render.h"
|
#include "render.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "collision.h"
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
@@ -20,20 +21,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 +46,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),
|
||||||
@@ -77,6 +79,7 @@ int main(void)
|
|||||||
{
|
{
|
||||||
// allow player to be controlled, fit everything within the size of the screen
|
// allow player to be controlled, fit everything within the size of the screen
|
||||||
UpdatePlayerControls();
|
UpdatePlayerControls();
|
||||||
|
checkCollision();
|
||||||
UpdateEntities(dt, screenWidth);
|
UpdateEntities(dt, screenWidth);
|
||||||
|
|
||||||
simTime += dt;
|
simTime += dt;
|
||||||
@@ -87,7 +90,6 @@ int main(void)
|
|||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
// Ground line
|
|
||||||
DrawLine(
|
DrawLine(
|
||||||
0,
|
0,
|
||||||
(int)ground_y,
|
(int)ground_y,
|
||||||
@@ -95,7 +97,6 @@ int main(void)
|
|||||||
(int)ground_y,
|
(int)ground_y,
|
||||||
DARKGRAY);
|
DARKGRAY);
|
||||||
|
|
||||||
// Ground Text
|
|
||||||
DrawText(
|
DrawText(
|
||||||
"GROUND",
|
"GROUND",
|
||||||
10,
|
10,
|
||||||
@@ -103,9 +104,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 +135,6 @@ int main(void)
|
|||||||
20,
|
20,
|
||||||
BLACK);
|
BLACK);
|
||||||
|
|
||||||
|
|
||||||
// if player exists, draw position and velocity
|
|
||||||
if (player)
|
if (player)
|
||||||
{
|
{
|
||||||
DrawText(
|
DrawText(
|
||||||
@@ -176,10 +175,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;
|
||||||
}
|
}
|
||||||
|
|||||||
20
src/player.c
20
src/player.c
@@ -7,6 +7,10 @@
|
|||||||
|
|
||||||
// let's a go!
|
// let's a go!
|
||||||
float curhorvel=0.0f; //current horizonatal velocity
|
float curhorvel=0.0f; //current horizonatal velocity
|
||||||
|
<<<<<<< HEAD
|
||||||
|
bool dir=0;
|
||||||
|
=======
|
||||||
|
>>>>>>> dff3a5d2c4b8cd3d6d86ab9792e394cd0d27a619
|
||||||
void UpdatePlayerControls(void)
|
void UpdatePlayerControls(void)
|
||||||
{
|
{
|
||||||
// if there isn't a player, you probably can't do much
|
// if there isn't a player, you probably can't do much
|
||||||
@@ -14,12 +18,16 @@ void UpdatePlayerControls(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(curhorvel==0.0f){
|
if(curhorvel==0.0f){
|
||||||
curhorvel=10.0f*scale;
|
curhorvel=65.5f*scale;
|
||||||
}
|
}
|
||||||
// if a key pressed, push player to the left
|
// if a key pressed, push player to the left
|
||||||
if (IsKeyDown(KEY_A))
|
if (IsKeyDown(KEY_A))
|
||||||
{
|
{
|
||||||
if(curhorvel<PMV){
|
<<<<<<< HEAD
|
||||||
|
dir=1;
|
||||||
|
=======
|
||||||
|
>>>>>>> dff3a5d2c4b8cd3d6d86ab9792e394cd0d27a619
|
||||||
|
if(curhorvel<MAX_PLAYER_SPEED){
|
||||||
curhorvel=curhorvel*PLAYER_SPEED_FACTOR;
|
curhorvel=curhorvel*PLAYER_SPEED_FACTOR;
|
||||||
}
|
}
|
||||||
ApplyForce(
|
ApplyForce(
|
||||||
@@ -30,7 +38,11 @@ void UpdatePlayerControls(void)
|
|||||||
// if d key pressed, push player to the right
|
// if d key pressed, push player to the right
|
||||||
else if (IsKeyDown(KEY_D))
|
else if (IsKeyDown(KEY_D))
|
||||||
{
|
{
|
||||||
if(curhorvel<=PMV){
|
<<<<<<< HEAD
|
||||||
|
dir=0;
|
||||||
|
=======
|
||||||
|
>>>>>>> dff3a5d2c4b8cd3d6d86ab9792e394cd0d27a619
|
||||||
|
if(curhorvel<=MAX_PLAYER_SPEED){
|
||||||
curhorvel=curhorvel*PLAYER_SPEED_FACTOR;
|
curhorvel=curhorvel*PLAYER_SPEED_FACTOR;
|
||||||
}
|
}
|
||||||
ApplyForce(
|
ApplyForce(
|
||||||
@@ -39,7 +51,7 @@ void UpdatePlayerControls(void)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
curhorvel=10.0f*scale;
|
curhorvel=65.5f*scale;
|
||||||
}
|
}
|
||||||
// if sspace key pressed (and player isn't already jumping), push player
|
// if sspace key pressed (and player isn't already jumping), push player
|
||||||
if (IsGrounded(player) &&
|
if (IsGrounded(player) &&
|
||||||
|
|||||||
@@ -3,6 +3,11 @@
|
|||||||
|
|
||||||
// FUNction declaration! yay!!!
|
// FUNction declaration! yay!!!
|
||||||
// run by main.c constantly to allow player input.
|
// run by main.c constantly to allow player input.
|
||||||
|
<<<<<<< HEAD
|
||||||
|
extern bool dir;
|
||||||
|
extern float curhorvel;
|
||||||
|
=======
|
||||||
|
>>>>>>> dff3a5d2c4b8cd3d6d86ab9792e394cd0d27a619
|
||||||
void UpdatePlayerControls(void);
|
void UpdatePlayerControls(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -6,14 +6,13 @@
|
|||||||
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_SPEED_FACTOR =1.1f; //1.1 is good
|
||||||
const float PLAYER_SPEED_FACTOR =1.3f;
|
const float JUMP_FORCE = 450.0f*scale;
|
||||||
const float JUMP_FORCE = 300.0f*scale;
|
|
||||||
|
|
||||||
const float AIR_DRAG = 0.999f;
|
const float AIR_DRAG = 0.999f;
|
||||||
|
|
||||||
const float GROUND_FRICTION = 1200.0f;
|
const float GROUND_FRICTION = 27.432f*scale;
|
||||||
const float MAX_PLAYER_SPEED = 300.0f;
|
const float MAX_PLAYER_SPEED = 10.0f*scale;
|
||||||
|
|
||||||
const float BOUNCE = 0.45f;
|
const float BOUNCE = 0.45f;
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ extern bool isSimulating;
|
|||||||
|
|
||||||
extern float simTime;
|
extern float simTime;
|
||||||
|
|
||||||
extern const float PMV;
|
extern const float MAX_PLAYER_SPEED;
|
||||||
|
|
||||||
extern const float PLAYER_SPEED_FACTOR;
|
extern const float PLAYER_SPEED_FACTOR;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user