mdh.hephaestus2.gamelib
Class Sprite

java.lang.Object
  |
  +--mdh.hephaestus2.gamelib.Sprite

public class Sprite
extends Object

A Sprite is a simple object that can appear on a Screen. Sprites have a name, a bounding rectangle, and an image, and know how to draw themselves and detect collisions with other Sprites.

Author:
Copyright © 2002 by Mark Hughes <kamikaze@kuoi.asui.uidaho.edu>

Constructor Summary
Sprite(String name)
          Creates a new sprite with a null image and bounds 0,0,0,0.
 
Method Summary
 boolean collide(Sprite b, boolean fast)
          Returns true if this sprite collides with sprite b.
 void draw(Graphics2D g)
          Draws the sprite image on a graphics context.
 Rectangle getBounds()
          Returns a rectangle of the sprite's bounds.
 Image getImage()
          Returns the current image that represents the sprite.
 String getName()
           
 void moveby(int dx, int dy)
          Moves the sprite by a given delta.
 void moveto(int x, int y)
          Moves the sprite to specified coords.
 void setImage(Image i)
          Changes the image shown for the sprite, and updates the bounds width and height.
 void update()
          Update() is called every tick to let the sprite move, etc.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Sprite

public Sprite(String name)
Creates a new sprite with a null image and bounds 0,0,0,0.

Method Detail

collide

public boolean collide(Sprite b,
                       boolean fast)
Returns true if this sprite collides with sprite b. If 'fast' is true, only the bounding rectangles are checked, otherwise the images are compared.


draw

public void draw(Graphics2D g)
Draws the sprite image on a graphics context. If the image is null, nothing is drawn.


getBounds

public final Rectangle getBounds()
Returns a rectangle of the sprite's bounds. x,y are the sprite's location, and width,height are the size of the sprite's image.


getImage

public final Image getImage()
Returns the current image that represents the sprite.


getName

public final String getName()

moveby

public final void moveby(int dx,
                         int dy)
Moves the sprite by a given delta.


moveto

public final void moveto(int x,
                         int y)
Moves the sprite to specified coords.


setImage

public final void setImage(Image i)
Changes the image shown for the sprite, and updates the bounds width and height.


update

public void update()
Update() is called every tick to let the sprite move, etc. The default implementation does nothing.