0

having trouble implementing the code that will make the ball wait for a click. I have implemented code that allows the restart through the click, but can't seem to do it from the start.

I have read and tried to work through all the similar posts on this and can't seem to grasp it.

Below is my code for when it hits the bottom of the window and waits to reset - which is within the main While loop: (I can have everything work smoothly except for the starting point)

while(velocityY == 0)
            {         
                GMouseEvent click = waitForEvent(MOUSE_EVENT);
                if(getEventType(click) == MOUSE_CLICKED)
                {
                        velocityX = drand48()+2;
                        velocityY = drand48()+2;
                        move(ball, velocityX, velocityY);                                 
                }
            }

I have noticed that people have been doing this in the loop that is: while (lives > 0 && bricks > 0)

I have tried implementing similar code in this while loop also.

Thanks,

Cormac

1 Answer 1

0

If I understand correctly, your game just "starts". And you want it to wait for the user to click before the ball is launched. That's fair. SPL comes with a handy-dandy function called waitForClick(). Try adding that before your main while loop and see if that solves your problem. Also, you might consider using it in the while loop above instead of instantiating a GMouseEvent object and doing the getEventType test. But one thing at a time!

1
  • Such an easy solution in the end! thanks! Dec 5, 2015 at 0:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .