Hi, this is my first real program. I made it with the FPS tutorial at the top of the page.
The code is here:
Rem ***** Main Source File *****
REMSTART
My First FPS
Created by Jacob Hook
DateStarted: 11-8-06
REMEND
`Setup Client Options
SYNC ON
SYNC RATE 0
HIDE MOUSE
`make the ink a pretty green
ink RGB(000,255,100),RGB(000,100,255)
`Create all media needed
` Our character
MAKE OBJECT SPHERE 1,50
COLOR OBJECT 1,RGB(000,255,000)
POSITION OBJECT 1,0,0,-400
` An enemy
MAKE OBJECT SPHERE 2,50
COLOR OBJECT 2,RGB(255,000,000)
POSITION OBJECT 2,130,0,0
` A large wall
MAKE OBJECT BOX 3 ,500,400,10
POSITION OBJECT 3,0,0,150
` An ammo crate
MAKE OBJECT BOX 4,15,20,50
COLOR OBJECT 4,RGB(000,255,255)
POSITION OBJECT 4,-40,0,0
` Some ground to walk on
MAKE OBJECT PLAIN 5,1000,1000
XROTATE OBJECT 5,-90
`Make sure all the objects are on ground level
FOR Object = 1 TO 4
POSITION OBJECT Object, OBJECT POSITION X(Object), OBJECT SIZE Y(Object)/2, ...
OBJECT POSITION Z(Object)
NEXT Object
`ai limb
make object sphere 9998, 10
make mesh from object 2,9998
delete object 9998
add limb 2,1,2
offset limb 2,1,0,0,500
`Add limb for intersection checks
MAKE OBJECT SPHERE 9999,10
MAKE MESH FROM OBJECT 1,9999
DELETE OBJECT 9999
`Bullet Intersection Limb
ADD LIMB 1,1,1
OFFSET LIMB 1,1,0,0,500
HIDE LIMB 1,1
`Front Intersection Limb
ADD LIMB 1,2,1
OFFSET LIMB 1,2,0,0,OBJECT SIZE Z(1)/2
HIDE LIMB 1,2
`Back Intersection Limb
ADD LIMB 1,3,1
OFFSET LIMB 1,3,0,0,-OBJECT SIZE Z(1)/2
HIDE LIMB 1,3
`Right Intersection Limb
ADD LIMB 1,4,1
OFFSET LIMB 1,4,OBJECT SIZE X(1)/2,0,0
HIDE LIMB 1,4
`Left Intersection Limb
ADD LIMB 1,5,1
OFFSET LIMB 1,5, -OBJECT SIZE X(1)/2,0,0
HIDE LIMB 1,5
`Define the main variables needed
health=5000 `your health
EnemyHP=1000` Enemy's Health
Ammo=1000` Starting Ammo
MaxAmmo=1000` Maximum amount of Ammo
Clips=3` Starting Clips
MaxClips=3` Maximum amount of Clips
Jumping=0
ScreenWidth#=SCREEN WIDTH()
ScreenHeight#=SCREEN HEIGHT()
`Start main DO/LOOP
DO
`Screen FPS
FPS=SCREEN FPS()
TEXT 0,0,"FPS: "+STR$(FPS)
`Movement Controls
IF KEYSTATE(17)=1
XAngle#=OBJECT ANGLE X(1)
XROTATE OBJECT 1,0
MOVE OBJECT 1,.5
XROTATE OBJECT 1,XAngle#
ENDIF
IF KEYSTATE(31)=1
XAngle#=OBJECT ANGLE X(1)
XROTATE OBJECT 1,0
MOVE OBJECT 1,-.5
XROTATE OBJECT 1,XAngle#
ENDIF
IF KEYSTATE(30)=1
MOVE OBJECT LEFT 1,.3
endif
IF KEYSTATE(32)=1
MOVE OBJECT RIGHT 1,.3
endif
`Define variables for lag reduction
X#=OBJECT POSITION X(1)
Y#=OBJECT POSITION Y(1)
Z#=OBJECT POSITION Z(1)
`Camera Positioning
POSITION CAMERA X#,Y#,Z#
`Space key Controls
IF SPACEKEY()=1 AND Jumping=0
Jump=1
endif
`JUMP Variable Definition
IF Jump=1
Jump_Speed#=.5
Jumping=1
Jump=0
ENDIF
`Jumping
IF Jumping=1
DEC Jump_Speed#,.001
POSITION OBJECT 1,X#,Y#+Jump_Speed#, Z#
ENDIF
`Mouse Camera Movement
Camy#=Camy#+MOUSEMOVEX()*.1
Camx#=Camx#+MOUSEMOVEY()*.1
IF Camx#>90 AND Camx#<135
Camx#=90
endif
IF Camx#>270 AND Camx#<225
Camx#=90
endif
YROTATE CAMERA Camy#
XROTATE CAMERA Camx#
YROTATE OBJECT 1,Camy#
XROTATE OBJECT 1,Camx#
`Mouseclick Shooting
IF KEYSTATE(19)=0 AND MOUSECLICK()=1
IF Ammo>0
DEC Ammo,1
endif
IF OBJECT EXIST(2)=1
IF Ammo>0 AND INTERSECT OBJECT (2, LIMB POSITION X(1,1), LIMB POSITION Y(1,1), LIMB POSITION Z(1,1), X#,Y#,Z#)>0
DEC EnemyHP,1
endif
ENDIF
ENDIF
`Check if the enemy should die, if so delete it
IF EnemyHP=0 AND OBJECT EXIST(2)=1
DELETE OBJECT 2
endif
`print "you got me" if enemy dies
if object exist(2)=0
center text ScreenWidth#/2,ScreenHeight#/2,"you got me..."
endif
`Reloading (press R)
IF MOUSECLICK()=0 AND KEYSTATE(19)=1 AND Ammo<MaxAmmo AND Clips>0
Reload=1
ENDIF
`Reloading Part 2 (delay)
IF Reload=1
INC Time#,.001
endif
IF Time#>=1
Ammo=MaxAmmo
DEC Clips,1
Time#=0
Reload=0
endif
`AI
if object exist(2)=1
yrotate object 2, object angle Y(2)+0.1
IF INTERSECT OBJECT (1, LIMB POSITION X(2,1), LIMB POSITION Y(2,1), LIMB POSITION Z(2,1),object position x(2),object position y(2),object position z(2))>0
DEC Health,1
ENDIF
ENDIF
`Ammo Crate code (obtain ammo from ground)
IF OBJECT EXIST(4)=1
IF Ammo<MaxAmmo AND INTERSECT OBJECT (4, X#,Y#-50,Z#, X#,Y#,Z#)>0
INC Clips,(MaxClips-Clips)
INC Ammo,(MaxAmmo-Ammo)
DELETE OBJECT 4
ENDIF
ENDIF
`Display text above enemy and crate object
IF OBJECT EXIST(2)=1
CENTER TEXT OBJECT SCREEN X(2),OBJECT SCREEN Y(2)-70,"Enemy Health: "+str$(EnemyHP)
endif
IF OBJECT EXIST(4)=1
CENTER TEXT OBJECT SCREEN X(4),OBJECT SCREEN Y(4)-20,"Ammo Crate"
endif
`Display our Ammo,Clips,and health on-screen
TEXT 0,ScreenHeight#-50,"Ammo: "+str$(Ammo)
TEXT 0,ScreenHeight#-40,"Clips: "+str$(Clips)
TEXT 0,ScreenHeight#-60, "health: "+str$(health)
`Show that we're reloading
IF Reload=1
CENTER TEXT ScreenWidth#/2,ScreenHeight#/2,"Reloading..."
endif
`Add a target reticule to the screen
CIRCLE ScreenWidth#/2,ScreenHeight#/2,5
`Check for collision with objects, and handle appropriately
`Ground Intersection Check
IF INTERSECT OBJECT (5,X#,(Y#-OBJECT SIZE Y(1)/2),Z#,X#,Y#,Z#)>0
Jumping=0
ELSE
IF Jumping=0
Jumping=1
Jump_Speed=-1
ENDIF
ENDIF
`Front Intersection Check
IF INTERSECT OBJECT (3,LIMB POSITION X(1,2),LIMB POSITION Y(1,2),LIMB POSITION Z(1,2),X#,Y#,Z#)
`If intersection infront, move the user backwards
MOVE OBJECT 1,-1
ENDIF
`Back Intersection Check
IF INTERSECT OBJECT (3,LIMB POSITION X(1,3),LIMB POSITION Y(1,3),LIMB POSITION Z(1,3),X#,Y#,Z#)
`If intersection behind, move user forwards
MOVE OBJECT 1,1
ENDIF
`Right Intersection Check
IF INTERSECT OBJECT (3,LIMB POSITION X(1,4),LIMB POSITION Y(1,4),LIMB POSITION Z(1,4),X#,Y#,Z#)
`If intersection to the right, move the user left
MOVE OBJECT LEFT 1,1
ENDIF
`Left Intersection Check
IF INTERSECT OBJECT (3,LIMB POSITION X(1,5),LIMB POSITION Y(1,5),LIMB POSITION Z(1,5),X#,Y#,Z#)
`If intersection to the left, move user right
MOVE OBJECT RIGHT 1,1
ENDIF
`Refresh the screen(SYNC) and call the LOOP function
SYNC
loop
end
My currant project is making text saying “you got me” or something like that when the cube is deleted and then have the text go away(I don't have any sounds to use). The only problem is I can’t figure out how to only make it stay up for a little while. It just stays on the screen forever.
After that?
I don’t know, but I think I’ll try to make a delay between shots so you don’t empty the whole clip in 5 seconds.