I've uploaded my game code for a dwarf fortress tribute. I've sort of hit a crossroads. I don't really know how to restrict the movement of my 3d camera.
I tried using a collision box, which used a csg difference to carve out a centre, and then 'attached' a hidden object to the camera and it was supposed to reset the position when it collided. But it hasn't worked so far.
I removed that part of the code because Im assuming the csg difference wouldn't allow for collision or something.
Can anyone help?
Rem Project: DFDFDF
Rem Created: Thursday, September 02, 2010
Rem ***** Main Source File *****
Rem Project: DF Tribute
Rem Created: Tuesday, August 24, 2010
Rem ***** Main Source File *****
`random
randomize timer()
`resolution
sync on : sync rate 60
if check display mode(1024,768,32)=1
set display mode 1024,768,32
endif
autocam off
set cursor (screen width()/2), (screen height()/2)
`vars
tankSize = 10
secObjectRange = (tankSize*tankSize*tankSize*tankSize)
rotY# = 1
flippidiBox = 1
lightZpos = 1
objInQuestion = 1
MainCameraNum = 1
CAMROTATE# = 1.0
`camera
make camera MainCameraNum
set current camera MainCameraNum
set camera range MainCameraNum, 1, secObjectRange
backdrop on : color backdrop 0
`lighting
make light 1
set spot light 1, 90, 180
set ambient light 0
color ambient light rgb(32,64,128)
//direct lighting
make light 2
set directional light 2, 0, 180, 0
color light 2, RGB(255,192,160)
//fog on
//fog distance 10000
//fog color rgb(255,128,64)
position light 1,(tankSize/2),(tankSize/2), (-1*(lightZpos))
point light 1,(tankSize/2),(tankSize/2), 0
color light 1,512,512,255
set light range 0,1000
`images
load image "smoke.jpg", 1
load image "dirt.jpg", 2
load image "question.png", 3
load image "boundary.png", 4
load image "heavens.jpg", 5
`array and type.
type flippidi
xPos as integer
yPos as integer
value as integer
toughness as integer
rockname as string
textureNumber as integer
fuel as boolean
flammable as boolean
underFog as boolean
boundary as boolean
endtype
remstart
grid(10,10).xPos=x
remend
`it is 11 across and 11 down
CamRate = 10
createCam(MainCameraNum, (tankSize/2), (tankSize/2)*3, (tankSize/4)*-2, (tankSize/2),(tankSize/2), 20)
`boxes array
dim grid(tankSize,tankSize,tankSize) as flippidi
`Creates 100 boxes (100 for debug)
for x=1 to tankSize
for y=1 to tankSize
for z=1 to tankSize
make object box flippidiBox,1,1,1
position object flippidiBox,x,y,z
texture object flippidiBox, 1
//default values for each box
grid(x,y).value=0
grid(x,y).rockname="default"
grid(x,y).toughness=13
grid(x,y).fuel=0
grid(x,y).flammable=0
grid(x,y).textureNumber=1
grid(x,y).underFog=1
grid(x,y).boundary=0
inc flippidiBox
next z
next y
next x
//designate box boundaries atm this code does nothing
for x=1 to tankSize
for y=1 to tankSize
grid(x,y).boundary=0
next y
next x
`sky sphere
make object sphere secObjectRange, (tankSize*tankSize)
position object secObjectRange,(tankSize/2),(tankSize/2),(tankSize/2)
texture object secObjectRange, 5
scale object secObjectRange,-100,-100,-100
set object light secObjectRange, 1
SET OBJECT SMOOTHING secObjectRange,1000
//this cam setting is a cool cam setting for staring down the side of the abyss hehe
//createCam(MainCameraNum, (tankSize/2), (tankSize/2)*2, -5, (tankSize/2),(tankSize/2), 0)
//createCam(MainCameraNum, (tankSize/2),(tankSize/2),(-2 * tankSize), (tankSize/2),(tankSize/2),0)
//zoomCam(MainCameraNum, (tankSize/2), (tankSize/2), (-2 * tankSize), (tankSize),(tankSize*2), 0, CamRate)
do
//returns the object number the mouse is over
objMouseUnder = pick object(mousex(),mousey(),mousez(),tankSize*tankSize*tankSize) `third dimension
camXValue = camera position x(MainCameraNum)
text 0,240,"Camera X:" + str$(camXValue)
camYValue = camera position y(MainCameraNum)
text 0,270,"Camera Y:" + str$(camYValue)
camZValue = camera position z(MainCameraNum)
text 0,300,"Camera Z:" + str$(camZValue)
//digging handler
digging(lastDugX, lastDugY)
aboveGroundLightMeUp()
text 0,210,"Null:" + str$(objNull)
if ((objMouseUnder > 1) && (objMouseUnder <= (tankSize*tankSize*tankSize))) `threw in a third dimension here
//x, y of block in question
objXValue = object position x(objMouseUnder)
objYValue = object position y(objMouseUnder)
objZValue = object position z(objMouseUnder)
//'Text Viewer', sprite display handler
boundaryAndFogDetect(objXValue, objYValue, 1)`third value is null value. i.e '0'won't run, '1' will run.
else
boundaryAndFogDetect(objXValue, objYValue, 0) `null value.
endif
//loopingFog(objXValue, objYValue)
//light handler
spotLightHandler(objMouseUnder, lightZpos)
//camera handler
//movement handler (bitwise)
remstart
if the only the downkey was pressed (0 || 2 || 0 || 0),
the flags value would be 2. If the downkey and the leftkey were pressed
(0 || 2 || 4 || 0), the value of flags would be 6.
If all keys were pressed, the value of flags would be 15.
remend
MWheelValue = mousemovez()
//movementFlag = (upkey() || downkey() << 1 || leftkey() << 2 || rightkey() << 3) `
if leftkey()=1 then turn camera left MainCameraNum,1
if rightkey()=1 then turn camera right MainCameraNum,1
if upkey()=1 then pitch camera up MainCameraNum,1
if downkey()=1 then pitch camera down MainCameraNum,1
if (MWheelValue<=120 && MWheelValue < 0)
move camera MainCameraNum, -1.0
endif
if (MWheelValue>=-120 && MWheelValue > 0)
move camera MainCameraNum, 1.0
endif
//make object cube (tankSize*tankSize)-tankSize
//position object (tankSize/2),(tankSize/2),(tankSize/2)
//debug text output
text 0,100, "Object Number:" + str$(objMouseUnder)
if objMouseUnder > 1
objXValue = object position x(objMouseUnder)
text 0,130,"Object X:" + str$(objXValue)
objYValue = object position y(objMouseUnder)
text 0,160,"Object Y:" + str$(objYValue)
objZValue = object position z(objMouseUnder)
text 0,190,"Object Z:" + str$(objZValue)
objZValue = object position z(objMouseUnder)
text 0,610,"movement:" + str$(movementFlag)
text 0,640,"mousewheel:" + str$(MWheelValue)
endif
sync
loop
remstart
function zoomCam(camera, x, y, z, aspX, aspY, aspZ, rate)
//for n = 1 to rate step 1
position camera camera, 10, y, z
point camera camera, aspX, aspY, aspZ
//wait 100
//next n
endfunction
remend
function boundaryAndFogDetect(DIGSQUAREX as dword , DIGSQUAREY as dword , isNull as Boolean )
//routine 'if a channel is dug' do these standard checks.
//routine 'if mouse is not over a box' do these, elsewise do nothing
if isNull <> 0
if grid(DIGSQUAREX,DIGSQUAREY).underFog = 1
//object is under fog.
sprite 1, (screen width()/2), (screen height()-30), 3
endif
if grid(DIGSQUAREX,DIGSQUAREY).boundary=1
sprite 1, (screen width()/2), (screen height()-30), 4
endif
else if sprite exist(1)
delete sprite 1
endif
endif
endfunction
function digging(DIGSQUAREX as dword , DIGSQUAREY as dword )
//routine 'if a channel is dug' do these standard checks.
//checks include: isAboveGround for lighting, texturing the objects around it,
//grid(x,y).textureNumber=1
endfunction
function aboveGroundLightMeUp()
//needs to test if the box is above ground, or dug out
endfunction
//this function will light up any block when the boolean 'grid(x,y).underFog' is True
function spotLightHandler(object as integer , light as float )
if (object > 0) `if an object exists
//if the array index is underfog, texture the box
point light 1, object position x(object), object position y(object), 0
position light 1,object position x(object), object position y(object), (-1*(light))
endif
endfunction
function createCam(cameraNum, camX, camY, camZ, camAspectX, camAspectY, camAspectZ)
set current camera cameraNum
position camera cameraNum, camX, camY, camZ
point camera cameraNum, camAspectX, camAspectY, camAspectZ
endfunction