be. dauntless. Astar. Astar

Summary
[0] -> x position of startPoint [1]`-> y position of startPoint
[0] -> x position of endPoint [1]`-> y position of endPoint
A 2 dimensional map containing references to all tiles
The standard cost of the tile.
The diagonal cost of the tile.
The height of the map
The width of the map
A binary heap containing the tiles
The kind of clipping to be used.
Constructor
Set the map for the engine
Build a new Map
Set the starting point (player position) for the engine
Set the clipping mode.
Set the end point for the engine.
find a path from the startPoint to the endPoint in the given map
find the surrounding tiles of the given tile.
Check whether or not all the settings are correct
Define the cost of the given tile
Toggle the tile to be walkable or not
Toggle the tile to be walkable or not
Opens the map (resets all the tiles)
Sets the standard cost for the map.
Sets the extra cost for going diagonal.

Variables

startPoint

private var startPoint: Array

Array containing 2 values

[0] -> x position of startPoint [1]`-> y position of startPoint

endPoint

private var endPoint: Array

Array containing 2 values

[0] -> x position of endPoint [1]`-> y position of endPoint

map

private var map: Array

A 2 dimensional map containing references to all tiles

standardCost

public static var standardCost: Number

The standard cost of the tile.  The more acurate is, the better A* will work

diagonalCost

public static var diagonalCost: Number

The diagonal cost of the tile.  The more acurate is, the better A* will work

mapH

private var mapH: Number

The height of the map

mapW

private var mapW: Number

The width of the map

heap

private var heap: BinaryHeap

A binary heap containing the tiles

mf

private var mf: Function

clippingMode

private var clippingMode: String

The kind of clipping to be used.  See ‘setClipping()’

Functions

Astar (constructor)

public function Astar()

Constructor

Parameters

None

Returns

Nothing

setMap

public function setMap(_map: Array):Void

Set the map for the engine

Parameters

_mapA 2d array of references to tiles, presenting the current map

Returns

Nothing

See Also

setStartPoint

setEndPoint

newMap

public function newMap(w: Number,
h: Number):Void

Build a new Map

Parameters

xwidth of the map
yheight of the map

Returns

Nothing

See Also

setMap

setStartPoint

public function setStartPoint(x: Number,
y: Number):Void

Set the starting point (player position) for the engine

Parameters

xthe x position of the player
ythe y position of the player

Returns

Nothing

See Also

setEndPoint

setMap

setClipping

public function setClipping(cl: String):Void

Set the clipping mode.  Options: “no”, “semi”, “full” “no” - No clipping, only horizontal and vertical movement “semi” - only clipping if there is no unwalkable tile in the way “full” - full clipping

Parameters

clippingclipping mode

Returns

Nothing

setEndPoint

public function setEndPoint(x: Number,
y: Number):Void

Set the end point for the engine.

Parameters

xthe x position of the player
ythe y position of the players

Returns

Nothing

See Also

setStartPoint

setMap

findPath

public function findPath():Object

find a path from the startPoint to the endPoint in the given map

Parameters

None

Returns

array/Booleanarray containing references of tiles presenting the path from startpoint to endpoint OR false if no path was found.

See Also

setStartPoint

setEndPoint

setMap

findSurroundingTiles

private function findSurroundingTiles(current: Tile):Array

find the surrounding tiles of the given tile.  If clipping is set to true, 8 tiles will be scanned.  If not: 4 tiles.

Parameters

xthe x value of the tile

Returns

arrayarray containing references to all the valid neighbour tiles

ready

private function ready():Boolean

Check whether or not all the settings are correct

Parameters

None

Returns

BooleanTrue: Game is ready, false: There was an error

setCost

public function setCost(x: Number,
y: Number,
c: Number):Void

Define the cost of the given tile

Parameters

xx position of the tile
yy position of the tile
costthe cost of the tile

Returns

Nothing

See also

setWalkable

setWalkable

public function setWalkable(x: Number,
y: Number,
b: Boolean):Void

Toggle the tile to be walkable or not

Parameters

xx position of the tile
yy position of the tile
walkableboolean representing the ability to walk on the tile or not

Returns

Nothing

See also

toggleWalkable

toggleWalkable

public function toggleWalkable(x: Number,
y: Number):Void

Toggle the tile to be walkable or not

Parameters

xx position of the tile
yy position of the tile

Returns

Nothing

See also

setWalkable

openMap

private function openMap()

Opens the map (resets all the tiles)

Parameters

None

Returns

Nothing

setStandardCost

public function setStandardCost(c: Number):Void

Sets the standard cost for the map.  The better you set cost, the faster the search will be

Parameters

costStandard cost of a tile

Returns

Nothing

setDiagonalCost

public function setDiagonalCost(c: Number):Void

Sets the extra cost for going diagonal.  Standard is 1.414.  If the provided cost is lower than 1, going diagonal will be preffered.

Parameters

costStandard cost of a tile

Returns

Nothing

private var startPoint: Array
[0] -> x position of startPoint [1]`-> y position of startPoint
private var endPoint: Array
[0] -> x position of endPoint [1]`-> y position of endPoint
private var map: Array
A 2 dimensional map containing references to all tiles
public static var standardCost: Number
The standard cost of the tile.
public static var diagonalCost: Number
The diagonal cost of the tile.
private var mapH: Number
The height of the map
private var mapW: Number
The width of the map
private var heap: BinaryHeap
A binary heap containing the tiles
private var mf: Function
private var clippingMode: String
The kind of clipping to be used.
public function Astar()
Constructor
public function setMap(_map: Array):Void
Set the map for the engine
public function newMap(w: Number,
h: Number):Void
Build a new Map
public function setStartPoint(x: Number,
y: Number):Void
Set the starting point (player position) for the engine
public function setClipping(cl: String):Void
Set the clipping mode.
public function setEndPoint(x: Number,
y: Number):Void
Set the end point for the engine.
public function findPath():Object
find a path from the startPoint to the endPoint in the given map
private function findSurroundingTiles(current: Tile):Array
find the surrounding tiles of the given tile.
private function ready():Boolean
Check whether or not all the settings are correct
public function setCost(x: Number,
y: Number,
c: Number):Void
Define the cost of the given tile
public function setWalkable(x: Number,
y: Number,
b: Boolean):Void
Toggle the tile to be walkable or not
public function toggleWalkable(x: Number,
y: Number):Void
Toggle the tile to be walkable or not
private function openMap()
Opens the map (resets all the tiles)
public function setStandardCost(c: Number):Void
Sets the standard cost for the map.
public function setDiagonalCost(c: Number):Void
Sets the extra cost for going diagonal.