I am trying to create a simple scoring function using sprite collision. I have my sprite ids defined under a seperate header and my class is in order. LEFT_SCORE is animated using a sprite sheet (obviously).

int Ball::leftGoal( )
    int leftScore = 1; 
    if (dbSpriteCollision (BALL, 12))
    dbSetSpriteFrame (LEFT_SCORE, leftScore);
    return 0;

The output I am getting is that leftScore increases as expected and the LEFT_SCORE sprite acts appropriately... But, the score never tallies. It works only while the two sprites (BALL and 12) are actually touching. After that the value of leftScore returns to 1. I am close to killing myself with a rubber mallet because I just can't think my way through how to structure the code.

I am obviously a noob and my comfort zone falls short of using pointers and other such complex concepts. Any help would be greatly appriciated.

Oh, yeah. Using the DarkGDK on this project and no other libraries.

You have to work on your conditions. you have to change it. you have given as ( ball, 12). so exactly when this condition is true you gets result.

Thanks for the quick reply Ravi.

I concur with you but all my feeble little brain comes up with is to declare a boolean variable and include it in my "if" statement, such as: Bool goalCheck. so you would have something like:

if (goalCheck == true && dbSpriteCollision (BALL, 12))
    *more arguments*
return 0

But how would I go about turning that condition on and off so that my int leftScore keeps it's new increased value. I would like to keep my variables local to this function if possible. There is probably a smarter way but sleepy. Sooo Sleepy.

SOLVED. I just Must not have had enough sleep.

For anyone who stumbles onto this thread with a similar problem; I had to initialize my scoring intiger (leftScore) at the beginning of Ball.cpp before all other functions. Then I had to move and hide one of the sprites upon collision to keep the score from incrimenting infinitely. After that it, all worked as I had planned.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.