Question

In: Computer Science

IN PSEUDOCODE and C++ Program 1: Stay on the Screen! Animation in video games is just...

IN PSEUDOCODE and C++

Program 1: Stay on the Screen! Animation in video games is just like animation in movies – it’s drawn image by image (called “frames”). Before the game can draw a frame, it needs to update the position of the objects based on their velocities (among other things). To do that is relatively simple: add the velocity to the position of the object each frame.

For this program, imagine we want to track an object and detect if it goes off the left or right side of the screen (that is, it’s X position is less than 0 and greater than the width of the screen, say, 100). Write a program that asks the user for the starting X and Y position of the object as well as the starting X and Y velocity, then prints out its position each frame until the object moves off of the screen. Design (pseudocode) and implement (source code) for this program.

Sample run 1:

Enter the starting X position: 50

Enter the starting Y position: 50

Enter the starting X velocity: 4.7

Enter the starting Y velocity: 2

X:50    Y:50

X:54.7 Y:52

X:59.4 Y:54

X:64.1 Y:56

X:68.8 Y:58

X:73.5 Y:60

X:78.2 Y:62

X:82.9 Y:64

X:87.6 Y:66

X:92.3 Y:68

X:97    Y:70

X:101.7 Y:72

Sample run 2:

Enter the starting X position: 20

Enter the starting Y position: 45

Enter the starting X velocity: -3.7

Enter the starting Y velocity: 11.2

X:20    Y:45

X:16.3 Y:56.2

X:12.6 Y:67.4

X:8.9   Y:78.6

X:5.2   Y:89.8

X:1.5   Y:101

X:-2.2 Y:112.2

Solutions

Expert Solution

Here is the completed code for this problem. Pseudocode is provided as comments before every statement. Go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

#include<iostream>

using namespace std;

int main(){

                //declaring minimum and maximum values for X

                int MIN_X=0, MAX_X=100;

                //declaring x, y, x velocity, y velocity

                double x, y, x_vel, y_vel;

               

                //prompting and reading starting x

                cout<<"Enter the starting X position: ";

                cin>>x;

                //prompting and reading starting y

                cout<<"Enter the starting Y position: ";

                cin>>y;

                //prompting and reading x velocity

                cout<<"Enter the starting X velocity: ";

                cin>>x_vel;

                //prompting and reading y velocity

                cout<<"Enter the starting Y velocity: ";

                cin>>y_vel;

               

                //printing x and y

                cout<<"X:"<<x<<"\tY:"<<y<<endl;

                //looping as long as x>=MIN_X and x<=MAX_X

                while(x>=MIN_X && x<=MAX_X){

                                //adding x_vel to x

                                x+=x_vel;

                                //adding y_vel to y

                                y+=y_vel;

                                //displaying x and y

                                cout<<"X:"<<x<<"\tY:"<<y<<endl;

                }

                return 0;

}

/*OUTPUT*/

Enter the starting X position: 20

Enter the starting Y position: 45

Enter the starting X velocity: -3.7

Enter the starting Y velocity: 11.2

X:20    Y:45

X:16.3 Y:56.2

X:12.6 Y:67.4

X:8.9   Y:78.6

X:5.2   Y:89.8

X:1.5   Y:101

X:-2.2 Y:112.2


Related Solutions

Program 1: Stay on the Screen! Animation in video games is just like animation in movies...
Program 1: Stay on the Screen! Animation in video games is just like animation in movies – it’s drawn image by image (called “frames”). Before the game can draw a frame, it needs to update the position of the objects based on their velocities (among other things). To do that is relatively simple: add the velocity to the position of the object each frame. For this program, imagine we want to track an object and detect if it goes off...
Please do this in C#. Stay on the Screen! Animation in video games is just like...
Please do this in C#. Stay on the Screen! Animation in video games is just like animation in movies – it’s drawn image by image (called “frames”). Before the game can draw a frame, it needs to update the position of the objects based on their velocities (among other things). To do that is relatively simple: add the velocity to the position of the object each frame. For this program, imagine we want to track an object and detect if...
Please do in Java!! Stay on the Screen! Animation in video games is just like animation...
Please do in Java!! Stay on the Screen! Animation in video games is just like animation in movies – it’s drawn image by image (called “frames”). Before the game can draw a frame, it needs to update the position of the objects based on their velocities (among other things). To do that is relatively simple: add the velocity to the position of the object each frame. For this program, imagine we want to track an object and detect if it...
I need assistance on this problem in Pseudocode and in C++ Program 1: Stay on the...
I need assistance on this problem in Pseudocode and in C++ Program 1: Stay on the Screen! Animation in video games is just like animation in movies – it’s drawn image by image (called “frames”). Before the game can draw a frame, it needs to update the position of the objects based on their velocities (among other things). To do that is relatively simple: add the velocity to the position of the object each frame. For this program, imagine we...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find...
write pseudocode not c program If- else programming exercises 1.    Write a C program to find maximum between two numbers. 2.    Write a C program to find maximum between three numbers. 3.    Write a C program to check whether a number is negative, positive or zero. 4.    Write a C program to check whether a number is divisible by 5 and 11 or not. 5.    Write a C program to check whether a number is even or odd. 6.    Write...
write pseudocode for the following problems not c code Pseudocode only Write a C program to...
write pseudocode for the following problems not c code Pseudocode only Write a C program to print all natural numbers from 1 to n. - using while loop Write a C program to print all natural numbers in reverse (from n to 1). - using while loop Write a C program to print all alphabets from a to z. - using while loop Write a C program to print all even numbers between 1 to 100. - using while loop...
C Program and pseudocode for this problem. Write a C program that plays the game of...
C Program and pseudocode for this problem. Write a C program that plays the game of "Guess the number" as the following: Your program choose the number to be guessed by selecting an integer at random in the rang of 1 to 1000. The program then asks the use to guess the number. If the player's guess is incorrect, your program should loop until the player finally gets the number right. Your program keeps telling the player "Too High" or...
Video games are rather complicated to program, not least of which because of the graphics work...
Video games are rather complicated to program, not least of which because of the graphics work that needs to be completed to finish a video game. Still, even relatively simple games have historically had a chance of becoming popular (e.g. Tetris®). Since you are learning to program for the first time, let's look at a text-only game. Write a program that has the computer generate a pseudorandom integer between -100 and +100, and ask the user to guess what the...
I need assistance on this problem in Pseudocode and in C++ Program Program 3: Give a...
I need assistance on this problem in Pseudocode and in C++ Program Program 3: Give a baby $5,000! Did you know that, over the last century, the stock market has returned an average of 10%? You may not care, but you’d better pay attention to this one. If you were to give a newborn baby $5000, put that money in the stock market and NOT add any additional money per year, that money would grow to over $2.9 million by...
IN PSEUDOCODE AND C++!! Program 1: Social Security Payout. If you’re taking this course, chances are...
IN PSEUDOCODE AND C++!! Program 1: Social Security Payout. If you’re taking this course, chances are that you’re going to make a pretty good salary – especially 3 to 5 years after you graduate. When you look at your paycheck, one of the taxes you pay is called Social Security. In simplest terms, it’s a way to pay into a system and receive money back when you retire (and the longer you work and the higher your salary, the higher...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT