Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Processing 3.4 Q2: Bumper Golf - You have a golf ball (the white circle) and a randomly placed hole (the grey circle). The white

Using Processing 3.4

Q2: Bumper Golf - You have a golf ball (the white circle) and a randomly placed hole (the grey circle). The white line is controlled by the mouse, and indicates how hard you will hit the ball, and in what direction. The ball will be hit when you press the mouse button. Dont shoot too hard, or the ball will go right over the hole and keep moving. Shoot straight, since the ball needs to be completely within the hole to fall in. This assignment is quite big compared to what you may be used to. Good commenting and explanations of what each region of code will do (basically, to help you break it down...) will be very beneficial and will save you a lot of debugging time. It will probably be helpful to write out what should happen in English first (in comments!!).

The challenge here is to keep track of what state everything is in (what is currently happening). Is the ball moving? How fast? In what direction? Is there a hole? Is the ball inside the hole? etc. You will need global constants for all of the game parameters. This includes the MIN_SPEED of the ball (below which it is considered to be not moving - try 0.5 pixels per frame), the FRICTION (how much of the velocity is retained from frame to frame - try 0.98). You will develop others, and some are mentioned below. You will also need global variables for the hole location (both x and y coordinates), a boolean variable for whether there is currently a hole, variables for the ball location (x and y), the ball speed in x and y directions, a boolean variable indicating if the ball is moving, and others. In the draw block, you need to balance the following tasks: If there is a hole, draw it. If not, create one at a random location. The hole size should be 1.5 times the ball size. If the ball is not moving, then draw a line from the ball to the mouse and draw a white ball. If the mouse is pressed, then shoot: o Determine the x and y distances from ball to the mouse cursor and scale them down to get the initial x and y velocities (try a scaling factor of 0.04). That means, the velocity in the x direction in pixels per frame will be this scaling factor times the distance (in pixels) in the x direction, and similarly for the y direction. o Add 1 stroke to the players score, and print this to the console using println. If the ball is moving, o Draw the ball. o Add the x velocity to the x position and the y velocity to the y position. o If the ball is too close to the left or right side of the canvas, (less than one ball radius), reverse the sign of the horizontal velocity. o If the ball is too close to the top or bottom of the canvas, (less than one ball radius), reverse the sign of the vertical velocity. o Apply friction to the ball speed (multiply both velocity components by the friction factor). o If the ball is completely inside the hole (hint: if the distance between the two centers is less than the hole radius minus the ball radius), and the ball isnt moving too fast (try 2 pixels per frame), then the ball is sunk. You can calculate the velocity as the length of the hypotenuse (is the longest side of a right-angled triangle) if you make a triangle with the x and y speeds. Move the hole and move the ball back to the center of the screen (with no speed!) when the user clicks to reset the game. Remember that If the total ball velocity is too slow, mark it as not moving at all. Note for Implementation: Write the program in English first. Implement and test your program in phases. First get the ball on the screen. Then be able to shoot it using the mouse. Then implement the wall rebounding. Finally, add the hole and the scoring.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions

Question

How were the HR functions affected by Hurricane Rita?

Answered: 1 week ago