Here's a simple 2D map stored and displayed, with quick and dirty jumping collision.
It relies on a 16x16 image tile.
set display mode 800,600,32
TILE_SIZE = 16
MAP_WIDTH = 34
MAP_HEIGHT = 24
dim map(MAP_HEIGHT,MAP_WIDTH)
MAP_OFFSET_X = 128
MAP_OFFSET_Y = 100
load image "c:\tile1.bmp", 1
gosub _LoadMap
rem player position
px = 400
py = 436
pWidth = 2
pHeight = 32
sync on
sync rate 60
DO
cls
rem draw the map
for y = 0 to MAP_HEIGHT-1
for x = 0 to MAP_WIDTH-1
tx = MAP_OFFSET_X + x*TILE_SIZE
ty = MAP_OFFSET_Y + y*TILE_SIZE
if map(y+1, x+1) = 1 then paste image 1, tx, ty
next x
next y
rem user controls
gosub _Controls
rem so we can see where Mario hits a block at
if showImpactFlag = 1 then gosub _ShowImpact
rem draw player
ink rgb(0,0,255),0
box px, py, px+pWidth, py+pHeight
rem screen output
set cursor 0,0
print screen fps()
sync
LOOP
_Controls:
if rightkey() then inc px, 2
if leftkey() then dec px, 2
if spacekey() and jumpFlag = 0 then jumpFlag = 1 : jumpForce# = 12
rem start jumping routine
if jumpFlag = 1
dec py, jumpForce#
jumpForce# = jumpForce# - 0.5
endif
tx = (px - MAP_OFFSET_X) / TILE_SIZE + 1
if jumpForce# > 0 then ty = (py - MAP_OFFSET_Y) / TILE_SIZE + 1
if jumpForce# < 0 then ty = ((py - MAP_OFFSET_Y)+pHeight) / TILE_SIZE + 1
if ty > 0 and ty <= MAP_HEIGHT and tx > 0 and tx <= MAP_WIDTH
if map(ty, tx) = 1
if jumpForce# < 0
jumpFlag = 0
py = (MAP_OFFSET_Y + (ty-1) * TILE_SIZE) - pHeight
endif
if jumpForce# > 0
jumpForce# = 0
map_hit_x = tx
map_hit_y = ty
showImpactFlag = 1
endif
endif
endif
if jumpFlag = 0
jy = (py+pHeight-MAP_OFFSET_Y) / TILE_SIZE + 1
if map(jy,tx) = 0 then jumpFlag = 1 : jumpForce# = 0
endif
rem end jumping routine
RETURN
_ShowImpact:
cx = MAP_OFFSET_X + ((map_hit_x-1)*TILE_SIZE) + TILE_SIZE/2
cy = MAP_OFFSET_Y + ((map_hit_y-1)*TILE_SIZE) + TILE_SIZE/2
inc radius#, 0.5
ink rgb(255,0,0),0
circle cx, cy, radius#
if radius# > 10 then radius# = 0 : showImpactFlag = 0
RETURN
_LoadMap:
restore mapdata
for y = 1 to MAP_HEIGHT
for x = 1 to MAP_WIDTH/2
read z
map(y, x) = z
x2 = (MAP_WIDTH+1)-x
map(y, x2) = z
next x
next y
RETURN
rem map is symmetrical, so we can reduce the amount of
rem redundant data by only designing half the actual map
mapdata:
DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1
DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
DATA 1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
DATA 1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
DATA 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
> SELECT * FROM users WHERE clue > 0
> 0 rows returned