- Code: Select all
if (<Actor A is colliding with Actor B>) {
// Do this
}
else {
// Do that
}
if (<Actor A is colliding with Actor B>) {
// Do this
}
else {
// Do that
}
int n;
Actor *actors;
actors = getAllActorsInCollision("Event Actor", &n);
if(actors)
{
int i;
for(i = 0; i < n; i++)
{
if(strcmp(actors[i].name, "B")==0) // colliding with an actor B
{
// do this
}
else
{
// do that
}
}
}
Actor *actors;
if(actors)
int n; // used to store the number of actors colliding with event actor
Actor *actors; // declares an Actor* pointer (used to point to an array of actors event actor is colliding with)
actors = getAllActorsInCollision("Event Actor", &n); // the &n passes the address of the variable n, so the function can change the value
// actors now points to an array of n actors, where n is equal to the number of actors colliding with the actor
// if no actors are colliding, actors is set to null
if(actors) // this makes sure actors is not null (there are actors colliding and getAlActorsInCollision succeeded)
{
int i;
for(i = 0; i < n; i++)
{
if(strcmp(actors[i].name, "B")==0) // colliding with an actor B
{
// do this
}
else
{
// do that
}
}
}
int checkCollision(char actor_1[30], char actor_2[30]) {
int n; // Used to store the number of actors colliding with event actor
int i;
Actor *actors; // Declares an Actor* pointer (used to point to an array of actors event actor is colliding with)
actors=getAllActorsInCollision(actor_1, &n); // The &n passes the address of the variable n, so the function can change the value
// Actors now points to an array of n actors, where n is equal to the number of actors colliding with the actor
// if no actors are colliding, actors is set to null
for(i=0;i<n;i++) {
if(strcmp(actors[i].name, actor_2)==0) // Check whether actor_1 collides with actor_2
return 1;
}
return 0;
}
if (checkCollision("Hover_Table_Right", "Key")) {
// Some code here
}
else {
// Additional code here
}
Users browsing this forum: No registered users and 1 guest