se.liu.student.kimgr905.tilegame
Class GameManager

java.lang.Object
  extended by com.brackeen.javagamebook.test.GameCore
      extended by se.liu.student.kimgr905.tilegame.GameManager

public final class GameManager
extends GameCore

GameManager manages all parts of the game.


Field Summary
private  GameAction exit
           
private  Sound explodeBossSound
           
private  Sound explodeSound
           
private  TileMap map
           
private  MidiPlayer midiPlayer
           
private  GameAction moveDown
           
private  GameAction moveLeft
           
private  GameAction moveRight
           
private  GameAction moveUp
           
private static javax.sound.sampled.AudioFormat PLAYBACK_FORMAT
           
private  TileMapRenderer renderer
           
private  TileGameResourceManager resourceManager
           
private  GameAction shoot
           
private  SoundManager soundManager
           
 
Fields inherited from class com.brackeen.javagamebook.test.GameCore
FONT_SIZE, screen
 
Constructor Summary
GameManager()
           
 
Method Summary
private  void acquirePowerUp(PowerUp powerUp)
          Gives the player the speicifed power up and removes it from the map.
private  void checkInput()
          Checks for input.
private  Sprite checkPlayerCollision(Player player)
          Checks if the player collidies with any sprites, and returns the colliding sprite (if any collision).
private  void checkShotCollision(Shot shot)
          PlayerShot collision.
 void draw(java.awt.Graphics2D g)
          Draws everything to the screen.
 java.io.InputStream getResourceAsStream(java.lang.String filename)
           
private  Sprite getSpriteCollision(Sprite sprite)
          Checks for sprite collison with the sprite given as argument and returns the collding sprite (if it collided), if no collision was found null is returned.
 void init()
          Set up resources used by the GameManager.
private  void initInput()
           
private  void insertShots(Ship ship)
          Insert shots for the specified ship.
private static boolean isCollision(Sprite s1, Sprite s2)
          Checks if two sprites collide with each other.
 javax.sound.midi.Sequence loadSequence(java.lang.String name)
           
 Sound loadSound(java.lang.String name)
           
static void main(java.lang.String[] args)
          Runs the program, arguments are ignored.
 void stop()
          Closes any resource used by the GameManager.
 void update(long elapsedTime)
          Updates Animation, position, and velocity of all Sprites in the current map.
private  void updateShip(Ship ship, long elapsedTime)
          Updates the ships x and y position, checks for collision.
private  void updateShot(Shot shot, long elapsedTime)
          Updates the shots x and y position, checks for collision.
 
Methods inherited from class com.brackeen.javagamebook.test.GameCore
gameLoop, lazilyExit, loadImage, run
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

map

private TileMap map

resourceManager

private TileGameResourceManager resourceManager

renderer

private TileMapRenderer renderer

moveLeft

private GameAction moveLeft

moveRight

private GameAction moveRight

moveUp

private GameAction moveUp

moveDown

private GameAction moveDown

exit

private GameAction exit

shoot

private GameAction shoot

midiPlayer

private MidiPlayer midiPlayer

soundManager

private SoundManager soundManager

explodeSound

private Sound explodeSound

explodeBossSound

private Sound explodeBossSound

PLAYBACK_FORMAT

private static final javax.sound.sampled.AudioFormat PLAYBACK_FORMAT
Constructor Detail

GameManager

public GameManager()
Method Detail

main

public static void main(java.lang.String[] args)
Runs the program, arguments are ignored.

Parameters:
args - arguments

init

public void init()
Set up resources used by the GameManager.

Overrides:
init in class GameCore

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String filename)

loadSound

public Sound loadSound(java.lang.String name)

loadSequence

public javax.sound.midi.Sequence loadSequence(java.lang.String name)

stop

public void stop()
Closes any resource used by the GameManager.

Overrides:
stop in class GameCore

initInput

private void initInput()

checkInput

private void checkInput()
Checks for input. When exit is pressed the program terminates.


draw

public void draw(java.awt.Graphics2D g)
Draws everything to the screen.

Specified by:
draw in class GameCore
Parameters:
g - Graphics2D

update

public void update(long elapsedTime)
Updates Animation, position, and velocity of all Sprites in the current map.

Overrides:
update in class GameCore
Parameters:
elapsedTime - the time elapsed since the last update in ms

updateShot

private void updateShot(Shot shot,
                        long elapsedTime)
Updates the shots x and y position, checks for collision.

Parameters:
shot - shot sprite
elapsedTime - the time elapsed since the last update in ms

updateShip

private void updateShip(Ship ship,
                        long elapsedTime)
Updates the ships x and y position, checks for collision.

Parameters:
ship - ship sprite
elapsedTime - the time elapsed since the last update in ms

insertShots

private void insertShots(Ship ship)
Insert shots for the specified ship.

Parameters:
ship - ship sprite

isCollision

private static boolean isCollision(Sprite s1,
                                   Sprite s2)
Checks if two sprites collide with each other.

Parameters:
s1 - a sprite
s2 - another sprite
Returns:
did the sprites collide or not

getSpriteCollision

private Sprite getSpriteCollision(Sprite sprite)
Checks for sprite collison with the sprite given as argument and returns the collding sprite (if it collided), if no collision was found null is returned.

Parameters:
sprite - a sprite
Returns:
the collding sprite or null

checkPlayerCollision

private Sprite checkPlayerCollision(Player player)
Checks if the player collidies with any sprites, and returns the colliding sprite (if any collision). If no collision is found null is returned.

Parameters:
player - the player
Returns:
the colliding sprite or null

checkShotCollision

private void checkShotCollision(Shot shot)
PlayerShot collision.

Parameters:
shot - player shot

acquirePowerUp

private void acquirePowerUp(PowerUp powerUp)
Gives the player the speicifed power up and removes it from the map.

Parameters:
powerUp - a power-up sprite