A library for tilemap based games.
File: |
Tilemap.lib |
Version: |
1.0 |
Author: |
Marcus Johansson |
Details
Constants
Sub routines
You can, and should, use this library with maps created in TM Editor. It takes care of rendering and collision handling for many types of 2D games.
Array indexing |
||
Name |
Description | |
TM_X |
X coordinate. |
|
TM_Y |
Y coordinate. |
|
TM_FLAG |
Flag. |
|
Collision info |
||
Name |
Description | |
TM_LEFT |
Left. |
|
TM_RIGHT |
Right. |
|
TM_UP |
Up. |
|
TM_DOWN |
Down. |
Map |
|||
Name |
Parameters |
Brief description |
|
function |
filename$ |
Load map. |
|
function |
Get loader flags. |
||
function |
Get map width. |
||
function |
Get map height. |
||
function |
Get world width. |
||
function |
Get world height. |
||
procedure |
w, h |
Init map. |
|
procedure |
img |
Set image. |
|
procedure |
cel, value |
Make cel an obstacle. |
|
procedure |
cel, value |
Make cel become an obstacle from top only. |
|
procedure |
l, r, t, b |
Set map border collision behavior. |
|
procedure |
x, y, cel |
Set cel. |
|
procedure |
x, y, flag |
Set flag. |
|
function |
x, y |
Get cel. |
|
function |
x, y |
Get cel. |
|
function |
x, y |
Get game flag. |
|
function |
x, y |
Get game flag. |
|
procedure |
x, y, w, h |
Set view. |
|
procedure |
x, y |
Set camera position. |
|
function |
cel |
Return true if image cel in map image is an obstacle. |
|
function |
x, y |
Convert from world to map coordinates. |
|
function |
Get map image. |
||
function |
Get camera x position in world. |
||
function |
Get camera y position in world. |
||
procedure |
Render. |
||
Coordinate conversion |
|||
Name |
Parameters |
Brief description |
|
function |
x, y |
Convert from screen coordinates to world. |
|
function |
x#, y# |
Convert from floating point screen coordinates to world. |
|
function |
x |
Convert from x screen coordinate to world. |
|
function |
x# |
Convert from floating point x screen coordinate to world. |
|
function |
y |
Convert from y screen coordinate to world. |
|
function |
y# |
Convert from floating point y screen coordinate to world. |
|
function |
x, y |
Convert from world coordinates to screen. |
|
function |
x#, y# |
Convert from floating point world coordinates to screen. |
|
function |
x |
Convert x world coordinate to screen. |
|
function |
x# |
Convert floating point x world coordinate to screen. |
|
function |
y |
Convert y world coordinate to screen. |
|
function |
y# |
Convert floating point y world coordinate to screen. |
|
function |
img, x, y |
Return true if image at world coordinates is visible. |
|
Collision handling |
|||
Name |
Parameters |
Brief description |
|
function |
img, imgx, imgy, dx, dy |
Try move image. |
|
function |
rectx, recty, w, h, dx, dy |
Try move rectangle. |
|
function |
img, imgx#, imgy#, dx#, dy# |
Try move image. |
|
function |
Get collision information. |
||
function |
Returns true if last collision occured leftwards. |
||
function |
Returns true if last collision occuered rightwards. |
||
function |
Returns true if last collision occured downwards. |
||
function |
Returns true if last collision occured upwards. |
||
function |
img1, x1, y1, img2, x2, y2 |
Return true if two images are overlapping. |
function TM_LoadMap ( filename$ )Load a map created with TM Editor.
Return value [ Back ] |
function TM_GetLoaderFlags[][] ( )This function returns the loader flags from the last loaded map. You can access a loader flag and its position with [n][TM_FLAG], [n][TM_X] and [n][TM_Y].
Return value [ Back ] |
function TM_MapWidth ( )This function returns the width of the map in tiles.
Return value [ Back ] |
function TM_MapHeight ( )This function returns the height of the map in tiles.
Return value [ Back ] |
function TM_WorldWidth ( )Get world width.
Return value [ Back ] |
function TM_WorldHeight ( )Get world height.
Return value [ Back ] |
procedure TM_InitMap ( w, h )Init a map with specified size. This procedure is only of use if you're not using TM Editor.
[ Back ] |
procedure TM_SetImage ( img )Set image for map to use. This function is only useful if you're not using TM Editor.
[ Back ] |
procedure TM_SetObstacle ( cel, value )Make cel in map image become an obstacle. This can be set in TM Editor.
[ Back ] |
procedure TM_SetOnlyDown ( cel, value )It is common in platform games that some tiles can only be collided with when approached from the top. To make a certain cel in the map image behave like that, you can use this procedure. @value True or false.
[ Back ] |
procedure TM_SetBorder ( l, r, t, b )When an object reaches the border of a map it can either continue moving or be stopped. This procedure sets the behavior for the four borders.
[ Back ] |
procedure TM_SetCel ( x, y, cel )Set cel in map image to use at a map position.
[ Back ] |
procedure TM_SetFlag ( x, y, flag )Set game flag at a map position.
[ Back ] |
function TM_GetCel ( x, y )Get cel index in map image at map position.
Return value [ Back ] |
function TM_GetCelAt ( x, y )Get cel index in map image at world position.
Return value [ Back ] |
function TM_GetFlag ( x, y )Get game flag at map position.
Return value [ Back ] |
function TM_GetFlagAt ( x, y )Get game flag at world position.
Return value [ Back ] |
procedure TM_SetView ( x, y, w, h )Set render view and size. If nothing is showing when you call 'TM_Render', you've probably forgot to call this procedure.
[ Back ] |
procedure TM_SetCamera ( x, y )Set the top left corner of the camera.
[ Back ] |
function TM_Obstacle ( cel )Return true if image cel in map image is an obstacle.
Return value [ Back ] |
function TM_ToTile[] ( x, y )Convert from world to map coordinates.
Return value [ Back ] |
function TM_GetImage ( )Get map image.
Return value [ Back ] |
function TM_CameraX ( )Get camera x position in world.
Return value [ Back ] |
function TM_CameraY ( )Get camera y position in world.
Return value [ Back ] |
procedure TM_Render ( )Render. [ Back ] |
function TM_ToWorld[] ( x, y )Convert from screen coordinates to world.
Return value [ Back ] |
function TM_ToWorldF#[] ( x#, y# )Convert from floating point screen coordinates to world.
Return value [ Back ] |
function TM_ToWorldX ( x )Convert from x screen coordinate to world.
Return value [ Back ] |
function TM_ToWorldXF# ( x# )Convert from floating point x screen coordinate to world.
Return value [ Back ] |
function TM_ToWorldY ( y )Convert from y screen coordinate to world.
Return value [ Back ] |
function TM_ToWorldYF# ( y# )Convert from floating point y screen coordinate to world.
Return value [ Back ] |
function TM_ToScreen[] ( x, y )Convert from world coordinates to screen.
Return value [ Back ] |
function TM_ToScreenF#[] ( x#, y# )Convert from floating point world coordinates to screen.
Return value [ Back ] |
function TM_ToScreenX ( x )Convert x world coordinate to screen.
Return value [ Back ] |
function TM_ToScreenXF# ( x# )Convert floating point x world coordinate to screen.
Return value [ Back ] |
function TM_ToScreenY ( y )Convert y world coordinate to screen.
Return value [ Back ] |
function TM_ToScreenYF# ( y# )Convert floating point y world coordinate to screen.
Return value [ Back ] |
function TM_Visible ( img, x, y )Return true if image at world coordinates is visible.
Return value [ Back ] |
function TM_Move[] ( img, imgx, imgy, dx, dy )This function returns an array containing the new coordinates of an image at specified position after trying to move it. The new coordinates are accessed with [TM_X] and [TM_Y]. If no collision occured, the coordinates are '(imgx + dx, imgy + dy)'.
Return value [ Back ] |
function TM_MoveRect[] ( rectx, recty, w, h, dx, dy )This function returns an array containing the new coordinates of a rectangle at specified position after trying to move it. The new coordinates are accessed with [TM_X] and [TM_Y]. If no collision occured, the coordinates are '(rectx + dx, recty + dy)'.
Return value [ Back ] |
function TM_MoveF#[] ( img, imgx#, imgy#, dx#, dy# )This function returns an array containing the new coordinates of an image at specified floating point position after trying to move it. The new coordinates are accessed with [TM_X] and [TM_Y]. If no collision occured, the coordinates are '(imgx + dx, imgy + dy)'.
Return value [ Back ] |
function TM_GetCollisionInfo[] ( )Get information about any collision that occured during the last call to any of the collision functions. You can check the values at the indexes TM_LEFT, TM_RIGHT, TM_UP and TM_DOWN to see in what direction the collision happened. If, for example, [TM_RIGHT] is true, the object that was moved collided with something on its right.
Return value [ Back ] |
function TM_CollisionLeft ( )Returns true if last collision occured leftwards.
Return value [ Back ] |
function TM_CollisionRight ( )Returns true if last collision occuered rightwards.
Return value [ Back ] |
function TM_CollisionDown ( )Returns true if last collision occured downwards.
Return value [ Back ] |
function TM_CollisionUp ( )Returns true if last collision occured upwards.
Return value [ Back ] |
function TM_ImageCol ( img1, x1, y1, img2, x2, y2 )Return true if two images are overlapping.
Return value [ Back ] |
Generated with NLDoc 20140627.