package background; /** * Background.java * * @author David Tran * @version 1.0 */ import java.awt.Graphics2D; import java.awt.Color; import java.awt.Stroke; import java.awt.BasicStroke; import java.awt.Point; import java.awt.geom.*; /** A "background" is a graphical image. Normally it is placed in the world * (the complete picture) when the world is created, and remains constant. * Every background that is constructed has an x- and y- coordinate, * representing its upperleft-most position in the graphics system, * as well as a width and height representing the maximum horizontal * and vertical distance from the x and y, respectively.
* PLEASE NOTE: No error checking is currently done to ensure positive * width and height values. */ public abstract class Background { /**xCoor and yCoor together represent the TOP-LEFT coordinate of the Background.*/ protected double xCoor; protected double yCoor; protected double width; protected double height; /** Name by which this background icon is known to the world * (for example, in a text input file). */ protected String externalName; /** * Initialize attributes for this Background * * @param x x-coordinate of background in the world (leftmost position of background) * @param y y-coordinate of background in the world (uppermost position of background) * @param w width of the background object * @param h height of the background object */ public Background(double x, double y, double w, double h) { this.externalName = "forgot to set the name!"; this.xCoor = x; this.yCoor = y; this.width = w; this.height = h; } /** * Returns the x position of this Background * * @return x-coordinate of the background's leftmost point */ public double getX(){ return this.xCoor; } /** * Returns the y position of this Background * * @return y-coordinate of the background's uppermost point */ public double getY(){ return this.yCoor; } /** * Returns the width of this Background * * @return width of the background */ public double getWidth(){ return this.width; } /** * Returns the height of this Background * * @return height of the background */ public double getHeight(){ return this.height; } /** * Updates the background in some particular way. * For now the background does not need to update itself. * You can override this method if you like, (for example, to get the effect * of rustling trees, changing house colors, deteriation of roads, * etc. for your backgrounds). * @param timeMillies the delay time in milliseconds */ public void update(double timeMillies) { } /** * Use the graphics system to draw the shapes representing this Background * * @param g the graphics system to use */ public abstract void draw(Graphics2D g); /** A name by which this background icon is known to the world * (for example, in a text file). */ public String getName() { return this.externalName; //hopefully each subclass will set this properly } }