Home Reference Source Repository
import Tile from 'roguelike/app/tiles/Tile.js'
public class | source

Tile

A grid tile in the dungeon

Constructor Summary

Public Constructor
public

Method Summary

Public Methods
public

addItem(item: Item)

Adds an Item to the pile of Items on the Tile.

public

Gets the Creature on this Tile

public

Gets the Chebyshev distance between this Tile and another.

public

Gets the Euclidean distance between this Tile and another, using the Pythagorean Theorem.

public

Gets the list of Items on this Tile

public

Gets a human-friendly name for this Tile

public

Gets the (up to) 4 neighbors in the cardinal directions from this Tile

public

Gets all Tiles immediately adjacent to this Tile (including diagonally)

public

Gets the room key for this Tile, if any

public

Get's the x coordinate of this tile

public

Get's the y coordinate of this tile

public

Tells whether this tile is considered a floor (not a pit).

public

Tells whether this tile is opaque (e.g.

public

Tells whether this tile is solid (e.g.

public

Removes the Creature from this Tile, if any

public

removeItem(param: Item | number): *

Removes an Item from the Tile

public

setCreature(creature: Creature)

Sets the Creature occupying this Tile.

public

Sets an identifier telling which room the Tile belongs to.

public

Gets a debug representation of this Tile

Public Constructors

public constructor(x: number, y: number) source

Params:

NameTypeAttributeDescription
x number

The x-coordinate this Tile will have within the Dungeon

y number

The y-coordinate this Tile will have within the Dungeon

Public Methods

public addItem(item: Item) source

Adds an Item to the pile of Items on the Tile. There is no limit to the number of items on a Tile

Params:

NameTypeAttributeDescription
item Item

The Item to add

public getCreature(): Creature source

Gets the Creature on this Tile

Return:

Creature

The Creature on this Tile

public getDirectDistance(other: Tile): number source

Gets the Chebyshev distance between this Tile and another. This is the number of steps a walking Creature will need to take to travel between the two tiles, assuming no obstacles

Params:

NameTypeAttributeDescription
other Tile

The to which distance will be measured

Return:

number

A distance, as an integer

public getEuclideanDistance(other: Tile): number source

Gets the Euclidean distance between this Tile and another, using the Pythagorean Theorem. This is used when determining if something is within range of a ranged attack

Params:

NameTypeAttributeDescription
other Tile

The to which distance will be measured

Return:

number

A distance, as a double

public getItems(): Array<Item> source

Gets the list of Items on this Tile

Return:

Array<Item>

public getName(): string source

Gets a human-friendly name for this Tile

Return:

string

public getNeighbors4(dungeon: Dungeon): Array<Tile> source

Gets the (up to) 4 neighbors in the cardinal directions from this Tile

Params:

NameTypeAttributeDescription
dungeon Dungeon

The dungeon this tile is in

Return:

Array<Tile>

public getNeighbors8(dungeon: Dungeon): Array<Tile> source

Gets all Tiles immediately adjacent to this Tile (including diagonally)

Params:

NameTypeAttributeDescription
dungeon Dungeon

The dungeon this tile is in

Return:

Array<Tile>

public getRoomKey(): string source

Gets the room key for this Tile, if any

Return:

string

public getX(): number source

Get's the x coordinate of this tile

Return:

number

public getY(): number source

Get's the y coordinate of this tile

Return:

number

public hasFloor(): boolean source

Tells whether this tile is considered a floor (not a pit). Most Creatures cannot walk over non-floor Tiles

Return:

boolean

true if the Tile has a walkable floor; false otherwise

public isOpaque(): boolean source

Tells whether this tile is opaque (e.g. a wall). Most Creatures cannot see through opaque Tiles.

Return:

boolean

true if the Tile is considered opaque; false otherwise

public isSolid(): boolean source

Tells whether this tile is solid (e.g. a wall). Most Creatures cannot pass through solid Tiles.

Return:

boolean

true if the Tile is considered solid; false otherwise

public removeCreature(): Creature source

Removes the Creature from this Tile, if any

Return:

Creature

The Creature that was removed

public removeItem(param: Item | number): * source

Removes an Item from the Tile

Params:

NameTypeAttributeDescription
param Item | number

The Item to remove or the index of it's position

Return:

*

public setCreature(creature: Creature) source

Sets the Creature occupying this Tile. A Tile can have a maximum of one Creature

Params:

NameTypeAttributeDescription
creature Creature

The Creature to place on this Tile

public setRoomKey(key: string) source

Sets an identifier telling which room the Tile belongs to. This can be used to apply rules to all Tiles in the same room

Params:

NameTypeAttributeDescription
key string

A string representing the room this Tile is in

public toString(): string source

Gets a debug representation of this Tile

Return:

string