`Setup Client Options
SYNC ON:SYNC RATE 0:HIDE MOUSE: AUTOCAM OFF:RANDOMIZE TIMER()
`---------------------------------------------------------------
`------------------Main Variables-------------------------------
`---------------------------------------------------------------
` CWeapon = Current Weapon
global CWeapon=0
`weapon
type weapon
name as string
ammo as integer
maxammo as integer
clips as integer
maxclips as integer
endtype
``setup arrays
dim weapon(3) as weapon
weapon(0).name="Unarmed"
weapon(1).name="Rifle"
weapon(1).ammo=8
weapon(1).maxammo=8
weapon(1).clips=5
weapon(1).maxclips=5
weapon(2).name="Shotgun"
weapon(2).ammo=8
weapon(2).maxammo=8
weapon(2).clips=6
weapon(2).maxclips=6
weapon(3).name="Rocket Launcher"
weapon(3).ammo=10
weapon(3).maxammo=10
weapon(3).clips=3
weapon(3).maxclips=3
`Define the main variables needed
PlayerHP=2000`----------Player's Health
MaxPlayerHP=2000`-------Player's Max Health
EnemyHP=2000`-----------Enemy's Health
MaxEnemyHP=2000`--------Enemy's Max Health
ArmorHP=500`------------Armor Health
play_out = 0`-----------Tells when player has gone off matrix
`---------------------------------------------------------------
`------------------In Game Objects------------------------------
`---------------------------------------------------------------
`Create Main Player
MAKE OBJECT SPHERE 1,50:COLOR OBJECT 1,RGB(255,000,000):POSITION OBJECT 1,RND(1000),Ground#+25,RND(1000)
`Create Enemy Player
MAKE OBJECT SPHERE 2,50:COLOR OBJECT 2,RGB(255,000,000):POSITION OBJECT 2,RND(1000),Ground#+25,RND(1000)
`create rifle
MAKE OBJECT CUBE 3,10:COLOR OBJECT 3,RGB(000,000,255):POSITION OBJECT 3,100,Ground#+5,160
`create rocket launcher
MAKE OBJECT CUBE 4,10:COLOR OBJECT 4,RGB(000,000,255):POSITION OBJECT 4,100,Ground#+5,190
`create shotgun
MAKE OBJECT CUBE 5,10:COLOR OBJECT 5,RGB(000,000,255):POSITION OBJECT 5,100,Ground#+5,220
`create armor
MAKE OBJECT CUBE 6,10:COLOR OBJECT 6,RGB(000,255,000):POSITION OBJECT 6,100,Ground#+5,250
`create ammo crate
MAKE OBJECT CUBE 7,10:COLOR OBJECT 7,RGB(000,255,000):POSITION OBJECT 7,100,Ground#+5,280
`create health crate
MAKE OBJECT CUBE 8,10:COLOR OBJECT 8,RGB(000,255,000):POSITION OBJECT 8,100,Ground#+5,310
`create bullets
for b=10 to 999
make object sphere b,1
color object b,rgb(200,100,50)
position object b, camera position x(),camera position y(),camera position z()
hide object b
next b
`create playing field
MAKE MATRIX 1,1000,1000,50,50
`make matrix the ground
ground#=GET GROUND HEIGHT(1,0,0)
`---------------------------------------------------------------
`------------------Player Limbs---------------------------------
`---------------------------------------------------------------
`Add limb for intersection checks
MAKE OBJECT SPHERE 9999,10
MAKE MESH FROM OBJECT 1,9999
DELETE OBJECT 9999
ADD LIMB 1,1,1
HIDE LIMB 1,1
`Add a second limb for ground checks
ADD LIMB 1,2,1
OFFSET LIMB 1,2,0,-50,0
DELETE MESH 1
HIDE LIMB 1,2
`---------------------------------------------------------------
`------------------Main Do/Loop---------------------------------
`---------------------------------------------------------------
DO
`---------------------------------------------------------------
`------------------Info Display---------------------------------
`---------------------------------------------------------------
display_items()
`display text enemyhp above enemy
IF OBJECT EXIST(2)=1
IF OBJECT IN SCREEN(2)=1
CENTER TEXT OBJECT SCREEN X(2),OBJECT SCREEN Y(2)-70,"Enemy Health: "+str$(EnemyHP)
ENDIF
ENDIF
`Display our Ammo, Clips, Health, and Armor on-screen
TEXT 0,SCREEN HEIGHT()-80,"Health: "+str$(PlayerHP)
if CWeapon > 0
TEXT 0,SCREEN HEIGHT()-60,weapon(CWeapon).name
TEXT 0,SCREEN HEIGHT()-50,"Ammo: "+str$(weapon(CWeapon).ammo)
TEXT 0,SCREEN HEIGHT()-40,"Clips: "+str$(weapon(CWeapon).clips)
endif
`Add a target reticule to the screen
CIRCLE SCREEN WIDTH()/2,SCREEN HEIGHT()/2,5
`Fix player moving through the matrix
if play_y# < ground#+25
play_y# = ground#+25
position object 1,play_x#, play_y#, play_z#
endif
`Screen FPS
FPS#=SCREEN FPS()
TEXT 500,0,"FPS: "+STR$(FPS#)
`Camera Positioning
POSITION CAMERA OBJECT POSITION X(1),OBJECT POSITION Y(1)+10,OBJECT POSITION Z(1)
`---------------------------------------------------------------
`------------------Movement Settings----------------------------
`---------------------------------------------------------------
`stop player from flying
xrotate object 1, 0
`Movement Controls
IF KEYSTATE(17)=1 THEN MOVE OBJECT 1,.9
IF KEYSTATE(31)=1 THEN MOVE OBJECT 1,-.9
IF KEYSTATE(30)=1 THEN MOVE OBJECT LEFT 1,.8
IF KEYSTATE(32)=1 THEN MOVE OBJECT RIGHT 1,.8
`Use variables to make code easier to read (shorter lines)
play_x# = object position x(1)
play_y# = object position y(1)
play_z# = object position z(1)
leg_x# = LIMB POSITION X(1,2)
leg_y# = LIMB POSITION Y(1,2)
leg_z# = LIMB POSITION Z(1,2)
enemy_x# = object position x(2)
enemy_y# = object position y(2)
enemy_z# = object position z(2)
`prevent player from moving off matrix
if play_x# < 0 then Play_x# = 0 : play_out = 1
if play_x# > 1000 then Play_x# = 1000 : play_out = 1
if play_z# < 0 then Play_z# = 0 : play_out = 1
if play_z# > 1000 then Play_z# = 1000 : play_out = 1
if play_out = 1
position object 1, Play_x#, Play_y# , Play_z#
play_out = 0
endif
`Space key Controls
IF SPACEKEY()=1 AND JUMPING=0
JUMP_SPEED#=1
JUMPING=1
ENDIF
`Jumping
IF JUMPING=1
DEC JUMP_SPEED#,.005
POSITION OBJECT 1,Play_x#,Play_y#+JUMP_SPEED#, Play_z#
IF Play_y#<=ground#+25 THEN JUMPING=0
ENDIF
`Put player direction back to mouselook angle
xrotate object 1, CAMX#
`Mouse Camera Movement
CAMY#=CAMY#+MOUSEMOVEX()*.1
CAMX#=CAMX#+MOUSEMOVEY()*.1
IF CAMX#>90 AND CAMX#<135 THEN CAMX#=90
IF CAMX#>270 AND CAMX#<225 THEN CAMX#=90
YROTATE CAMERA CAMY#
XROTATE CAMERA CAMX#
YROTATE OBJECT 1,CAMY#
XROTATE OBJECT 1,CAMX#
`enemy death, deletions, and regeneration
if EnemyHP=0 AND OBJECT EXIST(2)=1
DELETE OBJECT 2
MAKE OBJECT SPHERE 2,50: COLOR OBJECT 2,RGB(255,000,000): POSITION OBJECT 2,RND(600),Ground#,RND(600)
EnemyHP=2000
endif
`Reloading Part 2 (delay)
IF Reload=1 THEN INC Time#,.005
IF Time#>=1 THEN weapon(CWeapon).ammo=weapon(CWeapon).maxammo:DEC weapon(CWeapon).clips,1:Time#=0:Reload=0
`---------------------------------------------------------------
`------------------Enemy A.I.-----------------------------------
`---------------------------------------------------------------
if object exist(2)=1
point object 2,play_x#,play_y#,play_z#
move object 2, .8
endif
`---------------------------------------------------------------
`------------------Weapons/Items--------------------------------
`---------------------------------------------------------------
`Get Rifle
IF OBJECT EXIST(3)=1
IF INTERSECT OBJECT (3, Leg_x#, Leg_y#, Leg_z#, Play_x#,Play_y#, Play_z#)>0
DELETE OBJECT 3
CWeapon=1
SetWeapon()
ENDIF
ENDIF
`Get Shotgun
IF OBJECT EXIST(4)=1
IF INTERSECT OBJECT (4, Leg_x#, Leg_y#, Leg_z#, Play_x#,Play_y#, Play_z#)>0
DELETE OBJECT 4
CWeapon=2
SetWeapon()
ENDIF
ENDIF
`Get Rocket Launcher
IF OBJECT EXIST(5)=1
IF INTERSECT OBJECT (5, Leg_x#, Leg_y#, Leg_z#, Play_x#,Play_y#, Play_z#)>0
DELETE OBJECT 5
CWeapon=3
SetWeapon()
ENDIF
ENDIF
`Get Armor
IF OBJECT EXIST(6)=1
IF INTERSECT OBJECT (6, Leg_x#, Leg_y#, Leg_z#, Play_x#,Play_y#, Play_z#)>0
DELETE OBJECT 6
ENDIF
ENDIF
if object exist(6)=0
TEXT 0,SCREEN HEIGHT()-100,"Armor: "+str$(ArmorHP)
endif
`Ammo Crate code A (ammo increase)
IF OBJECT EXIST(7)=1
IF weapon(CWeapon).ammo<weapon(CWeapon).maxammo AND INTERSECT OBJECT (7, Leg_x#, Leg_y#, Leg_z#, Play_x#,Play_y#, Play_z#)>0
INC weapon(CWeapon).ammo,(weapon(CWeapon).maxammo-weapon(CWeapon).ammo)
DELETE OBJECT 7
ENDIF
ENDIF
`ammo crate code B (clips increase)
if object exist(7)=1
If weapon(CWeapon).clips<weapon(CWeapon).maxclips and weapon(Cweapon).ammo>= weapon(Cweapon).maxammo
if INTERSECT OBJECT (7, Leg_x#, Leg_y#, Leg_z#, Play_x#,Play_y#, Play_z#)>0
INC weapon(Cweapon).clips,1
delete object 7
endif
endif
endif
`health crate code
If PlayerHP<MaxPlayerHP and intersect object (8, Leg_x#, Leg_y#, Leg_z#, Play_x#, Play_y#, Play_z#)>0
inc PlayerHP,(MaxPlayerHP-PlayerHP)
delete object 8
endif
`---------------------------------------------------------------
`------------------Shooting-------------------------------------
`---------------------------------------------------------------
`Mouseclick Shooting
if keystate(19)=0 AND mouseclick()=1
IF weapon(CWeapon).ammo>0 THEN DEC weapon(CWeapon).ammo,1
If intersect object (2, limb position x(1,1), limb position y(1,1), limb position z(1,1), play_x#, Play_y#, PLay_z#)>0 then dec enemyhp,1
if CWeapon>0
TEXT 0,SCREEN HEIGHT()-50,"Ammo: "+str$(weapon(CWeapon).ammo)
TEXT 0,SCREEN HEIGHT()-40,"Clips: "+str$(weapon(CWeapon).clips)
endif
ENDIf
`Show that we're reloading
IF Reload=1 THEN CENTER TEXT SCREEN WIDTH()/2,SCREEN HEIGHT()/2,"Reloading..."
`Reloading (press R)
IF MOUSECLICK()=0 AND KEYSTATE(19)=1 AND weapon(CWeapon).ammo<weapon(CWeapon).maxammo AND weapon(CWeapon).clips>0
Reload=1
ENDIF
SYNC
LOOP
function SetWeapon()
select CWeapon
case 0: offset limb 1,1,0,0,10: endcase
case 1: offset limb 1,1,0,0,500: endcase
case 2: offset limb 1,1,0,0,600: endcase
case 3: offset limb 1,1,0,0,10000: endcase
endselect
endfunction
function display_items()
IF OBJECT EXIST(3)=1
IF OBJECT IN SCREEN(3)=1
CENTER TEXT OBJECT SCREEN X(3),OBJECT SCREEN Y(3)-20,"Rifle"
ENDIF
ENDIF
IF OBJECT EXIST(4)=1
IF OBJECT IN SCREEN(4)=1
CENTER TEXT OBJECT SCREEN X(4),OBJECT SCREEN Y(4)-20,"Shot Gun"
ENDIF
ENDIF
IF OBJECT EXIST(5)=1
IF OBJECT IN SCREEN(5)=1
CENTER TEXT OBJECT SCREEN X(5),OBJECT SCREEN Y(5)-20,"Rocket Launcher"
ENDIF
ENDIF
IF OBJECT EXIST(6)=1
IF OBJECT IN SCREEN(6)=1
CENTER TEXT OBJECT SCREEN X(6),OBJECT SCREEN Y(6)-20,"Armor"
ENDIF
ENDIF
IF OBJECT EXIST(7)=1
IF OBJECT IN SCREEN(7)=1
CENTER TEXT OBJECT SCREEN X(7),OBJECT SCREEN Y(7)-20,"Ammo"
ENDIF
ENDIF
IF OBJECT EXIST(8)=1
IF OBJECT IN SCREEN(8)=1
CENTER TEXT OBJECT SCREEN X(8),OBJECT SCREEN Y(8)-20,"Health"
ENDIF
ENDIF
endfunction