se.liu.student.kimgr905.tilegame
Class TileGameResourceManager

java.lang.Object
  extended by se.liu.student.kimgr905.tilegame.TileGameResourceManager

public final class TileGameResourceManager
extends java.lang.Object

The ResourceManager class loads and manages "host" Sprites used in the game. Game Sprites are cloned from "host" Sprites.

It also loads the TileMap from a textfile. As well as provides methods for converting tile and pixel positions.


Field Summary
private  Sprite biglazerSprite
           
private  Sprite boss1Sprite
           
private  Sprite bossAimedSprite
           
private  Sprite bossCannonSprite
           
private  Sprite bossLazerSprite
           
private  int currentMap
           
private  Sprite droneSprite
           
private  Sprite dualShotSprite
           
private  Sprite minilazerSprite
           
private  Sprite playerShotSprite
           
private  Sprite playerSprite
           
private  Sprite shieldSprite
           
private static int TILE_SIZE_BITS
           
private  Sprite weaponSprite
           
 
Constructor Summary
TileGameResourceManager()
          Creates a new ResourceManager.
 
Method Summary
 void addBossShot(TileMap map, Ship ship)
          Adds bosshots to the TileMap.
 void addPlayerShot(TileMap map, Player player)
          Adds playershots to the TileMap.
private static void addSprite(TileMap map, Sprite hostSprite, int tileX, int tileY)
          Adds and centers a sprite on the TileMap.
private  Animation createAimedShotAnim()
           
private  Animation createBiglazerAnim()
           
private  Animation createBoss1ExplodingAnim()
           
private  Animation createBossAnim()
           
private  Animation createCannonShotAnim()
           
private  Animation createDroneAnim()
           
private  Animation createDualShotAnim()
           
private  Animation createExplodingAnim()
           
private  Animation createLazerShotAnim()
           
private  Animation createMinilazerAnim()
           
private  Animation createPlayerAnim()
           
private  Animation createShotAnim()
           
 java.net.URL getResource(java.lang.String filename)
           
private  void loadCreatureSprites()
          Code for loading sprites and images
 java.awt.Image loadImage(java.lang.String name)
          Returns the image "name" from images/"name" as an ImageIcon.
private  TileMap loadMap(java.lang.String filename, int screenHeight)
          Loads a TileMap based on the filename given.
 TileMap loadNextMap(int screenHeight)
          Load the next map.
private  void loadPowerUpSprites()
           
private static int pixelsToTiles(int pixels)
          Converts a pixel position to a tile position.
 TileMap reloadMap(int screenHeight)
          Reloads the current map.
private static int tilesToPixels(int numTiles)
          Converts a tile position to a pixel position.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TILE_SIZE_BITS

private static final int TILE_SIZE_BITS
See Also:
Constant Field Values

currentMap

private int currentMap

playerSprite

private Sprite playerSprite

biglazerSprite

private Sprite biglazerSprite

droneSprite

private Sprite droneSprite

minilazerSprite

private Sprite minilazerSprite

weaponSprite

private Sprite weaponSprite

shieldSprite

private Sprite shieldSprite

boss1Sprite

private Sprite boss1Sprite

playerShotSprite

private Sprite playerShotSprite

dualShotSprite

private Sprite dualShotSprite

bossCannonSprite

private Sprite bossCannonSprite

bossLazerSprite

private Sprite bossLazerSprite

bossAimedSprite

private Sprite bossAimedSprite
Constructor Detail

TileGameResourceManager

public TileGameResourceManager()
Creates a new ResourceManager.

Method Detail

tilesToPixels

private static int tilesToPixels(int numTiles)
Converts a tile position to a pixel position.

Parameters:
numTiles - tile position
Returns:
pixel position

pixelsToTiles

private static int pixelsToTiles(int pixels)
Converts a pixel position to a tile position.

Parameters:
pixels - pixel position
Returns:
tile position

loadImage

public java.awt.Image loadImage(java.lang.String name)
Returns the image "name" from images/"name" as an ImageIcon.

Parameters:
name - file name
Returns:
an image

getResource

public java.net.URL getResource(java.lang.String filename)

loadNextMap

public TileMap loadNextMap(int screenHeight)
Load the next map.

Parameters:
screenHeight - height of the screen in pixels
Returns:
next map

reloadMap

public TileMap reloadMap(int screenHeight)
Reloads the current map.

Parameters:
screenHeight - height of the screen in pixels
Returns:
current map

addPlayerShot

public void addPlayerShot(TileMap map,
                          Player player)
Adds playershots to the TileMap.

Parameters:
map - TileMap
player - the player

addBossShot

public void addBossShot(TileMap map,
                        Ship ship)
Adds bosshots to the TileMap.

Parameters:
map - TileMap
ship - the boss

loadMap

private TileMap loadMap(java.lang.String filename,
                        int screenHeight)
                 throws java.io.IOException
Loads a TileMap based on the filename given.

Parameters:
filename - a filename
screenHeight - the height of the screen in pixels
Returns:
TileMap
Throws:
java.io.IOException

addSprite

private static void addSprite(TileMap map,
                              Sprite hostSprite,
                              int tileX,
                              int tileY)
Adds and centers a sprite on the TileMap.

Parameters:
map - TileMap
hostSprite - the sprite to clone from
tileX - tile x-position
tileY - tile y-position

loadCreatureSprites

private void loadCreatureSprites()
Code for loading sprites and images


createBoss1ExplodingAnim

private Animation createBoss1ExplodingAnim()

createBossAnim

private Animation createBossAnim()

createPlayerAnim

private Animation createPlayerAnim()

createBiglazerAnim

private Animation createBiglazerAnim()

createDroneAnim

private Animation createDroneAnim()

createShotAnim

private Animation createShotAnim()

createDualShotAnim

private Animation createDualShotAnim()

createLazerShotAnim

private Animation createLazerShotAnim()

createCannonShotAnim

private Animation createCannonShotAnim()

createAimedShotAnim

private Animation createAimedShotAnim()

createMinilazerAnim

private Animation createMinilazerAnim()

createExplodingAnim

private Animation createExplodingAnim()

loadPowerUpSprites

private void loadPowerUpSprites()