Hello all. I'm a very new user of DBPro, but a long time coder. I've been modifying the Huge Dungeon tutorial, hoping to end up with something along the lines of Dungeon Hack.
I'm testing with a small map of 20 x 20 squares, moving one square forward with each up arrow keypress. I'm not doing any collision detection, instead I'm checking the map array to see if the destination square is open before I move the camera. I'm not hiding or moving the cubes after I make them.
Here's the problem... Moving on the Z axis works fine, the walls stop my movement. On the X axis though, the cubes along the outside edge are shifted over by three squares. The cubes forming a room in the center of the dungeon are correct, and my diagnostics pick up the location and type of each cube. It's just the left and right hand edges of the map that are giving me fits.
here's the code...
REM Project: QuickHack
REM Created: 7/2/2009 7:54:15 AM
REM
REM written by Dark Richard
REM
REM based on DarkBasic Dungeon by Hubdule
REM (c) by Color Arts 2002
` Initialize some variables
backcolor=rgb(0,0,0)
mapsize=20
dim map$(mapsize,mapsize)
dim Facing$(4)
Facing$(1) = "North"
Facing$(2) = "East"
Facing$(3) = "South"
Facing$(4) = "West"
nCameraFacing = 3 ` the camera defaults to a south view
maxcubes=10
cubesize=200
nCount = 0
sync on
sync rate 350
hide mouse
set camera fov 100 ` 90 degrees is the default, this gives a somewhat wider view
backdrop on
color backdrop backcolor
fog on
fog color backcolor
fog distance (int(maxcubes/2)*cubesize)
set camera range 1,(maxcubes*cubesize)
set ambient light 60
autocam off
` Load the map
loadmap()
` Load images - these images come with the installation of DarkBASIC Professional
load image "C:\Program Files\The Game Creators\Dark Basic Professional Online\Projects\RoomDemo\media\room\LWALL.BMP",1 ` walls
load image "C:\Program Files\The Game Creators\Dark Basic Professional Online\Projects\RoomDemo\media\room\FLOOR.BMP",2 ` floor
load image "C:\Program Files\The Game Creators\Dark Basic Professional Online\Projects\RoomDemo\media\room\ROOF.BMP",3 `ceiling
for z = 1 to mapsize ` do the floor and ceiling
for x = 1 to mapsize
a$= map$(x,z)
if a$ <> "#"
inc nCount
make object plain nCount,cubesize,cubesize ` floor
texture object nCount,2
rotate object nCount,270,0,0
position object nCount,x*cubesize,(cubesize/2)*(-1),z*cubesize
show object nCount
inc nCount
make object plain nCount,cubesize,cubesize ` ceiling
texture object nCount,3
rotate object nCount,90,0,0
position object nCount,x*cubesize,(cubesize/2),z*cubesize
show object nCount
endif
next x
next z
for z = 1 to mapsize ` do the walls
for x = 1 to mapsize
a$ = map$(x,z)
if a$ = "#"
inc nCount
make object cube nCount,cubesize ` wall
texture object nCount,1
position object nCount,x*cubesize,0.0,z*cubesize
show object nCount
endif
if a$="S" ` Starting location
PlayerX = x
PlayerZ = z
endif
next x
next z
position camera (PlayerX*cubesize),0,PlayerZ*cubesize
sync
REM ******************************* MAIN LOOP ***********************
do
if upkey()=1
select nCameraFacing
case 1 ` check facing north move
NextMap$=map$(PlayerX,PlayerZ-1)
if NextMap$ <> "#"
Dec PlayerZ
for myx = 1 to 200
move camera 1
sync
next myx
NextMap$=map$(PlayerX,PlayerZ-1)
endif
endcase
case 2 ` check facing east move
NextMap$=map$(PlayerX+1,PlayerZ)
if NextMap$ <> "#"
Inc PlayerX
for myx = 1 to 200
move camera 1
sync
next myx
NextMap$=map$(PlayerX+1,PlayerZ)
endif
endcase
case 3 ` check facing south move
NextMap$=map$(PlayerX,PlayerZ+1)
if NextMap$ <> "#"
Inc PlayerZ
for myx = 1 to 200
move camera 1
sync
next myx
NextMap$=map$(PlayerX,PlayerZ+1)
endif
endcase
case 4 ` check facing west move
NextMap$=map$(PlayerX-1,PlayerZ)
if NextMap$ <> "#"
Dec PlayerX
for myx = 1 to 200
move camera 1
sync
next myx
NextMap$=map$(PlayerX-1,PlayerZ)
endif
endcase
endselect
endif
REMSTART disabled for testing
if downkey()=1
for myx = 1 to 200
move camera -1
sync
next myx
endif
REMEND
if leftkey()=1
for myx = 1 to 180
turn camera left 0.5
sync
next myx
dec nCameraFacing
if nCamerafacing = 0 then nCameraFacing = 4
select nCameraFacing
case 1
NextMap$=map$(PlayerX,PlayerZ-1)
endcase
case 2
NextMap$=map$(PlayerX+1,PlayerZ)
endcase
case 3
NextMap$=map$(PlayerX,PlayerZ+1)
endcase
case 4
NextMap$=map$(PlayerX-1,PlayerZ)
endcase
endselect
endif
if rightkey()=1
for myx = 1 to 180
turn camera right 0.5
sync
next myx
inc nCameraFacing
if nCamerafacing = 5 then nCameraFacing = 1
select nCameraFacing
case 1
NextMap$=map$(PlayerX,PlayerZ-1)
endcase
case 2
NextMap$=map$(PlayerX+1,PlayerZ)
endcase
case 3
NextMap$=map$(PlayerX,PlayerZ+1)
endcase
case 4
NextMap$=map$(PlayerX-1,PlayerZ)
endcase
endselect
endif
set cursor 1,1
print "X:" + str$(PlayerX) + " Z:" + str$(PlayerZ) + " Map$:" + map$(PlayerX,PlayerZ) + " NextMap$:" + NextMap$
print "Facing " + Facing$(nCameraFacing)
sync
loop
function loadmap()
for z = 1 to 20
read a$
for x = 1 to 20
map$(x,z) = mid$(a$,x)
next x
next z
data "####################"
data "#..................#"
data "#..................#"
data "#..................#"
data "#..................#"
data "#..................#"
data "#..................#"
data "#.....#####........#"
data "#.....#...#........#"
data "#.....#.S.#........#"
data "#.....#...#........#"
data "#.....##.##........#"
data "#..................#"
data "#.....#####........#"
data "#..................#"
data "#..................#"
data "#..................#"
data "#..................#"
data "#..................#"
data "####################"
endfunction
You should be able to see what I mean. Try moving to the west or east edges of the map.
It's probably something really obvious, but I'm just not seeing the problem.
Thanks in advance for any help.
Richard