Ok. I tried it and it didn't work at first but I understood what you were trying to do so I changed it a bit and now it works. Thanks!
Here is the updated code:
Rem Project: Dungeon2D
Rem Created: 01.10.2005 04:02:17
Rem ***** Main Source File *****
` Set display mode
set display mode 1024,768,32
sync on
sync rate 50
hide mouse
goto menu
newgame:
` Load images
load image "grey16.bmp",1
load image "brown16.bmp",2
load image "blue16.bmp",3
load image "darkred16.bmp",4
load image "white16.bmp",5
load image "yellow16.bmp",6
` Set the map size and the frame size
mapsize = 128
framex = 49
framey = 36
` How "far" can the player see?
playersight = 4
` Make the map array
dim map$(mapsize,mapsize,2)
` Load the map
loadmap("128x128.bmp",mapsize)
` Get player startposition
for x = 0 to mapsize
for y = 0 to mapsize
if map$(x,y,1) = "player"
playerx = x
playery = y
` Centre map around player
if x>16
scrollx = x-16
else
scrollx = 0
endif
if y>16
scrolly = y-16
else
scrolly = 0
endif
endif
next y
next x
` Player speed
moveOk = 1
moved = 0
playerSpeed = 150
` Got any keys?
key = 0
`****************************************************************************************
`************************************* MAIN LOOP ****************************************
do
cls
prevx = playerx
prevy = playery
prevscrollx = scrollx
prevscrolly = scrolly
` Player controls
if upkey()=1 and moveOk=1
dec playery,1
moved=1
moveOK=0
if playery<scrolly+10 then dec scrolly
endif
if downkey()=1 and moveOk=1
inc playery,1
moved=1
moveOK=0
if playery>framey+scrolly-10 then inc scrolly
endif
if leftkey()=1 and moveOk=1
dec playerx,1
moved=1
moveOK=0
if playerx<scrollx+10 then dec scrollx
endif
if rightkey()=1 and moveOk=1
inc playerx,1
moved=1
moveOK=0
if playerx>framex+scrollx-10 then inc scrollx
endif
` Stop scrolling when on edge of map
if scrollx > (mapsize-framex+1) then scrollx = (mapsize-framex+1)
if scrollx < 0 then scrollx = 0
if scrolly > (mapsize-framey+1) then scrolly = (mapsize-framey+1)
if scrolly < 0 then scrolly = 0
` Open doors and pick up keys
if spacekey()=1
if map$(playerx,playery+1,1) = "door" then map$(playerx,playery+1,1) = "space"
if map$(playerx,playery-1,1) = "door" then map$(playerx,playery-1,1) = "space"
if map$(playerx+1,playery,1) = "door" then map$(playerx+1,playery,1) = "space"
if map$(playerx-1,playery,1) = "door" then map$(playerx-1,playery,1) = "space"
if map$(playerx,playery+1,1) = "ldoor" and key>0 then map$(playerx,playery+1,1) = "space" : dec key,1
if map$(playerx,playery-1,1) = "ldoor" and key>0 then map$(playerx,playery-1,1) = "space" : dec key,1
if map$(playerx+1,playery,1) = "ldoor" and key>0 then map$(playerx+1,playery,1) = "space" : dec key,1
if map$(playerx-1,playery,1) = "ldoor" and key>0 then map$(playerx-1,playery,1) = "space" : dec key,1
if map$(playerx,playery+1,1) = "key" then map$(playerx,playery+1,1) = "space" : inc key,1
if map$(playerx,playery-1,1) = "key" then map$(playerx,playery-1,1) = "space" : inc key,1
if map$(playerx+1,playery,1) = "key" then map$(playerx+1,playery,1) = "space" : inc key,1
if map$(playerx-1,playery,1) = "key" then map$(playerx-1,playery,1) = "space" : inc key,1
endif
` Display map
if keystate(50)=1 then gosub map
` Player speed controll
if moved = 1
t = timer() + playerSpeed
moved = 0
endif
if t < timer() then moveOK = 1
` Prevent player from walking through walls
if map$(playerx,playery,1) = "wall"
playerx = prevx
playery = prevy
scrollx = prevscrollx
scrolly = prevscrolly
endif
` Prevent player from walking through doors
if map$(playerx,playery,1) = "door"
playerx = prevx
playery = prevy
scrollx = prevscrollx
scrolly = prevscrolly
endif
` Prevent player from walking through locked doors
if map$(playerx,playery,1) = "ldoor"
playerx = prevx
playery = prevy
scrollx = prevscrollx
scrolly = prevscrolly
endif
` Prevent player from walking through keys
if map$(playerx,playery,1) = "key"
playerx = prevx
playery = prevy
scrollx = prevscrollx
scrolly = prevscrolly
endif
` Draw the map frame
ink rgb(255,0,0),rgb(0,0,0)
box 8,8,8*103,16
box 8,8*76,8*103,8*77
box 8,16,16,8*76
box 8*102,16,8*103,8*76
` Draw the player
sprite 1,(playerx-scrollx+1)*16,(playery-scrolly+1)*16,3
` Make the nearest tiles visible
For y = playery-playersight to playery+playersight
For x = playerx-playersight to playerx+playersight
map$(x,y,2)= "1"
next x
next y
` Draw the map
for x = 0+scrollx to framex+scrollx
for y = 0+scrolly to framey+scrolly
if map$(x,y,2) = "1"
if map$(x,y,1) = "wall" then paste image 1,(x-scrollx+1)*16,(y-scrolly+1)*16
if map$(x,y,1) = "wall" then paste image 1,(x-scrollx+1)*16,(y-scrolly+1)*16
if map$(x,y,1) = "door" then paste image 6,(x-scrollx+1)*16,(y-scrolly+1)*16
if map$(x,y,1) = "player" then paste image 5,(x-scrollx+1)*16,(y-scrolly+1)*16
if map$(x,y,1) = "ldoor" then paste image 2,(x-scrollx+1)*16,(y-scrolly+1)*16
if map$(x,y,1) = "space" then paste image 5,(x-scrollx+1)*16,(y-scrolly+1)*16
if map$(x,y,1) = "key" then paste image 4,(x-scrollx+1)*16,(y-scrolly+1)*16
endif
next y
next x
` Draw some info
ink rgb(255,255,255),rgb(0,0,0)
set text size 20
set text to bold
text 16*54,16*2," = Player Position"
text 16*54,16*4," = Walls"
text 16*54,16*6," = Door"
text 16*54,16*8," = Locked Door"
text 16*54,16*10," = Key"
text 16*54,16*12," = Open Space"
paste image 3,16*53,16*2
paste image 1,16*53,16*4
paste image 6,16*53,16*6
paste image 2,16*53,16*8
paste image 4,16*53,16*10
paste image 5,16*53,16*12
text 16*53,16*16,"Keys = " + str$(key)
text 16*53,16*18,"FPS = " + str$(screen fps())
center text 1024/2,8*80,"Use arrowkeys to move around"
center text 1024/2,8*83,"Press spacebar to open doors or to pick up Keys"
center text 1024/2,8*86,"Press M to display the Map"
sync
loop
`********************************** MAIN LOOP END ***************************************
`****************************************************************************************
`************************************ SUB PROGRAM ***************************************
`**************************************** map *******************************************
map:
wait 300
load image "grey8.bmp",101
load image "brown8.bmp",102
load image "blue8.bmp",103
load image "darkred8.bmp",104
load image "white8.bmp",105
load image "yellow8.bmp",106
for x = 0 to mapsize
for y = 0 to mapsize
if map$(x,y,1) = "player" then map$(x,y,1) = "space"
next y
next x
map$(playerx,playery,1) = "player"
mapX = scrollx
mapY = scrolly
mapFrameX = framex*2
mapFrameY = framey*2
if sprite exist(1)=1 then delete sprite 1
while keystate(50)=0
cls
if leftkey()=1 then dec mapX
if rightkey()=1 then inc mapX
if upkey()=1 then dec mapY
if downkey()=1 then inc mapY
` Stop scrolling when on edge of map
if mapX > mapsize-mapFrameX+1 then mapX = mapsize-mapFrameX+1
if mapX < 0 then mapX = 0
if mapY > mapsize-mapFrameY+1 then mapY = mapsize-mapFrameY+1
if mapY < 0 then mapY = 0
` Draw the map frame
ink rgb(255,0,0),rgb(0,0,0)
box 8,8,8*103,16
box 8,8*76,8*103,8*77
box 8,16,16,8*76
box 8*102,16,8*103,8*76
` Draw the map
for x = 0+mapX to mapFrameX+mapX+1
for y = 0+MapY to mapFrameY+MapY+1
if map$(x,y,2) = "1"
if map$(x,y,1) = "wall" then paste image 101,(x-mapX+2)*8,(y-mapY+2)*8
if map$(x,y,1) = "door" then paste image 106,(x-mapX+2)*8,(y-mapY+2)*8
if map$(x,y,1) = "player" then paste image 103,(x-mapX+2)*8,(y-mapY+2)*8
if map$(x,y,1) = "ldoor" then paste image 102,(x-mapX+2)*8,(y-mapY+2)*8
if map$(x,y,1) = "space" then paste image 105,(x-mapX+2)*8,(y-mapY+2)*8
if map$(x,y,1) = "key" then paste image 104,(x-mapX+2)*8,(y-mapY+2)*8
endif
next y
next x
` Draw some info
ink rgb(255,255,255),rgb(0,0,0)
set text size 20
set text to bold
text 16*54,16*2," = Player Position"
text 16*54,16*4," = Walls"
text 16*54,16*6," = Door"
text 16*54,16*8," = Locked Door"
text 16*54,16*10," = Key"
text 16*54,16*12," = Open Space"
paste image 3,16*53,16*2
paste image 1,16*53,16*4
paste image 6,16*53,16*6
paste image 2,16*53,16*8
paste image 4,16*53,16*10
paste image 5,16*53,16*12
text 16*53,16*16,"Keys = " + str$(key)
text 16*53,16*18,"FPS = " + str$(screen fps())
center text 1024/2,8*80,"Use arrowkeys to scroll the Map"
center text 1024/2,8*83,"Press M to return to game"
sync
endwhile
delete image 101
delete image 102
delete image 103
delete image 104
delete image 105
delete image 106
cls
wait 300
return
`*********************************** GOTO PROGRAM ***************************************
`*************************************** menu *******************************************
menu:
wait 350
load image "selleft.bmp",8
load image "selright.bmp",9
option = 1
selectOk = 1
selected = 0
menuSpeed = 150
ink rgb(255,255,255),rgb(0,0,0)
set text font "Arial"
set text size 30
set text to bold
while spacekey()=0
cls
center text 512,150,"NEW GAME"
center text 512,250,"LOAD GAME"
center text 512,350,"MAP EDITOR"
center text 512,450,"OPTIONS"
center text 512,550,"QUIT"
if upkey()=1 and selectOk=1
dec option,1
selected=1
selectOK=0
endif
if downkey()=1 and selectOk=1
inc option,1
selected=1
selectOK=0
endif
if selected = 1
tm = timer() + menuSpeed
selected = 0
endif
if tm < timer() then selectOK = 1
if option < 1 then option = 5
if option > 5 then option = 1
if option = 1
paste image 8,396,155
paste image 9,612,155
endif
if option = 2
paste image 8,396,255
paste image 9,612,255
endif
if option = 3
paste image 8,396,355
paste image 9,612,355
endif
if option = 4
paste image 8,396,455
paste image 9,612,455
endif
if option = 5
paste image 8,396,555
paste image 9,612,555
endif
sync
endwhile
if option = 1 then goto newgame
if option = 2 then goto notReady
if option = 3 then goto notReady
if option = 4 then goto notReady
if option = 5 then goto quit
`*********************************** GOTO PROGRAM ***************************************
`************************************* notReady *****************************************
notReady:
cls
center text 512,334,"This Part Is Not Done Yet"
center text 512,434,"Press Any Key To Return To Main Menu"
sync
wait key
goto menu
`*********************************** GOTO PROGRAM ***************************************
`*************************************** quit *******************************************
quit:
end
`************************************* FUNCTION ****************************************
`************************************* loadmap *****************************************
function loadmap(filename$,size)
cls
load image filename$,100
paste image 100,1,1
for y=0 to size
for x=0 to size
tmp = point(x,y)
r = rgbr(tmp)
g = rgbg(tmp)
b = rgbb(tmp)
if r=128 and g=128 and b=128 then map$(x,y,1) = "wall"
if r=255 and g=128 and b=64 then map$(x,y,1) = "ldoor"
if r=255 and g=128 and b=0 then map$(x,y,1) = "ldoor"
if r=128 and g=0 and b=0 then map$(x,y,1) = "key"
if r=255 and g=255 and b=0 then map$(x,y,1) = "door"
if r=0 and g=0 and b=255 then map$(x,y,1) = "player"
if r=255 and g=255 and b=255 then map$(x,y,1) = "space"
if r=192 and g=192 and b=192 then map$(x,y,1) = "space"
next x
next y
delete image 100
cls
endfunction
There is one thing I want to change though. I don't want the player to see through walls and doors. Any idea on how I can do that?
-Ranietz-