This is example how to use write code cleaned and howto write Fly type camera:
file
SCREEN.dba
function _SCREEN_Create(_name as String, _w as integer, _h as Integer , _depth as Integer)
set window on
set window title _name
Set Display Mode _w,_h,_depth,1
SYNC ON : SYNC RATE 0
HIDE MOUSE
BACKDROP On
endfunction _SCREEN_Create
file
INPUT.dba
function INPUT_Camera_Movement()
if upkey()=1 or keystate(17)=1 then CAMERA_Forward(Camera_ID)
if downkey()=1 or keystate(31)=1 then CAMERA_Backward(Camera_ID)
if leftkey()=1 or keystate(30)=1 then CAMERA_StrifeLeft(Camera_ID)
if rightkey()=1 or keystate(32)=1 then CAMERA_StrifeRight(Camera_ID)
endfunction
file
CAMERA.dba
`************************************************************************************
` CAMERA: constant
`************************************************************************************
#CONSTANT _CAMERA_SPEED = 2
`************************************************************************************
` CAMERA: globals
`************************************************************************************
Global Camera_ID as Integer
`************************************************************************************
` CAMERA: Create
`************************************************************************************
function CAMERA_Create(_id as integer, _px as float, _py as float, _pz as float )
`Setup Camera
AUTOCAM OFF
Make Camera _id
POSITION CAMERA _id,_px,_py,_pz
SET CAMERA FOV _id,80
endfunction
`************************************************************************************
` CAMERA: Move forward
`************************************************************************************
function CAMERA_Forward(_id as Integer)
move camera _id, _CAMERA_SPEED
endfunction
`************************************************************************************
` CAMERA: Move backward
`************************************************************************************
function CAMERA_Backward(_id as Integer)
move camera _id, -_CAMERA_SPEED
endfunction
`************************************************************************************
` CAMERA: Strife left
`************************************************************************************
function CAMERA_StrifeLeft(_id as Integer)
angy# = camera angle y(_id)
angx# = camera angle x(_id)
xrotate camera _id,0
yrotate camera _id,angy#-90
CAMERA_Forward(_id) :
yrotate camera _id,angy#
xrotate camera _id,angx#
endfunction
`************************************************************************************
` CAMERA: Strafe right
`************************************************************************************
function CAMERA_StrifeRight(_id as Integer)
angy# = camera angle y(_id)
angx# = camera angle x(_id)
xrotate camera _id,0
yrotate camera _id,angy#+90
CAMERA_Forward(_id) :
yrotate camera _id,angy#
xrotate camera _id,angx#
endfunction
`************************************************************************************
` CAMERA: FreeLook
`************************************************************************************
function CAMERA_FreeLook(_id as Integer)
angy# = camera angle y(_id)
angx# = camera angle x(_id)
yrotate camera Camera_ID,angy#+mousemovex()/2.0
xrotate camera Camera_ID,angx#+mousemovey()/2.0
endfunction
[A] if below files are inserted to project via IDE
file main.dba
_SCREEN_Create("DEMO - 02",1024,600,32)
` load scene
set dir "data/level"
load object "simple.dbo", 1
Camera_ID = 1
CAMERA_Create(Camera_ID,0,50,-250)
do
INPUT_Camera_Movement()
CAMERA_FreeLook(Camera_ID)
sync
loop
END
[B] if below files are included to main source
#include "SCREEN.dba"
#include "INPUT.dba"
#include "CAMERA.dba"
_SCREEN_Create("DEMO - 02",1024,600,32)
` load scene
set dir "data/level"
load object "simple.dbo", 1
Camera_ID = 1
CAMERA_Create(Camera_ID,0,50,-250)
do
INPUT_Camera_Movement()
CAMERA_FreeLook(Camera_ID)
sync
loop
END