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.
-
animate
-
-
applause
-
-
back
-
-
clip
-
-
delay
- Animation frame rate = 12 FPS
-
gun
- Mouse/Gun image
-
gunImage
-
-
gunsound
-
-
infoFont
-
-
infoMetrics
-
-
killed
-
-
level
-
-
lost
-
-
music
-
-
musicOn
-
-
offGrfx
-
-
offImage
-
-
rand
-
-
srv
-
-
tracker
-
-
NightHunter()
-
-
getAppletInfo()
-
-
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.
-
keyDown(Event, int)
- Keyboard keyDown Event - check for user input
for new game or toggle music on/off.
-
mouseDown(Event, int, int)
- Mouse Down Event - check if mouse/gun is over
sprite, if it is kill sprite.
-
mouseEnter(Event, int, int)
- Mouse Enter Event - when mouse enters game frame
show gun crosshairs.
-
mouseExit(Event, int, int)
- Mouse Exit Event - when mouse exits game frame
hide gun crosshairs.
-
mouseMove(Event, int, int)
- Mouse Move Event - update gun crosshair position.
-
newGame()
- Setup a new game.
-
paint(Graphics)
- Paint method that uses the Media Tracker to insure images
are loaded.
-
run()
- When an object is derived from a "Runnable" class then this
method is called right after the thread "start()" method
completes.
-
start()
- Standard thread start handler method
-
stop()
- Standard thread termination handler method - *** added
call to stop music when thread terminates
-
update(Graphics)
- This image update method uses "double-buffering" for bitmap
images to eliminate screen flicker.
offImage
private Image offImage
back
private Image back
gunImage
private Image gunImage
music
private AudioClip music
gunsound
private AudioClip gunsound
applause
private AudioClip applause
clip
private AudioClip clip[]
offGrfx
private Graphics offGrfx
animate
private Thread animate
tracker
private MediaTracker tracker
srv
private SRVector srv
gun
private Sprite gun
- Mouse/Gun image
delay
private int delay
- Animation frame rate = 12 FPS
infoFont
private Font infoFont
infoMetrics
private FontMetrics infoMetrics
rand
private Random rand
musicOn
private boolean musicOn
level
private static int level
killed
private static int killed
lost
public static int lost
NightHunter
public NightHunter()
getAppletInfo
public String getAppletInfo()
- Overrides:
- getAppletInfo in class Applet
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
start
public void start()
- Standard thread start handler method
- Overrides:
- start in class Applet
stop
public void stop()
- Standard thread termination handler method - *** added
call to stop music when thread terminates
- Overrides:
- stop in class Applet
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.
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
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
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
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
mouseMove
public boolean mouseMove(Event evt,
int x,
int y)
- Mouse Move Event - update gun crosshair position.
- Overrides:
- mouseMove in class Component
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
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
newGame
void newGame()
- Setup a new game.