TGC Codebase Backup



Latest FPS Base by Tim Ballisto

9th Apr 2004 11:01
Summary

My latest(And much improved)version of FPS Base. Great for Newbies.



Description

This version has 3 enemies, all with simple AI, ammunition boxes, health boxes, a pause feature, more simple effects, and an accuracy counter. Runs at about 45 FPS on a Pentium 4.
A,S,D,W to move, leftclick to fire, rightclick to jump, mouse to aim, and p to pause (any other key unpauses the game.)



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    remstart
Aim with mouse.
Shoot with left mousekey.
Jump with right mousekey.
Move with A,S,D,W keys.
Pause with P
Unpause with any key except P
remend

hide mouse
autocam off
make object plain 2,162,120
lock object on 2
position object 2,0,0,100
`name object numbers
dim enemy(3)
dim ebullet(3)
dim eshot(3)
dim dstoe(3)
dim dstoeb(3)
gun=1
screenface=2
bullet=3
self=4
ammunition=5
forward=6
enemy(1)=7
ebullet(1)=8
health=9
enemy(2)=10
ebullet(2)=11
enemy(3=)12
ebullet(3)=13
`make objects and matrix
make object box health,50,150,50
position object health,rnd(4000),75,rnd(4000)
make object sphere enemy(1),100
make object sphere enemy(2),100
make object sphere enemy(3),100
color object enemy(1),rgb(0,255,0)
color object enemy(2),rgb(0,255,0)
color object enemy(3),rgb(0,255,0)
position object enemy(1),rnd(4000),100,rnd(4000)
position object enemy(2),rnd(4000),100,rnd(4000)
position object enemy(3),rnd(4000),100,rnd(4000)
make object cylinder forward,1
scale object forward,100,100,25000
hide object forward
make object sphere 4,50
position object 4,200,100,200
make matrix 1,4000,4000,60,60
make object cylinder 1,2
hide object gun
xrotate object gun,90
fix object pivot gun
color object gun,rgb(100,100,100)
scale object gun,100,100,500
position object gun,0,-7,15
lock object on gun
make object sphere 3,5
hide object bullet
color object bullet,rgb(255,0,0)
make object sphere ebullet(1),5
color object ebullet(1),rgb(255,0,0)
hide object ebullet(1)
make object sphere ebullet(2),5
color object ebullet(2),rgb(255,0,0)
hide object ebullet(2)
make object sphere ebullet(3),5
color object ebullet(3),rgb(255,0,0)
hide object ebullet(3)
hide object self
`set camera and sync
set camera range 1,5000
sync on
sync rate 100
`begin game loop
hide object screenface
show object gun
make object box ammunition,50,150,50
position object ammunition,rnd(4000),75,rnd(4000)
color object ammunition,rgb(50,50,50)
color object health,rgb(255,0,0)
startgame:
do
ncpx#=object position x(self)
ncpy#=object position y(self)
ncpz#=object position z(self)
rem ##############################AI
for econ=1 to 3 step 1
ehitu=object collision(self,0)
set object to object orientation enemy(econ),self
move object enemy(econ),-10
if dstoe<3000 and eshot(econ)=0
	position object ebullet(econ),object position x(enemy(econ))

,object position y(enemy(econ)),object position z(enemy(econ))
	set object to object orientation enemy(econ),self
	rotate object ebullet(econ),object angle x(enemy(econ)),object 

angle y(enemy(econ)),object angle z(enemy(econ))
	show object ebullet(econ)
	eshot(econ)=1
endif
if eshot(econ)=1
	move object ebullet(econ),-50
	if ehitu=ebullet(econ)
		corr=corr+5
		hide object ebullet(econ)
		eshot(econ)=0
		ssx=rnd(640):ssy=rnd(480)
		line ssx,ssy,0,0:line ssx,ssy,320,0:line ssx,ssy,0,240:

line ssx,ssy,640,0:line ssx,ssy,0,480:
		line ssx,ssy,680,480:line ssx,ssy,320,480:line ssx,ssy,

640,240:line ssx,ssy,640,480:line ssx,ssy,640,480:
	endif
	if dstoeb(econ)>3000
		hide object ebullet(econ)
		eshot(econ)=0
	endif
endif
next econ
rem ########################
if ehitu=ammunition
	position object ammunition,rnd(4000),75,rnd(4000)
	ammo=ammo+50
endif
if ehitu=health
	position object health,rnd(4000),75,rnd(4000)
	corr=corr-5
