/** * File: AlienMissile.java * Author: Brian Borowski * Date created: January 14, 2013 * Date last modified: January 21, 2013 */ import java.awt.Graphics; import java.awt.Image; import java.awt.Rectangle; public class AlienMissile { private final int xPos, speed; private float yPos = 0; private boolean hitGround; private static final Image bombImage; private static final int missileWidth, missileHeight; static { bombImage = Utility.getImage("images/alien_missile.png"); missileWidth = bombImage.getWidth(null); missileHeight = bombImage.getHeight(null); } public AlienMissile(final int speed, final int x, final int y) { xPos = x; yPos = y; this.speed = speed; } public boolean getHitGround() { return hitGround; } public void setHitGround(boolean hitGround) { this.hitGround = hitGround; } public int getXPos() { return xPos; } public int getYPos() { return (int)yPos; } public void moveDown(final float elapsedSeconds) { yPos += speed * elapsedSeconds; } public Rectangle getBoundingRectangle() { return new Rectangle( xPos - (missileWidth >> 1), (int)yPos, missileWidth, missileHeight); } public void paintComponent(final Graphics g) { g.drawImage(bombImage, xPos - (missileWidth >> 1), (int)yPos, null); } }