Set of commands for Better Map/Tile handling (proposal)

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
arquivista
No longer with us
Posts: 266
Joined: Tue Jul 06, 2010 8:39 am
Location: Insert Geolocation tag here
Contact:

Set of commands for Better Map/Tile handling (proposal)

Post by arquivista »

Browsing the 3 avaliable Tile tutorials in Wiki made me realize that for a 2D game engine still could have dev work concerning Maps/Tiles handling. A Map set of commands should be handling making Maps more easy without so much code envolved. So i started to think suggestions that could even better Love.

I remembered that in "Cool Basic" (a kind of finnish semi-halted language for now) had a easy and very good Map implementation that could spice Love devs. Since CB is Finnish and there isn't a real official help file in Exe distribution I found this short Cool Basic English help reference could be download here
http://www.coolbasic.com/phpBB3/downloa ... php?id=687. Also I attached only original zip Map/Tileset HTML file with complete set of Map/Tiles commands help. I remember that of all the coding languanges i already experience this one was the easiest Map/Tile learning/use I already had.

IMHO a kind of Set commands like MapEdit and SetMap could make our delight making Love Map engine superb and so easy! Notice the nice 4 layers of map of CB. What u think of it guys?

I resumed/edited the commands from this HTML file. You should consult the original file for extended explanation and game code (in Cool Basic of course) for better understanding.

-----------------------------------------------------

TILEMAPS

With tilemaps it's quite easy to create and render cool games levels/maps. In addition, they consume very little memory, and are fast to draw. CoolBasic tilemaps have 4 layers from which 2 can be drawn. You can also write extra data to tem and animate them.

Tilemaps are handled with the standard object commands. For instance, you position the map with the PositionObject-command. Only one map can be loaded at a time i.e. if you try to load or create another one, the previous is automatically overwritten. You can remove the map from game wold with the DeleteObject-command.

Tilemaps can be created on-the-fly or loaded from disk. (...)

EditMap

This command can alter the tilemap on-the-fly. Meaning that you can build and/or edit tilemaps during the game without any performance hit. You can, for instance, blow off walls or make obstacles. Or you can turn water into lava and so on..

Tilemaps are basically arrays. Each array cell contain a number of tile that is to be drawn there. For example, if your map is filled with the value of one, the map will draw only the first tile in the tileset. This way you can dramatically affect the look of the map or modify the collision layer (2).

CoolBasic tilemaps have 4 layers: Back, Fore, Hit and Data. Only 0 and 1 is drawn. The hit-layer (2) contains only ones and zeros (1 means collision wall). Thus, if you were to blow off a wall, you would write a zero to the hit-layer to that location you want the invisible wall to be destroyed.

The coordinates are measured in tiles, meaning that the upper left corner would be (1,1). With EditMap everything is possible. The only limitation is your level of imagination.

Usage:

EditMap map_variable, layer, X, Y, Nb_tile

Layer: 0=back, 1=Fore, 2=Hit, 3=Data
Nb_tile the index of tile in the tileset

SetMap

With this command you can hide or show layers of tilemap. Tilemaps have 2 drawable layers: Back and Over (0 and 1). Objects are drawn in between of these two. If your came only uses the back-layer, there's no need to draw the over-layer (despite it's blank). You'll gain a little boost in performance. On another hand, you could set the Back-layer invisible so you could create cool Z-depth background scrolling in conjunction of MakeObjectFloor. See the example.

Usage:

SetMap map_variable, Back, Over

Back, Over = True or False

(...)

SetTile

Use this command to build a tilemap on-the-fly. This command animates tileset i.e. the image that is used when map is drawn. Each tile has its own index number that begins from 1 and continues left to right, up to down. Like this:

01 02 03 04 05 06
07 08 09 10 11 12
13 14 15 16 17 18
19 20 21 22 23 24
25 26 27 28 29 30
31 32 33 34 35 36

You can animate each tile differently. It's done by defining a number of animated tiles. For example, the value of one will animate two-tile sequence (the selected tile + one after). Disable animation by setting OFF or zero to sequence length. The last tile is unanimateable; you can't create a sequence that wraps to the start.

Optionally, you can define a slowness-factory of the animation sequence. The value of one is normal, while 2 means twice as slow and so on. Defaults to one (normal speed)

Usage:

SetTile tile_index, length [, slowness_factor]

LoadMap

This function loads a tilemap from disk to memory and returns its handle. The map will be located at coordinates (0,0) by default. Tilemaps are drawn always centered and they use game world coordinate system. Notice that only one map can be loaded at a time. If you create or load a new map the previous one will automatically be overwritten.

Maps are made with Tilester – a tilemap editor and mapper that comes with CoolBasic. (...)

