more robust data collection
This commit is contained in:
@@ -5,44 +5,39 @@
|
|||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
|
||||||
void checkCollision(){
|
void checkCollision(){
|
||||||
float playerx=0.0;
|
objdet[MAX_ENTITIES][4];
|
||||||
float playery=0.0;
|
|
||||||
float plrsize=0.0;
|
//array structure:
|
||||||
|
// [entitiy #1][entity obj,x,y,size]
|
||||||
|
// [entitiy #2][entity obj,x,y,size]
|
||||||
|
// etc...
|
||||||
|
|
||||||
for (int i = 0; i < MAX_ENTITIES; i++){
|
for (int i = 0; i < MAX_ENTITIES; i++){
|
||||||
Entity *e = &entities[i];
|
Entity *e = &entities[i];
|
||||||
|
if (!e->active){
|
||||||
if (!e->active)
|
|
||||||
continue;
|
continue;
|
||||||
if(e->isPlayer == false){
|
}
|
||||||
float objposx=e->position.x;
|
objdet[i][0]=e;
|
||||||
//float objposy=e->position.y;
|
objdet[i][1]=e->position.x;
|
||||||
float objsize=e->size;
|
objdet[i][2]=e->position.y;
|
||||||
|
objdet[i][3]=e->size;
|
||||||
|
}
|
||||||
|
for(int u=0; u<=MAX_ENTITIES; u++){
|
||||||
|
for(int j=0; u<=MAX_ENTITIES; u++){
|
||||||
|
if(u!=j){
|
||||||
|
if(objdet[u][1]<objdet[j][1]){
|
||||||
|
ApplyForce(
|
||||||
|
objdet[u][0],
|
||||||
|
(Vector2){10000, 0}
|
||||||
|
);
|
||||||
|
ApplyForce(
|
||||||
|
objdet[j][0],
|
||||||
|
(Vector2){-10000, 0}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(playerx-(plrsize/2)<objposx+(objsize/2) && playerx-(plrsize/2)>objposx-(objsize/2)){
|
|
||||||
ApplyForce(
|
|
||||||
e,
|
|
||||||
(Vector2){10000, 1000}
|
|
||||||
);
|
|
||||||
if(dir){
|
|
||||||
ApplyForce(
|
|
||||||
player,
|
|
||||||
(Vector2){(curhorvel*3), 1000}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
ApplyForce(
|
|
||||||
player,
|
|
||||||
(Vector2){-(curhorvel*3), 1000}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
playerx=e->position.x;
|
|
||||||
playery=e->position.y;
|
|
||||||
if(playery==playery)
|
|
||||||
|
|
||||||
plrsize=e->size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user