Question
Please HELP! Data Structures JAVA Assignment: Create a Queue of type Vector2D to manage the movement animation Populate the first Queue (vecs1): Provide the code
Please HELP!
Data Structures JAVA
Assignment:
Create a Queue of type Vector2D to manage the movement animation
Populate the first Queue (vecs1):
Provide the code in the start() method. The purpose of the start method is to set up data before the game loop begins. Inside of this method, set up your coordinates for the vector Queue. You can use a loop if you want or do it manually; the choice is yours (although I would recommend a loop with constant "steps" between frames as far as x coordinate goes).
The image is going to need to move from left to right on the screen and restart at the beginning again. Therefore, your y coordinate should remain the same for ALL vectors in the Queue. Only the x coordinate should change.
Since your animation has to run continuously (until ESC is pressed), you need a way to "reset" the animation when each Queue runs out. Therefore, the algorithm for this animation is:
- Set up our timer object with our chosen delay (play around with the delay for speed)
- Load all vectors into vecs1 in start method (use a loop with "steps" for quickest coding!)
Now, once the game loop starts, everything else will occur inside the update method:
- Check to see if the timer is up; if so, update the current vector used by removing it from the Queue
- Make sure you save this vector into the currentVec. It also needs to be added to vecs2 right after being saved into currentVec.
- Use currentVec as position for addSpriteToFrontBuffer to display animated sprite
- Once the vecs1 Queue is empty, transfer vecs2 into vecs1 and repeat from step 1
Requirements:
- Load your frames into the first Queue
- Using a timer, two Vector2D queues, and your custom engine, make the image move from the left side of the screen to the right. Once the image reaches the end of the animation, it should reset by transferring the second Queue back to the first
I provided Vector2D.java.
/* This class is used to give you a handy way to pass a pair of 2D coordinates as a single object. The behavior (methods) of the class should allow for robust options in the 2 3 package Dato; 4 5 public class Vector2D { G 11 Fields // TODO: Add private class fields to store x and y values given in class constructor 8 private int x; private int y; 11 12e // Constructor public Vector2D(int x, int y){ // TODO: Save the constructor parameters into class fields this.x = x; this.y - y } // Methods public int getX() { // TODO: Remove my placeholder code below (which is there to prevent an error) and replace it with returning the value of your private field x return x; 1 public int gely // TODO: Remove my placeholder code below (which is there to prevent an error) and replace it with returning the value of your private field y return y; 1 15 16 17 18 190 20 21 22 23 24- 25 25 27 28 29 30 31 32 33 340 35 36 37 38 390 348 public void 5X(int i wX}{ // TODO: Update the value of x to be the value in newx (Absolute assignment) this.x = x; } public void setY(int new) 1/ TODO: Update the value of y to be the value in newy (Absolute assignment) this.y = Y; } public void adjustX(int adjustment) [ // TODO: Change the previous value of x by adding the adjustment to the previous value (Relative assignment) // Backward adjustments can be made by passing a negative number as an adjustment this.x + adjustment; 42 43 44 345 46 47 4 public void adjustY(int adjustment) // TODO: Change the previous value of y by adding the adjustment to the previous velue (Relative assignment) 1/ Backward adjustments can be made by passing a negative number as an adjustment this.y += adjustment; 1 50 51 } 52 6 5 package Main; 7* import java.awt.Color; 14 15 public class Main{ 16 // Fields (Static) below... 17 public static Color c = new Color(23, 160, 195); 18 public static boolean is ImageDronn = false; 19 public static stopwatchx timer = new stopwatchX (250); 20 public static Vector2D veci = new Vector2D(100, 50); 21 public static Queue
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started