Question

In: Computer Science

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

CursorPosition.java :

//import package
import java.util.*;
//java class
public class CursorPosition {
//main method
   public static void main(String[] args) {
       // creating object of Scanner class
       Scanner input = new Scanner(System.in);
       // asking user starting X position
       System.out.print("Enter the starting X position: ");
       double XX = input.nextDouble();// reading X position
       // asking user starting Y position
       System.out.print("Enter the starting Y position: ");
       double YY = input.nextDouble();// reading y position
       // asking user starting X velocity
       System.out.print("Enter the starting X velocity: ");
       double xVelocity = input.nextDouble();// reading X velocity
       // asking user starting Y velocity
       System.out.print("Enter the starting Y velocity: ");
       double yVelocity = input.nextDouble();// reading Y velocity
       //this loop will executes till value of X becomes less then 0 or
       //greater than 100 using while loop
       while (XX > 0 && XX <= 100) {
           System.out.printf("X:%.1f",XX);//printing X position
           System.out.print(" ");// used for space
           System.out.printf("Y:%.1f", YY);
           System.out.println();// used for new line
           //increment position by adding velocity
           XX = XX + xVelocity;
           // increment position by adding velocity
           YY = YY + yVelocity;
       }
       System.out.printf("X:%.1f", XX);//print position of X
       System.out.print(" ");// used for space
       System.out.printf("Y:%.1f", YY);//print position of Y

   }

}
*************************************

Screen 1:CursorPosition.java


Related Solutions

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...
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...
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...
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...
What is the influence of the media on children? Do you think exposure to video games...
What is the influence of the media on children? Do you think exposure to video games may be creating anxiety, anger, hostility, or even psychological disorders, such as oppositional defiant disorder, conduct disorder and ADHD?
Do violent video games play a role in school shootings and mass violence?
Do violent video games play a role in school shootings and mass violence?
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...
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