i have added to the code to this tutorial (i have disabled some parts while i work on them) i have changed the way jumping gravity and ground collision are handle, although i am having a bit of trouble with jumping (try jumping on the red floor) ahh yes i forgot to add (with my addition i have easily placed multiple floors in [something i couldnt get to work with limb collision])
heres the code:
REM ========================================================================================================================
REM Setup Client options
sync on : sync rate 0 : hide mouse
REM ========================================================================================================================
REM CREATE ALL MEDIA
REM (Character/Player)
make object sphere 1,50 : color object 1,RGB(000,255,000) : position object 1,0,0,-400
REM Enemy
make object sphere 2,50 : color object 2,RGB(255,000,000) : position object 2,130,0,0
REM a wall
make object box 3,500,400,10 : position object 3,0,0,150
REM an Ammo Crate
make object box 4,15,20,50 : color object 4,RGB(000,255,255) : position object 4,-40,0,0
REM The Ground
GroundNo = 5 : make object box GroundNo,1000,1,1000 : color object 5,RGB(100,100,150)
make object box 6,1000,1,1000 : color object 6,RGB(100,150,100) : position object 6,10,10,700
make object box 7,1000,1,1000 : color object 7,RGB(150,100,100) : position object 7,20,20,1400
REM ========================================================================================================================
REM MAKE SURE ALL OBJECTS ARE AT GROUND LEVEL
for ObjectNo = 1 to 4
position object ObjectNo,object position x(ObjectNo),object size y(ObjectNo)/2,object position z(ObjectNo)
next ObjectNo
REM ====================================================================================================
REM DEFINE VARIABLES
Gravity = 1
GravitySpeed# = 0.5
EnemyHP = 5000
Ammo=1000
MaxAmmo=1000
Clips=3
MaxClips=3
Jumping=0
ScrnX=screen width()
ScrnY=screen height()
REM ========================================================================================================================
REM START MAIN GAME LOOP
do
REM print screen FPS
FPS=screen fps()
text 0,0,"FPS: "+str$(FPS)
REM Movement Controls
if keystate(17) = 1
XAngle#=object angle x(1)
xrotate object 1,0
move object 1,0.5
xrotate object 1,XAngle#
endif
if keystate(31) = 1
XAngle#=object angle x(1)
xrotate object 1,0
move object 1,-0.5
xrotate object 1,XAngle#
endif
if keystate(30) = 1 then move object left 1,0.3
if keystate(32) = 1 then move object right 1,0.3
REM Define Variables For Lag Reduction
ObjX#=object position x(1)
ObjY#=object position y(1)
ObjZ#=object position z(1)
REM camera positioning
position camera ObjX#,ObjY#,ObjZ#
REM space key controls
if spacekey()=1 and Jumping = 0 then Jump = 1
REM Jump Variable definition
if Jump = 1
JumpSpeed#=0.5
Jumping=1
Jump=0
Gravity = 0
endif
REM Jumping
if Jumping = 1
dec JumpSpeed#,0.002
position object 1,ObjX#,ObjY#+JumpSpeed#,ObjZ#
for Ground = GroundNo to GroundNo+1
if object collision(1,Ground)=1
Jumping = 0
Gravity = 1
endif
next Ground
endif
REM mouse camera rotation
CamX#=CamX#+mousemovey()*0.1
CamY#=CamY#+mousemovex()*0.1
if camera angle x() > 90 and camera angle x() < 135
xrotate camera 90
endif
if camera angle y() > 270 and camera angle y() < 225
yrotate camera 90
endif
xrotate camera CamX#
yrotate camera CamY#
xrotate object 1,CamX#
yrotate object 1,CamY#
REM Check to see if the enemy should die
if EnemyHP = 0 and object exist(2)=1 then delete object 2
REM Reloading
if mouseclick()=0 and keystate(19)=1 and Ammo<MaxAmmo and Clips>0
Reload=1
endif
REM reloading part 2
if Reload = 1 then inc Time#,0.001
if Time#>=1 then Ammo=MaxAmmo : dec Clips,1 : Time#=0 : Reload=0
REM Ammo Crate
if object exist(4)=1
if Ammo<MaxAmmo and intersect object(4,ObjX#,ObjY#-50,ObjZ#,ObjX#,ObjY#,ObjZ#)>0
inc Clips,(MaxClips-Clips)
inc Ammo,(MaxAmmo-Ammo)
delete object 4
endif
endif
REM Display HUD info
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"
REM display Ammo And Clips
text 0,ScrnY-50,"Ammo: "+str$(Ammo)
text 0,ScrnY-40,"Clips: "+str$(Clips)
REM show reloading message
if Reload = 1 then center text ScrnX/2,ScrnY/2,"Reloading..."
REM add targeting reticle
circle ScrnX/2,ScrnY/2,5
REM check for collision with objects
REM ground
REM Gravity
for Ground = GroundNo to GroundNo+2
if object collision(1,Ground)=0 and Jumping = 0
dec GravitySpeed#,0.003
position object 1,object position x(1),object position y(1)+GravitySpeed#,object position z(1)
if GravitySpeed# = 0.05
GravitySpeed# = 0.05
endif
else
if Gravity = 1
position object 1,object position x(1),object position y(Ground)+object size y(1)/2+0.1,object position z(1)
GravitySpeed# = 0.0
endif
endif
next Ground
sync
loop
i have a dream of perfect tactical realism in games
have a question about military tactics?
ask me at this post http://forum.thegamecreators.com/?m=forum_view&t=94634&b=1