Canon - public void draw(Graphics g SPRITE.draw(g(int...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.awt.Graphics; import java.awt.Image; public class Canon { //Constants private final String CANON_ICON = "base.gif"; private final int MAX_WIDTH;//size of the canvas on which the canon moves. private final int MAX_HEIGHT; private final double initialXSpeed = 1; //Variables private double upperLeftX, upperLeftY;//Position of the canon at its upper left corner. private final Sprite SPRITE; //graphical representation of the canon. public Canon(double theX, int theY, int theMaxWidth, int theMaxHeight){ upperLeftX = theX; upperLeftY = theY; MAX_WIDTH = theMaxWidth; MAX_HEIGHT = theMaxHeight; SPRITE = SpriteStore.get().getSprite(CANON_ICON);
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } public void draw(Graphics g) { SPRITE.draw(g, (int) upperLeftX, (int) upperLeftY); } public double getHeight(){ return SPRITE.getHeight(); } public double getWidth(){ return SPRITE.getWidth(); } public double getX(){ return upperLeftX; } public void move(boolean leftPressed, boolean rightPressed, Canon canon, int screenWidth) { if(canon.getX()>0&&canon.getX()<screenWidth){ if(leftPressed&&rightPressed); else if(leftPressed) upperLeftX = upperLeftX-initialXSpeed; else if(rightPressed) upperLeftX = upperLeftX+initialXSpeed; } } }...
View Full Document

This note was uploaded on 06/10/2011 for the course COMP 110 taught by Professor Stotts during the Spring '08 term at UNC.

Ask a homework question - tutors are online