TGC Codebase Backup



First Person Shooter upgraded by Francesco

4th May 2004 14:11
Summary

Move forwards with "w", backwards with "s". Change direction with the mouse. Jump with "ctrl". Click to shoot. Try to get the yellow ball before it ca



Description

The jump part is not very well coded, but that's the best thing I could make. Sorry if the code is so much of a mess...SORRY!!



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    hide mouse
start:
j#=timer()

autocam off
hide mouse
rem Make a floor texture
cls rgb(0,255,0)
get image 1,0,0,32,32
backdrop on

`make objects and matrix

make object box 4,2,2,15
position object 4,0,-5,-250
make matrix 1,4000,4000,50,100
randomize matrix 1,50
prepare matrix texture 1,1,1,1
d#=0
make object sphere 5,50
color object 5,-255
position object 5,rnd(4000),get ground height(1,object position x(5)+25,object position z(5))+50,rnd(4000)
Fog on
Fog distance 2000
Fog color RGB(0,0,-100)
Color Backdrop RGB(0,0,-100)
set matrix wireframe off 1
set normalization on
Make object cylinder 1,2
xrotate object 1,90
fix object pivot 1 
scale object 1,100,100,500
position object 1,0,object position y(4),15
lock object on 1
make object sphere 2,3
color object 2,0
hide object 2
hide object 4
set ambient light 20
set point light 0,10,10,10
position light 0,2000,300,2000
make light 1
set spot light 1,30,50
position light 1,object position x(4),object position y(4)-20,object position z(4)
`set camera and sync
set camera range 1,3000
set light range 1,10000
color light 1,-255
sync on
d#=50
ert:
l#=timer()



`begin game loop
do
position light 1,object position x(4),object position y(4),object position z(4)
point light 1,object position x(5),object position y(5),object position z(5)
`position camera at location and rotation of object 4
position camera object position x(4),object position y(4),object position z(4)
rotate camera object angle x(4),object angle y(4),object angle z(4)
`define camera variables
wvtx=object angle x(4)
wvty=object angle y(4)
wvtz=object angle z(4)
wcax=wrapvalue(wvtx)
wcay=wrapvalue(wvty)
wcaz=wrapvalue(wvtz)
`controls
	`aiming
cya#=wrapvalue(cya#+(mousemovex()/3.0))
cxa#=cxa#+(mousemovey()/3.0)
if cxa#<-45.0 then cxa#=-45.0
if cxa#>45.0 then cxa#=45.0
cx#=newxvalue(x#,cya#,sin(cxa#)*10)
cz#=newzvalue(z#,cya#,sin(cxa#)*10)
rotate camera wrapvalue(cxa#),cya#,0
rotate object 4,0,camera angle y(),0
position camera object position x(4),object position y(4),object position z(4)
	`walking
If keystate(17)=1 then move object 4,8
If keystate(31)=1 then move object 4,-8
if object position x(4)<0 then position object 4,0,object position y(4),object position z(4)
if object position z(4)<0 then position object 4,object position x(4),object position y(4),0
if object position x(4)>4000 then position object 4,4000,object position y(4),object position z(4)
if object position z(4)>4000 then position object 4,object position x(4),object position y(4),4000

	`jumping
position object 4,object position x(4),get ground height(1,object position x(4),object position z(4))+80,object position z(4)
if controlkey()=1 and ajump=1
	jumpb=1
	height=200
endif
if jumpb=1
	height=height-5
	position object 4,object position x(4),object position y(4)+height,object position z(4)
endif
if object position y(4)>250 then ajump=0 else ajump=1
if object position y(4)<120
	position object 4,object position x(4),object position y(4)+height,object position z(4)
	jump=0
	height=0
endif
if object collision(5,2)=1
position object 5,rnd(4000),get ground height(1,object position x(5),object position z(5))+25,rnd(4000) : goto ert
endif


	`shooting
if mouseclick()>0 and dst=0
	shot=1
	bdst=1
	show object 2
	position object 2,object position x(4),object position y(4)-1,object position z(4)
	rotate object 2,camera angle x(),camera angle y(),camera angle z()
endif
if object position x(2)<0 or object position x(2)>4000 or object position z(2)>4000 or object position z(2)<0 or object position y(2)<0 or object position y(2)>1000
	hide object 2
	dst=0
	shot=0
endif
if shot=1
	dst=dst+1
	bdst=bdst+1
endif
if shot=1
	move object 2,50
	dst=dst+1
endif

if 8000<=(timer()-l#)
position object 5,rnd(4000),get ground height(1,object position x(5),object position z(5))+25,rnd(4000) : d#=d#-10 : goto ert
endif
r#=timer()
if object collision(5,2)=1 then d#=d#+10
if d#=>100 then goto erg
if d#=<0 then goto lose

   `radar box you can change these values to suit your needs
   INK RGB(0,255,0),0
  box 320,10,360,50
	
   INK RGB(255,0,0),0
     `This if assumes your character is object number 1.
      `It gives your object's circle a larger radius and a different colour.
         radius# = 2
         INK RGB(255,0,0),0
CIRCLE ((SCREEN WIDTH()-320)+(OBJECT POSITION X(4)/100)),(50 - (OBJECT POSITION Z(4)/100)),radius#
ink rgb(0,0,-255),0
CIRCLE ((SCREEN WIDTH()-320)+(OBJECT POSITION X(5)/100)),(50 - (OBJECT POSITION Z(5)/100)),radius#

      sync


   `d# is the the d#ent of the "health"
   `img is the image number you wish to use for the texture for the Health Bar object
   `obj is the Object Number of the Health Bar

   `This Simply draws a box to the screen, with red indicating health, white indicating a lack of health,
   `the image is then captured as a texture and applied to the object.

   `You'll notice that you can see the box being drawn to the screen, this should disapear when you put
   `this function into your main app...
   `If it does not, at the start of your code, put the command Draw To Back
   `This will draw all 2D operations behind any 3D on the screen.


   Ink RGB(255,255,0),0
   Box 10,30,110,40
   Ink RGB(0,-255,0),0
	Box 10,30,d#+10,40 
   if d#>110 then d#=110
	if d#<10 then d#=10
   
set cursor 10,10
print "Score: ",d#
set cursor 10,50
print "You have ",8-(timer()-l#)/1000," seconds to get the ball"

`sync
`end game loop
set cursor 10,100
print "Press R to win"
if inkey$()="r" then goto erw
loop

erg:
j#=timer()
delete object 1
delete object 2
delete object 4
delete object 5
delete matrix 1
delete light 1
backdrop off
do
cls 0 : set cursor 320,240 : print "YOU WON!!!!"
sync
if 3000<(timer()-j#) then goto start
loop
lose:
j#=timer()
delete object 1
delete object 2
delete object 4
delete object 5
delete matrix 1
delete light 1
backdrop off
do
cls 0 : set cursor 320,240 : print "YOU LOSE!!!!"
sync
if 3000<(timer()-j#) then goto start
loop
erw:
j#=timer()
delete object 1
delete object 2
delete object 4
delete object 5
delete matrix 1
delete light 1
backdrop off
do
cls 0 : set cursor 320,240 : print "YOU ARE A CHEATER!!!!"
sync
if 3000<(timer()-j#) then goto start
loop