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)Sample run 1:Enter the starting X position: 50Enter the starting Y position: 50Enter the starting X velocity: 4.7Enter the starting Y velocity: 2X:50 Y:50X:54.7 Y:52X:59.4 Y:54X:64.1 Y:56X:68.8 Y:58X:73.5 Y:60X:78.2 Y:62X:82.9 Y:64X:87.6 Y:66X:92.3 Y:68X:97 Y:70X:101.7 Y:72Sample run 2:Enter the starting X position: 20Enter the starting Y position: 45Enter the starting X velocity: -3.7Enter the starting Y velocity: 11.2X:20 Y:45X:16.3 Y:56.2X:12.6 Y:67.4X:8.9 Y:78.6X:5.2 Y:89.8X:1.5 Y:101X:-2.2 Y:112.2

Respuesta :

Answer:

Pseudocode of the program:

Step 1: Start

Step 2: Declare variable x, y, velocity_X and velocity_y of float type to store value from user

Step 3: Ask user to provide value of x and y coordinate and velocity in x and y direction. Store in the respective variables

Step 4: While value of x and y is greater than 0 and less than 100, repeat step 5-7

Step 5: print the value of x and y

Step 6:If value of x is less than 0

The object exited from left

else If value of x is greater than 100

The object exited from right

If value of y is less than 0

The object exited from bottom

else If value of y is greater than 100

The object exited from top

Step 7: calculate new x and y coordinate as x= velocity_X and y= velocity_Y

Step 8: Stop

C-program

ConsoleApplication1

{

Video Animation

{

static void Main(string[] args)

{

// Take user inputs

Console.Write("Give the starting X position: ");

double X = Convert.ToDouble(Console.ReadLine());

Console.Write("Enter the starting Y position: ");

double Y = Convert.ToDouble(Console.ReadLine());

Console.Write("Enter the starting X velocity: ");

double velocity_X = Convert.ToDouble(Console.ReadLine());

Console.Write("Enter the starting Y velocity: ");

double velocity_Y = Convert.ToDouble(Console.ReadLine());

// Print starting values

Console.WriteLine("X:{0} Y:{1}", X, Y);

// Iterate loop till object goes out of screen

while (X>=0 && X<=100 )

{

// Increment values

// Print X and Y

X += velocity_X;

Y += velocity_Y;

Console.WriteLine("X:{0} Y:{1}", X, Y);

}

}

}

}

ACCESS MORE
EDU ACCESS
Universidad de Mexico