Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need to create a sprite that moves from the left to the right of the screen, using only two queues. The requirements for this

I need to create a sprite that moves from the left to the right of the screen, using only two queues.

The requirements for this assignment are to:

  1. Load your custom sprite (128 x 128) into the game engine using Art.txt
  2. Make your sprite appear when running the program
  3. Write the Vector2D class using the template
  4. Load your frames into the first Queue
  5. 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.

Does this look good so far?

Main.java

--------------------

package Main;

import java.awt.Color; import java.util.LinkedList; import java.util.Queue; import Data.Vector2D; import logic.Control; import timer.stopWatchX;

public class Main{ // Fields (Static) below... public static Color c = new Color(0,128,0); public static boolean isImageDrawn = false; public static stopWatchX timer = new stopWatchX(250); public static Queue vec1 = new LinkedList<>(); public static Queue vec2 = new LinkedList<>(); public static Vector2D currentVec = new Vector2D(0, 0); // End Static fields... public static void main(String[] args) { Control ctrl = new Control(); // Do NOT remove! ctrl.gameLoop(); // Do NOT remove! } /* This is your access to things BEFORE the game loop starts */ public static void start(){ // TODO: Code your starting conditions here...NOT DRAW CALLS HERE! (no addSprite or drawString) int x = 0; while (x != 1000) { vec1.add(new Vector2D(currentVec.getX(), currentVec.getY())); currentVec.adjustX(x); x++; } } /* This is your access to the "game loop" (It is a "callback" method from the Control class (do NOT modify that class!))*/ public static void update(Control ctrl) { // TODO: This is where you can code! (Starting code below is just to show you how it works) while (!vec1.isEmpty()) { if(timer.isTimeUp()) { currentVec = vec1.remove(); vec2.add(new Vector2D(currentVec.getX(), currentVec.getY())); ctrl.addSpriteToFrontBuffer(currentVec.getX(), currentVec.getY(), "star"); //ctrl.drawString(20, 150, "", c); // Test drawing text on screen where you want (Remove later! Test only!) vec1 = vec2; timer.resetWatch(); } } } }

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 future. */

package Data;

public class Vector2D { // Fields // TODO: Add private class fields to store x and y values given in class constructor private int x; private int y; // 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; } public int getY(){ // 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; } public void setX(int newX){ // TODO: Update the value of x to be the value in newX (Absolute assignment) this.x = newX; } public void setY(int newY){ // TODO: Update the value of y to be the value in newY (Absolute assignment) this.y = newY; } 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; } public void adjustY(int adjustment){ // TODO: Change the previous value of y by adding the adjustment to the previous value (Relative assignment) // Backward adjustments can be made by passing a negative number as an adjustment this.y+=adjustment; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago