This commit is contained in:
@@ -7,42 +7,41 @@
|
|||||||
void checkCollision(){
|
void checkCollision(){
|
||||||
for(int u=0; u<=MAX_ENTITIES-1; u++){
|
for(int u=0; u<=MAX_ENTITIES-1; u++){
|
||||||
Entity *en1 = &entities[u];
|
Entity *en1 = &entities[u];
|
||||||
for(int j=1; j<=MAX_ENTITIES-1; j++){
|
if(!en1->active){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for(int j=u+1; j<=MAX_ENTITIES-1; j++){
|
||||||
if(u!=j){
|
if(u!=j){
|
||||||
Entity *en2 = &entities[j];
|
Entity *en2 = &entities[j];
|
||||||
if (fabsf(en1->position.x - en2->position.x) < (en1->size * 0.5f + en2->size * 0.5f))
|
if(!en2->active){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (fabsf(en1->position.x - en2->position.x) < (en1->size * 0.5f + en2->size * 0.5f) && fabsf(en1->position.y - en2->position.y) < (en1->size * 0.5f + en2->size * 0.5f))
|
||||||
{
|
{
|
||||||
|
|
||||||
|
float forcex=fabs(((en1->mass+en2->mass)/2)*((((en1->velocity.x)+(scale*1.5))+((en2->velocity.x)+(scale*1.5)))/2)+((en1->force.x+en2->force.x)/2))*(scale);
|
||||||
|
float forcey=fabs(((en1->mass+en2->mass)/2)*((((en1->velocity.y)+(scale*1.5))+((en2->velocity.y)+(scale*1.5)))/2))*(scale);
|
||||||
if(en1->position.x < en2->position.x){
|
if(en1->position.x < en2->position.x){
|
||||||
ApplyForce(
|
ApplyForce(
|
||||||
en1,
|
en1,
|
||||||
(Vector2){-10000, 0}
|
(Vector2){-forcex, -forcey}
|
||||||
);
|
);
|
||||||
ApplyForce(
|
ApplyForce(
|
||||||
en2,
|
en2,
|
||||||
(Vector2){10000, 0}
|
(Vector2){forcex, forcey}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
ApplyForce(
|
ApplyForce(
|
||||||
en1,
|
en1,
|
||||||
(Vector2){10000, 0}
|
(Vector2){forcex, -forcey}
|
||||||
);
|
);
|
||||||
ApplyForce(
|
ApplyForce(
|
||||||
en2,
|
en2,
|
||||||
(Vector2){-10000, 0}
|
(Vector2){-forcex, forcey}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if(fabsf(en1->position.y - en2->position.y) < (en1->size * 0.5f + en2->size * 0.5f)){
|
|
||||||
// ApplyForce(
|
|
||||||
// en1,
|
|
||||||
// (Vector2){0, 10000}
|
|
||||||
// );
|
|
||||||
// ApplyForce(
|
|
||||||
// en2,
|
|
||||||
// (Vector2){0, -10000}
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ extern bool isSimulating;
|
|||||||
|
|
||||||
extern float simTime;
|
extern float simTime;
|
||||||
|
|
||||||
|
extern const float scale;
|
||||||
|
|
||||||
extern const float MAX_PLAYER_SPEED;
|
extern const float MAX_PLAYER_SPEED;
|
||||||
|
|
||||||
extern const float PLAYER_SPEED_FACTOR;
|
extern const float PLAYER_SPEED_FACTOR;
|
||||||
|
|||||||
BIN
wrldboxMacOS
BIN
wrldboxMacOS
Binary file not shown.
Reference in New Issue
Block a user