SpaceInvaders
Class Ship

java.lang.Object
  |
  +--SpaceInvaders.Ship

public class Ship
extends java.lang.Object

Encapsulates the spaceship functionality.

Version:
1.2, 3 January 2002
Author:
Susan B. Cavanaugh

Field Summary
private static int height
          spaceship image height in pixels
private  Point prevPos
          previous position of spaceship
private  Point screenPos
          position of spaceship on the screen
private static int width
          spaceship image width in pixels
 
Constructor Summary
Ship()
          Default constructor initializing spaceship's image position to (300, 430).
Ship(Point p)
          Accepts screen coordinates for spaceship's image position.
 
Method Summary
 void draw(java.awt.Graphics g)
          Overwrites the previous move and leaves the actual spaceship image handling and drawing to the applet's paint method.
static int getHeight()
          Gets the height of a spaceship image.
 Point getPosition()
          Gets the screen position.
static int getWidth()
          Gets the width of a spaceship image.
 void move(boolean moveRight)
          Moves spaceship either right or left.
static void setHeight(int h)
          Sets the height of a spaceship image.
 void setPosition(Point p)
          Sets the screen position of this spaceship image.
static void setWidth(int w)
          Sets the width of a spaceship image.
 Laser shoot()
          Shoots a yellow laser from top of spaceship.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

width

private static int width
spaceship image width in pixels

height

private static int height
spaceship image height in pixels

screenPos

private Point screenPos
position of spaceship on the screen

prevPos

private Point prevPos
previous position of spaceship
Constructor Detail

Ship

public Ship()
Default constructor initializing spaceship's image position to (300, 430).

Ship

public Ship(Point p)
Accepts screen coordinates for spaceship's image position.
Parameters:
p - screen location
Method Detail

setWidth

public static void setWidth(int w)
Sets the width of a spaceship image.
Parameters:
w - width in pixels

getWidth

public static int getWidth()
Gets the width of a spaceship image.
Returns:
width in pixels

setHeight

public static void setHeight(int h)
Sets the height of a spaceship image.
Parameters:
h - height in pixels

getHeight

public static int getHeight()
Gets the height of a spaceship image.
Returns:
height in pixels

setPosition

public void setPosition(Point p)
Sets the screen position of this spaceship image.
Parameters:
p - screen position

getPosition

public Point getPosition()
Gets the screen position.
Returns:
screen position

draw

public void draw(java.awt.Graphics g)
Overwrites the previous move and leaves the actual spaceship image handling and drawing to the applet's paint method.
Parameters:
g - the graphics context

move

public void move(boolean moveRight)
Moves spaceship either right or left.
Parameters:
moveRight - move spaceship right flag; true for right move

shoot

public Laser shoot()
Shoots a yellow laser from top of spaceship.
Returns:
a new Laser object.