TGC Codebase Backup



Simple camera movement system by Anonymous Coder

19th Feb 2005 14:39
Summary

This is the first version of a set of simple movement functions.



Description

I have used small parts of code and some of the basic principals to make this. Remember to add the arra declariation to your main game file not your include file!!

To Do:
------
* Add a mouse movement function
* Add a better physics system
* Add a jump system
* Add a shooting system
* Add a collision function



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    


Rem Do not try to run this program without a main loop as it will not work


Rem IF YOU ARE GOING TO INCLUDE THE FUNCTION FILE (THIS FILE) YOU MUST ADD THE ARRAY DECLARATION TO YOUR MAIN GAME FILE NOT YOUR FUNCTION FILE
REM IF NOT STILL INCLUDE THEM IN THE FILE!!!!!

REMSTART
REM ADD THIS TO YOUR MAIN FILE

Rem These are needed!! do not delete them!!
Rem initilise importaant variables
dim camSpeed#(1)
dim camXspeed#(1)
dim camYspeed#(1)
dim camZspeed#(1)
dim gravity#(1)

camSpeed#(1) = 10
gravity#(1) = 0.1
Rem ^^^^^^^^^^^^^ DO NOT DELETE

REMEND



remstart
rem to test this program

Rem These are needed!! do not delete them!!
Rem initilise importaant variables
dim camSpeed#(1)
dim camXspeed#(1)
dim camYspeed#(1)
dim camZspeed#(1)
dim gravity#(1)

camSpeed#(1) = 10
gravity#(1) = 0.1
Rem ^^^^^^^^^^^^^ DO NOT DELETE

Sync On
Sync Rate 30
Hide mouse
Backdrop on
Set camera range 1,5000

autocam off

Fog on
Fog distance 4000
Fog color RGB(128,128,128)
Color Backdrop RGB(128,128,128)

Rem make matrix variables
mX# = 10000
mZ# = 10000

Rem make matrix
Make matrix 1,mX#,mZ#,20,20

rem Randomize the matrix
randomize matrix 1,125
X#=5000
Z#=5000



do

if upkey() = 1 then cam_move(1,0,0,0)
if downkey() = 1 then cam_move(0,1,0,0)
if leftkey() = 1 then cam_move(0,0,1,0)
if rightkey() = 1 then cam_move(0,0,0,1)

cam_physics()

sync


loop

remend

function cam_move(fward, bward, sleft, sright)


Rem get important variables
camX# = camera position X()
camY# = camera position Y()
camZ# = camera position Z()

camAX# = camera angle X()
camAY# = camera angle Y()
camAZ# = camera angle Z()

if fward = 1
Rem if the fward variable is 1

newcamX# = newxvalue(camX#, camAY#, camSpeed#(1))
newcamZ# = newZvalue(camZ#, camAY#, camSpeed#(1))

endif

if bward = 1

newcamX# = newxvalue(camX#, camAY#, -5)
newcamZ# = newZvalue(camZ#, camAY#, -5)

endif


if sleft = 1

newcamX# = newxvalue(camX#, wrapvalue(camAY# + 90), -5)
newcamZ# = newZvalue(camZ#, wrapvalue(camAY# + 90), -5)

endif

if sright = 1

newcamX# = newxvalue(camX#, wrapvalue(camAY# - 90), -5)
newcamZ# = newZvalue(camZ#, wrapvalue(camAY# - 90), -5)

endif


camX# = newcamX#
camZ# = newcamZ#

position camera camX#, camY#, camZ#

fward = 0

endfunction

function cam_physics()



Rem get important variables
camX# = camera position X()
camY# = camera position Y()
camZ# = camera position Z()

camAX# = camera angle X()
camAY# = camera angle Y()
camAZ# = camera angle Z()


Rem add gravity
camYspeed#(1) = camYspeed#(1) + gravity#(1)

camY# = camY# - camYspeed#(1)

   `work out the height of the character
   if camY#<get ground height(1,camX#,camZ#) + 50
      camY#=get ground height(1,camX#,camZ#) + 50
   endif

position camera camX#, camY#, camZ#


endfunction