This is my first FPS and I have learned a lot through the various tutorials (Especially Ruccus' FPS Tutorial), but I cannot figure out how to implement collisions. I've used the limb technique, which is currently shown in my code, and I've tried Sparky's dll. I have Sparky's loaded right and everything in the right folders. When I used Sparky's I was still going through everything. None of the tutorial have worked for me. If anyone could help I would greatly appreciate it. If it would be better for me to re write all of the Sparky's dll and repost my code then let me know. Neither was working for me. I know some things in my code could have been done a better way. If it will not apply to making collisions work, just ignore it. I'll go back later and organize it more
SYNC ON:SYNC RATE 0:HIDE MOUSE
SET CAMERA RANGE 1,100000
`Create all media needed
` Our character
MAKE OBJECT SPHERE 1,900:COLOR OBJECT 1,RGB(000,255,000):POSITION OBJECT 1,-3522,-43.5,776
` An enemy
LOAD OBJECT "C:\Program Files (x86)\The Game Creators\Dark Basic Professional\Projects\Crimson Haze\Media\H-Zombie-Static.X", 2
POSITION OBJECT 2,-1939,-480,413
SCALE OBJECT 2,28000,30000,30000
` Enemy die
LOAD OBJECT "C:\Program Files (x86)\The Game Creators\Dark Basic Professional\Projects\Crimson Haze\Media\H-Zombie-Die.X",3
SCALE OBJECT 3,28000,30000,30000
POSITION OBJECT 3, OBJECT POSITION X (2), OBJECT POSITION Y(2), OBJECT POSITION Z(2)
HIDE OBJECT 3
` Enemy hurt
LOAD OBJECT "C:\Program Files (x86)\The Game Creators\Dark Basic Professional\Projects\Crimson Haze\Media\H-Zombie-Impact.X",6
SCALE OBJECT 6,28000,30000,30000
POSITION OBJECT 6, OBJECT POSITION X (2), OBJECT POSITION Y(2), OBJECT POSITION Z(2)
HIDE OBJECT 6
` An ammo crate
MAKE OBJECT BOX 4,15,20,50:COLOR OBJECT 4,RGB(000,255,255):POSITION OBJECT 4,-2713,-52,-682
` Map
LOAD OBJECT "C:\Program Files (x86)\The Game Creators\Dark Basic Professional\Projects\Crimson Haze\Media\Warehouse.x", 5
`Make sure all the objects are on ground level
FOR Object = 4 TO 4
POSITION OBJECT Object, OBJECT POSITION X(Object), OBJECT SIZE Y(Object)/2,OBJECT POSITION Z(Object)
NEXT Object
`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,100000
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
EnemyHP=10 `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)
`Screen Coordinates
Text 0,9,"X: "+Str$(Object Position X(1))+" Y: "+Str$(Object Position Y(1))+" Z: "+Str$(Object Position Z(1))
`Movement Controls
IF KEYSTATE(17)=1
XAngle#=OBJECT ANGLE X(1)
XROTATE OBJECT 1,0
MOVE OBJECT 1,9
XROTATE OBJECT 1,XAngle#
ENDIF
IF KEYSTATE(31)=1
XAngle#=OBJECT ANGLE X(1)
XROTATE OBJECT 1,0
MOVE OBJECT 1,-9
XROTATE OBJECT 1,XAngle#
ENDIF
IF KEYSTATE(30)=1 THEN MOVE OBJECT LEFT 1,7
IF KEYSTATE(32)=1 THEN MOVE OBJECT RIGHT 1,7
`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 THEN Jump=1
`JUMP Variable Definition
IF Jump=1
Jump_Speed#=2.5
Jumping=1
Jump=0
ENDIF
`Jumping
IF Jumping=1
DEC Jump_Speed#,.05
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 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#
`Mouseclick Shooting
IF KEYSTATE(19)=0 AND MOUSECLICK()=1
IF Ammo>0 THEN DEC Ammo,1
IF OBJECT EXIST(2)=1
` Hurt Enemy and animation
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 THEN DEC EnemyHP,1
HIDE OBJECT 2
SHOW OBJECT 6
PLAY OBJECT 6,1
ENDIF
ENDIF
`Check if the enemy should die, if so delete it and play animation
IF EnemyHP=0 AND OBJECT EXIST(2)=1 THEN DELETE OBJECT 2: DELETE OBJECT 6: SHOW OBJECT 3: PLAY OBJECT 3,1
`Reloading (press R)
IF MOUSECLICK()=0 AND KEYSTATE(19)=1 AND Ammo<MaxAmmo AND Clips>0
Reload=1
ENDIF
`Reloading (delay)
IF Reload=1 THEN INC Time#,.001
IF Time#>=1 THEN Ammo=MaxAmmo:DEC Clips,1:Time#=0:Reload=0
`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 THEN CENTER TEXT OBJECT SCREEN X(2),OBJECT SCREEN Y(2)-70,"Enemy Health: "+str$(EnemyHP)
IF OBJECT EXIST(4)=1 THEN CENTER TEXT OBJECT SCREEN X(4),OBJECT SCREEN Y(4)-20,"Ammo Crate"
`Display our Ammo and Clips on-screen
TEXT 0,ScreenHeight#-50,"Ammo: "+str$(Ammo)
TEXT 0,ScreenHeight#-40,"Clips: "+str$(Clips)
`Show that we're reloading
IF Reload=1 THEN CENTER TEXT ScreenWidth#/2,ScreenHeight#/2,"Reloading..."
`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 (5,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 (5,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 (5,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 (5,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
Nathaniel