Sliding box math collision by Phaelax7th Dec 2003 11:57
|
---|
Summary Sliding box math collision. Collision data is stored in an array. For non-rotated boxes. Description Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com `-----------SLIDING MATH COLLISION------ ` `Coded by Phaelax (phaelax@hotmail.com) `The information the SOBJECT# array holds is as follows: `1=x position `2=z position `3=half of objects size on x-axis `4=half of objects size on z-axis sync on sync rate 60 hide mouse make matrix 1,1000,1000,10,10 make object cube 1,30 make object cube 2,50 scale object 2,300,100,100 position object 2,400,25,150 make object cube 3,90 position object 3,800,45,500 rem define half of player object size playersize#=15.0 rem define properties of collision objects dim sobject#(2,4) rem properties of object 1 sobject#(1,1)=400 sobject#(1,2)=150 sobject#(1,3)=75 sobject#(1,4)=25 rem properties of object 2 sobject#(2,1)=800 sobject#(2,2)=500 sobject#(2,3)=45 sobject#(2,4)=45 DO oldx#=x# oldz#=z# gosub player_controls for t=1 to 2 if abs(x#-sobject#(t,1))<sobject#(t,3)+playersize# and abs(z#-sobject#(t,2))<sobject#(t,4)+playersize# if abs(oldx#-sobject#(t,1))<sobject#(t,3)+playersize# then z#=oldz# if abs(oldz#-sobject#(t,2))<sobject#(t,4)+playersize# then x#=oldx# endif next t gosub camera_status position object 1,x#,15,z# sync LOOP PLAYER_CONTROLS: if shiftkey()=1 then runspeed#=6.0 if upkey()=1 x#=newxvalue(x#,a#,6+runspeed#) z#=newzvalue(z#,a#,6+runspeed#) endif if downkey()=1 x#=newxvalue(x#,a#,-6-runspeed#) z#=newzvalue(z#,a#,-6-runspeed#) endif if leftkey()=1 x#=newxvalue(x#,wrapvalue(a#-90.0),5.0+runspeed#) z#=newzvalue(z#,wrapvalue(a#-90.0),5.0+runspeed#) endif if rightkey()=1 x#=newxvalue(x#,wrapvalue(a#+90.0),5.0+runspeed#) z#=newzvalue(z#,wrapvalue(a#+90.0),5.0+runspeed#) endif RETURN CAMERA_STATUS: rem rotate camera according to mouse a#=wrapvalue(a#+(mousemovex()/3.0)) rem position and rotate camera cxa#=cxa#+(mousemovey()/3.0) if cxa#<-90.0 then cxa#=-90.0 if cxa#>90.0 then cxa#=90.0 position camera x#,y#+50,z# rotate camera wrapvalue(cxa#),a#,0 RETURN |