org.haphazard.gui.engine
Class Map

java.lang.Object
  extended byorg.haphazard.gui.engine.Map

public class Map
extends java.lang.Object

Handles a map of the world


Field Summary
 Point3D camera
           
 java.lang.String mLink
           
 Point3D screenStart
          if you ever want to start drawing from another pixel-location than 0,0,0
 java.awt.Dimension screenTileDimension
          how many tiles to draw on the screen do NOT set this to more than necessary
static int[][][] viewArea
           
 
Constructor Summary
Map(int width, int height)
          Creates a new instance of Map
Map(int width, int height, java.lang.String name)
          Creates a new instance of Map
 
Method Summary
 boolean canWalkOnTile(Point3D tileCoordinate)
          Checks if a character can walk on a tile
 void centerCameraOn(Point3D location)
          Centers the camera on the specified location
 int coordinateCheck(Point3D pos)
          Checks if it's OK to move to the position
 java.awt.Dimension getDimension()
          Gets the dimension of this map
 java.lang.String getName()
          returns the name of this map
 Tile getTile(Point3D location)
          Gets the tile for a certain location
 java.awt.Dimension getTileDimension()
          Returns the dimension of the tiles in this Map.
 boolean isOnMap(int x, int y)
          Checks if a point is within the map
 boolean isOnMap(Point3D coordinate)
          Checks if a point is within the map
 void optimize()
          optimize this ground by drawing all non-animated tiles to a BufferedImage
 void paintBackground(java.awt.Graphics2D g, int windowWidth, int windowHeight)
          This draws the ground to a Graphics2d
 void paintComponent(java.awt.Graphics2D g, int windowWidth, int windowHeight)
          Paints the map
 java.awt.Point project(Point3D coordinate)
          project the tile x and y coordinate to screen coordinate FIXME: add functionality to take care of elevated tiles
 void setFogOfWar(Point3D middleLocation, boolean value)
          Sets the fog of war on a specified coordinate
 void setSubWorld(java.lang.String subWorld, Point3D location, Point3D enterLocation)
          Sets a subWorld on a specific tile
 void setTile(Point3D location, Tile tile)
          Sets the tile for the location
 void setTileDimension(java.awt.Dimension dimension)
          Set the size of the tiles in pixels
 void setTileSet(GraphicalObject object)
          Sets the GraphicalObject that contains the tiles
 void setTileValues(Point3D location, Sprite spriteDisplayed, int treadableValue, int[] elevation)
          Sets the values of a tile.
 java.lang.String toString()
          Make this map to a string.
 Point3D unProject(int x, int y)
          Unprojects coordinates from pixel space to tile space.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

mLink

public java.lang.String mLink

viewArea

public static final int[][][] viewArea

camera

public Point3D camera

screenStart

public Point3D screenStart
if you ever want to start drawing from another pixel-location than 0,0,0


screenTileDimension

public java.awt.Dimension screenTileDimension
how many tiles to draw on the screen do NOT set this to more than necessary

Constructor Detail

Map

public Map(int width,
           int height)
Creates a new instance of Map

Parameters:
width - The width of the gaming ground
height - The height of the gaming ground

Map

public Map(int width,
           int height,
           java.lang.String name)
Creates a new instance of Map

Parameters:
width - The width of the gaming ground
height - The height of the gaming ground
Method Detail

getName

public java.lang.String getName()
returns the name of this map

Returns:
the name

setSubWorld

public void setSubWorld(java.lang.String subWorld,
                        Point3D location,
                        Point3D enterLocation)
Sets a subWorld on a specific tile

Parameters:
subWorld - the name of the subWorld (map). The name should be in GlobalMapUtilities (i.e. load the maps with GlobalMapUtilities.getInstance().loadMapFromFile())

setTile

public void setTile(Point3D location,
                    Tile tile)
Sets the tile for the location

Parameters:
location - The location to set the tile for
tile - The tile to set

getTile

public Tile getTile(Point3D location)
Gets the tile for a certain location

Parameters:
location - The location to get the tile for
Returns:
The tile for that location

getTileDimension

public java.awt.Dimension getTileDimension()
Returns the dimension of the tiles in this Map.

Returns:
The dimension of the tiles

setTileDimension

public void setTileDimension(java.awt.Dimension dimension)
Set the size of the tiles in pixels


canWalkOnTile

public boolean canWalkOnTile(Point3D tileCoordinate)
Checks if a character can walk on a tile

Parameters:
tileCoordinate - The coordinate of the tile to walk on
Returns:
true if the character can walk there

coordinateCheck

public int coordinateCheck(Point3D pos)
Checks if it's OK to move to the position

Parameters:
pos - The position on the map to check
Returns:
0 if ok, 1 if character there (attack), 2 if not movable, 3 if subWorld

project

public java.awt.Point project(Point3D coordinate)
project the tile x and y coordinate to screen coordinate FIXME: add functionality to take care of elevated tiles

Returns:
the point with the screen coordinate or a Point(-1,-1) it its outside the ground array

unProject

public Point3D unProject(int x,
                         int y)
Unprojects coordinates from pixel space to tile space. Compensates for menubar

Parameters:
x - The x-coordinate
y - The y-coordinate
Returns:
The point in tile space

setTileValues

public void setTileValues(Point3D location,
                          Sprite spriteDisplayed,
                          int treadableValue,
                          int[] elevation)
Sets the values of a tile.

Parameters:
spriteDisplayed - the sprite that the tile has
elevation - the elevation of the tile

setTileSet

public void setTileSet(GraphicalObject object)
Sets the GraphicalObject that contains the tiles

Parameters:
object - the GraphicalObject

getDimension

public java.awt.Dimension getDimension()
Gets the dimension of this map

Returns:
The dimension of the map

toString

public java.lang.String toString()
Make this map to a string. (i.e. it returns the name and the size of the ground array)

Returns:
the map represented as a string

isOnMap

public boolean isOnMap(Point3D coordinate)
Checks if a point is within the map

Parameters:
coordinate - The coordinate to check
Returns:
True is the coordinate is a valid map coordinate

isOnMap

public boolean isOnMap(int x,
                       int y)
Checks if a point is within the map

Parameters:
x - The x-coordinate to check
y - The y-coordinate to check
Returns:
True is the coordinate is a valid map coordinate

optimize

public void optimize()
optimize this ground by drawing all non-animated tiles to a BufferedImage


setFogOfWar

public void setFogOfWar(Point3D middleLocation,
                        boolean value)
Sets the fog of war on a specified coordinate

Parameters:
middleLocation - The location in the middle of the fog
value - the value to set

centerCameraOn

public void centerCameraOn(Point3D location)
Centers the camera on the specified location


paintComponent

public void paintComponent(java.awt.Graphics2D g,
                           int windowWidth,
                           int windowHeight)
Paints the map

Parameters:
g - The graphics to use when painting
windowWidth - The width of the window to draw in
windowHeight - The height of the window to draw in

paintBackground

public void paintBackground(java.awt.Graphics2D g,
                            int windowWidth,
                            int windowHeight)
This draws the ground to a Graphics2d