Advertisement
Guest User

Untitled

a guest
Sep 17th, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. GObject object = detectCollision(window, ball);
  2.  
  3. if (object != NULL)
  4. {
  5. // bounce on paddle
  6. if (object == paddle)
  7. {
  8. if (y > 0)
  9. y = -y;
  10. }
  11.  
  12. // bounce on bricks
  13. else if (strcmp(getType(object), "GRect") == 0)
  14. {
  15. if (y < 0)
  16. {
  17. y = -y;
  18. removeGWindow(window, object);
  19.  
  20. // convert i from int to string
  21. sprintf(s, "%i", counter);
  22. setLabel(label, s);
  23. counter++;
  24. }
  25. }
  26. }
  27.  
  28. if(object !== NULL)
  29.  
  30. {
  31. // The object can be a brick or paddle
  32.  
  33. if(object == paddle)
  34. {
  35. /*change the velocity in the y-direction
  36. When the ball hits the paddle, you know that before hitting,
  37. the velocity of the ball was negative bcoz it's coming down.
  38. Hence, you don't need "if y>0 in your code"
  39. */
  40. }
  41. else if (strcmp(getType(object),"GRect") == 0)
  42. {
  43. //change the velocity in the y-direction again
  44. velocity_y = -velocity_y;
  45.  
  46. //remove the brick from the window
  47. removeGWindow (window, object);
  48.  
  49. //increase points and decrease bricks
  50. points++;
  51. bricks--;
  52.  
  53. //update scoreboard
  54. updateScoreboard(window, label, points);
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement