Challenge:
Winner?:
Yes
Code Snippet:
`R2 Rancher `Coding Challenge Entry 6-Apr-2005 `By Patrick Lewis (RiiDii) Sync On:Sync Rate 60:Autocam OFf Type Coordinates x as FLoat y as Float z as Float Endtype Global Object as Coordinates Global Target as Coordinates #Constant MaxRU = 20 Type RUnit Energy as Integer Resource as Integer WayX as Float WayZ as Float ObjectID as DWord red as float green as float EndType Dim R2(MaxRU) as RUnit Dim Raider(5) as RUnit Dim Drone(10) as RUnit Position Camera 250,180,0 Make Matrix 1,500,500,20,20 Create Bitmap 1,256,256 Box 0,0,255,255,Rgb(120,120,120),Rgb(100,100,100),RGB(110,110,110),Rgb(95,95,95) Get Image 1,0,0,255,255 Prepare Matrix Texture 1,1,10,10 Set Matrix Texture 1,1,0 Update Matrix 1 Set Current Bitmap 0 Delete Bitmap 1 New_R2(250,2.5,250) New_Energy() KD=0 Money=200 Raiders=0 Do ax#=0:az#=0:ac#=0 For i = 0 To MaxRU If R2(i).ObjectID>0 Return_Object(R2(i).ObjectID) ax#=ax#+Object.x:az#=az#+Object.z:ac#=ac#+1 Head_To_Way(i) Endif Next i For i = 0 To 5 If Raider(i).ObjectID>0 Raider_To_Way(i) Endif Next i For i = 0 To 10 If Drone(i).ObjectID>0 Drone_To_Way(i) Endif Next i If KD<1 And Lower$(Inkey$())="e" And Money>0 New_Energy() KD=20 Money=Money-10 Endif If KD<1 And Lower$(Inkey$())="r" And Money>0 New_Resource(-1,-1,-1) KD=20 Money=Money-10 Endif If KD<1 And Lower$(Inkey$())="s" Flag=0:KD=20 For i=1 to MaxRU RU=Rnd(MaxRU) If R2(RU).ObjectID>0 Flag=1 Delete Object R2(RU).ObjectID R2(RU).ObjectID=0 Money=Money+100 Exit Endif Next i If Flag=0 Then Sold$="No Buyers." Else Sold$="Sold!!!" Endif If KD<1 And Lower$(Inkey$())="d" And Raiders = 1 And Money>499 KD=20 For i = 0 to 10 If Drone(i).ObjectID=0 New_Drone(rnd(490)+5,3.5,rnd(490)+5) Money=Money-500 Exit Endif Next i Endif If Raiders>0 And Rnd(200)=1 New_Raider(rnd(490)+5,2.5,rnd(490)+5) Endif If KD>0 KD=KD-1 Clear Entry Buffer If Sold$<>"" Set Cursor 0,20 Print Sold$ Endif Else Sold$="" Endif ax#=ax#/ac# az#=az#/ac# Point Camera 0,ax#,2.5,az# Set Cursor 0,0:Print "Money: ";Money If Money>999 Then Raiders=1 Sync Loop Function New_Energy() For i = 101 to 199 If Object Exist(i)=0 Then Exit Next i If i >199 then ExitFunction Make Object Sphere i,5 Do Position Object i,rnd(490)+5,2.5,rnd(490)+5 If Object Collision (i,0)=0 Then Exit Loop EndFunction Function New_Resource(x#,y#,z#) For i = 201 to 299 If Object Exist(i)=0 Then Exit Next i If i >299 then ExitFunction Make Object Cube i,5 If y#>-1 Position Object i,x#,y#,z# Else Do Position Object i,rnd(490)+5,2.5,rnd(490)+5 If Object Collision (i,0)=0 Then Exit Loop Endif EndFunction Function Energy_Look(RU) ObjectID=R2(RU).ObjectID Set Object Collision Off ObjectID If Object Exist(2) Then Delete Object 2 Make Object Sphere 2,1 Return_Object(ObjectID) Position Object 2,Object.x,Object.y,Object.z Scale Object 2,10000,10000,10000 `For i = 1 to 200 ` x=rnd(screen width()):y=rnd(screen height()) ` if Pick Object(x,y,2,2)=2 Then Dot x,y `Next i ec=Object Collision(2,0) If ec>100 and ec<200 Return_Object(ec) R2(RU).WayX=Object.x:R2(RU).WayZ=Object.z Endif Delete Object 2 Set Object Collision On ObjectID Endfunction Function Resource_Look(RU) ObjectID=R2(RU).ObjectID Set Object Collision Off ObjectID If Object Exist(2) Then Delete Object 2 Make Object Sphere 2,1 Return_Object(ObjectID) Position Object 2,Object.x,Object.y,Object.z Scale Object 2,10000,10000,10000 `For i = 1 to 100 ` x=rnd(screen width()):y=rnd(screen height()) ` if Pick Object(x,y,2,2)=2 Then Dot x,y `Next i ec=Object Collision(2,0) If ec>200 and ec<300 Return_Object(ec) R2(RU).WayX=Object.x:R2(RU).WayZ=Object.z Endif Delete Object 2 Set Object Collision On ObjectID Endfunction Function Raider_Look(RU) ObjectID=Raider(RU).ObjectID Set Object Collision Off ObjectID If Object Exist(2) Then Delete Object 2 Make Object Sphere 2,1 Return_Object(ObjectID) Position Object 2,Object.x,Object.y,Object.z Scale Object 2,10000,10000,10000 `For i = 1 to 100 ` x=rnd(screen width()):y=rnd(screen height()) ` if Pick Object(x,y,2,2)=2 Then Dot x,y `Next i ec=Object Collision(2,0) If ec>9 and ec<300 Return_Object(ec) Raider(RU).WayX=Object.x:Raider(RU).WayZ=Object.z Endif Delete Object 2 Set Object Collision On ObjectID Endfunction Function Drone_Look(RU) ObjectID=Drone(RU).ObjectID Set Object Collision Off ObjectID If Object Exist(2) Then Delete Object 2 Make Object Sphere 2,1 Return_Object(ObjectID) Position Object 2,Object.x,Object.y,Object.z Scale Object 2,20000,20000,20000 `For i = 1 to 100 ` x=rnd(screen width()):y=rnd(screen height()) ` if Pick Object(x,y,2,2)=2 Then Dot x,y `Next i ec=Object Collision(2,0) If ec>400 and ec<410 Return_Object(ec) Drone(RU).WayX=Object.x:Drone(RU).WayZ=Object.z Else If Drone(RU).Energy<3000 and ec>200 and ec<300 Return_Object(ec) Drone(RU).WayX=Object.x:Drone(RU).WayZ=Object.z Endif Endif Delete Object 2 Set Object Collision On ObjectID Endfunction Function New_Way(RU) If Object Exist(2) Then Delete Object 2 ObjectID=R2(RU).ObjectID Make Object Sphere 2,1 Scale Object 2,2000,2000,2000 Do Position Object 2,rnd(5000.0)/10.0,2.5,rnd(5000.0)/10.0 If Object Collision(2,ObjectID)=0 Then Exit Loop Return_Target(2) R2(RU).WayX=Target.x R2(RU).WayZ=Target.z Delete Object 2 EndFunction Function New_R_Way(RU) If Object Exist(2) Then Delete Object 2 ObjectID=Raider(RU).ObjectID Make Object Sphere 2,1 Scale Object 2,2000,2000,2000 Do Position Object 2,rnd(5000.0)/10.0,2.5,rnd(5000.0)/10.0 If Object Collision(2,ObjectID)=0 Then Exit Loop Return_Target(2) Raider(RU).WayX=Target.x Raider(RU).WayZ=Target.z Delete Object 2 EndFunction Function New_D_Way(RU) If Object Exist(2) Then Delete Object 2 ObjectID=Drone(RU).ObjectID Make Object Sphere 2,1 Scale Object 2,2000,2000,2000 Do Position Object 2,rnd(5000.0)/10.0,2.5,rnd(5000.0)/10.0 If Object Collision(2,ObjectID)=0 Then Exit Loop Return_Target(2) Drone(RU).WayX=Target.x Drone(RU).WayZ=Target.z Delete Object 2 EndFunction Function Head_To_Way(RU) If R2(RU).Energy <1 Return_Object(R2(RU).ObjectID) New_Resource(Object.x,Object.y,Object.z) Delete Object R2(RU).ObjectID R2(RU).ObjectID=0 ExitFunction Endif If R2(RU).WayX=0 Then New_Way(RU) IF R2(RU).Energy<2500 Then Energy_Look(RU) Else Resource_Look(RU) If Object Exist(2) Then Delete Object 2 ObjectID=R2(RU).ObjectID Make Object Sphere 2,1 Return_Object(ObjectID) Position Object 2,Object.x,Object.y,Object.z Set Object To Object Orientation 2,ObjectID Move Object 2,10 Point Object 2,R2(RU).WayX,Object.y,R2(RU).WayZ Move Object 2,2 Return_Target(2) Point Object ObjectID,Target.x,Object.y,Target.z If rnd(20)=1 then Turn Object Right ObjectID,rnd(2)-1 Move Object ObjectID,1 Delete Object 2 R2(RU).Energy=R2(RU).Energy-1 dec r2(ru).green,0.02 inc r2(ru).red,0.02 set object emissive objectid,rgb(r2(ru).red,r2(ru).green,0) R2_Collide(RU) Return_Object(ObjectID) If R2(RU).Resource>499 Then New_R2(Object.x,Object.y,Object.z):R2(RU).Resource=0 dx#=(Object.x-R2(RU).WayX):dz#=(Object.z-R2(RU).WayZ) d#=dx#*dx#+dz#*dz# if d#<25 then New_Way(RU) EndFunction Function Raider_To_Way(RU) If Raider(RU).WayX=0 Then New_R_Way(RU) Raider_Look(RU) If Object Exist(2) Then Delete Object 2 ObjectID=Raider(RU).ObjectID Make Object Sphere 2,1 Return_Object(ObjectID) Position Object 2,Object.x,Object.y,Object.z Set Object To Object Orientation 2,ObjectID Move Object 2,10 Point Object 2,Raider(RU).WayX,Object.y,Raider(RU).WayZ Move Object 2,2 Return_Target(2) Point Object ObjectID,Target.x,Object.y,Target.z If rnd(20)=1 then Turn Object Right ObjectID,rnd(2)-1 Move Object ObjectID,.8 Delete Object 2 Raider_Collide(RU) Return_Object(ObjectID) dx#=(Object.x-Raider(RU).WayX):dz#=(Object.z-Raider(RU).WayZ) d#=dx#*dx#+dz#*dz# if d#<25 then New_R_Way(RU) EndFunction Function Drone_To_Way(RU) If Drone(RU).WayX=0 Then New_D_Way(RU) Drone_Look(RU) If Object Exist(2) Then Delete Object 2 ObjectID=Drone(RU).ObjectID Make Object Sphere 2,1 Return_Object(ObjectID) Position Object 2,Object.x,Object.y,Object.z Set Object To Object Orientation 2,ObjectID Move Object 2,10 Point Object 2,Drone(RU).WayX,Object.y,Drone(RU).WayZ Move Object 2,2 Return_Target(2) Point Object ObjectID,Target.x,Object.y,Target.z If rnd(20)=1 then Turn Object Right ObjectID,rnd(2)-1 Move Object ObjectID,1.2 Drone(RU).Energy=Drone(RU).Energy-1 If Drone(RU).Energy<1 Delete Object Drone(RU).ObjectID Drone(RU).ObjectID=0 ExitFunction Endif Delete Object 2 Drone_Collide(RU) Return_Object(ObjectID) dx#=(Object.x-Drone(RU).WayX):dz#=(Object.z-Drone(RU).WayZ) d#=dx#*dx#+dz#*dz# if d#<25 then New_D_Way(RU) EndFunction Function R2_Collide(RU) ObjectID=R2(RU).ObjectID OC=Object Collision(ObjectID,0) If OC>100 and OC<200 Delete Object OC R2(RU).Energy=R2(RU).Energy+1000 dec r2(ru).red,20 inc r2(ru).green,20 Endif If OC>200 and OC<300 Delete Object OC R2(RU).Resource=R2(RU).Resource+100 Endif Endfunction Function Raider_Collide(RU) ObjectID=Raider(RU).ObjectID OC=Object Collision(ObjectID,0) If OC>100 and OC<300 Delete Object OC Endif If OC>9 and OC<MaxRU+10 Delete Object OC R2(OC-10).ObjectID=0 Endif Endfunction Function Drone_Collide(RU) ObjectID=Drone(RU).ObjectID OC=Object Collision(ObjectID,0) If (OC>399 and OC<410) or (OC>100 and OC<200) Delete Object OC If OC<200 Then Drone(RU).Energy=Drone(RU).Energy+1000 Else Raider(OC-400).ObjectID=0 Endif Endfunction Function New_R2(x#,y#,z#) Flag=0 For i=0 to MaxRU If R2(i).ObjectID=0 Flag=1 Exit Endif Next i If Flag = 0 then ExitFunction R2(i).ObjectID=10+i Make_R2(10+i) Position Object 10+i,x#,y#,z# R2(i).Energy=5000 r2(i).green=100 EndFunction Function New_Raider(x#,y#,z#) Flag=0 For i=0 to 5 If Raider(i).ObjectID=0 Flag=1 Exit Endif Next i If Flag = 0 then ExitFunction Raider(i).ObjectID=400+i Make_Raider(400+i) Position Object 400+i,x#,y#,z# EndFunction Function New_Drone(x#,y#,z#) Flag=0 For i=0 to 10 If Drone(i).ObjectID=0 Flag=1 Exit Endif Next i If Flag = 0 then ExitFunction Drone(i).ObjectID=500+i Drone(i).Energy=5000 Make_Drone(500+i) Position Object 500+i,x#,y#,z# EndFunction Function Make_R2(ObjectID) If Object Exist(ObjectID) Then Delete Object ObjectID If Object Exist(2) Then Delete Object 2 `Arms Make Object Sphere 2,2 Make Mesh From Object 2,2 Delete Object 2 Make Object Cylinder 2,2 Scale Limb 2,0,100,50,100 Add limb 2,1,2 Add Limb 2,2,2 Scale Limb 2,1,100,1,100 Scale Limb 2,2,100,1,100 Offset Limb 2,1,0,.5,0 Offset Limb 2,2,0,-.5,0 Pitch Object Up 2,90 Fix Object Pivot 2 Make Mesh From Object 2,2 Delete Object 2 Make Object 2,2,0 Make Object Box ObjectID,2,5,1 Make Mesh From Object ObjectID,ObjectID Delete Object ObjectID Add Limb 2,1,ObjectID Offset Limb 2,1,0,-2.5,0 Turn Object Right 2,90 Fix Object Pivot 2 Make Mesh From Object 3,2 Delete Object 2 `Body Make Object Sphere ObjectID,5 Make Mesh From Object ObjectID,ObjectID Delete Object ObjectID Make Object Cylinder ObjectID,5 Add Limb ObjectID,1,ObjectID Offset Limb ObjectID,1,0,2.5,0 `Leg Make Object Box 2,1,3,1.5 Make Mesh From Object 4,2 Delete Object 2 `Feet Make Object Box 2,1.5,.8,2.5 Make Mesh From Object 2,2 Delete Object 2 Add Limb ObjectID,2,4 Offset Limb ObjectID,2,0,-3,1.6 Add Limb ObjectID,3,2 Link Limb ObjectID,2,3 Offset Limb ObjectID,3,0,-1.5,0 Add Limb ObjectID,4,3 Offset Limb ObjectID,4,2.8,1,-.2 Add Limb ObjectID,5,2 Link Limb ObjectID,4,5 Offset Limb ObjectID,5,0,-5,0 Add Limb ObjectID,6,3 Offset Limb ObjectID,6,-2.8,1,-.2 Add Limb ObjectID,7,2 Link Limb ObjectID,6,7 Offset Limb ObjectID,7,0,-5,0 Rotate Limb ObjectID,4,30,0,0 Rotate Limb ObjectID,6,30,0,0 Rotate Limb ObjectID,3,15,0,0 Rotate Limb ObjectID,5,-15,0,0 Rotate Limb ObjectID,7,-15,0,0 Pitch Object Up ObjectID,15 Fix Object Pivot ObjectID set object emissive objectid,rgb(0,100,0) EndFunction Function Make_Raider(ObjectID) If Object Exist(ObjectID) Then Delete Object ObjectID Make Object Sphere ObjectID,3 Make Mesh From Object ObjectID,ObjectID Delete Object ObjectID Make Object Cone ObjectID,5 Add Limb ObjectID,1,ObjectID Offset Limb ObjectID,1,0,2.5,0 If Object Exist(2) Then Delete Object 2 Make Object Cylinder 2,1 Scale Object 2,25,100,25 Pitch Object Down 2,90 Fix Object Pivot 2 Make Mesh From Object 2,2 Delete Object 2 Add Limb ObjectID,2,2 Offset Limb ObjectID,2,1.5,.5,1 Color Object ObjectID,RGB(105,52,52) EndFunction Function Make_Drone(ObjectID) If Object Exist(ObjectID) Then Delete Object ObjectID Make Object Cylinder ObjectID,1 Scale Object ObjectID,25,200,25 Offset Limb ObjectID,0,0,2,0 Pitch Object Down ObjectID,90 Fix Object Pivot ObjectID Make Mesh From Object ObjectID,ObjectID Delete Object ObjectID Make Object Sphere ObjectID,3 For i = 1 to 8 Add Limb ObjectID,i,ObjectID Rotate Limb ObjectID,i,Rnd(360),Rnd(360),0 Next i Color Object ObjectID,RGB(255,0,0) EndFunction Function Return_Object(ObjectID) Object.x=Object Position X(ObjectID):Object.y=Object Position Y(ObjectID):Object.z=Object Position Z(ObjectID) EndFunction Function Return_Target(TargetID) Target.x=Object Position X(TargetID):Target.y=Object Position Y(TargetID):Target.z=Object Position Z(TargetID) EndFunction