Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void followTheLeader() //Function that prints a circle that moves towards the x and y coordinates of the mouse.
- {
- int mouseX = 0; //Initialisation of the variabls for the mouse position.
- int mouseY = 0;
- int windowWidth = 640; //Initialisation of the window size.
- int windowHeight = 480;
- bool goTime = true; //Initialisation of the loop control variable.
- int radius = 5; //Initialisation of radius of circle.
- float circleX = 100; //Initialisation of the x and y values of the circle.
- float circleY = 100;
- float circleXspeed = 3.3; //Initialisation of the x and y change, x and y speed.
- float circleYspeed = 3.3;
- while (goTime)
- {
- SDL_Event event; //Initialises SDL event.
- SDL_GetMouseState(&mouseX, &mouseY); //Retrieves current mouse coordinates and assigns it to mouseX and mouseY.
- if (mouseX >= circleX) //If mouse coordinate x is greater than circle coordinate, value circle coordinate.
- {
- circleX = circleX + circleXspeed;
- }
- if (mouseX < circleX) //If mouseX is greater than circleX, value subtracted from circleX.
- {
- circleX = circleX - circleXspeed;
- }
- if (mouseY >= circleY) //If muouse Y is great than circleY, value added to circleY.
- {
- circleY = circleY + circleYspeed;
- }
- if (mouseY < circleY) //If mouseY is less than circleY, value subtracted from circleY.
- {
- circleY = circleY - circleYspeed;
- }
- glm::vec2 circleCentre2(circleX, circleY); //new x and y coordinates assigned to vector circleCentre.
- glm::vec3 circleColor(255, 0, 0); //Initialises 3D colour vector to hold circle colour.
- CGG::SetBackground(0, 0, 0);
- drawCircle(radius, circleCentre2, circleColor); //Draws circle, inputting circleCentre and circleColour vectors.
- CGG::ProcessFrame();
- //if (!CGG::ProcessFrame())goTime = false;
- if (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT)) //If right button pressed, program exits to mainMenu.
- {
- CGG::Cleanup();
- mainMenu();
- break;
- }
- 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.
- {
- radius = radius + 1;
- if (radius > 200)
- {
- radius = 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement