Well I have a main loop which consists of functions:
DO
UpdateSpeed()
UpdateCameraPosition()
UpdateShipPosition()
CollisionTest()
ValueKeep()
YROTATE OBJECT 2, (Object Angle Y(2)+0.01)
TEXT 200,0, STR$(OBJECT POSITION X(3),0)
TEXT 200,10, STR$(OBJECT POSITION Y(3),0)
TEXT 200,20, STR$(OBJECT POSITION Z(3),0)
Sync
LOOP
end
And the Functions.dba source file:
Function UpdateCameraPosition()
XPos as Float
YPos as Float
ZPos as Float
XPos=Object Position X(3)
YPos=Object Position Y(3)
ZPos=Object Position Z(3)
Position Camera XPos,YPos,ZPos
Set Camera to Object Orientation 3
Move Camera -5
ENDFUNCTION
Rem Update Ship Position
Function UpdateShipPosition()
IF SCANCODE() = 30 then
ROLL OBJECT LEFT 3, 1
IF SCANCODE() = 32 then
ROLL OBJECT RIGHT 3, 1
IF UPKEY() = 1 then
PITCH OBJECT DOWN 3, 1
IF DOWNKEY() = 1 then
PITCH OBJECT UP 3, 1
IF LEFTKEY() = 1 then
TURN OBJECT LEFT 3, 1
IF RIGHTKEY() = 1 then
TURN OBJECT RIGHT 3, 1
POSITION OBJECT 780, OBJECT POSITION X(3),OBJECT POSITION Y(3),OBJECT POSITION Z(3)
ENDFUNCTION
Rem Setup Object
Function SetupObject()
AUTOCAM OFF
MAKE CAMERA 1
SET CURRENT CAMERA 1
POSITION CAMERA 1, 205, 4, 0
BACKDROP ON
COLOR BACKDROP 1, rgb(0,0,0)
LOAD IMAGE "textures/earth.jpg", 1
MAKE OBJECT SPHERE 2, 1000
TEXTURE OBJECT 2, 1
POSITION OBJECT 2,0,0,0
SC_SETUPOBJECT 2,0,1
SC_ALLOWOBJECTSCALING 2
SC_UPDATEOBJECT 2
SC_setObjectCollisionOn 2
LOAD OBJECT "objects/sky.3ds", 780
LOAD IMAGE "textures/sky.bmp", 3
TEXTURE OBJECT 780, 3
SCALE OBJECT 780, 10000,10000,10000
LOAD OBJECT "ships/probe.3ds",3
LOAD IMAGE "textures/UV.png", 2
TEXTURE OBJECT 3, 2
POSITION OBJECT 3, 500,0,0
SC_SETUPOBJECT 3,0,0
SC_ALLOWOBJECTSCALING 3
SCALE OBJECT 3, 5,5,5
SC_UPDATEOBJECT 3
SC_setObjectCollisionOn 3
POINT OBJECT 3, 0,0,0
SetupBars()
ENDFUNCTION
Rem Speed
Function UpdateSpeed()
WAIT 20
IF SCANCODE() = 17 AND SPRITE WIDTH(1) < 100 then
SIZE SPRITE 1, SPRITE WIDTH(1)+1 , 25
IF SCANCODE() = 31 AND SPRITE WIDTH(1) > 0 then
SIZE SPRITE 1, SPRITE WIDTH(1)-1 , 25
ENDFUNCTION
Rem Collision
Function CollisionDetect()
SIZE SPRITE 1, 0, 25
Hull = Hull-5
FOR x = 1 to 3
MOVE OBJECT 3, x*-1
WAIT 100
NEXT
ENDFUNCTION Hull
Rem Setup Bars
Function SetupBars()
`Start Speed Bar
LOAD IMAGE "sprites/spd.png", 100
LOAD IMAGE "sprites/back.png", 101
SPRITE 1, 10, 70, 100
SIZE SPRITE 1, 0, 25
SPRITE 2, 10, 70, 101
SIZE SPRITE 2, 100, 25
SET SPRITE 2, 0, 2
SET SPRITE PRIORITY 2, 1
`End Speed Bar
`Start Hull Bar
LOAD IMAGE "sprites/hul.png", 102
SPRITE 3, 10, 10, 102
SIZE SPRITE 3, 100, 25
SPRITE 4, 10, 10, 101
SIZE SPRITE 4, 100, 25
SET SPRITE 4, 0, 2
SET SPRITE PRIORITY 4, 2
`End Hull Bar
`Start Shield Bar
LOAD IMAGE "sprites/she.png", 103
SPRITE 5, 10, 40, 103
SIZE SPRITE 5, 100, 25
SPRITE 6, 10, 40, 101
SIZE SPRITE 6, 100, 25
SET SPRITE 6, 0, 2
SET SPRITE PRIORITY 6, 3
`End Shield Bar
ENDFUNCTION
Rem Collision Detection
Function CollisionTest()
SC_UPDATEOBJECT 2
SC_UPDATEOBJECT 3
IF SC_objectCollision (3,0) then CollisionDetect()
ENDFUNCTION Hull
Rem Value Keeping
FUNCTION ValueKeep()
SIZE SPRITE 3, Hull, 25
ENDFUNCTION Hull
I really don't like this, because its a linear only structure, so if I put a wait command in one of the functions the entire program has to suffer since it has to loop that command over and over.
Intel Core i5 3.2 GHz, 4 GB RAM, NVIDIA GeForce 9800 GT
Endangered City. An Endangered Species