diff --git a/src/collision.c b/src/collision.c index 94490cf..14135c9 100644 --- a/src/collision.c +++ b/src/collision.c @@ -20,8 +20,17 @@ void checkCollision(){ { float forcex=fabsf(((en1->mass+en2->mass)/2)*((((en1->velocity.x)+(scale))+((en2->velocity.x)+(scale)))/2))*(scale); - float forcey=fabsf(((en1->mass+en2->mass)/2)*((((en1->velocity.y)+(scale))+((en2->velocity.y)+(scale)))/2))*(scale); - if(en1->position.x < en2->position.x){ + float forcey=fabsf(((en1->mass+en2->mass)/2)*((((en1->velocity.y)+(scale))+((en2->velocity.y)+(scale)))/2))*(scale/4); + if(en1->position.y+en1->size*0.6f <= en2->position.y+en2->size*0.5f){ + ApplyForce( + en1, + (Vector2){0, -((en1->mass*g))} + ); + en1->velocity.y = en1->velocity.y * 0.1f; + en1->velocity.x = en1->velocity.x * en2->drag; + } + else if(en1->position.x < en2->position.x){ + ApplyForce( en1, (Vector2){-forcex, 0} diff --git a/src/entity.h b/src/entity.h index 442e8c4..775a895 100644 --- a/src/entity.h +++ b/src/entity.h @@ -20,6 +20,7 @@ typedef struct Entity Vector2 force; Color color; + float drag; } Entity; diff --git a/src/main.c b/src/main.c index dd8262f..22e3720 100644 --- a/src/main.c +++ b/src/main.c @@ -59,7 +59,8 @@ int main(void) GetRandomValue(50,255), GetRandomValue(50,255), 255 - }); + }, + GetRandomValue(0, 1) + 0.1f); } if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) @@ -72,7 +73,8 @@ int main(void) m.y, 25, 1.0f, - ORANGE); + ORANGE, + 0.1f); } if (isSimulating) diff --git a/src/world.c b/src/world.c index ffcdef1..a283714 100644 --- a/src/world.c +++ b/src/world.c @@ -52,7 +52,8 @@ Entity *SpawnEntity( float y, float size, float mass, - Color color) + Color color, + float drag) { for (int i = 0; i < MAX_ENTITIES; i++) { @@ -67,6 +68,7 @@ Entity *SpawnEntity( e->mass = mass; e->size = size; + e->drag = drag; e->position = (Vector2){x, y}; e->velocity = (Vector2){0, 0}; @@ -104,7 +106,8 @@ void InitWorld(void) 120, 40, 1.0f, - BLUE); + BLUE, + 0.1f); if (player) { @@ -118,7 +121,8 @@ void InitWorld(void) 50, 25, 1.0f, - RED); + RED, + 0.9f); } simTime = 0.0f; diff --git a/src/world.h b/src/world.h index 4cd9163..232a135 100644 --- a/src/world.h +++ b/src/world.h @@ -18,6 +18,7 @@ extern const float MAX_PLAYER_SPEED; extern const float PLAYER_SPEED_FACTOR; + void ApplyForce(Entity *e, Vector2 force); bool IsGrounded(Entity *e); @@ -26,7 +27,8 @@ Entity *SpawnEntity( float y, float size, float mass, - Color color); + Color color, + float drag); void ClearWorld(void); void InitWorld(void); diff --git a/wrldboxMacOS b/wrldboxMacOS index d36617d..aaee823 100755 Binary files a/wrldboxMacOS and b/wrldboxMacOS differ