Here's an update. It's not in 20-Line rules format yet, but I will convert soon.
For anyone interested: This game works almost completely off a sliding Vertex-Based Collision (VBC) system I have been working on for a little while now. It's finally fine-tuned to be fast and accurate, with a few parameter settings to help optimize performance. Besides the collision system, I've added simple gravity (simple downward velocity, no acceleration) and momentum.
Resistance to movement is handled by the collision system as well as rolling "downhill" even if the "downhill" is in-between the bars and going "uphill". The bars are angled up at 4.5 degrees, so the restance to moving towards the camera is actually due to the 'gravity' and the object's tendancy to roll downhill.
For everyone else: Enjoy. Post your scores. And feedback, comments, suggestions, etc. are more-than-welcome.
Sync On
Sync Rate 60
Autocam Off
Global n#
Global cFlag as Integer
Global LimbMatrix As Integer
Global EyeVector As Integer
Global LookAtVector As Integer
Global LookUpVector As Integer
LimbMatrix=10
EyeVector=11
LookAtVector=12
LookUpVector=13
r = Make Matrix4( LimbMatrix )
r = Make Vector3(1)
r = Make Vector3(EyeVector)
r = Make Vector3(LookAtVector)
r = Make Vector3(LookUpVector)
Make Object Sphere 1,8,15,15
Prepare_Limb(1,0)
Scale Object 1,85,85,85
Make Object Cylinder 2,1
Set Object Collision Off 1
Scale Object 2,150,6000,150
Offset Limb 2,0,0,.48,0
Pitch Object Up 2,90
Fix Object Pivot 2
Make Mesh From Object 2,2
Delete Object 2
Make Object 2,2,0
Set Object Cull 2,0
Clone Object 3,2
Position Object 2,-1.8,-10,60
Position Object 3,1.8,-10,60
Set Object Collision Off 2
Set Object Collision Off 3
Make object Plain 5,10,60
Pitch Object Down 5,90
Set Object Cull 5,0
Position Object 5,0,-15,30
Set Object Emissive 5,Rgb(0,255,0)
Set Object Collision Off 5
Position Camera 0,0,-20
Do
Position Object 1,0,10,56
Rotate Object 2,4.5,0,0
Rotate Object 3,4.5,0,0
mm#=0
Do
`Turn Object Right 1,33
z#=Object Position Z(1)
Move Object Down 1,.4
c2=Check_Collision(1,0,2,1,1)
fx#=fpos(20,0)
fy#=fpos(20,1)
fz#=fpos(20,2)
Position Object 1 , fx# , fy# , fz#
c3=Check_Collision(1,0,3,1,1)
Move Object Up 1,.4
If c2=0 and c3=0
dn#=1
Else
dn#=0
Endif
fx#=fpos(20,0)
fy#=fpos(20,1)
fz#=fpos(20,2)
Position Object 1,fx#,fy#-dn#,fz#+mm#
If Object Position Z(1)>59
Position Object 1,Object Position X(1),Object Position Y(1),59
Endif
mm#=(Object Position Z(1)-z#)*.9
mc#=(MouseClick()=1)*2-1
Turn Object Right 3,.3*RightKey()*mc#
Turn Object Left 2,.3*LeftKey()*mc#
If Object Position Y(1)<-10
Exit
Endif
Set Cursor 0,0
Print "Score: ";Int(60-Object Position Z(1))
Print
Print "FPS: ";Screen FPS()
Sync
Loop
Do
Set Cursor 0,0
Print "Score: ";Int(60-Object Position Z(1))
Print
Print "Press any key to try again"
If Inkey$()<>""
Exit
Endif
Sync
Loop
loop
Function Prepare_Limb(ObjectID,LimbID)
Local tx#
Local ty#
Local tz#
Local ac as Integer
Local n as Integer
Local max as Integer
If Limb Exist(ObjectID,LimbID)=0
ExitFunction
Endif
arry=ObjectID*20+LimbID
ac=Array Count(PreLimb())
If ac<arry
max=1
If ac>1
For i = 1 to ac
If max<PreLimb(i)
max=PreLimb(i)
Endif
Next i
Endif
Dim PreLimb(arry) as Integer
PreLimb(arry)=1
Dim LMX(arry,max) as Float
Dim LMY(arry,max) as Float
Dim LMZ(arry,max) as Float
Endif
Lock VertexData for Limb ObjectID,LimbID
VIC=Get Vertexdata Index Count()
n=0
LMX(arry,n)=Get VertexData Position X(Get IndexData(0))
LMY(arry,n)=Get VertexData Position Y(Get IndexData(0))
LMZ(arry,n)=Get VertexData Position Z(Get IndexData(0))
For i = 1 to VIC
tx#=Get VertexData Position X(Get IndexData(i))
ty#=Get VertexData Position Y(Get IndexData(i))
tz#=Get VertexData Position Z(Get IndexData(i))
flag=0
For j=0 to n
if Int(tx#*100)=Int(LMX(arry,j)*100) and Int(ty#*100)=Int(LMY(arry,j)*100) and Int(tz#*100)=Int(LMZ(arry,j)*100)
flag=1
Exit
Endif
Next j
If flag=0
n=n+1
If n>max
max=n
PreLimb(arry)=n
Dim LMX(arry,n) as Float
Dim LMY(arry,n) as Float
Dim LMZ(arry,n) as Float
Endif
LMX(arry,n)=tx#
LMY(arry,n)=ty#
LMZ(arry,n)=tz#
Endif
Next i
Unlock VertexData
Endfunction
Function Check_Collision(ObjectID as DWord,LimbID as DWord,TargetID as DWord,accuracy#,cycles)
arry=ObjectID*20+LimbID
if Array Count(cflag(0))<arry
Dim cFlag(arry) as Integer
Dim fpos(arry,2) as Float
Dim n(arry) as Float
Endif
If Array Count(PreLimb())<arry
Exit Prompt "Check_Collision():Limb was not prepared. Use Prepare_Limb() function first.","Error"
End
Else
If PreLimb(arry)<1
Exit Prompt "Check_Collision():Limb was not prepared. Use Prepare_Limb() function first.","Error"
End
Endif
Endif
LimbMatrix4(LimbMatrix, ObjectID, LimbID)
ox#=Limb Position X(ObjectID,LimbID)
oy#=Limb Position Y(ObjectID,LimbID)
oz#=Limb Position Z(ObjectID,LimbID)
st=1.0/accuracy#
MC=PreLimb(arry)
If cFlag(arry)=0
n(arry)=1
fpos(arry,0)=ox#
fpos(arry,1)=oy#
fpos(arry,2)=oz#
Else
if n(arry)>1
n(arry)=2
fpos(arry,0)=fpos(arry,0)+ox#
fpos(arry,1)=fpos(arry,1)+oy#
fpos(arry,2)=fpos(arry,2)+oz#
Endif
Endif
For i = 0+cFlag(arry) to MC step st
Set Vector3 1,LMX(arry,i),LMY(arry,i),LMZ(arry,i)
Transform Coords Vector3 1, 1, LimbMatrix
d#=Intersect Object(TargetID,ox#,oy#,oz#,X Vector3(1),Y Vector3(1),Z Vector3(1))
if d#>0
Set Vector3 1,X Vector3(1)-ox#,Y Vector3(1)-oy#,Z Vector3(1)-oz#
d2#=Length Vector3(1)
id2#=d2#-d#
Multiply Vector3 1,-(id2#/d2#)
fpos(arry,0)=fpos(arry,0)+(ox#+X Vector3(1))*id2#
fpos(arry,1)=fpos(arry,1)+(oy#+Y Vector3(1))*id2#
fpos(arry,2)=fpos(arry,2)+(oz#+Z Vector3(1))*id2#
n(arry)=n(arry)+id2#
Endif
Next i
cFlag(arry)=cFlag(arry)+1
if cFlag(arry)>cycles
cFlag(arry)=0
Endif
fpos(arry,0)=fpos(arry,0)/n(arry)
fpos(arry,1)=fpos(arry,1)/n(arry)
fpos(arry,2)=fpos(arry,2)/n(arry)
Hit=(n(arry)>1)
EndFunction Hit
`Thanks to Dmitry K for this function!
Function LimbMatrix4(ResultMatrix, Object, Limb)
AX#=Limb Direction X( Object, Limb ) : AY#=Limb Direction Y( Object, Limb ) : AZ#=Limb Direction Z( Object, Limb )
CX#=Cos(AX#) : SX#=Sin(AX#) : CY#=Cos(AY#) : SY#=Sin(AY#) : CZ#=Cos(AZ#) : SZ#=Sin(AZ#)
Set Vector3 EyeVector, Limb Position X( Object, Limb), Limb Position Y( Object, Limb), Limb Position Z( Object, Limb)
Set Vector3 LookAtVector, -1.0*SZ#*(-1.0*SX#)+CZ#*SY#*CX#+Limb Position X(Object,Limb), CZ#*(-1.0*SX#)+SZ#*SY#*CX#+Limb Position Y(Object,Limb), CY#*CX#+Limb Position Z(Object,Limb)
Set Vector3 LookUpVector, -SZ#*CX#+CZ#*SY#*SX#, CZ#*CX#+SZ#*SY#*SX#, CY#*SX#
Build LookAt LHMatrix4 ResultMatrix, EyeVector, LookAtVector, LookUpVector
r=Inverse Matrix4( ResultMatrix, ResultMatrix )
EndFunction
"Droids don't rip your arms off when they lose." -H. Solo
REALITY II