Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- GObject object = detectCollision(window, ball);
- if (object != NULL)
- {
- // bounce on paddle
- if (object == paddle)
- {
- if (y > 0)
- y = -y;
- }
- // bounce on bricks
- else if (strcmp(getType(object), "GRect") == 0)
- {
- if (y < 0)
- {
- y = -y;
- removeGWindow(window, object);
- // convert i from int to string
- sprintf(s, "%i", counter);
- setLabel(label, s);
- counter++;
- }
- }
- }
- if(object !== NULL)
- {
- // The object can be a brick or paddle
- if(object == paddle)
- {
- /*change the velocity in the y-direction
- When the ball hits the paddle, you know that before hitting,
- the velocity of the ball was negative bcoz it's coming down.
- Hence, you don't need "if y>0 in your code"
- */
- }
- else if (strcmp(getType(object),"GRect") == 0)
- {
- //change the velocity in the y-direction again
- velocity_y = -velocity_y;
- //remove the brick from the window
- removeGWindow (window, object);
- //increase points and decrease bricks
- points++;
- bricks--;
- //update scoreboard
- updateScoreboard(window, label, points);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement