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

Solutions

Expert Solution

Pseudocode for screen animation, to print the position of the object until it goes out of frame:

Declaration
number x_pos, y_pos, x_velocity, y_velocity;
number width;
Start
// Input the start position of x and y and starting x velocity and y velocity
Input x_pos, y_pos, x_velocity. y_velocity;
  
width = 100; // set the width of the screen
  
// loop that continues till x_pos or y_pos are beyond the boundary i.e until the object moves off of the screen
// i.e position of x < 0 or position of x > 100 or position of y < 0 or position of y > 100
while(x_pos >=0 and x_pos <= width and y_pos >=0 and y_pos <=100)
do
Print "X: ",x_pos,"Y: ",y_pos; // print the values of x_pos and y_pos
x_pos = x_pos + x_velocity; // update x_pos after every frame
y_pos = y_pos + y_velocity; // update y_pos after every frame
end while

Print "X: ",x_pos,"Y: ",y_pos; // print the final values of x_pos and y_pos
End
  
//end of pseudocode

C++ code:

// C++ program to track the position of an object each frame until the object moves off of the screen

#include <iostream>
using namespace std;

int main()
{
   float x_pos, y_pos, x_velocity, y_velocity;
   float width = 100;
   // input of starting x position
   cout<<"Enter the starting X position: ";
   cin>>x_pos;
   // input of starting y position
   cout<<"Enter the starting Y position: ";
   cin>>y_pos;
   // input of starting x velocity
   cout<<"Enter the starting X velocity: ";
   cin>>x_velocity;
   // input of starting y velocity
   cout<<"Enter the starting Y velocity: ";
   cin>>y_velocity;

   // loop that prints out the object's position and update the position
   // each frame until the object moves off of the screen
   while(x_pos >=0 && x_pos <= width && y_pos >=0 && y_pos <=width)
   {
       cout<<"X : "<<x_pos<<" Y : "<<y_pos<<endl; // display the current position
       // update the x position and y position for the next frame
       x_pos += x_velocity;
       y_pos += y_velocity;
   }

   // display the final positions when the object is off the screen
   cout<<"X : "<<x_pos<<" Y : "<<y_pos<<endl;
   return 0;
}  

//end of program

Output:


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 the left or...
using java program Stay on the Screen! Animation in video games is just like animation in...
using java program 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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT