Question

In: Computer Science

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

If you have any doubts, please give me comment...

import java.util.Scanner;

public class FrameAnimation{

    public static void main(String[] args) {

        Scanner scnr = new Scanner(System.in);

        double X, Y, X_Velocity, Y_Velocity;

        System.out.print("Enter the starting X position: ");

        X = scnr.nextDouble();

        System.out.print("Enter the starting Y position: ");

        Y = scnr.nextDouble();

        System.out.print("Enter the starting X velocity: ");

        X_Velocity = scnr.nextDouble();

        System.out.print("Enter the starting Y velocity: ");

        Y_Velocity = scnr.nextDouble();

        System.out.println("X:"+X+"\t"+"Y:"+Y);

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

            X += X_Velocity;

            Y += Y_Velocity;

            System.out.printf("X:%.1f\tY:%.1f\n", X, Y);

        }

    }

}


Related Solutions

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...
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...
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...
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...
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...
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...
Write a Java program that reads a name and displays on the screen.
Write a Java program that reads a name and displays on the screen.
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...
Write a java program that prints to the screen a countdown 2,4,6,8, and then "Who do...
Write a java program that prints to the screen a countdown 2,4,6,8, and then "Who do we appreciate!" (hint use a for loop). Create a java program which prints out a random goodwill message i.e. (Have a great day!) please have at least 4 messages. Write a java program that will ask the user to enter a number and print out to the screen until the number -3 is entered. Write a JAVA program that calls a method that finds...
Write a java program that simulates thousands of games and then calculate the probabilities from the...
Write a java program that simulates thousands of games and then calculate the probabilities from the simulation results. Specifically in the game, throw two dice, the possible summations of the results are: 2, 3, ..., 12. You need to use arrays to count the occurrence and store the probabilities of all possible summations. Try to simulate rolling two dice 100, 1000, 10,0000 times, or more if needed. Choose one simulation number so that the probabilities you calculated is within 1%...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT