Question

In: Computer Science

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 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.

//////// WRITE IN PSEUDOCODE ////////

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

////////WRITE IN PSEUDOCODE//////

Solutions

Expert Solution

Please find the PSEUDOCODE for this problem below. Earlier, pseudo code was just an informal way of representing the execution of a problem/task using plain English. Now there are so many different versions of rules and syntax for designing a pseudo code. So I’m not sure which one are you looking for, I’m just making everything simple so that a normal person with no coding skills can understand what’s happening just by reading below text. 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

Note: I have written a solution for this question in C++ before. So if you want that code also, just mention it in comments.

EDIT: added code in C++

Set MIN_X to 0

Set MAX_X to 100

Input Variable X

Input Variable Y

Input Variable X_VEL

Input Variable Y_VEL

Display "X: "+X+" Y: "+Y

WHILE X >= MIN_X and X <= MAX_X DO

                X=X+X_VEL

                Y=Y+Y_VEL

                Display "X: "+X+" Y: "+Y

ENDWHILE

Code in C++

#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 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...
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...
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...
Castle View Games would like to invest in a division to develop software for video games....
Castle View Games would like to invest in a division to develop software for video games. To evaluate this decision, the firm first attempts to project the working capital needs for this operation. Its chief financial officer has developed the following estimates (in millions of dollars): Year 1 Year 2 Year 3 Year 4 Year 5 Cash 6 12 15 15 15 Accounts receivable 21 22 24 24 24 Inventory 5 7 10 12 13 Accounts payable 18 22 24...
Is aggression a learned behavior? How do television/movies/video games influence this aggression. Does this matter? Is...
Is aggression a learned behavior? How do television/movies/video games influence this aggression. Does this matter? Is there a connection between violence in the media and violence in society?
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...
Linkedina has a ROE of 24% that is expected to stay like that for years 1...
Linkedina has a ROE of 24% that is expected to stay like that for years 1 to 3. In year 4 the ROE is expected to change to $12 (for both new and old projects) and stay there forever. The firm's stock has just paid a dividend of 6 AUD and the retention ratio is 40%. Assume the retention ratio is held constant forever and the opportunity cost of equity capital is 12$. What is your estimate of the value...
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...
1. What impact do video games have on the school age child’s acquisition of physical and...
1. What impact do video games have on the school age child’s acquisition of physical and cognitive skills? 2. How can an adolescent achieve a sense of their own identity?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT