Shrimpalimpa,
I dug around the forums and found an old post I made that includes a quick example of how to make a tile make maker and layer different features. It may be helpful and it also starts to lay the foundation for collision based on the current visibile feature in the tile layer.
Posted: 21st Apr 2009 03:22 Edited at: 21st Apr 2009 15:16
Link
From: Latch
[EDIT]
To start, I'm not a newbie. I think this is great thread because you guys see things through so I thought I'd throw a couple of ideas in the mix. I don't want to scare any newbies away if what I post seems too difficult; these are only some ideas. You can take them or leave them. I'm not trying to tell you how to do anything. If I post some code, look through it and see if it makes sense. If I make a mistake or seem to be doing something the hard way, feel free to give me what for!
Also, I keep talking about 16 layers. It's really just an arbitrary number. It just to show it can be done with little overhead in the map design. It could as easily be 4.
@Obese
Quote: "So how are we going to store all this data? For each tile we need to store several images (layers)"
You don't actually have to store several images on a single map square. The master level tile set holds the images that can be used on the map. A map array, holds a reference to a particular image/tile. The layering only holds the reference to the tile as well. The master level tile set is always numbered the same, so you know what the tile type is by the number that is referenced in the map file. The picture (image) is in the master level tile set. If tiles 1 - 16 are passable tiles, those pictures could be anything, blank spaces, a road, grass, shallow water - anything.
The tile number from the master level tileset is stored in the map array. The actual in game map can be drawn on the fly - tile by tile, or predrawn on an offscreen bitmap, or partially predrawn and updated as movement occurs, or drawn and saved as a a picture file (though that may be huge depending on the map size - jpg, bmp, png, etc.) - any number of methods could be applied (I like having the initial visible area predrawn offscreen and then just updated as the map scrolls into or out of view). The only visible image is the last one drawn, so if you had a stack/layers of 16 images, there would ultimately be only 1 displayed (using transparency - a composite of all 16 images).
I knocked together a quick example. I didn't create a nice neat layout for a master tile set, I just created 3 images in memory that can be used as tiles. The map editor will allow you to stack 16 layers on a single tile. It won't allow you to have 2 of the exact same tile overlap because that would waste layers. However, you could alternate between 2 images and fill up all 16 layers if you felt so inclined.
If you point at a position on the screen, it will tell you the x,y tile position, the number of layers used on that tile and which tiles/images from the master tile set are assigned to that layer. The highest layer number is the one on top for the map. So you could lay down some grass, then put a road or two on top of it.
Using this method, you could check through the layers to see if there was an action tile (by master tile number) and then trigger whatever is necessary based on the x,y tile position.
Feel free to put tiles anywhere on the screen. The information text will still display on top.
Here's the example:
remstart
==============================================================
= Title : Tile map editor quick example
= Author : latch
= Date : 04/20/2009
= Update :
= Version: .01
==============================================================
Comments This is a demonstration of creating a map using a
master tile set and layers. I didn't spend the time
to actually lay out the tileset as a single image,
but just created 3 simple tiles in memory as images:
1 = grass
2 = east-west road
3 = north-south road
Where ever you point the mouse, it will give you
information on the current tile you are over. That
information includes the current x,y tile position,
the current layer count (up to 16), and the what
tile is on what layer.
You select an image/tile with 1,2 or 3. When you
click the left mouse button, that tile will be placed
at the mouse position and the layer information
will be updated. You cannot place the same tile
on consecutive layers. That allows you to hold
the mouse button and drag the mouse all over the screen
for fast tile placement of the same image without
accidentally adding the same image to all 16 layers.
==============================================================
remend
rem =============================================================
rem = SET UP DISPLAY
rem =============================================================
autocam off
set display mode 640,480,32
sync on
sync rate 60
rem =============================================================
rem = MAIN
rem =============================================================
_main:
gosub _init
do
gosub _assign_tiles
gosub _check_mouse
gosub _display
sync
loop
end
rem =============================================================
rem = SUBROUTINES - PROCEDURES
rem =============================================================
_init:
gosub _textures
remstart
the map array will hold the number of the tile for a particular layer.
There can be 16 active layers with map(x,y,0) holding the highest layer
number used for the particular tile coordinates. That way we can stop
a user from adding too many layers.
The format is
map(tilex,tiley,layer) where map(tilex,tiley,0) = the current layer of this
map tile position
remend
dim map(bitmap width(0)/32,bitmap height(0)/32,16)
rem set the default image tile to grass
img=1
return
`----------------------------------------------------------------
_textures:
rem grass tile
cls rgb(0,100,0)
for n=1 to 1000
c=rnd(100)+50
ink rgb(0,c,0),0
dot rnd(32),rnd(32)
next n
rem the ,1 at the end copies the image to video memory
get image 1,0,0,32,32,1
sync
rem west-east road
cls 0
ink RGB(113,56,0),0
box 0,7,32,23
get image 2,0,0,32,32,1
sync
rem north-south road
cls 0
ink RGB(113,56,0),0
box 7,0,23,32
get image 3,0,0,32,32,1
sync
rem draw the map on bitmap 1
create bitmap 1,bitmap width(0),bitmap height(0)
ink rgb(255,255,255),0
return
`----------------------------------------------------------------
_check_mouse:
rem check for the left mouse click to place a tile at the mouse position
if mouseclick()=1
tx=mousex()/32
ty=mousey()/32
rem check the layer count, increase it, then max out at 16
rem if there is an attempt to put the same image on the same
rem layer, don't increase the layer
oldL=map(tx,ty,0)
rem check if the last layer had this same image so as not to duplicate
if map(tx,ty,oldL) <> img
map(tx,ty,0)=map(tx,ty,0)+1
if map(tx,ty,0) > 16 then map(tx,ty) = 16
L=map(tx,ty,0)
map(tx,ty,L)=img
rem paste image with transparency
paste image img,tx*32,ty*32,1
endif
endif
return
`----------------------------------------------------------------
_assign_tiles:
set current bitmap 1
rem assign the apropriate image
select inkey$()
case "1" : img=1 : endcase
case "2" : img=2 : endcase
case "3" : img=3 : endcase
endselect
return
`----------------------------------------------------------------
_display:
rem the map is being drawn on bitmap 1, so copy it to 0 to see it
copy bitmap 1,0
rem display the current tile information
set current bitmap 0
text 0,0,"Press 1 to select grass tile"
text 0,20,"Press 2 to select East-West road tile"
text 0,40,"Press 3 to select North-South road tile"
text 0,60,"Current image = "+str$(img)
tx=mousex()/32
ty=mousey()/32
text 0,80,"Layer count at "+str$(tx)+","+str$(ty)+" = "+str$(map(tx,ty,0))
for n=1 to 16
text 0,80+(n*20),"Layer "+str$(n)+" tile number = "+str$(map(tx,ty,n))
next n
return
Hopefully it's helpful.
Enjoy your day.