Class NightHunter

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----java.awt.Panel
                           |
                           +----java.applet.Applet
                                   |
                                   +----NightHunter

public class NightHunter
extends Applet
implements Runnable
This is the main class that is instantiated to begin the "Night Hunter" Java game. This class handles high-level animation, game timing loop, sound issues, and user input.


Variable Index

 o animate
 o applause
 o back
 o clip
 o delay
Animation frame rate = 12 FPS
 o gun
Mouse/Gun image
 o gunImage
 o gunsound
 o infoFont
 o infoMetrics
 o killed
 o level
 o lost
 o music
 o musicOn
 o offGrfx
 o offImage
 o rand
 o srv
 o tracker

Constructor Index

 o NightHunter()

Method Index

 o getAppletInfo()
 o init()
Game initialization method - starts the MediaTracker (needed to make sure images are completely loaded), load game background the mouse - gun images, and load audio clips.
 o keyDown(Event, int)
Keyboard keyDown Event - check for user input for new game or toggle music on/off.
 o mouseDown(Event, int, int)
Mouse Down Event - check if mouse/gun is over sprite, if it is kill sprite.
 o mouseEnter(Event, int, int)
Mouse Enter Event - when mouse enters game frame show gun crosshairs.
 o mouseExit(Event, int, int)
Mouse Exit Event - when mouse exits game frame hide gun crosshairs.
 o mouseMove(Event, int, int)
Mouse Move Event - update gun crosshair position.
 o newGame()
Setup a new game.
 o paint(Graphics)
Paint method that uses the Media Tracker to insure images are loaded.
 o run()
When an object is derived from a "Runnable" class then this method is called right after the thread "start()" method completes.
 o start()
Standard thread start handler method
 o stop()
Standard thread termination handler method - *** added call to stop music when thread terminates
 o update(Graphics)
This image update method uses "double-buffering" for bitmap images to eliminate screen flicker.

Variables

 o offImage
 private Image offImage
 o back
 private Image back
 o gunImage
 private Image gunImage
 o music
 private AudioClip music
 o gunsound
 private AudioClip gunsound
 o applause
 private AudioClip applause
 o clip
 private AudioClip clip[]
 o offGrfx
 private Graphics offGrfx
 o animate
 private Thread animate
 o tracker
 private MediaTracker tracker
 o srv
 private SRVector srv
 o gun
 private Sprite gun
Mouse/Gun image

 o delay
 private int delay
Animation frame rate = 12 FPS

 o infoFont
 private Font infoFont
 o infoMetrics
 private FontMetrics infoMetrics
 o rand
 private Random rand
 o musicOn
 private boolean musicOn
 o level
 private static int level
 o killed
 private static int killed
 o lost
 public static int lost

Constructors

 o NightHunter
 public NightHunter()

Methods

 o getAppletInfo
 public String getAppletInfo()
Overrides:
getAppletInfo in class Applet
 o init
 public void init()
Game initialization method - starts the MediaTracker (needed to make sure images are completely loaded), load game background the mouse - gun images, and load audio clips.

Overrides:
init in class Applet
 o start
 public void start()
Standard thread start handler method

Overrides:
start in class Applet
 o stop
 public void stop()
Standard thread termination handler method - *** added call to stop music when thread terminates

Overrides:
stop in class Applet
 o run
 public void run()
When an object is derived from a "Runnable" class then this method is called right after the thread "start()" method completes. *** This method is the heart of the game because this is where a new game is set up and this is where the game timing loop is implemented.

 o update
 public void update(Graphics g)
This image update method uses "double-buffering" for bitmap images to eliminate screen flicker. Draw the screen image as well as game info (level etc.). If game is over display "Game Over" message and stop music. *** This is where new creatures get added randomly depending on game level.

Overrides:
update in class Container
 o paint
 public void paint(Graphics g)
Paint method that uses the Media Tracker to insure images are loaded. If images are not completely loaded then a message will be displayed to the user until the image is loaded.

Overrides:
paint in class Container
 o mouseEnter
 public boolean mouseEnter(Event evt,
                           int x,
                           int y)
Mouse Enter Event - when mouse enters game frame show gun crosshairs.

Overrides:
mouseEnter in class Component
 o mouseExit
 public boolean mouseExit(Event evt,
                          int x,
                          int y)
Mouse Exit Event - when mouse exits game frame hide gun crosshairs.

Overrides:
mouseExit in class Component
 o mouseMove
 public boolean mouseMove(Event evt,
                          int x,
                          int y)
Mouse Move Event - update gun crosshair position.

Overrides:
mouseMove in class Component
 o mouseDown
 public boolean mouseDown(Event evt,
                          int x,
                          int y)
Mouse Down Event - check if mouse/gun is over sprite, if it is kill sprite. Play gun sound and sprite death sound if hit.

Overrides:
mouseDown in class Component
 o keyDown
 public boolean keyDown(Event evt,
                        int key)
Keyboard keyDown Event - check for user input for new game or toggle music on/off.

Overrides:
keyDown in class Component
 o newGame
 void newGame()
Setup a new game.