I'm working on a personal game with SDL and I have two arrays:
float player[]={...};
float blueEnemy[]={...};
I have also a function:
float *moveOpposite(float *actor) {
// Skipped content.
return actor;
}
And then, I have the problematic one:
float *collideWith(float *x, float *y, float *(f)(float *a)) {
if ((((x[0]+x[2])>y[0])&&(x[0]<(y[0]+y[2])))&&(((x[1]+x[3])>y[1])&&(x[1]<(y[1]+y[3])))) {
*x = *f(x);
}
return x;
}
Ignore the collision mess. In my game, actors are arrays with xPos, yPos, width, height, speed, etc. The first four are obrigatory. Functions like "moveActor" or "moveOpposite" works arbitrarilly with all actors. collideWith is one of these functions. So, I'll explain it:
It takes the first actor and the second actor (Which are arrays with at least size 4), as parameters, and it also takes a function as a parameter. This argument-function also takes an actor as argument and returns it. Inside the collideWith function, after the test, I update the first argument with the result of the argument-function, and return the result. I would apply it like this:
*player=*collideWith(player,blueEnemy,*moveOpposite(player));
When I try to compile it, I get an horrid error:
cannot convert 'float' to 'float* (*)(float*)' for argument '3' to 'float* collideWith(float*, float*, float* (*)(float*))'|
This collision functions that takes another function as an argument is really important for my engine.
Your call needs to pass a function, hence instead of
*player=*collideWith(player,blueEnemy,*moveOpposite(player));
you might just need
*player=*collideWith(player,blueEnemy,&moveOpposite);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments