So, your intent is to have just one room?
Z depth is related to placement of object on the Z axis. I was mistaken; I thought you had set a couple of the objects at 5.0 on the Z axis, but you have them all at 0. My bad.
To me it would be easier to make the sprite into an object and then check collision. A really crude version:
sync on
sync rate 30
color backdrop 0
Position camera 0,50,70,-150
hide mouse
Make object box 1,5,50,0
` load image "media\line.bmp",1
` Texture object 1,1
position object 1,2.5,25,0
set object collision to polygons 1
Make object box 2,5,50,0
` load image "media\line.bmp",2
` Texture object 2,2
position object 2,25,2.5,0
zrotate object 2,90
Set object collision to polygons 2
Make object box 3,5,50,0
` load image "media\line.bmp",3
` Texture object 3,3
position object 3,75,2.5,0
zrotate object 3,90
Set object collision to polygons 3
Make object box 4,5,50,0
` load image "media\line.bmp",4
` Texture object 4,4
position object 4,97.5,25,0
set object collision to polygons 4
REM Make top wall
Make object box 5,5,50,0
` load image "media\line.bmp",5
` Texture object 5,5
position object 5,92.5,115,0
set object collision to polygons 5
color object 5,rgb(255,255,0)
Make object box 6,5,50,0
` load image "media\line.bmp",6
` Texture object 6,6
position object 6,25,142.5,0
zrotate object 6,90
Set object collision to polygons 6
Make object box 7,5,50,0
` load image "media\line.bmp",7
` Texture object 7,7
position object 7,75,142.5,0
zrotate object 7,90
Set object collision to polygons 7
Make object box 8,5,50,0
` load image "media\line.bmp",8
` Texture object 8,8
position object 8,97.5,115,0
set object collision to polygons 8
make object cube 20,5
color object 20,rgb(255,0,0)
`load image "media\entity.bmp", 9
color backdrop rgb(255,255,255)
entity_x# as float
entity_x# = 46.0
entity_y# as float
entity_y# = 97.0
global entity_z# as integer
entity_z# = 0.0
position object 20,entity_x#,entity_y#,entity_z#
exit_x as float
exit_x = 97.5
exit_y as float
exit_y = 70
ink rgb(255,0,0)
box 0,0,48,48
get image 9,0,0,49,49
cls
move camera -300
do
`sprite 1,entity_x,entity_y,9
text 10,10,"x = " +str$(entity_x#)
text 10,30,"Y="+str$(entity_y#)
if RIGHTKEY() = 1
entity_x# = entity_x# + 1
position object 20,entity_x#,entity_y#,entity_z#
if object collision(20,0) > 0
entity_x# = entity_x# - 1
position object 20,entity_x#,entity_y#,entity_z#
endif
endif
if LEFTKEY() = 1
entity_x# = entity_x# - 1
position object 20,entity_x#,entity_y#,entity_z#
if object collision(20,0) > 0
entity_x# = entity_x# + 1
position object 20,entity_x#,entity_y#,entity_z#
endif
endif
if downkey() = 1
entity_y# = entity_y# - 1
position object 20,entity_x#,entity_y#,entity_z#
if object collision(20,0) > 0
entity_y# = entity_y# + 1
position object 20,entity_x#,entity_y#,entity_z#
endif
endif
if upkey() = 1
entity_y# = entity_y# + 1
position object 20,entity_x#,entity_y#,entity_z#
if object collision(20,0) > 0
entity_y# = entity_y# - 1
position object 20,entity_x#,entity_y#,entity_z#
endif
endif
`position object 20,entity_x#,entity_y#,entity_z#
if keystate(22) = 1 then move camera -10
if keystate(32) = 1 then move camera 10
sync
loop
end
You can use the 'U' key to move the camera up and the 'D' key to move it down.
If this is a school project with just one room then the standard collision checks should be fine. If you are working on a game, you should search for Sparky's collision and use it instead.