Module Level
Loads .tmx tilemap and runs the level designed on it.
Inits player, mobs and offers utilities for help spatial hashing, collision system and pathfinding.
Tilemap description:
You can design a map using a lot of layers, both tile layer and object layer. But there are two required:
Tile layer “0”: where the entities are drawn and used for check wall collisions.
— Tiles with propertyobstacle = true
works as invisible wall.Object layer “Events”: used for instance objects.
— The object is instanciated where the object is placed.
— Must be defined with thetype = spawn
and had a property defined as type with the value that describes the object. SeeLevel:_mobSpawn()
.
— The object spawn with propertytype = player
instance the player avatar where is placed.
Class Level
Level:create (tmxPath) | Create a Level . |
Level:update (dt) | Update stage. |
Level:drawQuadCollider (entity) | Debug function. |
Level:drawPath (entity) | Debug function. |
Level:drawEntities (tilePositionX, tilePositionY, tileDrawX, tileDrawY, self) | Draw the entities of a tile. |
Level:draw () | Draw stage. |
Level:shake () | Shake cam effect. |
Level:_mobSpawn () | Spawn player and mobs on the map. |
Level:tileToCoords (tileX, tileY) | Turns an isometric grid tile number to world location. |
Level:coordsToTile (x, y) | Turns a world location into an isometric grid tile number. |
Buckets functions
Level:getBucket (tile) | Gets the bucket that make reference to the location specified. |
Level:putIntoBucket (entity, tile, oldTile) | Puts an entity into a bucket. |
Level:removeFromBucket (entity, tile) | Remove an entity from his bucket. |
Level:clearBuckets (buckets) | Clears all the buckets. |
Level:updateBucket (entity) | Update the position in the bucket if it’s necessary. |
Collision functions
Level:bucketsInsideCollider (quadCollider) | Gets a list of buckets that are contained by a quad collider. |
Level:checkCollideEntities (entity, x, y) | Checks if an Entity is colliding with another one. |
A* functions
Level:findNeighbors (row, col) | For an row and column given, returns a list of walkable neighbors and distances to them. |
Level:flattenMap () | Flat the bidimensional array of the map. |
Class Level
Level Class.- Level:create (tmxPath)
-
Create a Level .
Loads the .tmx tilemap.
Supose the files placed into “res/levels/” folder.
Parameters:
- tmxPath the file name of .tmx
- Level:update (dt)
-
Update stage.
- Calls the method
update(dt)
of all Entity objects. - Updates the camera position, following the player.
Parameters:
- dt delta time
- Calls the method
- Level:drawQuadCollider (entity)
-
Debug function.
Draw for a given entity his bound box.
Parameters:
- entity the Entity object
- Level:drawPath (entity)
-
Debug function.
Draw for a given entity the path that is walking.
Parameters:
- entity the Entity object
- Level:drawEntities (tilePositionX, tilePositionY, tileDrawX, tileDrawY, self)
-
Draw the entities of a tile.
Draw all the entities which are on a specific tile of the .tmx map, sorted by depth.
This function will be called by
TileLayer:setAfterTileFunction()
from AdvTileLoader library and was made following her documentation.Parameters:
- tilePositionX tile X position
- tilePositionY tile Y position
- tileDrawX unused
- tileDrawY unused
- self unused
- Level:draw ()
-
Draw stage.
Represent the actual level state. Draw the map, the entities and the mouse.
- Level:shake ()
-
Shake cam effect.
Effect that fake an earthquake
- Level:_mobSpawn ()
-
Spawn player and mobs on the map.
From the layer “Events” on the map, load the objects defined like “spawn” and depending on his property “type” make an instance.
- Level:tileToCoords (tileX, tileY)
-
Turns an isometric grid tile number to world location.
Parameters:
- tileX tile x position
- tileY tile y position
Returns:
- x x world coordination
- y y world coordination
- Level:coordsToTile (x, y)
-
Turns a world location into an isometric grid tile number.
Parameters:
- x x world coordination
- y y world coordination
Returns:
-
{x,y}
a table with an isometric grid tile position
Buckets functions
Buckets functions. Useful utilities for spatial hashing.- Level:getBucket (tile)
-
Gets the bucket that make reference to the location specified.
Parameters:
- tile {x,y} a table with an isometric grid tile position
Returns:
-
Gets bucket. Returns nil if the bucket does not exist.
- Level:putIntoBucket (entity, tile, oldTile)
-
Puts an entity into a bucket.
If the entity has moved then provide his old tile location for remove it from there.
Parameters:
- entity the Entity that wants to insert in the bucket.
- tile {x,y} a table with an isometric grid tile position
- oldTile {x,y} (optional) a table with an isometric grid tile position
- Level:removeFromBucket (entity, tile)
-
Remove an entity from his bucket.
Parameters:
- entity the Entity to be removed
- tile {x,y} a table with an isometric grid tile position
- Level:clearBuckets (buckets)
-
Clears all the buckets.
Parameters:
- buckets ¿?¿??¿ <– this param no make sense.
- Level:updateBucket (entity)
-
Update the position in the bucket if it’s necessary.
If the Entity is on the same tile that the last time, this function no makes nothing.
Parameters:
- entity the Entity to be updated.
Collision functions
Collision functions. Useful utilities for cheks collitions between Entity objects.- Level:bucketsInsideCollider (quadCollider)
-
Gets a list of buckets that are contained by a quad collider.
Parameters:
- quadCollider {x1,y1,x2,y2} table with two pair of coordinates in world location.
- Level:checkCollideEntities (entity, x, y)
-
Checks if an Entity is colliding with another one.
Saves onentity.collision
a table with Entity objects with which collided.If x and y params are passed, this function works like the Entity was there, as forecast.
Parameters:
- entity the Entity to be checked
- x (optional) world location x coordinate.
- y (optional) world location y coordinate.
Returns:
A* functions
A* functions. Useful utilities for pathfinding, needed for AStar library.- Level:findNeighbors (row, col)
-
For an row and column given, returns a list of walkable neighbors and distances to them.
Parameters:
- row isometric grid tile y position
- col isometric grid tile x position
Returns:
- table with positions of neighbors in flatten array.
- table with distances to reach the neighbor at the same position in neighbors table returned.
- Level:flattenMap ()
-
Flat the bidimensional array of the map.
Returns:
-
table with nodes created with newNode (AStar lib).