Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is done in the Process Development Environment. This is the starter code float Xb, Yb, r, speedX, speedY; //ball location, size, and speed float

This is done in the Process Development Environment.

This is the starter code

float Xb, Yb, r, speedX, speedY; //ball location, size, and speed float Xp, Yp, w, h; //paddle location, wdith and height

boolean isGameOver = false; // when true, just draw the GameOver message and stop the animation loop to end the game int score = 0;

void setup() { size(400, 400);

// initialize ball attributes Xb = random(r, width-r); Yb = 30; r = 15; speedX = int(random(2, 4)); speedY = int(random(2, 4));

// initialize paddle attributes w = 30; h = 8; Xp = width/2; Yp = height - h; // hide mouse cursor noCursor(); }

void draw() { background(0);

if (!isGameOver) { //play as long as it is not game over

// DRAW game elements // draw Ball fill(255); noStroke(); ellipse(Xb, Yb, 2*r, 2*r); // draw paddle stroke(0, 255, 0); strokeCap(ROUND); strokeWeight(h); line(Xp-w, Yp, Xp+w, Yp); // draw score fill(255, 0, 0); textAlign(LEFT); textSize(16); text("Score: " + score, 5, 15);

// MOVE game elements // move Paddle Xp = mouseX; // move ball Xb += speedX; Yb += speedY;

// CHECK for collisions // REQ1: Add code to bounce the ball off the two sides and the top edge [+2 marks] // REQ2: Add code to check if ball lands on the paddle. Here is the pseudo-code: // if the ball is at the bottom edge (hint: check Yb) [+1 mark] // if ball lands on paddle (hint: see the assignment on how to check this) [+2 marks] // increment score, bounce ball up, and increase speed by 10% [+2 marks] // else // set isGameOver to true; [+1 mark]

} else { // if game over //REQ3: Add code for putting the GameOver message and stoping the animation loop [+2 marks] } }

/o other functions are required! (e.g. don't implement mousePressed, keyPressed, etc)image text in transcribed

Q2.#15] Pong Game: in this question, we will reuse the bouncing ball idea again but in a different game. Here, the player does not control the ball. The game starts with the ball moving in a certain direction, bouncing off the left, right, and top edges. The ball, however, doesn't bounce off the bottom edge. Instead, the player uses the mouse to horizontally move a paddle located at the bottom of the sketch, trying to hit the ball when it is at the bottom edge. The score is incremented whenever the player successfully hits the ball with the paddle. If the player misses the ball, the game ends with a message that shows the score. To make the game a bit challenging, the ball speed increases a little bit (eg. by 10%) every time the player hits the ball Score: 0 Score: 1 Score: 1 Game Over Your score is 1 Player moves the paddle to hit the When the ball is hit, score is incremented and ball speed increases If ball touches bottom edge, the game is over, and the animation stops with the message shown above ball up How to check if the ball lands on the paddle? When the ball is at the lower edge, measure the distance d as illustrated below. The ball lands on the paddle if d is less than (W-r) (Xp, Yp) (Xb,Yb) (Xp-W, Yp) 2w Q2.#15] Pong Game: in this question, we will reuse the bouncing ball idea again but in a different game. Here, the player does not control the ball. The game starts with the ball moving in a certain direction, bouncing off the left, right, and top edges. The ball, however, doesn't bounce off the bottom edge. Instead, the player uses the mouse to horizontally move a paddle located at the bottom of the sketch, trying to hit the ball when it is at the bottom edge. The score is incremented whenever the player successfully hits the ball with the paddle. If the player misses the ball, the game ends with a message that shows the score. To make the game a bit challenging, the ball speed increases a little bit (eg. by 10%) every time the player hits the ball Score: 0 Score: 1 Score: 1 Game Over Your score is 1 Player moves the paddle to hit the When the ball is hit, score is incremented and ball speed increases If ball touches bottom edge, the game is over, and the animation stops with the message shown above ball up How to check if the ball lands on the paddle? When the ball is at the lower edge, measure the distance d as illustrated below. The ball lands on the paddle if d is less than (W-r) (Xp, Yp) (Xb,Yb) (Xp-W, Yp) 2w

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

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions