z`/------------------------------------------------/ `/------------------STATION 13--------------------/ `/------------------------------------------------/ `/-----------------Source Code--------------------/ `/------------------------------------------------/ `-------------------------------------------------- `-------------------VARIABLES---------------------- `-------------------------------------------------- res# = 0 mx# = mousex() my# = mousey() mc# = mouseclick() REM OBJECT DECLARATION player#=1 level#=2 pistolarm#=3 pistolgun#=4 ARarm#=5 ARgun#=6 levelglass#=7 levelclipping#=8 skysphere#=9 playerhead#=10 cameralimb#=11 playercollide#=12 gunflare#=13 door1# = 14 door2# = 15 door3# = 16 door4# = 17 door5# = 18 door6# = 19 door7# = 20 door8# = 21 door9# = 22 door10# = 23 door11# = 24 door12# = 25 REM VARIABLE DECLARATION camheight# = 25 coltequip#=1 mp5equip#=1 PlayerHP as integer = 100 counter=10000 counter2=10401 entityNoOf = 10 Dim EnemyHP(100) as integer for i = 1 to 100 EnemyHP(i) = 100 next i ColtAmmo#=12 ColtMaxAmmo#=12 ColtAmmoReserve#=72 ColtMaxAmmoReserve#=72 ColtAmmoDifference# = ColtAmmoReserve#-ColtAmmo# ColtAccuracy# = 50 Mp5Ammo#=50 Mp5MaxAmmo#=50 Mp5AmmoReserve#=300 Mp5MaxAmmoReserve#=300 Mp5AmmoDifference# = Mp5AmmoReserve#-Mp5Ammo# ShootTime#=0 REM Textures pistoltex# = 4 flaretex# = 5 bullettex# = 6 sparktex# = 7 bulletglasstex# = 8 skytex# = 9 armtex# = 10 ARtex# = 11 zombie1tex# = 12 `Brightness Brightness#=0 Light=0 `Set gun holding-limb position gunOffsetX AS FLOAT = 15.0 gunOffsetY AS FLOAT = -20.0 gunOffsetZ AS FLOAT = 20.0 `Variables xPos AS FLOAT zPos AS FLOAT speed AS FLOAT = 8.0 xLook AS FLOAT yAng AS FLOAT lookSpeed AS FLOAT = 0.2 mouseMovementX AS FLOAT mouseMovementY AS FLOAT ink rgb(255,255,255),0 global rtimer as integer global stimer as integer global vtimer as integer dim shootTimer(50) as float dim entAttack(100) as integer for i = 1 to 100 entAttack(i) = 0 next i dim entAttackAnim(100) as integer for i = 1 to 100 entAttackAnim(i) = 0 next i dim entAttackTime#(100) as integer for i = 1 to 100 entAttackTime#(i) = 0 next i dim entAttackTime2#(100) as integer for i = 1 to 100 entAttackTime2#(i) = 0 next i dim AIentityanimPrev$(100) as string dim AIFadeValue#(100) as integer for i = 1 to 100 AIFadeValue#(i) = 100 next i MAKE MEMBLOCK 1,1000 hide mouse `Light Vector / Matrixs Global ActiveLights vec = make vector4(1) mat = make matrix4(2) mat = make matrix4(3) mat = make matrix4(4) mat = make matrix4(5) `-------------------------------------------------- `--------------------MAIN MENU--------------------- `-------------------------------------------------- gosub ResolutionChoice gosub DevScreen do gosub MainMenu loop endmenu: `-------------------------------------------------- `--------------------MAIN LOOP--------------------- `-------------------------------------------------- do looptime() gosub handle_drawdata gosub handle_messages gosub handle_player gosub handle_flashlight gosub handle_AI gosub weapon_shooting gosub weapon_reloading gosub weapon_switching gosub handle_backcamera Update_DynamicLights() AI Update sync loop handle_AI: for i = 40 to (entityNoOf + 40) if object exist(i) = 1 set object speed i+100, 40/fps.factor# aishoot(i) if entAttack(i) = 1 play object i,124,154 else AIentityanim$ = AI Get Entity Action$ (i) if AIentityanim$ = "Stopped" and AIentityanimprev$(i) <> "Stopped" loop object i+100,2,11 AIentityanimprev$(i) = "Stopped" endif if AIentityanim$ = "Moving Forwards" and AIentityanimprev$(i) <> "Moving Forwards" loop object i+100,12,53 AIentityanimprev$(i) = "Moving Forwards" endif if AIentityanim$ = "Moving Backwards" and AIentityanimprev$(i) <> "Moving Backwards" loop object i+100,12,53 AIentityanimprev$(i) = "Moving Backwards" endif if AIentityanim$ = "Strafing Left" and AIentityanimprev$(i) <> "Strafing Left" loop object i+100,54,74 AIentityanimprev$(i) = "Strafing Left" endif if AIentityanim$ = "Strafing Right" and AIentityanimprev$(i) <> "Strafing Right" loop object i+100,74,94 AIentityanimprev$(i) = "Strafing Right" endif endif SC_UpdateObject i endif next i return if memblock exist(1) then delete memblock 1 `-------------------------------------------------- `-------------------SUBROUTINES-------------------- `-------------------------------------------------- `-------------------------------------------------- `-------------------RESOLUTION--------------------- `-------------------------------------------------- ResolutionChoice: print "Please choose your resolution of choice" print "1. 800 x 600" print "2. 960 x 720" print "3. 1024 x 768" print "4. 1280 x 960" print "5. 1280 x 1024" print "6. 1600 x 1200" repeat key$ = inkey$() if key$ = "0" then set display mode 640,480,32,1 : res# = 1 if key$ = "1" then set display mode 800,600,32 : res# = 1 if key$ = "2" then set display mode 960,720,32 : res# = 1 if key$ = "3" then set display mode 1024,768,32 : res# = 1 if key$ = "4" then set display mode 1280,960,32 : res# = 1 if key$ = "5" then set display mode 1280,1024,32 : res# = 1 if key$ = "6" then set display mode 1600,1200,32 : res# = 1 until res# = 1 return `-------------------------------------------------- `---------------------MAIN MENU-------------------- `-------------------------------------------------- MainMenu: `New Game if mx#>50 and mx#<130 and my#>403 and my#<417 set cursor 50,400 ink rgb (255,0,0),0 print "New Game" newgame#=1 else if newgame#=1 ink rgb (255,255,255),0 set cursor 50,400 print "New Game" newgame#=0 else ink rgb (255,255,255),0 set cursor 50,400 print "New Game" endif endif if newgame#=1 and mc#>0 ink rgb (255,255,255),0 set cursor 50,50 print "Loading New Game..." wait 2000 cls newgame# = 2 goto LoadingGame endif `Options Menu if mx#>50 and mx#<110 and my#>453 and my#<467 set cursor 50,450 ink rgb (255,0,0),0 print "Options" options#=1 else if options#=1 ink rgb (255,255,255),0 set cursor 50,450 print "Options" options#=0 else ink rgb (255,255,255),0 set cursor 50,450 print "Options" endif endif if options#=1 and mc#>0 ink rgb (255,255,255),0 set cursor 50,50 print "Options in progress..." wait 2000 cls endif `Exit if mx#>50 and mx#<130 and my#>507 and my#<517 set cursor 50,500 ink rgb (255,0,0),0 print "Quit Game" exitgame#=1 else if exitgame#=1 ink rgb (255,255,255),0 set cursor 50,500 print "Quit Game" exitgame#=0 else ink rgb (255,255,255),0 set cursor 50,500 print "Quit Game" endif endif if exitgame#=1 and mc#>0 end endif yrotate object 1,20 sync return `-------------------------------------------------- `-------------------DEV SCREEN--------------------- `-------------------------------------------------- DevScreen: cls print "Station 13 Map Loading Setup" print "Copyright Phil Smith 2006" DIM intMediaArray(10) as integer DIM strMediaArray(10) as string print intMediaArray(0) = 1 : map# = 1 if intMediaArray(0) = 1 print "The file name of the map:" print "(e.g. 'map002')" input "",mapload$ mapname$ = "../Media/maps/" + mapload$ + "/map.dbo" wait 100 print print "Map to load is: "; print mapname$ wait 400 if file exist (mapname$) = 1 strMediaArray(0) = mapname$ else print "No such map exists!" wait 1000 goto DevScreen endif endif if intMediaArray(0) = 1 glassname$ = "../Media/maps/" + mapload$ + "/glass.x" if file exist (glassname$) = 1 strMediaArray(1) = glassname$ print print "Glass map found" else print print "No glass set for map" endif endif wait 100 if intMediaArray(0) = 1 clippingname$ = "../Media/maps/" + mapload$ + "/clipping.x" if file exist (clippingname$) = 1 strMediaArray(2) = clippingname$ print "Clipping map found" else print print "No clipping map set up for map" endif endif wait 100 if intMediaArray(0) = 1 print print "Scale the map?" print "(y/n)" repeat key$ = inkey$() if key$ = "y" then intMediaArray(3) = 1 : scale# = 1 if key$ = "n" then intMediaArray(3) = 0 : scale# = 1 until scale# = 1 wait 100 print if intMediaArray(3) = 1 print "The factor to scale by:" print "(100 is the base/normal factor)" input "",scalemap# endif endif print print "Turn on the flashlight shader?" print "(y/n)" print repeat key$ = inkey$() if key$ = "y" then intMediaArray(4) = 1 : flashlight# = 1 : print "Flashlight on" if key$ = "n" then intMediaArray(4) = 0 : flashlight# = 1 until flashlight# = 1 wait 600 cls goto LoadingGame return `-------------------------------------------------- `-------------------VISUAL LOADING----------------- `-------------------------------------------------- MenuVisuals: sync rate 0 set text font "Trebuchet MS" set text size 20 set text to bold load music "..\Media\music\Unrelenting.mp3",1 load image "..\Media\skies\stars.bmp",1 load image "..\Media\Textures\title2.bmp",2 set image colorkey 0,255,0 set camera range 1,20000 position camera 0,0,-50 make object cube 1, -10000 set object light 1,0 scale object texture 1,2.0,2.0 texture object 1,1 make object plain 2,77,24 position object 2,0,20,-3 set object transparency 2,1 rotate object 2,0,180,0 texture object 2,2 loop music 1 return `-------------------------------------------------- `-----------------NEW GAME LOADING----------------- `-------------------------------------------------- LoadingGame: cls sync off set text to normal if object exist(1) then delete object 1 if object exist(2) then delete object 2 if image exist(1) then delete image 1 if object exist(2) then delete image 2 color backdrop rgb(0,0,0) sync on sync rate 0 type timerinfo startloop factor# endtype global fps as timerinfo autocam off print : print "Loading core files..." : sync print : print "Loading shaders..." : sync gosub setup_shaders print : print "Loading textures..." : sync gosub setup_textures print : print "Loading sounds..." : sync gosub setup_sounds print : print "Loading world..." : sync gosub setup_customworld gosub setup_player gosub setup_objects gosub setup_gunsprites gosub setup_AI fps.startloop=timer() goto endmenu return `-------------------------------------------------- `-------------------SOUND SETUP-------------------- `-------------------------------------------------- setup_sounds: load sound "..\Media\sounds\mp5fire.wav",1 return `-------------------------------------------------- `------------------SHADER SETUP-------------------- `-------------------------------------------------- setup_shaders: REM Shader Loading load effect "..\Media\shaders\FlashLight.fx",1,0 load image "..\Media\shaders\SpotLight2.dds",1,2 return `-------------------------------------------------- `------------------TEXTURE SETUP------------------- `-------------------------------------------------- setup_textures: REM Image Loading load image "..\Media\Textures\wall_m_28.bmp",3 `Door 001 load image "..\Media\weapons\pistol\pistol.bmp", pistoltex# `Pistol Texture set image colorkey 255,255,255 load image "..\Media\Textures\flare3.png",flaretex# `Bullet flare load image "..\Media\Textures\bullet hole.png",bullettex# `Bullet Hole load image "..\Media\Textures\glass bullet hole.png",bulletglasstex# `Bullet Hole load image "..\Media\Textures\spark.bmp",sparktex# load image "..\Media\Skies\stars.bmp", skytex# load image "..\Media\weapons\pistol\hand.bmp", armtex# `Arm Texture load image "..\Media\weapons\AR\Assault Rifle WIP.bmp", ARtex# `AR Texture load image "../Media/models/zombie1/zombie1.bmp", zombie1tex# `Zombie 1 Texture return `-------------------------------------------------- `------------------WORLD LOADING------------------- `-------------------------------------------------- setup_world: load object "../Media/maps/map001/map.dbo",2 scale object 2,92,92,92 set object effect 2,1 : texture object 2,2,1 : set object normals 2 : set object light 2,0 : set object cull 2,1 SC_setupComplexObject 2,1,3 SC_UpdateObject 2 if file exist ("../Media/maps/map001/glass.x") = 1 load object "../Media/maps/map001/glass.x",5 scale object 5,92,92,92 SC_setupComplexObject 5,2,3 ghost object on 5 fade object 5,25 set object light 5,0 endif if file exist ("../Media/maps/map001/clipping.x") = 1 load object "../Media/maps/map001/clipping.x",6 scale object 6,92,92,92 SC_setupComplexObject 6,2,3 hide object 6 endif return `-------------------------------------------------- `-----------------DEV WORLD LOADING---------------- `-------------------------------------------------- setup_customworld: REM Map File Loading load object strMediaArray(0),2 if intMediaArray(3) = 1 then scale object 2,scalemap#,scalemap#,scalemap# if intMediaArray(4) = 1 then set object effect 2,1 : texture object 2,2,1 : set object normals 2 : set object light 2,0 : set object cull 2,1 SC_setupComplexObject 2,1,3 SC_UpdateObject 2 set ambient light 200 if file exist (glassname$) = 1 load object strMediaArray(1),levelglass# if intMediaArray(3) = 1 then scale object levelglass#,scalemap#,scalemap#,scalemap# SC_setupComplexObject levelglass#,2,3 ghost object on levelglass# fade object levelglass#,25 set object light levelglass#,0 endif if file exist (clippingname$) = 1 load object strMediaArray(2),levelclipping# if intMediaArray(3) = 1 then scale object levelclipping#,scalemap#,scalemap#,scalemap# SC_setupComplexObject levelclipping#,2,1 hide object levelclipping# endif if mapload$ = "arena2" for i = 1 to 12 doorload$ = "../Media/maps/arena2/door" + str$(i) + ".dbo" doornumber# = (i + door1#) - 1 load object doorload$, doornumber# SC_setupComplexObject doornumber#,1,3 next i endif return `-------------------------------------------------- `-------------------PLAYER SETUP-------------------- `-------------------------------------------------- setup_player: REM Player make object sphere player#,20 position object player#,0,0,0 SC_setupObject player#,0,2 hide object player# REM Player Camera make camera 2 position camera 2, 800,500,800 set camera view 2,screen width()-300, 10,screen width()-10,300 make object sphere playerhead#,2 hide object playerhead# REM Player Camera Limb make object cube cameralimb#,2 make mesh from object 1,cameralimb# add limb playerhead#,1,1 add limb playerhead#,2,1 offset limb playerhead#,1,0,0,20 delete mesh 1 hide object cameralimb# SC_setupObject playerhead#,0,2 REM Player Collision Cube (For enemies attacking) make object sphere Playercollide#, 120 `hide object Playercollide# glue object to limb Playercollide#,playerhead#,2 set object wireframe Playercollide#,1 return `-------------------------------------------------- `------------------GUNSPRITES SETUP---------------- `-------------------------------------------------- setup_gunsprites: REM Bullet Hole Images for i=10000 to 10400 make object plain i,2,2 set object transparency i,1 set image colorkey 255,255,255 texture object i,bullettex# set object light i,1 hide object i next i REM Bullet Hole Glass Images for i=10401 to 10801 make object plain i,7,7 set object transparency i,1 set image colorkey 255,255,255 texture object i,bulletglasstex# set object light i,0 hide object i next i REM Gun Flare make object plain gunflare#,10,10 set object transparency gunflare#,1 ghost object on gunflare# fade object gunflare#,10 set image colorkey 255,255,255 texture object gunflare#,flaretex# set object light gunflare#,0 position object gunflare#,8,9.5,32 glue object to limb gunflare#,playerhead#,1 set camera range 1,20000 return `-------------------------------------------------- `------------------OBJECTS SETUP------------------- `-------------------------------------------------- setup_objects: load object "..\Media\weapons\pistol\Pistol Animation.md2",pistolarm# texture object pistolarm#, pistoltex# scale object pistolarm#,180,180,180 GLUE OBJECT TO LIMB pistolarm#,playerhead#,1 position object pistolarm#,-1,1,16 set object frame pistolarm#,1 set object speed pistolarm#,60 disable object zdepth pistolarm# set object smoothing pistolarm#,80 set object light pistolarm#,1 load object "..\Media\weapons\pistol\Arm Animation.md2",pistolgun# `rotate object pistolgun#,90,0,0 texture object pistolgun#, armtex# scale object pistolgun#,180,180,180 GLUE OBJECT TO LIMB pistolgun#,playerhead#,1 position object pistolgun#, -1, 1, 16 set object frame pistolgun#,1 set object speed pistolgun#,60 set object light pistolgun#,1 disable object zdepth pistolgun# set object smoothing pistolgun#,80 load object "..\Media\weapons\AR\arms animated.md2",ARarm# texture object ARarm#, armtex# scale object ARarm#,170,170,180 GLUE OBJECT TO LIMB ARarm#,playerhead#,1 position object ARarm#,-2,-2,10 set object frame ARarm#,1 set object speed ARarm#,60 disable object zdepth ARarm# set object smoothing ARarm#,80 set object light ARarm#,1 hide object ARarm# load object "..\Media\weapons\AR\assault rifle animated.md2",ARgun# texture object ARgun#, ARtex# scale object ARgun#,170,170,180 GLUE OBJECT TO LIMB ARgun#,playerhead#,1 position object ARgun#, -2, -2, 10 set object frame ARgun#,1 set object speed ARgun#,60 set object light ARgun#,1 disable object zdepth ARgun# set object smoothing ARgun#,80 hide object ARgun# make object sphere skysphere#, -8000 set object light skysphere#,0 texture object skysphere#,skytex# scale object texture skysphere#,2.0,2.0 return `-------------------------------------------------- `--------------------AI SETUP---------------------- `-------------------------------------------------- setup_AI: randomize timer() AI Start AI Set Radius 9.0 AI Add Obstacle From Level 2,0,0,1,1,0 if mapload$ = "arena2" for i = 1 to 12 doornumber# = (i + door1#) - 1 AI Add Obstacle From Level doornumber#,0,0,1,1,0 next i endif AI Add Player player# For i = 40 to (entityNoOf + 40) load object "../Media/models/zombie1/zombie1.md2",i+100 texture object i+100, zombie1tex# rotate object i+100,0,180,0 make object box i,60,500,60 hide object i make mesh from object 5,i add limb i,1,5 glue object to limb i+100,i,1 set object light i,1 AI Add Enemy i,1 AI Set Entity Speed i,80 ai set entity aggressive i AI Set Entity View Arc i,90,170 Ai set entity view range i,1000 ai set entity hearing range i,2400 scale object i,30,30,30 set object smoothing i,40 position object i,rnd(50)*rnd(15)+100,-25,rnd(50)*rnd(15)+100 SC_setupObject i,0,2 `SC_drawObjectBounds i next i AI Complete Obstacles return `-------------------------------------------------- `---------------------HANDLERS--------------------- `-------------------------------------------------- `-------------------------------------------------- `------------------PLAYER MOVEMENT----------------- `-------------------------------------------------- rem THIS SECTION OF PLAYER MOVEMENT IS TAKEN FROM THE SPARKY COLLISION SYSTEM TUTORIAL handle_player: position camera curvevalue (object position x(player#),camera position x(0),2),curvevalue (object position y(player#),camera position y(0),2)+camheight#,curvevalue (object position z(player#),camera position z(0),5) rem FPS cam block oldcamy#=camy# oldcamx#=camx# camy#= wrapvalue(camy#+mousemoveY()*0.2) camx#= wrapvalue(camx#+mousemoveX()*0.2) if camy#>85 and camy#<180 then camy#=85 if camy#<285 and camy#>200 then camy#=284 yrotate camera curveangle(camx#,oldcamx#,25) xrotate camera curveangle(camy#,oldcamy#,25) rem record old position oldx#=object position x(player#) oldy#=object position y(player#) oldz#=object position z(player#) oldx2#=object position x(playerhead#) oldy2#=object position y(playerhead#) oldz2#=object position z(playerhead#) rem handle forwards if keystate(17)=1 speed#=speed#+1 yrotate object player#,camera angle y(0) endif rem handle backwards if keystate(31)=1 speed#=speed#+1 yrotate object player#,camera angle y(0)+180 endif rem handle left if keystate(30)=1 speed#=speed#+1 yrotate object player#,camera angle y(0)+270 endif rem handle right if keystate(32)=1 speed#=speed#+1 yrotate object player#,camera angle y(0)+90 endif rem handle diagonals if keystate(17)=1 and keystate(32)=1 speed#=speed#+1.5 yrotate object player#,camera angle y(0)+45 endif if keystate(17)=1 and keystate(30)=1 speed#=speed#+1.5 yrotate object player#,camera angle y(0)+315 endif if keystate(31)=1 and keystate(30)=1 speed#=speed#+1.5 yrotate object player#,camera angle y(0)+225 endif if keystate(31)=1 and keystate(32)=1 speed#=speed#+1.5 yrotate object player#,camera angle y(0)+135 endif rem speed limits if speed#>speedlim# then speed#=speedlim# if speed#<0 then speed#=0 rem speed calculation if speed#>0 then move object player#,speed#/fps.factor# speed#=speed#-0.5 rem player# new position newx#=object position x(player#) newy#=object position y(player#) newz#=object position z(player#) newx2#=object position x(playerhead#) newy2#=object position y(playerhead#) newz2#=object position z(playerhead#) rem handle jumping and gravity if spacekey()=1 and canjump=0 jump#=10 canjump=1 endif if spacekey()=0 and height#<30 then canjump=0 rem calculate height height#=SC_intersectObject ( 0,object position x(player#),object position y(player#),object position z(player#), object position x(player#),object position y(player#)-100000,object position z(player#)) cieling#=SC_intersectObject ( 0,object position x(player#),object position y(player#),object position z(player#), object position x(player#),object position y(player#)+100,object position z(player#)) IF height#<26 gravity#=0 endif IF cieling#<20 and cieling#>0 jump#=0 endif rem handle gravity if jump#>0 position object player#,object position x(player#),object position y(player#)+jump#,object position z(player#) jump#=jump#-0.70 endif if jump#<1 position object player#,object position x(player#),object position y(player#)-gravity#,object position z(player#) gravity#=gravity#+0.70 endif rem handle on ground calculation if height#<25 then position object player#,object position x(player#),object position y(player#)+(25-height#),object position z(player#) rem handle sliding using Sparky slide#=SC_SphereSlide ( 0, oldx#, oldy#, oldz#, newx#, newy#, newz#,15, 0 ) slidex#=SC_getCollisionSlideX () slidez#=SC_getCollisionSlideZ () if slide#>0 position object player#,slidex#,object position y(player#),object position z(player#) endif if slide#>0 position object player#,object position x(player#),object position y(player#),slidez# endif slidex#=0 slidey#=0 slidez#=0 position object playerhead#,camera position x(),camera position y(),camera position z() rotate object playerhead#, camera angle x(),camera angle y(),camera angle z() SC_UpdateObject player# position object skysphere#,newx2#,newy2#,newz2# rotate object skysphere#,0,5,5 point camera 2,newx2#,newy2#,newz2# return `-------------------------------------------------- `--------------------FLASHLIGHT-------------------- `-------------------------------------------------- handle_flashlight: `Flash Light On/OFf if KEYSTATE(33)=1 and NoPress=0 and Light=0 then Light=1:NoPress=1 if KEYSTATE(33)=1 and NoPress=0 and Light=1 then Light=0:NoPress=1 if Light=0 then Brightness#=Brightness#-0.1 if Light=1 then Brightness#=Brightness#+0.1 if Brightness#>1.0 then Brightness#=1.0 if Brightness#<0.0 then Brightness#=0.0 set effect constant float 1,"BrightNess",Brightness# if KEYSTATE(33)=0 then NoPress=0 `Move Flash Light to camera pos / Rotate cubic light if Brightness#>0.0 set vector4 1,camera position x(),camera position y(),camera position z(),0 set effect constant vector 1,"LightPosition",1 angX#=curveangle(camera angle x(),angX#,4) angY#=curveangle(camera angle Y(),angY#,4) rotate x matrix4 2,(angX#)/57.3 rotate y matrix4 3,(angY#)/57.3 rotate z matrix4 4,(angZ#)/57.3 multiply matrix4 5,2,3:multiply matrix4 5,5,4 set effect constant matrix 1,"LightAngle",5 endif return `-------------------------------------------------- `-------------------BULLET HOLES------------------- `-------------------------------------------------- playerbullets: REM Raycast The Bullet Hole oldx#=camera position x() oldy#=camera position y() oldz#=camera position z() move camera 2000 randomize timer() a = rnd(ColtAccuracy#) - rnd(ColtAccuracy#) : posneg(a) : x#=camera position x() + a a = rnd(ColtAccuracy#) - rnd(ColtAccuracy#) : posneg(a) : y#=camera position y() + a a = rnd(ColtAccuracy#) - rnd(ColtAccuracy#) : posneg(a) : z#=camera position z() + a move camera -2000 play sound 1 AI Create Sound object position x(player#),object position z(player#),1,12 gosub castbullets gosub enemy_damage return castbullets: collide=SC_rayCastGroup(1,oldx#,oldy#,oldz#,x#,y#,z#,0) if collide>0 REM get the collision point newx#=SC_getStaticCollisionX() newy#=SC_getStaticCollisionY() newz#=SC_getStaticCollisionZ() rem get collision normal normx#=SC_getCollisionNormalX() normy#=SC_getCollisionNormalY() normz#=SC_getCollisionNormalZ() rem position and point a marker in the right direction position object counter,newx#+normx#/10.0,newy#+normy#/10.0,newz#+normz#/10.0 point object counter,newx#+normx#,newy#+normy#,newz#+normz# show object counter counter = counter + 1 if counter>10400 then counter = 10000 endif collide=SC_rayCastGroup(2,oldx#,oldy#,oldz#,x#,y#,z#,0) if collide>0 REM get the collision point newx#=SC_getStaticCollisionX() newy#=SC_getStaticCollisionY() newz#=SC_getStaticCollisionZ() rem get collision normal normx#=SC_getCollisionNormalX() normy#=SC_getCollisionNormalY() normz#=SC_getCollisionNormalZ() rem position and point a marker in the right direction position object counter2,newx#+normx#/10.0,newy#+normy#/10.0,newz#+normz#/10.0 point object counter2,newx#+normx#,newy#+normy#,newz#+normz# show object counter2 counter2 = counter2 + 1 if counter2>10801 then counter2 = 10401 endif return `-------------------------------------------------- `-----------------WEAPON SWITCHING----------------- `-------------------------------------------------- weapon_switching: if keystate(2) = 1 if coltequip# = 1 show object 3 show object 4 hide object 5 hide object 6 position object gunflare#,10,8,32 endif endif if keystate(3) = 1 if mp5equip# = 1 hide object 3 hide object 4 show object 5 show object 6 position object gunflare#,2.5,9,32 endif endif return `-------------------------------------------------- `-------------------WEAPON PICKUP------------------ `-------------------------------------------------- weapon_pickup: hit# = object collision (player#,0) if hit# = 6 delete object 6 delete object 5 mp5equip# = 1 hide object 4 show object 3 time# = timer() messagestring$ = "Got the Assualt Rifle!" endif return `-------------------------------------------------- `------------------WEAPON SHOOTING----------------- `-------------------------------------------------- weapon_shooting: `inc PistolShootTime#,0.05 if object visible(pistolgun#)=1 if mouseclick()=1 and NoClick=0 and Reloading#=0 then PistolShootTime#=1:NoClick=1 if PistolShootTime#>=1 IF ColtAmmo#>0 then DEC ColtAmmo#,1 : play sound 1 : set object speed pistolgun#,90 : play object pistolgun#,1,10 : set object speed pistolarm#,90 : play object pistolarm#,1,10 : FlareTime = 2 : gosub playerbullets: if ColtAccuracy# < 180 then ColtAccuracy# = ColtAccuracy# + 10 if ColtAmmo#>0 then ColtFire# = 1 PistolShootTime#=0 ShootTIme#=0 endif endif if mouseclick()=0 then NoClick=0 if object visible(ARgun#)=1 IF MOUSECLICK()=1 AND Reloading#=0 then inc ShootTime#,0.20/fps.factor# IF ShootTime#>=1 IF Mp5Ammo#>0 then DEC Mp5Ammo#,1 : gosub playerbullets : set object speed ARgun#,90 : play object ARgun#,1,10 : set object speed ARarm#,90 : play object ARarm#,1,10 : if ColtAccuracy# < 180 then ColtAccuracy# = ColtAccuracy# + 10 : FlareTime = 2 ShootTIme#=0 endif endif if controlkey()=1 Set_DynamicLight(camera position x(),camera position y(),camera position z(),200,200,155,500) endif FlareTime=FlareTime-1 if FlareTime>0 then Show Object gunflare# : Set_DynamicLight(camera position x(),camera position y(),camera position z(),200,200,155,500) if FlareTime<0 then Hide Object gunflare# if ColtAccuracy# > 40 then ColtAccuracy# = ColtAccuracy# - 1.5 if ColtAccuracy# > 150 then ColtAccuracy# = 150 if mouseclick() = 2 then ColtAmmoReserve# = ColtMaxAmmoReserve# if inkey$() = "p" then ColtAmmoReserve# = 24 return `-------------------------------------------------- `------------------WEAPON RELOADING---------------- `-------------------------------------------------- weapon_reloading: if object visible(pistolgun#)=1 IF KEYSTATE(19)=1 and mouseclick() = 0 and ColtAmmoReserve# > 0 and ColtAmmo# < ColtMaxAmmo# THEN Reloading#=1 : set object speed pistolgun#,10/fps.factor# : play object pistolgun#,10,25 : set object speed pistolarm#,10/fps.factor# : play object pistolarm#,10,25 IF Reloading#=1 then inc Reloadtime#,0.012 IF Reloadtime#>=1 ColtAmmoDifference# = ColtMaxAmmo#-ColtAmmo# if ColtAmmoReserve# > ColtAmmoDifference# ColtAmmo# = ColtAmmo# + ColtAmmoDifference# ColtAmmoReserve# = ColtAmmoReserve# - ColtAmmoDifference# else if ColtAmmoReserve# > 0 ColtAmmo# = ColtAmmo# + ColtAmmoReserve# ColtAmmoReserve# = 0 endif endif Reloadtime#=0 Reloading#=0 set object speed pistolgun#,60 : set object speed pistolarm#,60 endif endif if object visible(5)=1 IF KEYSTATE(19)=1 and mouseclick() = 0 and Mp5Ammo# < Mp5MaxAmmo# THEN Reloading#=1 : set object speed ARarm#,15/fps.factor# : set object speed ARgun#,15/fps.factor# : play object ARarm#, 65,85 : play object ARgun#, 65,85 IF Reloading#=1 then inc Reloadtime#,0.015/fps.factor# IF Reloadtime#>=1 Mp5AmmoDifference# = Mp5MaxAmmo#-Mp5Ammo# if Mp5AmmoReserve# > Mp5AmmoDifference# Mp5Ammo# = Mp5Ammo# + Mp5AmmoDifference# Mp5AmmoReserve# = Mp5AmmoReserve# - Mp5AmmoDifference# else if Mp5AmmoReserve# > 0 Mp5AmmoReserve# = Mp5AmmoDifference# Mp5Ammo# = ColtAmmo# + Mp5AmmoDifference# Mp5AmmoReserve# = Mp5AmmoReserve# - Mp5AmmoDifference# endif endif Reloadtime#=0 Reloading#=0 endif endif return `-------------------------------------------------- `---------------------DRAW DATA-------------------- `-------------------------------------------------- handle_drawdata: set cursor 0,0 print "Frames/S:",screen fps() dot (screen width()/2),(screen height()/2) circle (screen width()/2),(screen height()/2),ColtAccuracy#/10 if object visible(pistolarm#)=1 TEXT 0,SCREEN HEIGHT()-70,"Ammo: "+str$(ColtAmmo#) TEXT 0,SCREEN HEIGHT()-60,"Reserve Ammo: "+str$(ColtAmmoReserve#) endif if object visible(ARarm#)=1 TEXT 0,SCREEN HEIGHT()-70,"Ammo: "+str$(Mp5Ammo#) TEXT 0,SCREEN HEIGHT()-60,"Reserve Ammo: "+str$(Mp5AmmoReserve#) endif TEXT 0,SCREEN HEIGHT()-50,"Health: "+str$(PlayerHP) return `-------------------------------------------------- `-----------------HANDLE MESSAGES------------------ `-------------------------------------------------- handle_messages: text 0,15,messagestring$ if timer() - time# = 3000 messagestring$ = "" time# = timer() endif return `-------------------------------------------------- `--------------------DEV CAMERA-------------------- `-------------------------------------------------- handle_backcamera: if KEYSTATE(23)=1 and NoPressCam=0 and backcamera=0 then backcamera=1:NoPressCam=1 if KEYSTATE(23)=1 and NoPressCam=0 and backcamera=1 then backcamera=0:NoPressCam=1 if backcamera = 1 then set camera view 2,screen width()-300, 10,screen width()-10,300 : show object player# : set object wireframe player#,1 if backcamera = 0 then set camera view 2,0,0,0,0 : hide object player# : set object wireframe player#,0 if KEYSTATE(23)=0 then NoPressCam=0 return `-------------------------------------------------- `-------------------PLAYER DAMAGE------------------ `-------------------------------------------------- player_damage: PlayerHP = PlayerHP - 4 return `-------------------------------------------------- `--------------------ENEMY DAMAGE------------------ `-------------------------------------------------- enemy_damage: REM HURT ENEMY for i = 40 to 50 if object exist(i) = 1 if SC_rayCast(i,oldx#,oldy#,oldz#,x#,y#,z#,0) = 1 EnemyHP(i) = EnemyHP(i) - 4 endif REM KILL ENEMY if EnemyHP(i) <= 0 unglue object i+100 position object i+100, object position x(i), object position y(i), object position z(i) rotate object i+100, object angle x(i), object angle y(i), object angle z(i) stop object i+100 Ai Kill Entity i delete object i SC_RemoveObject i endif endif next i for i = 40 to 50 if object exist(i) = 0 and object exist(i+100) = 1 if AIFadeValue#(i) < 0 fade object i+100, AIFadeValue#(i) dec AIFadeValue#(i),1 else delete object i+100 endif endif next i return `-------------------------------------------------- `-------------------AI ANIMATION------------------- `-------------------------------------------------- `-------------------------------------------------- `---------------------FUNCTIONS-------------------- `-------------------------------------------------- `-------------------------------------------------- `--------------------AI SHOOTING------------------- `-------------------------------------------------- function AiShoot(ent) inc entAttackTime#(ent),1 if object collision(ent,12) = 1 entAttackAnim(ent) = 1 if entAttackTime#(ent) >= 150 if entAttack(ent) = 0 entAttack(ent) = 1 entAttackTime#(ent) = 0 endif endif endif if entAttack(ent) = 1 play object ent,124,154 if object collision(ent,12) = 1 then inc entAttackTime2#(ent),1 if entAttackTime2#(ent) >= 20 gosub player_damage entAttack(ent) = 0 entAttackTime#(ent) = 0 endif endif endfunction `-------------------------------------------------- `---------------------AI BULLETS------------------- `-------------------------------------------------- function EnemyBullet(ent,player) REM Raycast The Bullet Hole oldx#=object position x(ent) oldy#=object position y(ent) oldz#=object position z(ent) x#=object position x(player) y#=object position x(player) z#=object position x(player) collide=SC_rayCastGroup(1,oldx#,oldy#,oldz#,x#,y#,z#,0) play sound 1 AI Create Sound object position x(ent),object position z(ent),1,12 gosub castbullets endfunction `-------------------------------------------------- `-------------------TIMER MOVEMENT----------------- `-------------------------------------------------- function looptime() loopspeed=timer()-fps.startloop if loopspeed>0 fps.startloop=timer() fps.factor#=16.66/loopspeed endif endfunction `-------------------------------------------------- `------------------POSNEG DEVIATION---------------- `-------------------------------------------------- function posneg(x) randomize timer() y = rnd(1) if y = 0 x = x else z = x*2 x = x - z endif endfunction `-------------------------------------------------- `--------------------IMAGE COLOUR------------------ `-------------------------------------------------- function MakeColorImage(image,mem,color) make memblock mem,16 write memblock dword mem,0,1 write memblock dword mem,4,1 write memblock dword mem,8,32 write memblock dword mem,12,color make image from memblock image,mem delete memblock mem endfunction `-------------------------------------------------- `-----------------MAKE DYNAMIC LIGHT--------------- `-------------------------------------------------- Function Set_DynamicLight(LposX#,LposY#,LposZ#,ColR#,ColG#,ColB#,Range#) ActiveLights=ActiveLights+1 if ActiveLights>6 then ActiveLight=6 set vector4 1,LposX#,LposY#,LposZ#,0 set effect constant vector 1,"LightPosition_"+str$(ActiveLights),1 set vector4 1,ColR#/255,ColG#/255,ColB#/255,0 set effect constant vector 1,"LightColor_"+str$(ActiveLights),1 set effect constant float 1,"LightRange_"+str$(ActiveLights),Range# Endfunction `-------------------------------------------------- `----------------UPDATE DYNAMIC LIGHTS------------- `-------------------------------------------------- Function Update_DynamicLights() set effect technique 1,"Light"+str$(ActiveLights) ActiveLights=0 Endfunction