Hello!
I've just been playing around with darkBasic for the last couple of days, browsing tutoials and example code. To learn more, I wanted to create a simple FPS, but I got stuck on the "gun movement". How would I do to make my gun not go out of screen when I look around with the mouse?
Sync On
Sync Rate 30
Hide mouse
Backdrop on
Set camera range 1,5000
Fog on
Fog distance 4000
Fog color RGB(128,128,128)
Color Backdrop RGB(128,128,128)
Rem make matrix
Make matrix 1,10000,10000,20,20
Rem texture matrix
Load image "grass09.bmp",1
Prepare matrix texture 1,1,1,1
Fill matrix 1,0,1
rem Randomize the matrix
randomize matrix 1,125
X#=5000
Z#=5000
//Map
Load Object "testMap.x",100
Position Object 100,0,120,-1200
SC_SetupObject 100,0,0
Load Image "hk53_n.bmp",4219
//Character
Make Object Sphere 1,25
Position Object 1,-700,160,-1400
//HIDE Object 1
//Gun
Load Object "hk53_n.3ds",101
Texture Object 101,4219
//Bottom collision
Make Object sphere 10,1
MAKE MESH FROM OBJECT 1,10
DELETE OBJECT 10
ADD LIMB 1,1,1
OFFSET LIMB 1,1,0,1,0
HIDE LIMB 1,1
position object 101,5000,Get Ground Height(1,5000,5500),5500
turn object left 101,14
Do
//Cursor
//paste image cursor,mousex()-100,mousey()-100,1
//position object 101, camera position x(),camera position y() - 15,camera position z() + 15
position object 1, camera position x(),camera position y() - 15,camera position z() + 15
yrotate camera camera angle y()+mousemovex()
xrotate camera camera angle x()+mousemovey()
//position camera object position x(1),object position y(1),object position z(1)
oldx# = object position x(1)
oldy# = object position y(1)
oldz# = object position z(1)
//Control camera
If Upkey()=1
XTest# = Newxvalue(X#,CameraAngleY#,10)
ZTest# = Newzvalue(Z#,CameraAngleY#,10)
If XTest#>0 and XTest#<10000 and ZTest#>0 and ZTest#<10000
X#=XTest#
Z#=ZTest#
Endif
Endif
If Downkey()=1
XTest# = Newxvalue(X#,Wrapvalue(CameraAngleY#-180),10)
ZTest# = Newzvalue(Z#,Wrapvalue(CameraAngleY#-180),10)
If XTest#>0 and XTest#<10000 and ZTest#>0 and ZTest#<10000
X#=XTest#
Z#=ZTest#
Endif
Endif
If Leftkey()=1
XTest# = Newxvalue(X#,Wrapvalue(CameraAngleY#-90),10)
ZTest# = Newzvalue(Z#,Wrapvalue(CameraAngleY#-90),10)
If XTest#>0 and XTest#<10000 and ZTest#>0 and ZTest#<10000
X#=XTest#
Z#=ZTest#
Endif
Endif
If Rightkey()=1
XTest# = Newxvalue(X#,Wrapvalue(CameraAngleY#+90),10)
ZTest# = Newzvalue(Z#,Wrapvalue(CameraAngleY#+90),10)
If XTest#>0 and XTest#<10000 and ZTest#>0 and ZTest#<10000
X#=XTest#
Z#=ZTest#
Endif
Endif
//Gravity
IF INTERSECT OBJECT (100, LIMB POSITION X(1,1), LIMB POSITION Y(1,1), LIMB POSITION Z(1,1), OBJECT POSITION X(1),OBJECT POSITION Y(1), OBJECT POSITION Z(1)) < 1
IF JUMPING#=0
POSITION OBJECT 1,OBJECT POSITION X(1),OBJECT POSITION Y(1) - SPEED#,OBJECT POSITION Z(1)
ENDIF
ENDIF
//End of gravity
//Jumping
//IF UPKEY()=1 AND JUMPING#=0
//IF INTERSECT OBJECT (5492, LIMB POSITION X(2000,1), LIMB POSITION Y(2000,1), LIMB POSITION Z(2000,1), OBJECT POSITION X(2000),OBJECT POSITION Y(2000), OBJECT POSITION Z(2000))>0
//JUMP#=1
//ENDIF
//ENDIF
IF JUMP#=1
JUMP_SPEED#=2:JUMPING#=1:JUMP#=0
ENDIF
IF JUMPING#=1
DEC JUMP_SPEED#,.015
POSITION OBJECT 1,OBJECT POSITION X(1),OBJECT POSITION Y(1)+JUMP_SPEED#, OBJECT POSITION Z(1)
IF INTERSECT OBJECT (100, LIMB POSITION X(1,1), LIMB POSITION Y(1,1), LIMB POSITION Z(1,1), OBJECT POSITION X(1),OBJECT POSITION Y(1), OBJECT POSITION Z(1))>0 THEN JUMPING#=0
ENDIF
Sync
Loop
Thanks in advance!