Fork me on GitHub
View source

package com.haxepunk.masks

class SlopedGrid


extends Hitbox

Uses a hash grid to determine collision, faster than using hundreds of Entities for tiled levels, etc.

Constructor

View source

new (width : Int, height : Int, tileWidth : Int, tileHeight : Int, x : Int = 0, y : Int = 0) : Void

Constructor.


Parameters:
width   

Width of the grid, in pixels.

height   

Height of the grid, in pixels.

tileWidth   

Width of a grid tile, in pixels.

tileHeight   

Height of a grid tile, in pixels.

x   

X offset of the grid.

y   

Y offset of the grid.

Variables

read only columns : Int

How many columns the grid has

read only data : Array<Array<Tile>>

The grid data.

read only rows : Int

How many rows the grid has.

read only tileHeight : Int

The tile height.

read only tileWidth : Int

The tile width.

usePositions : Bool

If x/y positions should be used instead of columns/rows.

Functions

View source

clearRect (column : Int = 0, row : Int = 0, width : Int = 1, height : Int = 1) : Void

Makes the rectangular region of tiles non-solid.


Parameters:
column   

First column.

row   

First row.

width   

Columns to fill.

height   

Rows to fill.

View source

clearTile (column : Int = 0, row : Int = 0) : Void

Makes the tile non-solid.


Parameters:
column   

Tile column.

row   

Tile row.

View source

collidePoint (cx : Float, cy : Float) : Bool

Checks collision against SlopedGrid from a point


Parameters:
cx   

x-axis of the collision point

cy   

y-axis of the collision point


Returns:

If the point collides with SlopedGrid

View source

getTile (column : Int = 0, row : Int = 0) : Tile

Gets the value of a tile.


Parameters:
column   

Tile column.

row   

Tile row.


Returns:

tile value.

View source

setRect (column : Int = 0, row : Int = 0, width : Int = 1, height : Int = 1, type : TileType, slope : Float = 0, yOffset : Float = 0) : Void

Sets the value of a rectangle region of tiles.


Parameters:
column   

First column.

row   

First row.

width   

Columns to fill.

height   

Rows to fill.

type   

The type of the tiles

slope   

The slope of the tiles

yOffset   

The y offset of the tiles

View source

setTile (column : Int = 0, row : Int = 0, type : TileType, slope : Float = 0, yOffset : Float = 0) : Void

Sets the value of a tile.


Parameters:
column   

Tile column.

row   

Tile row.

type   

The type of the tile

slope   

The slope of the tile

yOffset   

The y offset of the tile