Can anyone figure out what is wrong with this code?
This is what happens every once in a while in the same places(The red isn't there in the game - it's just there to show what is wrong.):
Here
Here is the code:
hide mouse
sync on
sync rate 0
set display mode 640,480,16
Variables:
Screensizex = 4 :`num of tiles per screen
Screensizey = 3 :`...
Tilesize = 64 :`size of tile
Level = 1 :`current level
maxlevels = 1 :`max amount of levels
largestmap = 64 :`largest map size
playerx = 0 :`player coordinates
playery = 0 :`...
keypress = 0 :`Is a one if a key is being pressed
Playerdir = 2 :`player direction 1-up 2-down 3-left 4-right
Keys = 0 :`num of keys the player has
Dim Mapsize(maxlevels,2) :`mapsize of levels
Mapsize(1,1) = 68 : Mapsize(1,2) = 65
Dim Map$(largestmap,largestmap,2) :`map info = x,y,1 - "door","wall", etc. 2 - visibility
Loading:
Load image "Title.jpg",1
Load image "Floor.jpg",2
Load image "Wall.jpg",3
Load image "door.jpg",4
Load image "Locked door.jpg",5
Load image "open door.jpg",6
Load image "key.jpg",7
Load image "stairs up.jpg",8
Load image "stairs down.jpg",9
Load image "Playerup.bmp",10
Load image "Playerdown.bmp",11
Load image "Playerleft.bmp",12
Load image "Playerright.bmp",13
Start:
gosub Loadmap
gosub refreshscreen
Do
gosub keystuff
sync
Loop
LOADMAP:
CLS 0
Filename$ = "Level"+str$(level)+".bmp"
Open to read 1,Filename$: Rem Colour Image
Read word 1,Discard: Rem Identifier
Read long 1,Discard: Rem File Size
Read long 1,Discard: Rem Reserved
Read long 1,Discard: Rem Bitmap Data Offset
Read long 1,Discard: Rem Bitmap Header Size
Read long 1,ImageWidth: Rem Width
Read long 1,ImageHeight: Rem Height
Read word 1,Discard: Rem Planes
Read word 1,bitsperpixel: Rem Bits Per Pixel
Read long 1,Discard: Rem Compression
Read long 1,bmpdatasize: Rem Bitmap Data Size
Read long 1,Discard: Rem HResolution
Read long 1,Discard: Rem VResolution
Read long 1,Discard: Rem Colors
Read long 1,Discard: Rem Important Colors
Rem Dim an array using the image width and height values
Dim ImageArray(ImageWidth,ImageHeight,2)
Rem Read in the pixel data into the array
For By = ImageHeight-1 to 0 step-1
For Bx=0 to ImageWidth-1
read byte 1,Blue
read byte 1,Green
read byte 1,Red
ImageArray(Bx,By,0) = Red
ImageArray(Bx,By,1) = Green
ImageArray(Bx,By,2) = Blue
Next Bx
Next By
Close File 1
For y = 0 to imageheight - 1
For x = 0 to imagewidth - 1
If imagearray(x,y,0) = 128 and imagearray(x,y,1) = 128 and imagearray(x,y,2) = 128 then map$(x,y,1) = "wall"
If imagearray(x,y,0) = 192 and imagearray(x,y,1) = 192 and imagearray(x,y,2) = 192 then map$(x,y,1) = "floor"
If imagearray(x,y,0) = 255 and imagearray(x,y,1) = 255 and imagearray(x,y,2) = 0 then map$(x,y,1) = "door"
If imagearray(x,y,0) = 255 and imagearray(x,y,1) = 128 and imagearray(x,y,2) = 64 then map$(x,y,1) = "lock"
If imagearray(x,y,0) = 255 and imagearray(x,y,1) = 0 and imagearray(x,y,2) = 0 then map$(x,y,1) = "key"
If imagearray(x,y,0) = 0 and imagearray(x,y,1) = 0 and imagearray(x,y,2) = 0 then map$(x,y,1) = "wall"
If imagearray(x,y,0) = 0 and imagearray(x,y,1) = 255 and imagearray(x,y,2) = 255 then map$(x,y,1) = "up"
If imagearray(x,y,0) = 255 and imagearray(x,y,1) = 255 and imagearray(x,y,2) = 255
playerx = x
playery = y
map$(x,y,1) = "floor"
endif
next x
next y
return
REFRESHSCREEN:
cls
For y = playery - screensizey to playery + screensizey
For x = playerx - screensizex to playerx + screensizex
xpos = x - (playerx - screensizex)
ypos = y - (playery - screensizey)
If map$(x,y,1) = "wall" then paste image 3,xpos*tilesize,ypos*tilesize
If map$(x,y,1) = "floor" then paste image 2,xpos*tilesize,ypos*tilesize
If map$(x,y,1) = "door" then paste image 4,xpos*tilesize,ypos*tilesize
If map$(x,y,1) = "lock" then paste image 5,xpos*tilesize,ypos*tilesize
If map$(x,y,1) = "key" then paste image 7,xpos*tilesize,ypos*tilesize
If map$(x,y,1) = "open" then paste image 6,xpos*tilesize,ypos*tilesize
If map$(x,y,1) = "up" then paste image 8,xpos*tilesize,ypos*tilesize
next x
next y
Paste image 1,1,448
If playerdir = 1 then Sprite 1,screensizex*tilesize,screensizey*tilesize,10
If playerdir = 2 then Sprite 1,screensizex*tilesize,screensizey*tilesize,11
If playerdir = 3 then Sprite 1,screensizex*tilesize,screensizey*tilesize,12
If playerdir = 4 then Sprite 1,screensizex*tilesize,screensizey*tilesize,13
center text 608,10,"Keys:"
center text 608,25,str$(keys)
return
KEYSTUFF:
If upkey() = 1 and keypress = 0
if map$(playerx,playery-1,1) <> "wall" and map$(playerx,playery-1,1) <> "door" and map$(playerx,playery-1,1) <> "lock" then playery = playery - 1
playerdir = 1
gosub refreshscreen
keypress = 1
endif
If downkey() = 1 and keypress = 0
if map$(playerx,playery+1,1) <> "wall" and map$(playerx,playery+1,1) <> "door" and map$(playerx,playery+1,1) <> "lock" then playery = playery + 1
playerdir = 2
gosub refreshscreen
keypress = 2
endif
If rightkey() = 1 and keypress = 0
if map$(playerx+1,playery,1) <> "wall" and map$(playerx+1,playery,1) <> "door" and map$(playerx+1,playery,1) <> "lock" then playerx = playerx + 1
playerdir = 4
gosub refreshscreen
keypress = 4
endif
If leftkey() = 1 and keypress = 0
if map$(playerx-1,playery,1) <> "wall" and map$(playerx-1,playery,1) <> "door" and map$(playerx-1,playery,1) <> "lock" then playerx = playerx - 1
playerdir = 3
gosub refreshscreen
keypress = 3
endif
If upkey() = 0 and keypress = 1
keypress = 0
endif
If downkey() = 0 and keypress = 2
keypress = 0
endif
If rightkey() = 0 and keypress = 4
keypress = 0
endif
If leftkey() = 0 and keypress = 3
keypress = 0
endif
If spacekey() = 1 and map$(playerx,playery-1,1) = "door" and playerdir = 1
map$(playerx,playery-1,1) = "open"
gosub refreshscreen
endif
If spacekey() = 1 and map$(playerx,playery+1,1) = "door" and playerdir = 2
map$(playerx,playery+1,1) = "open"
gosub refreshscreen
endif
If spacekey() = 1 and map$(playerx-1,playery,1) = "door" and playerdir = 3
map$(playerx-1,playery,1) = "open"
gosub refreshscreen
endif
If spacekey() = 1 and map$(playerx+1,playery,1) = "door" and playerdir = 4
map$(playerx+1,playery,1) = "open"
gosub refreshscreen
endif
If spacekey() = 1 and map$(playerx,playery,1) = "key"
map$(playerx,playery,1) = "floor"
keys = keys + 1
gosub refreshscreen
endif
Return
And the media is attached if you need it.
Green Bunnies rule!