Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I HAVE THIS C CODE BOUNCING BALL COMPLETE BUT BUT THE PADDLE IS NOT MOVING SIDE WAYS HOW TO MAK IS GO SIDE WAYS AND

I HAVE THIS C CODE BOUNCING BALL COMPLETE BUT BUT THE PADDLE IS NOT MOVING SIDE WAYS HOW TO MAK IS GO SIDE WAYS AND CONTROLLING IT USING RIGHT OR LEFT ARROW

PLEASE DO IT RIGHT AND MAKE SURE IT WORKS THANK YOU!!!!!!

#include #include #include // Define constants for the screen size and ball velocity. #define SCREEN_WIDTH 60 #define SCREEN_HEIGHT 20 #define BALL_VELOCITY 1 #define PADDLE_WIDTH 20 #define PADDLE_side 60 #define PADDLE_Y SCREEN_HEIGHT - 2 int paddle_x = SCREEN_WIDTH / 2 - PADDLE_WIDTH / 2; int main() { // Initialize the random number generator. srand(time(NULL)); // Initialize the ball position and velocity. int ball_x = SCREEN_WIDTH / 2; int ball_y = 1; int ball_velocity_x = BALL_VELOCITY; int ball_velocity_y = BALL_VELOCITY; // Game loop. while (1) { // Clear the screen. system("cls"); // Draw the ceiling. for (int i = 0; i < SCREEN_WIDTH + 2; i++) { printf("x"); } printf(" "); // Draw the ball. for (int i = 0; i < ball_y; i++) { printf(" "); } for (int i = 0; i < ball_x; i++) { if (i == SCREEN_WIDTH / 2 - 3 || i == SCREEN_WIDTH / 2 + 2) { printf(" "); } else { printf(" "); } } printf("O "); //The paddle for (int i = 0; i < paddle_x; i++) { printf(" "); } for (int i = 0; i < PADDLE_WIDTH; i++) { printf("_"); } printf(" "); //Bottom border for (int i = ball_y + 1; i < SCREEN_HEIGHT; i++) { printf(" "); } for (int i = 0; i < SCREEN_WIDTH + 2; i++) { printf("x"); } printf(" "); // Update the ball position and velocity. ball_x += ball_velocity_x; ball_y += ball_velocity_y; if (ball_x == 0 || ball_x == SCREEN_WIDTH - 1) { ball_velocity_x = -ball_velocity_x; } if (ball_y == 0 || ball_y == SCREEN_HEIGHT - 1) { ball_velocity_y = -ball_velocity_y; } // Wait for a short time to control the game speed. for (int i = 0; i < 100000000; i++) { // Do nothing. } } return 0; }

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

Probabilistic Databases

Authors: Dan Suciu, Dan Olteanu, Christopher Re, Christoph Koch

1st Edition

3031007514, 978-3031007514

More Books

Students also viewed these Databases questions

Question

How does a freemium business model work?

Answered: 1 week ago

Question

b. Will new members be welcomed?

Answered: 1 week ago

Question

c. Will leaders rotate periodically?

Answered: 1 week ago

Question

b. Will there be one assigned leader?

Answered: 1 week ago