adding top collision
This commit is contained in:
@@ -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 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);
|
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){
|
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(
|
ApplyForce(
|
||||||
en1,
|
en1,
|
||||||
(Vector2){-forcex, 0}
|
(Vector2){-forcex, 0}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ typedef struct Entity
|
|||||||
Vector2 force;
|
Vector2 force;
|
||||||
|
|
||||||
Color color;
|
Color color;
|
||||||
|
float drag;
|
||||||
|
|
||||||
} Entity;
|
} Entity;
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,8 @@ int main(void)
|
|||||||
GetRandomValue(50,255),
|
GetRandomValue(50,255),
|
||||||
GetRandomValue(50,255),
|
GetRandomValue(50,255),
|
||||||
255
|
255
|
||||||
});
|
},
|
||||||
|
GetRandomValue(0, 1) + 0.1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
|
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT))
|
||||||
@@ -72,7 +73,8 @@ int main(void)
|
|||||||
m.y,
|
m.y,
|
||||||
25,
|
25,
|
||||||
1.0f,
|
1.0f,
|
||||||
ORANGE);
|
ORANGE,
|
||||||
|
0.1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSimulating)
|
if (isSimulating)
|
||||||
|
|||||||
10
src/world.c
10
src/world.c
@@ -52,7 +52,8 @@ Entity *SpawnEntity(
|
|||||||
float y,
|
float y,
|
||||||
float size,
|
float size,
|
||||||
float mass,
|
float mass,
|
||||||
Color color)
|
Color color,
|
||||||
|
float drag)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < MAX_ENTITIES; i++)
|
for (int i = 0; i < MAX_ENTITIES; i++)
|
||||||
{
|
{
|
||||||
@@ -67,6 +68,7 @@ Entity *SpawnEntity(
|
|||||||
|
|
||||||
e->mass = mass;
|
e->mass = mass;
|
||||||
e->size = size;
|
e->size = size;
|
||||||
|
e->drag = drag;
|
||||||
|
|
||||||
e->position = (Vector2){x, y};
|
e->position = (Vector2){x, y};
|
||||||
e->velocity = (Vector2){0, 0};
|
e->velocity = (Vector2){0, 0};
|
||||||
@@ -104,7 +106,8 @@ void InitWorld(void)
|
|||||||
120,
|
120,
|
||||||
40,
|
40,
|
||||||
1.0f,
|
1.0f,
|
||||||
BLUE);
|
BLUE,
|
||||||
|
0.1f);
|
||||||
|
|
||||||
if (player)
|
if (player)
|
||||||
{
|
{
|
||||||
@@ -118,7 +121,8 @@ void InitWorld(void)
|
|||||||
50,
|
50,
|
||||||
25,
|
25,
|
||||||
1.0f,
|
1.0f,
|
||||||
RED);
|
RED,
|
||||||
|
0.9f);
|
||||||
}
|
}
|
||||||
|
|
||||||
simTime = 0.0f;
|
simTime = 0.0f;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ extern const float MAX_PLAYER_SPEED;
|
|||||||
|
|
||||||
extern const float PLAYER_SPEED_FACTOR;
|
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);
|
||||||
|
|
||||||
@@ -26,7 +27,8 @@ Entity *SpawnEntity(
|
|||||||
float y,
|
float y,
|
||||||
float size,
|
float size,
|
||||||
float mass,
|
float mass,
|
||||||
Color color);
|
Color color,
|
||||||
|
float drag);
|
||||||
|
|
||||||
void ClearWorld(void);
|
void ClearWorld(void);
|
||||||
void InitWorld(void);
|
void InitWorld(void);
|
||||||
|
|||||||
BIN
wrldboxMacOS
BIN
wrldboxMacOS
Binary file not shown.
Reference in New Issue
Block a user