org.newdawn.asd.data
Class Map

java.lang.Object
  extended byorg.newdawn.asd.data.Map
All Implemented Interfaces:
TileMap

public class Map
extends java.lang.Object
implements TileMap

A map in the game including any monsters running around, walls and items.


Constructor Summary
Map(long seed, GameWorld world)
          Create a new map.
 
Method Summary
 void addActor(Actor actor)
          Add an actor to the game map
 boolean blocked(int x, int y)
          Check if a particular location on the map blocks movement
 boolean containsActor(Actor actor)
          Check whether a particular actor is contained within this map
 Path findPath(Actor finder, int sx, int sy, int dx, int dy, boolean considerActors)
          Find a path from a source square to a destination square
 Actor getActorById(int id)
          Get an actor based on its unique ID
 ActorList getActors()
          Get the list of actors currently roaming this map
 int getChecksum()
          Retrieve the checksum from the content of this map
 int getMapHeight()
          Get the height of the map in tiles
 int getMapWidth()
          Get the width of the map in tiles
 int getPlayerActorCount()
          Get the number of player actors contained in this map
 MapLocation getStart(int index)
          Get the location at which players should start
 int getTileAt(int x, int y)
          Get the index of the tile at the specified location
 int getTileAt(int x, int y, int layer)
          Get the tile at a specified location.
 GameWorld getWorld()
          Get the world in which the map is held
 boolean hasLOS(Actor source, Actor target)
          Check if one actor can "see" another, i.e has line of sight (LOS)
 boolean hasLOS(float sx, float sy, float ex, float ey)
          Check if a particular location has line of sight (LOS) to the the destination specified
 boolean isBlocked(int x, int y)
          Is a particular tile location current blocked
 void removeActor(Actor actor)
          Remove an actor from the game map
 void update(int delta)
          Update the map and all the actors contained
 boolean validActorPosition(Actor actor, float x, float y)
          Check if the specified location would be valid (i.e.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Map

public Map(long seed,
           GameWorld world)
Create a new map. This will cause a map to be generated

Parameters:
world - The game world in which the map is created
seed - The seed to base the map generation on
Method Detail

getWorld

public GameWorld getWorld()
Get the world in which the map is held

Returns:
The game world in which this world is held

getStart

public MapLocation getStart(int index)
Get the location at which players should start

Parameters:
index - The index of the start position to get
Returns:
The location at which players should start

update

public void update(int delta)
Update the map and all the actors contained

Parameters:
delta - The amount of simulation time in milliseconds the actors and map should be moved on.

getTileAt

public int getTileAt(int x,
                     int y)
Get the index of the tile at the specified location

Parameters:
x - The x coordinate of the tile to retrieve
y - The y coordinate of the tile to retrieve
Returns:
The index of the tile at the specified location

addActor

public void addActor(Actor actor)
Add an actor to the game map

Parameters:
actor - The actor to add

removeActor

public void removeActor(Actor actor)
Remove an actor from the game map

Parameters:
actor - The actor to remove

getPlayerActorCount

public int getPlayerActorCount()
Get the number of player actors contained in this map

Returns:
The number of player actors contained in this map

getActors

public ActorList getActors()
Get the list of actors currently roaming this map

Returns:
The actors currently roaming the map

getActorById

public Actor getActorById(int id)
Get an actor based on its unique ID

Parameters:
id - The ID of the actor to be retrieve
Returns:
The actor with the specified ID or null if no actor with the specified ID exists.

hasLOS

public boolean hasLOS(float sx,
                      float sy,
                      float ex,
                      float ey)
Check if a particular location has line of sight (LOS) to the the destination specified

Parameters:
sx - The source x coordinate of the check
sy - The source y coordinate of the check
ex - The target x coordinate of the check
ey - The target y coordinate of the check
Returns:
True if there is an unblocked line of site from source to target.

hasLOS

public boolean hasLOS(Actor source,
                      Actor target)
Check if one actor can "see" another, i.e has line of sight (LOS)

Parameters:
source - The source actor from where the LOS starts
target - The target actor the source is looking at
Returns:
True if there is an unblocked line of sight between the actors

blocked

public boolean blocked(int x,
                       int y)
Check if a particular location on the map blocks movement

Parameters:
x - The x coordinate of the location to check
y - The y coordinate of the location to check
Returns:
True if the specified location is blocked

validActorPosition

public boolean validActorPosition(Actor actor,
                                  float x,
                                  float y)
Check if the specified location would be valid (i.e. not blocked) for a given actor.

Parameters:
actor - The actor that could potentially be at the location
x - The x coordinate of the location
y - The y coordinate of the location
Returns:
True if the actor would be valid at the specified location

getChecksum

public int getChecksum()
Retrieve the checksum from the content of this map

Returns:
The checksum of this map

getTileAt

public int getTileAt(int x,
                     int y,
                     int layer)
Description copied from interface: TileMap
Get the tile at a specified location. The index returned should allow the renderer to look up a renderable object in a renderer dependent tileset.

Specified by:
getTileAt in interface TileMap
Parameters:
x - The x position of the tile to retrieve
y - The y position of the tile to retrieve
layer - The layer of the tile to retrieve (zero being the base)
Returns:
The tile at the specified location
See Also:
TileMap.getTileAt(int, int, int)

getMapWidth

public int getMapWidth()
Description copied from interface: TileMap
Get the width of the map in tiles

Specified by:
getMapWidth in interface TileMap
Returns:
The width of the map in tiles
See Also:
TileMap.getMapWidth()

getMapHeight

public int getMapHeight()
Description copied from interface: TileMap
Get the height of the map in tiles

Specified by:
getMapHeight in interface TileMap
Returns:
The height of the map in tiles
See Also:
TileMap.getMapHeight()

isBlocked

public boolean isBlocked(int x,
                         int y)
Description copied from interface: TileMap
Is a particular tile location current blocked

Specified by:
isBlocked in interface TileMap
Parameters:
x - The x coordinate of the tile location to check
y - The y coordinate of the tile location to check
Returns:
True if the specified locaiton is blocked
See Also:
TileMap.isBlocked(int, int)

findPath

public Path findPath(Actor finder,
                     int sx,
                     int sy,
                     int dx,
                     int dy,
                     boolean considerActors)
Find a path from a source square to a destination square

Parameters:
finder - The actor doing the finding
sx - The x-coordinate of the start location
sy - The y-coordinate of the start location
dx - The x-coordinate of the destination location
dy - The y-coordinate of the destination location
considerActors - True if we should consider other actors blocking
Returns:
The found path or null if no path could be found

containsActor

public boolean containsActor(Actor actor)
Check whether a particular actor is contained within this map

Parameters:
actor - The actor to check for
Returns:
True if the actor is contained in this map