- Code: Select all
#define UP 1
#define RIGHT 2
#define DOWN 3
#define LEFT 4
int checkCollision(char*ccActor)
{
Actor*playr=getclone(ccActor);
int d=distance(x,y,playr->x,playr->y);
int d2=0;
int s=checkSide(ccActor);
if((s==UP)||(s==DOWN))
{
d2=(height/2)+(playr->height/2);
}
else if((s==LEFT)||(s==RIGHT))
{
d2=(width/2)+(playr->width/2);
}
if(d2<=d)
{
return s;
}
return 0;
}
int checkSide(char*csActor)
{
Actor*playr=getclone(csActor);
double dir = direction(x,y,playr->x,playr->y);
if((dir>=315)||(dir<=45))
{
return RIGHT;
}
else if((dir>=45)&&(dir<=135))
{
return UP;
}
else if((dir>=135)&&(dir<=225))
{
return LEFT;
}
else if((dir>=225)&&(dir<=315))
{
return DOWN;
}
return 0;
}
Would it be better to use this function or the built in collision event for my game? Also the game runs on an ipod and so i dont know if this would be stressful for that processor
Edit: i fixed a mistake i made. i had originally made this code for java so i had to change it a bit to work for GE