Get Instant Help From 5000+ Experts For
question

Writing: Get your essay and assignment written from scratch by PhD expert

Rewriting: Paraphrase or rewrite your friend's essay with similar meaning at reduced cost

Editing:Proofread your work by experts and improve grade at Lowest cost

And Improve Your Grades
myassignmenthelp.com
loader
Phone no. Missing!

Enter phone no. to receive critical updates and urgent messages !

Attach file

Error goes here

Files Missing!

Please upload all relevant files for quick & complete assistance.

Guaranteed Higher Grade!
Free Quote
wave
COMP 1010 Introduction To Computer Science 1

Q1: Game Setup Set up an Active Processing program that will draw the initial configuration of the game.Write a setupGame()function that will set the initial value for all necessary variables (see below), and a drawGame()function that will draw the canvasas described below, similar to the samplesshown at right.You are responsible for drawing the green, ball, hole,and obstacle. A function to draw the score is provided below.Use globals to store the position and size of the ball,hole, and obstacle, and to keep track of the score. (Which globals should be variable and which should be constant?)Generate the initial game configuration as follows:Choose a reasonable ball size,andset the hole size to be twice the ball size.The green should be randomly chosen to be either horizontal or vertical(50-50 probability).The green should occupy the middle third of the canvas.Place the ball (white in images at right) on an imaginary tee, randomly placed in the left third (ifthe hole ishorizontal) or bottomthird(if the hole is vertical) of the green. Make sure that the entire ball is within the green.Place the hole (black in images at right) randomly in the right (if horizontal hole) or top (if vertical hole) third of the green. Make sure that the hole is at least one hole width away from the edge of the green.Place a rectangular obstacle randomly in the middle third of the green. Make sure that the obstacle is entirely within the green.Seta minimum and maximum length for the width and height ofthe obstacle, and choose different (random) dimensions each time the program runs.Copy and paste the following drawScore() function into your program. Call it from your drawGame() function. We will learn about text in Unit 8.void drawScore(){textSize(20);String toPrint = "Number of shots taken: "+shotsTaken;text(toPrint, width/2-textWidth(toPrint)/2, 50);}NOTE:In order for this function to work, you mustkeep track of the score in a global variable named shotsTaken.Q2: Move the Ball Make the ballmove, such that:The initial speed is based on the distance from the ball to the mouse, where a small distance between the mouse and ball gives a low speed and a large distance betweenthe mouse and ball gives a high speed.To implement this variety in the speed:oDetermine the largest possible distance from the ball to the mouse, keeping in mind that a mouse click will only register if the mouse is on the canvas.oChoose a MAX_SPEED (try 10pixelsinitially), and scale the distancefrom the ball to the mouseinto a ball speed between 0 and MAX_SPEED.Store the direction of motion for the ball as the angle from the ball to the location of the mouse when clicked.Choose a SPEED_STEP (try 0.05pixelsinitially), and reduce the ball speed by this amount each frame.In each frame, convert the direction and speed to a change in x and y coordinates, and updatethe ball positionto make the ball move.

support
Whatsapp
callback
sales
sales chat
Whatsapp
callback
sales chat
close