I'll have this finished tonight. The example will cover 3 methods.
1. Hard coded collision boxes
2. Using an image as a collision map
3. Building the world out of tiles and using one layer as a collision map
preview:
EDIT:
Here is the Media for 3. (Srym photobucket converted them to .jpg so you may need to re flood fill the black. I'll try to fix it later)
man
block
ladder
Here is 3. (It's a crude as can be)
rem BARE BONES TILEWORLD MAP with BUILT IN COLLISION
rem Setup Display
sync on
sync rate 30
set display mode 640,480,32
rem Load Media
load image "Block.bmp",1,1
paste image 1,0,0,1
get image 2,0,0,63,63,1
delete image 1
cls
load image "ladder.bmp",1,1
paste image 1,0,0,1
get image 3,0,0,63,63,1
delete image 1
cls
load image "Man.bmp",1,1
paste image 1,0,0,1
get image 9,0,0,63,63,1
delete image 1
cls
rem Create an Array to hold our world info that is stored in Data statements
dim TileWorld(10,7,4)
rem Set the read pointer to the beginning of the Data statements
restore WorldDat
rem fill our World Array with the info from the Data statements
for z=0 to 3
for y=0 to 6
for x=0 to 9
read arval
imgnum=arval
TileWorld(x,y,z)=imgnum
next x
next y
next z
rem set player inital world coordinates
PlayerX=2
PlayerY=5
rem MAIN LOOP
do
cls 0
rem read the TileWorld Array, and Paste the right image to the screen
for z=0 to 3
for y=0 to 6
for x=0 to 9
imgnum = TileWorld(x,y,z)
rem if an element's value don't paste an image
if imgnum<>0
paste image imgnum,x*64,y*64,1
endif
next x
next y
next z
rem update players position
paste image 9, PlayerX*64,PlayerY*64,1
rem Get user input
rem if the player presses right and the tile next to him is clear (=0) then move player right as long as he is not at the right max.
if rightkey()=1 and TileWorld(PlayerX+1,PlayerY,2)=0 and PlayerX<6
inc PlayerX, 1
endif
rem if player presses left and the tile next to him is clear (=0) then move player left. As long he is not at the left min.
if leftkey()=1 and TileWorld(PlayerX-1,PlayerY,2)=0 and PlayerX<>0
dec PlayerX, 1
endif
rem if player presses up, see if a ladder is present behind him (=3) on the layer above the blocks
if upkey()=1 and TileWorld(PlayerX,PlayerY,3)=3
dec PlayerY,1
endif
rem if player presses down, see if there is a ladder present below his current position
if downkey()=1 and TileWorld(PlayerX,PlayerY+1,3)=3
inc PlayerY, 1
endif
rem if the tile under a player is not a block AND the player is not on a ladder make him fall down until there is one
if TileWorld(PlayerX,PlayerY+1,2)=0 and TileWorld(PlayerX,PlayerY,3)<>3
inc PlayerY, 1
endif
sync
loop
end
rem layer 0
WorldDat:
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
rem layer 1
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
rem layer 2
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 0,0,2,2,2,2,0,0,0,0
data 0,0,0,0,0,0,0,0,0,2
data 0,2,2,2,0,0,0,2,2,2
data 0,0,0,0,0,0,2,2,2,2
data 2,2,2,2,2,2,2,2,2,2
rem layer 3
data 0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
data 0,0,3,0,0,0,0,0,0,0
data 0,0,3,0,0,0,0,0,0,0
data 0,0,3,0,0,0,0,0,0,0
data 0,0,3,0,0,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0
=====================
Next I'll do 1. and 2. and edit them in