Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. void followTheLeader() //Function that prints a circle that moves towards the x and y coordinates of the mouse.
  2. {
  3. int mouseX = 0; //Initialisation of the variabls for the mouse position.
  4. int mouseY = 0;
  5. int windowWidth = 640; //Initialisation of the window size.
  6. int windowHeight = 480;
  7. bool goTime = true; //Initialisation of the loop control variable.
  8. int radius = 5; //Initialisation of radius of circle.
  9. float circleX = 100; //Initialisation of the x and y values of the circle.
  10. float circleY = 100;
  11. float circleXspeed = 3.3; //Initialisation of the x and y change, x and y speed.
  12. float circleYspeed = 3.3;
  13. while (goTime)
  14. {
  15.  
  16. SDL_Event event; //Initialises SDL event.
  17. SDL_GetMouseState(&mouseX, &mouseY); //Retrieves current mouse coordinates and assigns it to mouseX and mouseY.
  18. if (mouseX >= circleX) //If mouse coordinate x is greater than circle coordinate, value circle coordinate.
  19. {
  20. circleX = circleX + circleXspeed;
  21. }
  22. if (mouseX < circleX) //If mouseX is greater than circleX, value subtracted from circleX.
  23. {
  24. circleX = circleX - circleXspeed;
  25. }
  26. if (mouseY >= circleY) //If muouse Y is great than circleY, value added to circleY.
  27. {
  28. circleY = circleY + circleYspeed;
  29. }
  30. if (mouseY < circleY) //If mouseY is less than circleY, value subtracted from circleY.
  31. {
  32. circleY = circleY - circleYspeed;
  33. }
  34.  
  35. glm::vec2 circleCentre2(circleX, circleY); //new x and y coordinates assigned to vector circleCentre.
  36. glm::vec3 circleColor(255, 0, 0); //Initialises 3D colour vector to hold circle colour.
  37. CGG::SetBackground(0, 0, 0);
  38. drawCircle(radius, circleCentre2, circleColor); //Draws circle, inputting circleCentre and circleColour vectors.
  39.  
  40. CGG::ProcessFrame();
  41. //if (!CGG::ProcessFrame())goTime = false;
  42. if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT)) //If right button pressed, program exits to mainMenu.
  43. {
  44. CGG::Cleanup();
  45. mainMenu();
  46. break;
  47. }
  48. if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT)) //If left button is pressed, radius of circle is increased until 200 is reached, then it is reset.
  49. {
  50. radius = radius + 1;
  51. if (radius > 200)
  52. {
  53. radius = 0;
  54. }
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement