int x=250; // Horizontal position of ball int direction_x=2; // Change in horizontal position each time draw() executed int y=150; // Vertical position of ball int direction_y=2; // Change in horizontal position each time draw() executed int lives=15; int score=0; void setup() { size(400,400); // Create a window 400x400 pixels } void draw() { background(255,255,255); // Clear screen to white fill(0,255,0); // Set fill colour to blue rect(0,mouseY-60,20,120); // Position rectangle using mouse fill(255,0,0); ellipse(x,y,20,20); // Draw blue disk centered on x,y diameter 20     x=x+direction_x; if(x<10) { direction_x=x; // Bounce x=30; // Force x to beyond the paddle on a restart lives--; // Reduce lives by one if(lives==0) exit(); // If lives is zero then quit } if(x>(width-10)) direction_x=-direction_x; //Right side //Vertical movement y=y+direction_y;   if(y /10) direction_y=-direction_y; //Bottom side //Score if((x / 30) &&(abs(mouseY-y)< 60)) { x=30; direction_x=-direction_x; // Bounce score++; }   if(y>(height-10)) direction_y=-direction_y; //Bottom side     textSize(32); fill(0,0,255); text(score, 10, 30); // Display score text(lives,width-30, 30) // Display lives }       (Q) Here is the code for Processing(4.2.1), There is some error in the code. I'm unable to run the code. Please debug the code and submit the output.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

int x=250; // Horizontal position of ball
int direction_x=2; // Change in horizontal position each time draw() executed
int y=150; // Vertical position of ball
int direction_y=2; // Change in horizontal position each time draw() executed
int lives=15;
int score=0;
void setup()
{
size(400,400); // Create a window 400x400 pixels
}
void draw()
{
background(255,255,255); // Clear screen to white
fill(0,255,0); // Set fill colour to blue
rect(0,mouseY-60,20,120); // Position rectangle using mouse

fill(255,0,0);
ellipse(x,y,20,20); // Draw blue disk centered on x,y diameter 20

 

 


x=x+direction_x;

if(x<10)
{
direction_x=x; // Bounce
x=30; // Force x to beyond the paddle on a restart
lives--; // Reduce lives by one
if(lives==0) exit(); // If lives is zero then quit
}

if(x>(width-10)) direction_x=-direction_x; //Right side

//Vertical movement
y=y+direction_y;

 

if(y /10) direction_y=-direction_y; //Bottom side
//Score
if((x / 30) &&(abs(mouseY-y)< 60))
{
x=30;
direction_x=-direction_x; // Bounce
score++;
}

 



if(y>(height-10)) direction_y=-direction_y; //Bottom side

 




 

textSize(32);
fill(0,0,255);
text(score, 10, 30); // Display score
text(lives,width-30, 30) // Display lives
}

 
 
 

(Q) Here is the code for Processing(4.2.1), There is some error in the code.
I'm unable to run the code.
Please debug the code and submit the output.

Expert Solution
Step 1
 int x=250; // Horizontal position of ball
    int direction_x=2; // Change in horizontal position each time draw() executed
    int y=150; // Vertical position of ball
    int direction_y=2; // Change in horizontal position each time dra) executed
    int lives=3;
    int score=0;
    void setup()
    {
     size(400,400); // Create a window 400x400 pixels
    }
    void draw()
    {
    background(255,255,255); // Clear screen to white
    fill(0,255,0); // Set fill colour to blue
    rect(0,mouseY-60,20,120); // Position rectangle using mouse

    fill(0,0,255);
    ellipse(x,y,20,20); // Draw blue disk centered on x,y diameter 20
    x=x+direction_x; // Update position
    if(x<10) direction_x=-direction_x; // Reverse direction if hit boundary
    if(x>(width-10)) direction_x=-direction_x;

    y=y+direction_y;
    if(y<10) direction_y=-direction_y;
    // if(y>(height-10)) direction_y=-direction_y;

    if(y>(height-10)) // If ball bits bottom of screen then miss..
    {
    direction_y=-direction_y; // Bounce
    lives--; // Reduce lives by one
    if(lives==0) exit(); // If lives is zero then quit
    }

    if(x<10)
    {
    direction_x=-direction_x; // Bounce
    x=30; // Force x to beyond the paddle on a restart
    lives--; // Reduce lives by one
    if(lives==0) exit(); // If lives is zero then quit
    }

    if((x<30)&&(abs(mouseY-y)<60)) // If ball has bit paddle then..
    {
    direction_x=-direction_x; // Bounce
    score++; // Increase score by one
    }

    textSize(32);
    fill(0,0,255);
    text(score, 10, 30); // Display score
    text(lives,width-30, 30); // Display lives
   } 
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education