Tilemaps always come with 4 layers: Back, Over, Hit and Data. Only Back ond Over are drawn. Ove-layer is drawn on top of other objects, so you ccn create areas that objects can hide in. Also, you can set the drawing of unnecessary layers OFF (for example if you don't need Over) with the SetMap-command.

A tileset is used to draw tilemaps. It’s a big image that contains smaller images representing tiles. Tiles are ordered seamlessly together. You should take a look of the sample tilesets in the Media-folder in order to comprehend. A tileset is simply an image, and the following formats ae supported: BMP/JPG/PNG/TGA. The tileset can also be changed on-the-fly during the game.

The hit-layer contains ones and zeros that represent te unwalkable areas i.e. collision data.

You can also utilize the data-layer to store additional information to the map. For-example identify some triggering-zones, make mud, lava, store born locations, teleports and so one. Use GetMap or GetMap2 to retrueve this data. The data-layer is aimed for advanced users, beginners might find it dfficult to understand and/or use.

Tilemaps are commaded with the standard object commands and functions. For example, you can position a map by using the PositionObject –command. The map is also animated using the PlayObject-command. Please notice that the purpose of PlayObject is lightly different with tilemaps. For more information, check out the PlayObject manual.

Tilemaps should usually be created first before other objects. By doing that you ensure that the map will be drawn on the background.

(...)

Usage:

map_variable = LoadMap (filename$, tileset$)

Tileset = image file

MakeMap

(...)

Usage:

map_variable = MakeMap (width, height, tile_width, tile_height)

width and height in tiles
tile_width and tile_height in pixels

GetMap

This function allows you to read map data according to game world coordinates. See the example.

Usage:

tile = GetMap (layer, X#, Y#)

layer = 0-3 (0=back, 1=over, 2=hit, 3=data)

(...)

GetMap2

This is the same but the coordinates are measured in tiles, not game world coordinates. The upper left corner of the map starts from (1,1).

Usage:

tile = GetMap2 (layer, X, Y)


MapWidth

Tells the map width, in tiles. To get the map width in pixels use the ObjectSizeX-function.

Usage:

width = MapWidth ()



MapHeight

Tells the map height, in tiles. To get the map height in pixels use the ObjectSizeY-function.

Usage:

height = MapHeight ()
Attachments
tilemaps.html.zip
(6.02 KiB) Downloaded 88 times
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Set of commands for Better Map/Tile handling (proposal)

Post by kikito »

I think a lib would certainly help.

I don't think it belongs inside the core LÖVE, but on an external (Lua-only) library it could be a nice addition. I don't think it would be incredibly difficult to implement (and probably with a better naming - that SetMap function made me go brrr).

If you want to implement it, I offer my help.
When I write def I mean function.
User avatar
arquivista
No longer with us
Posts: 266
Joined: Tue Jul 06, 2010 8:39 am
Location: Insert Geolocation tag here
Contact:

Re: Set of commands for Better Map/Tile handling (proposal)

Post by arquivista »

kikito wrote:I think a lib would certainly help.

I don't think it belongs inside the core LÖVE, but on an external (Lua-only) library it could be a nice addition. I don't think it would be incredibly difficult to implement (and probably with a better naming - that SetMap function made me go brrr).

If you want to implement it, I offer my help.
As usually in almost of 2D game engines we see inner/core sets for map/tile/camera commands I was only proposing/asking the feature and leave it to discussion (well seems none of devs are really interested in the subject anyway). Thanx for the offer kikito but I'm not really a advanced coder (dealed only with a lot of basics when in windows) like much of you and i'm also stepping in Lua for now. For sure I can't deal yet with lib dev since I even have 98% of Love/Lua world to discover. So this I will leave this for later ;)
--------------------------------------------------------
To Do: Insert Signature Here
--------------------------------------------------------
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Set of commands for Better Map/Tile handling (proposal)

Post by kikito »

Allright.

I might have to add something similar to this some time in the future (if I'm to add A* algorithms) to PÄSSION. But I'm talking about after summer.

In the meantime, enjoy learning Lua!
When I write def I mean function.
User avatar
arquivista
No longer with us
Posts: 266
Joined: Tue Jul 06, 2010 8:39 am
Location: Insert Geolocation tag here
Contact:

Re: Set of commands for Better Map/Tile handling (proposal)

Post by arquivista »

kikito wrote: In the meantime, enjoy learning Lua!
I will thx, Lua is my kind of code. I'm only sorry that Mac side seems don't offer a lot in terms of independent self compilers as Windows do. A lot of Mac Lua avaliable resources is more XCode integration stuff.

Probably also there is already some Lua map/tile libs. I will try do some research later.
--------------------------------------------------------
To Do: Insert Signature Here
--------------------------------------------------------
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 6 guests