endif
rem ############################AI
camx#=camera position x()
camy#=camera position y()
camz#=camera position z()
for eds=1 to 3 step 1
dstoe(eds)=sqrt((object position x(enemy(eds))-camx#)^2+(object position 

y(enemy(eds))-camy#)^2+(object position z(enemy(eds))-camz#)^2)
dstoeb(eds)=sqrt((object position x(enemy(eds))-object position x(

ebullet(eds)))^2+(object position y(enemy(eds))-object position y(

ebullet(eds)))^2+(object position z(enemy(eds))-object position z(

ebullet(eds)))^2)
next eds
set cursor 0,0
if corr>99
	corr=0
	kills=0
	ammo=1000
	for c=0 to 255 step 20
		cls rgb(c,0,0)
		if fog available()=1 then fog distance (c*5) : fog color 

(c*256*256)
		sync
	next c
endif
if ammo<100 then ink rgb(150,0,0),1
print "Charges: ";ammo
if ammo<100 then ink rgb(255,255,255),1
if corr>90
	ink rgb(150,0,0),1
endif
if corr>=0
	print "Corruption: ";corr;"%"
endif
if corr<0
	print "Encryption: ";abs(corr)/5;"Mb"
endif
if corr>90 then ink rgb(255,255,255),1
print "Viruses Deleted: ";kills
if shots>0
	shots#=shots
	kills#=kills
	acc=(kills#/shots#)*100
endif
print "Accuracy: ";acc;"%"
print "Frames/S:",screen fps()
ncxa#=camera angle x()
ncya#=camera angle y()
`keep player in bounds
nibopx#=object position x(self)
nibopy#=object position y(self)
nibopz#=object position z(self)
`position camera at location and rotation of object self
position camera object position x(self),object position y(self),object 

position z(self)
rotate camera object angle x(self),object angle y(self),object angle z(

self)
`define camera variables
wvtx=object angle x(self)
wvty=object angle y(self)
wvtz=object angle z(self)
wcax=wrapvalue(wvtx)
wcay=wrapvalue(wvty)
wcaz=wrapvalue(wvtz)
`controls
   `aiming

rotate camera wrapvalue(cxa#),cya#,0
rotate object self,0,camera angle y(),0
position camera object position x(self),object position y(self),object 

position z(self)

   `walking
if keystate(25)=1 then gosub paused
if keystate(17)=1
   x#=newxvalue(x#,cya#,16.0) : z#=newzvalue(z#,cya#,16.0)
endif
if keystate(31)=1
   x#=newxvalue(x#,cya#,-16.0) : z#=newzvalue(z#,cya#,-16.0)
endif
if keystate(30)=1
   x#=newxvalue(x#,wrapvalue(cya#-90.0),20.0)
   z#=newzvalue(z#,wrapvalue(cya#-90.0),20.0)
endif
if keystate(32)=1
   x#=newxvalue(x#,wrapvalue(cya#+90.0),20.0)
   z#=newzvalue(z#,wrapvalue(cya#+90.0),20.0)
endif
   `jumping
if jumpb=1
   height#=height#-.7
endif
if mouseclick()=2 and ajump=1
   jumpb=1
   height#=15
endif
if height#<-13 then height#=-13
if object position y(self)>100 then ajump=0 else ajump=1
position object self,object position x(self),object position y(self)+

height#,object position z(self)
if object position y(self)<100
   jumpb=0
   height#=0
endif
   `shooting
if shot=1
	if object collision(forward,enemy(1))=1
		kills=kills+1
		position object enemy(1),rnd(4000),100,rnd(4000)
	endif
	if object collision(enemy(2),forward)=1
		kills=kills+1
		position object enemy(2),rnd(4000),100,rnd(4000)
	endif
	if object collision(enemy(3),forward)=1
		kills=kills+1
		position object enemy(3),rnd(4000),100,rnd(4000)
	endif
endif
if mouseclick()=1 and dst=0 and ammo>0
	set ambient light 25
	if light exist(1) then delete light 1
	make light 1
	shots=shots+1
	ammo=ammo-1
   shot=1
   bdst=1
   dst=1
   show object bullet
   position object bullet,camera position x(),camera position y(),camera 

position z()
   rotate object bullet,camera angle x(),camera angle y(),camera angle 

z()
	rotate object forward,object angle x(bullet),object angle y(

bullet),object angle z(bullet)
	position object forward,object position x(bullet),object 

position y(bullet),object position z(bullet)
endif
if object position x(bullet)<0 or object position x(bullet)>4000 or 

object position z(bullet)>4000 or object position z(bullet)<0 or object 

position y(bullet)<0 or object position y(bullet)>1000
	set ambient light 50
   hide object bullet
   dst=0
   shot=0
endif
if shot=1
	position object forward,object position x(bullet),object 

position y(bullet),object position z(bullet)
   dst=dst+1
   bdst=bdst+1
rem	position light 1,object position x(bullet),object position y(

bullet),object position z(bullet)
   move object bullet,250
   dst=dst+1
	set point light 1,object position x(bullet),object position y(

bullet),object position z(bullet)
endif
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#))
cz#=newzvalue(z#,cya#,sin(cxa#))
if cz#<0
	cz#=ncpz#
	z#=ncpz#
endif
if cz#>4000
	cz#=ncpz#
	z#=ncpz#
endif
if cx#<0
	cx#=ncpx#
	x#=ncpx#
endif
if cx#>4000
	cx#=ncpx#
	x#=ncpx#
endif
position object self,cx#,object position y(self)+height#,cz#
`sync
sync
`end game loop
loop
paused:
wait (250)
do
center text 320,240,"Paused"
if scancode()>0 then return
sync
loop