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...
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?
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?
observational learning and violence. Do you believe that watching violence on video games and/or television leads...
observational learning and violence. Do you believe that watching violence on video games and/or television leads to violent behavior? How does the information in your assigned reading and the statistics presented support or challenge your beliefs?
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?
please watch this video TED Talk: "What it's like to be the child of immigrants" Michael...
please watch this video TED Talk: "What it's like to be the child of immigrants" Michael Rain. Question 1. What are two of the challenges that michael rain discussed as being a child of an immigrant? Question 2. How has the media, your family, and your community shaped your perception of immigrants and refuges? Is this an accurate perception.
Many employees do not like having a position dealing with numbers. However, the video this week...
Many employees do not like having a position dealing with numbers. However, the video this week is a good illustration of the connection between numbers (dollars!) and the relationship between a small business and the town in which it resides. Marty Doepke states that Pop's is the largest source of tax revenue for the very small town of Arcadia, Oklahoma. Speak on the importance of the accounting and finance functions of business. Be creative in your responses, but address the...
I need this in Java please: Lab11B: Understanding the constructor. Remember that the constructor is just...
I need this in Java please: Lab11B: Understanding the constructor. Remember that the constructor is just a special method (with no return type) that has the same name as the class name. Its job is to initialize all of the attributes. You can actually have more than one constructor, so long as the parameters are different. Create a class called Turtle that has two attributes: 1) speed and 2) color. Then, create a constructor that has no parameters, setting the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT