Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can you guys add the * pseudocode * (please add / pseudocode * only * /) for som

ID: 3684879 • Letter: C

Question

Can you guys add the *pseudocode* (please add /pseudocode *only*/) for some of the essential functionality of this PaddleBallController class stub below?


public class PaddleBallController implements ActionListener, MouseMotionListener {

// Add the field declarations

// The constructor:

public PaddleBallController() {

   // Instantiate the Ball, Paddle, and Display objects/fields

// Pass THIS object to the Display object

   // Setup a new Timer: this will generate the events that drive the game

// Register with THIS object

   // Register the mouse event handler

// Register THIS object as the listener

}

// Method to have the game ball and game paddle draw themselves

public void drawGame(Graphics g) {

}

// Deal with Timer Events

public void actionPerformed(ActionEvent e) {

// Ball moves within size of the display area

// Determine if the ball is in contact with the paddle

// Is the top of the ball now in contact with the paddle?

// Cause the GUI/Display Object to redraw itself

}

// Check for user moving the Paddle via MouseEvents

public void mouseDragged(MouseEvent me) {

}

public void mouseMoved(MouseEvent me) {

}

}

Explanation / Answer

//Paola Boettner
//Paddle Ball Pseudocode

//1. Start a draw loop to write your code in.

//2. Set your background.

//3. Draw your paddle. Get the paddle to move with your mouse using mouseX.

// draw the paddle
//fill(240, 126, 65);
//rect(mouseX - 50, 350, 100, 10);

//4. Draw the ball on the paddle. Get the ball to move along with the paddle.

// draw the ball
//fill(255, 234, 0);
//ellipse(ballX, ballY, 20, 20);

//5. Write code to move the ball. Hint 1: You will need variables for ballMoving, ballX, ballY, ballSpeedX, ballSpeedY, initialSpeedX, initialSpeedY. Remember variable definitions go outside the draw loop. Hint 2: You will need a conditional statement involving ballMoving.

// move the ball
// if (ballMoving) {
// ballX = ballX + ballSpeedX;
// ballY = ballY + ballSpeedY;
//}
//else {
// ballX = mouseX;
// ballY = 340;
//}
  
// draw the ball
//fill(255, 234, 0);
//ellipse(ballX, ballY, 20, 20);

// mouse click code!
  
  
  
//6. Write code for the ball to bounch off the right, left and top walls. You can use your bouncy ball code from last time.


// check if ball has hit the top wall
// if (ballY <= 10) {
// ballSpeedY = -ballSpeedY;
// }
// check if the ball has hit the left wall
// if (ballX <= 10) {
// ballSpeedX = -ballSpeedX;
// }
// check if the ball has hit the right wall
// if (ballX >= 390) {
// ballSpeedX = -ballSpeedX;
// }

//7. Write code for the ball to bounce off the paddle.
//if (ballY >= 340 && ballY < 346 && ballX >= mouseX - 50 && ballX <= mouseX + 50) {
// ballSpeedY = -ballSpeedY;
// }

//8. Write code for the game to re-start if the ball hits the bottom wall.

// check if ball fell out the bottom
// if (ballY >= 400) {
// ballMoving = false;
//}

var initialSpeedX = 5;
var initialSpeedY = -6;
var ballSpeedX = initialSpeedX;
var ballSpeedY = initialSpeedY;

var ballX = 0;
var ballY = 0;
var ballMoving = false;


var draw = function() {
background(0, 108, 135);
  
// draw the paddle
fill(240, 126, 65);
rect(mouseX - 50, 350, 100, 10);
  
// move the ball
if (ballMoving) {
ballX = ballX + ballSpeedX;
ballY = ballY + ballSpeedY;
}
else {
ballX = mouseX;
ballY = 340;
}
  
// draw the ball
fill(255, 234, 0);
ellipse(ballX, ballY, 20, 20);
  
//Here goes the code for the ball to bounce or restart (bottom)
// check if ball has hit the top wall
if (ballY <= 10) {
ballSpeedY = -ballSpeedY;
}
// check if the ball has hit the left wall
if (ballX <= 10) {
ballSpeedX = -ballSpeedX;
}
// check if the ball has hit the right wall
if (ballX >= 390) {
ballSpeedX = -ballSpeedX;
}
// check if the ball has hit the paddle
if (ballY >= 340 && ballY < 346 && ballX >= mouseX - 50 && ballX <= mouseX + 50) {
ballSpeedY = -ballSpeedY;
}
// check if ball fell out the bottom
if (ballY >= 400) {
ballMoving = false;
}
};
// this function gets called automatically
// when the mouse is clicked
var mouseClicked = function() {
if (!ballMoving) {
// reset the ball speed
ballSpeedX = initialSpeedX;
ballSpeedY = initialSpeedY;
  
ballMoving = true;
}
};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote