Rem Project: Starship
Rem Created: 6/25/2004 8:18:22 PM
 
Rem ***** Main Source File *****
 
 
Set Display Mode 1280,960,32
sync on : sync rate 30 : Color Backdrop rgb(0,0,0)
set camera range 0,1,7000
Position Camera 0,0,0,0
Autocam off
Set Image Colorkey 0,0,0
 
CreateStarField(16)
Make Object Sphere 2, 10000
Texture Object 2,16
Scale Object Texture 2,4,4
Position Object 2,0,0,0
Set Object Light 2,0
Set Object Cull 2,0
Fade Object 2,1000
 
 
Dim Modules#(1000,4)
 
 
ink rgb(255,255,255),0
 
`Images
Module(1)
DryDock(3)
CreatePlanet(4)
CreateClouds(5)
Const_Skin1(6)
Const_Skin2(7)
Fire(8)
Beam_Effect1(9)
Grid1(11)
Beam_Effect1(12)
BaySide(13)
Star(15)
 
Set Ambient Light 1
Rem Fog On
Rem Fog Color 0
Rem Fog Distance 3000
Autocam Off
Make Light 2
Position Light 2,460,0,460
Set Directional Light 2,-1,0,0
Set Light Range 2,200
Color Light 2,RGB(0,0,250)
 
Rem <<< Base Module >>>
Make Object Cube 1,50
Position Object 1,450,0,460
Texture Object 1,1
Scale Object Texture 1,.25,.25
 
Make Object Cube 750,5
Position Object 750,-20,15,40
Texture Object 750,1
Scale Object Texture 750,.25,.25
Ghost Object On 750
Lock Object On 750
Hide Object 750
Disable Object ZDepth 750
 
Rem <<< Bright Star >>>
Make Object Plain 11,600,600
Texture Object 11,15
Set Object 11,1,1,0
Ghost Object On 11
Position Object 11,1800,100,100
Turn Object Right 11,90
Fade Object 11,1000
Make Light 1
Set Point Light 1, 1800,100,100
Color Light 1,240,240,255
Set Light Range 1, 10000
 
Rem <<< Planet >>>
 
PlanX = (rnd(1000)+1500)*(rnd(1)*2-1)
PlanY = 0
PLanZ = (rnd(1000)+1500)*(rnd(1)*2-1)
 
Make Object Sphere 502,1000,30,30
Position Object 502,PlanX,PlanY,PlanZ
Roll Object Left 502,38
Texture Object 502,5
Ghost Object On 502
Set Object 502,1,0,1,1,1,0,1
Fade Object 502,150
 
 
Make Object Sphere 507,970,30,30
Position Object 507,PlanX,PlanY,PlanZ
Texture Object 507,4
Roll Object Left 507,40
Set Object Smoothing 507,100
 
Make Object Sphere 508,1030,30,30
Position Object 508,PlanX,PlanY,PlanZ
Texture Object 508,5
Ghost Object On 508
Fade Object 508,60
 
Rem <<< Dry Dock >>>
 
Make Object Cube 503,0
Make Object Box 504,1000,3,1000
 
Make Mesh From Object 503,504
Add Limb 503,1,503
Offset Limb 503,1,0,0,500
Texture Limb 503,1,3
Rotate Limb 503,1,90,0,0
Scale Limb Texture 503,1,11,11
 
Make Mesh From Object 504,504
Add Limb 503,2,504
Offset Limb 503,2,0,0,-500
Texture Limb 503,2,3
Rotate Limb 503,2,90,0,0
Scale Limb Texture 503,2,11,11
 
Make Mesh From Object 505,504
Add Limb 503,3,505
Offset Limb 503,3,0,500,0
Texture Limb 503,3,3
Scale Limb Texture 503,3,11,11
 
Make Mesh From Object 506,504
Add Limb 503,4,506
Offset Limb 503,4,0,-500,0
Texture Limb 503,4,3
Scale Limb Texture 503,4,11,11
Fade Object 503,200
 
Delete Object 504
Set Object 503,1,1,0
Make Object Cube 2001,50
Texture Object 2001,11
Set Object 2001,1,0,0
Ghost Object On 2001
Fade Object 2001,250
 
Rem <<< Construction Bay >>>
 
Make Object Box 700,.5,.5,.5
Color Object 700,0
Make Object Box 701,104,79,8
For i = 1 to 4
   Make Mesh From Object 700+i,701
   Add Limb 700,i,700+i
   Texture Limb 700,i,13
Next i
Delete Object 701
Offset Limb 700,1,0,0,42
Offset Limb 700,2,0,0,-42
Offset Limb 700,3,0,42,0
Offset Limb 700,4,0,-42,0
Rotate Limb 700,3,90,0,0
Rotate Limb 700,4,90,0,0
Position Object 700,460,0,460
Set Object 700,1,1,1
Fix Object Pivot 700
Fade Object 700,200
 
Make Object Cylinder 701,70
Set Object 701,1,0,0,1,0,0,1
Scale Object 701,100,400,100
Texture Object 701,12
Scale Object Texture 701,4,1
Ghost Object On 701
Roll Object Right 701,90
Position Object 701,350,0,460
Fade Object 701,200
Make Particles 1,12,80,20
Position Particles 1,510,0,460
Color Particles 1,0,10,200
Rotate Particles 1,0,0,90
Set Particle Gravity 1,0
Set Particle Velocity 1,100
Set Particle Life 1,5
 
Make Object Box 702,280,60,60
Position Object 702,350,0,460
Set Object 702,1,1,0
Color Object 702,0
 
Rem <<< Constructor >>>
 
Make Object Sphere 600,25,20,20
Position Object 600,0,0,50
Make Object Box 601,25,10,25
Make Mesh From Object 601,601
Add Limb 600,1,601
Offset Limb 600,1,0,0,-15
Delete Object 601
Make Object Cylinder 602,3
Scale Object 602,100,1500,100
Pitch Object Up 602,90
Make Mesh From Object 602,602
Add Limb 600,2,602
Offset Limb 600,2,10.9,0,15
Make Mesh From Object 603,602
Add Limb 600,3,603
Offset Limb 600,3,-10.9,0,15
Scale Object 602,200,60,200
Make Mesh From Object 604,602
Add Limb 600,4,604
Offset Limb 600,4,-9,0,-28
Make Mesh From Object 605,602
Add Limb 600,5,605
Offset Limb 600,5,9,0,-28
Scale Object 602,190,65,190
Make Object Sphere 603,3
Scale Object 603,195,195,65
Make Mesh From Object 606,603
Add Limb 600,6,606
Offset Limb 600,6,-9,0,-28
Make Mesh From Object 607,603
Add Limb 600,7,607
Offset Limb 600,7,9,0,-28
Delete Object 603
Make Object Cube 604,1
Make Mesh From Object 608,604
Add Limb 600,8,608
Offset Limb 600,8,0,0,70
Hide Limb 600,8
Delete Object 604
 
Delete Object 602
 
 
 
Rem Hide Object 600
 
For I = 604 to 605
   Make Object Cylinder I,3
   Scale Object I,95,1800,95
   Texture Object I,9
   Ghost Object On I
   Pitch Object Up I,90
   Fade Object I,400
Next I
Glue Object to Limb 604,600,2
Glue Object to Limb 605,600,3
 
Texture Limb 600,0,7
Scroll Limb Texture 600,0,.5,-.1
For i = 1 to 5
   Texture Limb 600,i,6
Next I
Texture Limb 600,6,8
Texture Limb 600,7,8
Disable Object ZDepth 600
 
For I = 0 to 7
   Set Limb Smoothing 600,i,20
Next I
 
Make Object Sphere 610,80
Texture Object 610,12
Ghost Object On 610
Glue Object to Limb 610,600,0
 
Rem <<< Set Initial Camera Position and Variables >>>
Position Camera 0,0,0
Speed# = 0
yRot# = 0
AyRot# = 0
spin# = 0
spin2#= 0
AutoDock = 0
ySpeed#=0
Modnum=0
Grids = 1
ShieldOn=0
LastSaved=2
 
Do
Select AutoDock
Case 0,4
Rem <<< Control input for Constructor Movement >>>
   a$=""
   CX=Object Position X(600):CY=Object Position Y(600):CZ=Object Position Z(600)
   If Upkey()=1
      Speed# = Speed#+.2
   Else
      Speed#=Speed#-.1
   Endif
   If LeftKey()=1
      yRot# = yRot#-.2
   Else
      If yRot#<0 Then yRot#=yRot#+.1
   Endif
   If RightKey()=1
      yRot# = yRot#+.2
   Else
      If yRot#>0 Then yRot#=yRot#-.1
   Endif
   If yRot#<.2 And yRot#>-.2 Then yRot#=0
   If DownKey()=1 Then Speed# = Speed#-.2
   IF Speed# >10 Then Speed# = 10
   If Speed# <0 Then Speed# = 0
   If yRot# > 5 then yRot# = 5
   If yRot# <-5 then yRot# = -5
   AyRot#=0
 
Rem <<< Auto Align >>>
   If yRot# = 0
      Limb0X# = Int(Limb Position X(600,0)*10)/10
      Limb0Z# = Int(Limb Position Z(600,0)*10)/10
      Limb1X# = Int(Limb Position X(600,1)*10)/10
      Limb1Z# = Int(Limb Position Z(600,1)*10)/10
      DiffX# = Limb0X#-Limb1X#: DiffZ# = Limb0Z#-Limb1Z#
      If DiffX#*DiffZ# <> 0
         If Abs(DiffX#)>Abs(DiffZ#)
            If DiffX#*DiffZ#>0 Then AyRot#=.1
            If DiffX#*DiffZ#<0 Then AyRot#=-.1
         Else
            If DiffX#*DiffZ#>0 Then AyRot#=-.1
            If DiffX#*DiffZ#<0 Then AyRot#=.1
         Endif
      Endif
   Endif
 
Rem <<< Control Contstructor Vertical Movement >>>
   a$ = Inkey$()
   If a$="a"
      ySpeed#=1
   Endif
   If a$="z"
      ySpeed#=-1
   Endif
 
Rem Save Ship
   If AutoDock=0 and a$="s" and ModNum-LastSaved>0
      Gosub SaveShip
   Endif
 
Rem <<< Keep Constructor in Dry Dock >>>
   If Object Position Y(600) <-460
      Position Object 600,Object Position X(600),-458,Object Position Z(600)
      Speed#=0:ShieldOn=10
   Endif
   If Object Position Y(600) >460
      Position Object 600,Object Position X(600),458,Object Position Z(600)
      Speed#=0:ShieldOn=10
   Endif
   If Object Position Z(600) <-460
      Position Object 600,Object Position X(600),Object Position Y(600),-458
      Speed#=0:ShieldOn=10
   Endif
   If Object Position Z(600) >460
      Position Object 600,Object Position X(600),Object Position Y(600),458
      Speed#=0:ShieldOn=10
   Endif
   If Object Position X(600) <-460
      Position Object 600,-458,Object Position Y(600),Object Position Z(600)
      Speed#=0
   Endif
   If Object Position X(600) >460
      Position Object 600,458,Object Position Y(600),Object Position Z(600)
      Speed#=0
   Endif
   If CheckLimbHit(600,0,80,700)=1
      Move Object 600,Speed#*-2
      Speed#=Int(Speed#/2)
      ShieldOn = 10
   Endif
   If ModNum>1
      LS=80:CLimb=0
      If Autodock=4
         LS=50
         CLimb=8
      Endif
      For i = 1 to ModNum-1
         cHit=CheckLimbhit(600,CLimb,LS,1000+i)
         If cHit=1
            Move Object 600,Speed#*-2
            Speed#=Int(Speed#/2)
            ySpeed#=OldySpeed#*-1
            yRot#=yRot#*-1
            IF LS=80 Then ShieldOn=10
         Endif
      Next i
   Endif
 
Rem <<< Check for Autodock >>>
   cHit = Checkhit(600,702)
   If cHit=1 And AutoDock<>4
      AutoDock = 1
      Speed#=0:yRot#=0:AyRot#=0:ySpeed#=0
      Enable Object ZDepth 600
   Endif
 
Rem <<< Check for Dropping Module Off And Drop >>>
   Rem <Check Grid Overlap>
   GridFlag = 0: GridHit = 0:TGridHit=0:Dist=2000
   If Autodock = 4 and asc(a$) = 13
      For i = 1 to Grids
         If CheckLimbHit(600,8,50,2000+i)=1
            GridFlag = 1
            TGridHit = 2000+i
            TDist=GetLimbDistance(600,8,2000+i)
            If TDist<Dist
               GridHit=TGridHit
               Dist=TDist
            Endif
         Endif
      Next i
   Endif
 
   Set Cursor 0,100: Print CheckLimbHit(1000+ModNum,8,50,2000+Grids);" ";Limb Position X(600,8);" ";Limb Position Z(600,8):Print Grids:Print ModNum
   If Autodock = 4 and asc(a$) = 13 and GridFlag=1
      Unglue Object 1000+ModNum
      Modules#(ModNum,1)=ModuleNum
      Show Object 1
      Position Object 1000+ModNum,Object Position X(GridHit), Object Position Y(GridHit),Object Position Z(GridHit)
      Modules#(ModNum,2) =Object Position X(1000+ModNum)
      Modules#(ModNum,3) =Object Position Y(1000+ModNum)
      Modules#(ModNum,4) =Object Position Z(1000+ModNum)
      Rotate Object 1000+ModNum,Object Angle X(1),Object Angle Y(1),Object Angle Z(1)
      AutoDock =0
      Hide Object 750
      Rem <Create New Grids>
      Restore GridOffset
      OldGrid = 2000+Grids
      For i = 1 to 6
         Read GX,GY,GZ
         Grids=Grids+1
         CopyObject(2000+Grids,2001)
         Position Object 2000+Grids,Object Position X(GridHit)+GX,Object Position Y(GridHit)+GY,Object Position Z(GridHit)+GZ
         TGrids=Grids
         Overlap=0
         For j = 2001 to OldGrid
            If CheckHit(2000+Grids,j) = 1
               Overlap=1
            Endif
         Next j
         If Overlap=1
            Delete Object 2000+Grids
            Grids=Grids-1
         Endif
         If TGrids=Grids
            Texture Object 2000+Grids,11
            Set Object 2000+Grids,1,0,0
            Ghost Object On 2000+Grids
            Fade Object 2000+Grids,250
         Endif
      Next i
      Hide Object GridHit
      ScrollRow#=-.25*OldRow
      ScrollCol#=-.25*OldCol
      Scroll Object Texture 750,ScrollRow#,ScrollCol#
      ModNum=ModNum+1
   Endif
   If ShieldOn>0
      ShieldOn = ShieldOn-1
      Show Object 610
   Else
      Hide Object 610
   Endif
EndCase
Case 1
 
Rem <<< Autodock >>>
Rem <<< Turn Constructor Toward Bay>>>
   Speed#=0:yRot#=0:AyRot#=0:ySpeed#=0
   If Int(Limb Position Z(600,0)*10)>Int(Limb Position Z(600,1)*10)
      aYRot#=.2
   Endif
   If Int(Limb Position Z(600,0)*10)<Int(Limb Position Z(600,1)*10)
      aYRot#=-.2
   Endif
Rem <<< Raise or Lower Constructor >>>
   If Int(Object Position Y(600)*10)<0 Then ySpeed# =.5
   If Int(Object Position Y(600)*10)>0 Then ySpeed# =-.5
Rem <<< Move Contructor Towards Bay >>>
   MoveX#=0
   If Int(Object Position X(600)*20)/20<380 Then MoveX#=.5
   If Int(Object Position X(600)*20)/20>380 Then MoveX#=-.5
   MoveZ#=0
   If Int(Object Position Z(600)*20)/20<460 Then MoveZ#=.2
   If Int(Object Position Z(600)*20)/20>460 Then MoveZ#=-.2
   Position Object 600,Object Position X(600)+MoveX#,Object Position Y(600),Object Position Z(600)+MoveZ#
   If MoveX#+MoveZ#+ySpeed#+AyRot#=0
      AutoDock=2
      Show Object 750
      ModuleNum=0
      OldModuleNum=0
      KeyDelay=0
      OldRow=0
      OldCol=0
 
      If ModNum=0 Then Modnum=Modnum+1
      CopyObject(1000+ModNum,1)
      Hide Object 1
      Hide Object 1000+ModNum
      Position Object 1,450,0,460
      Texture Object 1000+ModNum,1
      Position Object 1000+ModNum,450,0,460
      Show Object 1000+ModNum
   Endif
EndCase
 
 
` <<< Docked: Select Module >>>
Case 2
   a$ = ""
   Restore ModuleList
   For i = 0 to ModuleNum
      Read ModName$
   Next I
   If KeyDelay<1
      a$=Inkey$()
      KeyDelay = 10
   Else
      a$=""
      KeyDelay=KeyDelay-1
   Endif
   If a$="," Then ModuleNum=ModuleNum-1
   If a$="." Then ModuleNum=ModuleNum+1
   Set Cursor 0,100: Print ModuleNum
   If ModuleNum<>OldModuleNum
      If ModuleNum<0 Then ModuleNum=15
      If ModuleNum>15 Then   ModuleNum=0
      Col=Int(ModuleNum/4)
      Row=ModuleNum-(Col*4)
      OldModuleNum=ModuleNum
` <<< Unscroll Last Texture Scroll >>>
      ScrollRow#=-.25*OldRow
      ScrollCol#=-.25*OldCol
      Scroll Object Texture 1000+ModNum,ScrollRow#,ScrollCol#
      Scroll Object Texture 750,ScrollRow#,ScrollCol#
` <<< Scroll New Texture Scroll >>>
      ScrollRow#=.25*Row
      ScrollCol#=.25*Col
      Scroll Object Texture 1000+ModNum,ScrollRow#,ScrollCol#
      Scroll Object Texture 750,ScrollRow#,ScrollCol#
      OldRow = Row:OldCol = Col
   Endif
   Set Cursor 100,100:Print ModName$
   If asc(a$)=13
      Autodock = 3
      ReleaseWait=0
   Endif
EndCase
` <<< Release From Autodock with Module in tow >>>
Case 3
   POsition Object 1000+ModNum,0,0,0
   Glue Object To Limb 1000+ModNum,600,8
   Speed#=-.3
   If Checkhit(600,702)=0
      ReleaseWait = ReleaseWait+1
      If ReleaseWait>10
         Speed#=0
         Autodock =4
      Endif
   Endif
EndCase
 
EndSelect
Set Cursor 0,0
Print Autodock
Print Asc(Inkey$())
 
` <<< Clean Up Movement and Camera >>>
   Move Object 600, Speed#
   Rem Scale Object 602,190,200+(Speed#*20),190
   Rem Scale Object 603,190,200+(Speed#*20),190
   Turn Object Right 600, yRot#+AyRot#
   Position Object 600, Object Position X(600),Object Position Y(600) + ySpeed#,Object Position Z(600)
   OldySpeed#=ySpeed#
   ySpeed#=0
   spin# = spin#+.2
   spin2# = spin2#+.3
   Turn Object Left 502,-.02
   Turn Object Left 507,-.02
   Turn Object Right 750, 3
   Scroll Limb Texture 600,6,.2,.3
   Scroll Limb Texture 600,7,.3,.2
   Rem Scroll Object Texture 602,.3,.2
   Rem Scroll Object Texture 603,.2,.3
   Scroll Object Texture 604,0,.3
   Scroll Object Texture 605,0,.3
   Scroll Object Texture 610,.3,.2
   Scroll Object Texture 701,0,.2
   If Spin2#>10
      Spin#=Spin#*-1
      Spin2#=Spin2#*-1
      Scroll Limb Texture 600,6,Spin#,Spin2#
      Scroll Limb Texture 600,7,Spin2#,Spin#
      Rem Scroll Object Texture 602,Spin2#,Spin#
      Rem Scroll Object Texture 603,Spin#,Spin2#
      Scroll Object Texture 604,0,Spin2#
      Scroll Object Texture 605,0,Spin2#
      Scroll Object Texture 605,Spin2#,Spin#
      Scroll Object Texture 701,0,Spin#
      Spin#=0
      Spin2#=0
   Endif
   Turn Object Left 701,.25
 
   Move Object 600,-80
   Move Object Up 600,20
   Set Camera To Follow Object Position X(600), Object Position Y(600),Object Position Z(600),0,0,0,50,1
   Move Object Down 600,20
   Move Object 600,80
   Point Camera Object Position X(600),Object POsition Y(600),Object POsition Z(600)
   Sync
 
Loop
 
SaveShip:
Set Text Size 32
a$=""
Do
   Center Text 700,400,"Save and Exit: Are You Sure (Y/N)?";
   a$= inkey$()
   If a$="n" then Return
   If a$="y" then exit
   Sync
Loop
 
If ModNum<3 then Return
Rotate Object 1001,0,0,0
 
`Combine all the individual module objects together to make a single object with limbs.
For i = LastSaved to ModNum-1
   Position Object 1000+i,0,0,0
   Make Mesh From Object 8000+i,1000+i
   Add Limb 1001,i-1,8000+i
   Offset Limb 1001,i-1,Modules#(i,2),Modules#(i,3),Modules#(i,4)
   Texture Limb 1001,i-1,1
   Scale Limb Texture 1001,i-1,.25,.25
   ModuleNum=Modules#(i,1)
   Col=Int(ModuleNum/4)
   Row=ModuleNum-(Col*4)
   ScrollRow#=.25*Row
   ScrollCol#=.25*Col
   Scroll Limb Texture 1001,i-1,ScrollRow#,ScrollCol#
   Delete Object 1000+i
Next i
LastSaved=ModNum-1
If File Exist ("Starship.dbo")=1
   Delete File "Starship.dbo"
Endif
Save Object "Starship.dbo",1001
Delete Object 1001
Save Array "ShipMods.ssm",Modules#(1000,4)
Load Object "Starship.dbo",1001
 
 
For I = 1 to 20
   SET OBJECT SMOOTHING 1001,100
Next I
 
Do
   Sync
   Turn Object Left 1001,1
   Roll Object Right 1001,1.2
   Pitch Object Up 1001,.6
Loop
 
Return
 
End
 
Function CheckHit(Object1,Object2)
   If Object Exist(Object1)=0 or Object Exist(Object2)=0 Then ExitFunction 0
   XH=0:YH=0:ZH=0:Hit=0
   X1#=Object Position X(Object1)
   Y1#=Object Position Y(Object1)
   Z1#=Object Position Z(Object1)
   X2#=Object Position X(Object2)
   Y2#=Object Position Y(Object2)
   Z2#=Object Position Z(Object2)
   SX1#=Object Size X(Object1)
   SY1#=Object Size Y(Object1)
   SZ1#=Object Size Z(Object1)
   SX2#=Object Size X(Object2)
   SY2#=Object Size Y(Object2)
   SZ2#=Object Size Z(Object2)
   XH=((X1#+(SX1#/2))>(X2#-(SX2#/2))) * ((X1#-(SX1#/2))<(X2#+(SX2#/2)))
   YH=((Y1#+(SY1#/2))>(Y2#-(SY2#/2))) * ((Y1#-(SY1#/2))<(Y2#+(SY2#/2)))
   ZH=((Z1#+(SZ1#/2))>(Z2#-(SZ2#/2))) * ((Z1#-(SZ1#/2))<(Z2#+(SZ2#/2)))
   Hit = XH*YH*ZH
Endfunction Hit
 
Function CheckLimbHit(Object1,Limb1,LimbSize1,Object2)
   If Object Exist(Object1)=0 Then ExitFunction 0
   If Object Exist(Object2)=0 Then ExitFunction 0
   If Limb Exist(Object1,Limb1)=0 Then ExitFunction 0
   XH=0:YH=0:ZH=0:Hit=0
   X1#=Limb Position X(Object1,Limb1)
   Y1#=Limb Position Y(Object1,Limb1)
   Z1#=Limb Position Z(Object1,Limb1)
   X2#=Object Position X(Object2)
   Y2#=Object Position Y(Object2)
   Z2#=Object Position Z(Object2)
   SX1#=LimbSize1
   SY1#=LimbSize1
   SZ1#=LimbSize1
   SX2#=Object Size X(Object2)
   SY2#=Object Size Y(Object2)
   SZ2#=Object Size Z(Object2)
   XH=((X1#+(SX1#/2))>(X2#-(SX2#/2))) * ((X1#-(SX1#/2))<(X2#+(SX2#/2)))
   YH=((Y1#+(SY1#/2))>(Y2#-(SY2#/2))) * ((Y1#-(SY1#/2))<(Y2#+(SY2#/2)))
   ZH=((Z1#+(SZ1#/2))>(Z2#-(SZ2#/2))) * ((Z1#-(SZ1#/2))<(Z2#+(SZ2#/2)))
   Hit = XH*YH*ZH
Endfunction Hit
 
Function CopyObject(ObjectTo,ObjectFrom)
   Do
      MeshNum = Rnd(5000)+1
      If Mesh Exist(MeshNum)=0 Then Exit
   Loop
   OX=Object Position X(ObjectFrom):OY=Object Position Y(ObjectFrom):OZ=Object Position Z(ObjectFrom)
   AX=Object Angle X(ObjectFrom):AY=Object Angle Y(ObjectFrom):AZ=Object Angle Z(ObjectFrom)
   Position Object ObjectFrom,0,0,0
   Rotate Object ObjectFrom,0,0,0
   Make Mesh From Object MeshNum,ObjectFrom
   Make Object ObjectTo,MeshNum,0
   Delete Mesh MeshNum
   Position Object ObjectFrom,OX,OY,OZ
   Rotate Object ObjectFrom,AX,AY,AZ
EndFunction
 
Function GetDistance(O1,O2)
   If Object Exist(O1)=0 Or Object Exist(O2)=0 Then ExitFunction -1
   DX=Object Position X(O1)-Object Position X(O2)
   DY=Object Position Y(O1)-Object Position Y(O2)
   DZ=Object Position Z(O1)-Object Position Z(O2)
   Distance=SQRT(DX^2+DY^2+DZ^2)
EndFunction Distance
 
Function GetLimbDistance(O1,L1,O2)
   If Object Exist(O1)=0 Or Object Exist(O2)=0 Then ExitFunction -1
   If Limb Exist(O1,L1)=0 Then ExitFunction -1
   DX=Limb Position X(O1,L1)-Object Position X(O2)
   DY=Limb Position Y(O1,L1)-Object Position Y(O2)
   DZ=Limb Position Z(O1,L1)-Object Position Z(O2)
   Distance=SQRT(DX^2+DY^2+DZ^2)
EndFunction Distance
 
Function CreatePlanet(image)
   If Bitmap Exist(1)
      Delete Bitmap 1
   Endif
   create bitmap 1,640,480
   Lock Pixels
   Ink rgb(10,10,240),1
   For i = 0 to 480
      Line 0,i,640,i
   Next i
 
   For j = 1 to rnd(10)+7
      Ink rgb(10,rnd(100)+50,10),1
      Radius = Rnd(50)+25
      cx=rnd(530)+55
      cy=rnd(370)+55
      For i = 0 to 360
         Radius=Radius+(Rnd(4)-2)
         x#=Cos(i/2)*(Radius)+cx
         y#=Sin(i/2)*(Radius)+cy
         if x#>638 then x#=638
         if x#<0 then x#=0
         if y#>478 then y#=478
         if y#<0 then y#=0
         Line cx,cy,x#,y#
         Line cx,cy,x#+1.0,y#
         Line cx,cy,x#,y#+1.0
      Next i
   Next j
   Unlock Pixels
   Blur Bitmap 1,6
   Get Image image,1,1,639,479
   Set Current Bitmap 0
   Delete Bitmap 1
EndFunction
 
Function CreateClouds(image)
   If Bitmap Exist(1)
      Delete Bitmap 1
   Endif
   create bitmap 1,640,480
   Lock Pixels
   Ink rgb(10,10,10),1
   Box 0,0,639,479
   For j = 1 to rnd(10)+7
      w=rnd(50)+180
      Ink rgb(w,w,w),1
      Radius = Rnd(50)+25
      cx=rnd(530)+55
      cy=rnd(370)+55
      For i = 0 to 360
         Radius=Radius+(Rnd(4)-2)
         x#=Cos(i/2)*(Radius)+cx
         y#=Sin(i/2)*(Radius)+cy
         if x#>638 then x#=638
         if x#<0 then x#=0
         if y#>478 then y#=478
         if y#<0 then y#=0
         Line cx,cy,x#,y#
         Line cx,cy,x#+1.0,y#
         Line cx,cy,x#,y#+1.0
      Next i
   Next j
   Unlock Pixels
   Blur Bitmap 1,6
   Get Image image,1,1,639,479
   Set Current Bitmap 0
   Delete Bitmap 1
EndFunction
 
Function CreateStarField(image)
   If Bitmap Exist(1)
      Delete Bitmap 1
   Endif
   create bitmap 1,1000,1000
   Lock Pixels
   For j = 1 to 3
      For i = 1 to 1500
         Dot Rnd(999),Rnd(999),rgb(200+rnd(55),200+rnd(55),200+rnd(55))
      Next i
      Blur Bitmap 1,1
   Next j
   Unlock Pixels
   Get Image image,0,0,999,999
   Set Current Bitmap 0
   Delete Bitmap 1
EndFunction
 
 
Function Const_Skin1(Image)
   If Bitmap Exist(1)
      Delete Bitmap 1
   Endif
   Create Bitmap 1,501,501
   Lock Pixels
   Ink rgb(255,255,255),0
   Box 0,0,500,500
   Ink RGB(128,128,128),0
   For i = 0 to 500 step 500/8
      Line i,0,i,500
      Line i+1,0,i+1,500
      Line 0,i,500,i
      Line 0,i+1,500,i+1
   Next i
   If Image Exist(image)
      Delete Image image
   Endif
   Unlock Pixels
   Get Image image,0,0,500,500
   Set Current Bitmap 0
   Delete BItmap 1
Endfunction
 
Function Const_Skin2(Image)
   If Bitmap Exist(1)
      Delete Bitmap 1
   Endif
   Create Bitmap 1,501,501
   Lock Pixels
   Ink rgb(255,255,255),0
   Box 0,0,500,500
   Ink RGB(128,128,128),0
   For i = 0 to 500 step 500/8
      Line i,0,i,500
      Line i+1,0,i+1,500
      Line 0,i,500,i
      Line 0,i+1,500,i+1
   Next i
   Box 125,60,375,185
   If Image Exist(image)
      Delete Image image
   Endif
   Unlock Pixels
   Get Image image,0,0,500,500
   Set Current Bitmap 0
   Delete Bitmap 1
Endfunction
 
Function Fire(image)
   If Bitmap Exist(1)
      Delete Bitmap 1
   Endif
   Create Bitmap 1,65,65
   Lock Pixels
   Ink rgb(200,0,0),0
   Box 0,0,64,64
   For i = 0 to 200
      red =rnd(200)+55
      Dot rnd(64),rnd(64),rgb(red,red-50,red-50)
   Next i
   If Image Exist(image)
      Delete Image image
   Endif
   Unlock Pixels
   Get Image image,0,0,64,64,1
   Set Current Bitmap 0
   Delete BItmap 1
Endfunction
 
Function Beam_Effect1(image)
   If Bitmap Exist(1)
      Delete Bitmap 1
   Endif
   Create Bitmap 1,257,257
   Lock Pixels
   Ink rgb(0,0,50),0
   Box 0,0,256,256
   Ink RGB(0,0,170),0
   For i = 0 to 30
      lx=rnd(256)
      ly1=rnd(256)
      ly2=rnd(256)
      Line lx,ly1,lx,ly2
   Next i
   If Image Exist(image)
      Delete Image image
   Endif
   Unlock Pixels
   Get Image image,0,0,256,256,1
   Set Current Bitmap 0
   Delete Bitmap 1
Endfunction
 
Function Grid1(image)
   If Bitmap Exist(1)
      Delete Bitmap 1
   Endif
   Create Bitmap 1,257,257
   Lock Pixels
   Ink rgb(0,0,50),0
   Box 0,0,256,256
   Ink RGB(100,100,0),0
   Box 0,0,256,3
   Box 0,0,3,256
   Box 252,0,256,256
   Box 0,252,256,256
   If Image Exist(image)
      Delete Image image
   Endif
   Unlock Pixels
   Get Image image,0,0,256,256,1
   Set Current Bitmap 0
   Delete Bitmap 1
Endfunction
 
Function BaySide(image)
   If Bitmap Exist(1)
      Delete Bitmap 1
   Endif
   Create Bitmap 1,257,257
   Lock Pixels
   Ink rgb(100,100,100),0
   Box 0,0,256,256
   Ink RGB(175,175,175),0
   Box 20,20,236,236
   Ink Rgb(255,255,0),0
   For i = 236 to 256
      line i,0,0,i
      line i,256,256,i
   Next i
   If Image Exist(image)
      Delete Image image
   Endif
   Unlock Pixels
   Get Image image,0,0,256,256,1
   Set Current Bitmap 0
   Delete Bitmap 1
Endfunction
 
Function Star(image)
   If Bitmap Exist(1)
      Delete Bitmap 1
   Endif
   Create Bitmap 1,513,513
   Lock Pixels
   Ink rgb(110,90,90),0
   For i = 1 to 200
      Ink rgb(200-i,100-(i/2),100-(i/2)),0
      Circle 256,256,i
      Circle 256+1,256,i
   Next i
   Ink rgb(255,250,250),0
   For i = 1 to 20
      Circle 256,256,i
      Circle 256+1,256,i
   Next i
   Blur Bitmap 1,1
   If Image Exist(image)
      Delete Image image
   Endif
   Unlock Pixels
   Get Image image,0,0,512,512,1
   Set Current Bitmap 0
   Delete Bitmap 1
Endfunction
 
Function Drydock(image)
   If Bitmap Exist(1)
      Delete Bitmap 1
   Endif
   Create Bitmap 1,513,513
   Lock Pixels
   Ink rgb(100,100,100),0
   Box 0,0,512,512
   Ink 0,0
   Box 10,10,246,246
   Box 10,266,246,502
   Box 266,10,502,246
   Box 266,266,502,502
   If Image Exist(image)
      Delete Image image
   Endif
   Unlock Pixels
   Get Image image,0,0,256,256,1
   Set Current Bitmap 0
   Delete Bitmap 1
Endfunction
 
Function Module(image)
   If Bitmap Exist(1)
      Delete Bitmap 1
   Endif
   Create Bitmap 1,513,513
   Lock Pixels
   Ink RGB(128,128,128),0
   Box 0,0,512,512
   Restore ModuleSymbols
   Ink rgb(200,200,0),0
   For y=0 to 3
      For x=0 to 3
         Read m$
         Center Text x*64+32,y*64+32,m$
      Next x
   Next y
   If Image Exist(image)
      Delete Image image
   Endif
   Unlock Pixels
   Get Image image,0,0,256,256,1
   Set Current Bitmap 0
   Delete Bitmap 1
Endfunction
 
ModuleList:
Data "Hull (Empty)","Bridge","Shields","Deflectors"
Data "Marine Quarters","Computer","Phasors","Officer Quarters"
Data "Torpedo Bay","Medical Bay","Crew Quarters","Transporters"
Data "Armor","Repair Bay","Engines (Thrusters)","Warp Engines"
 
ModuleSymbols:
Data "H","B","S","D"
Data "M","C","P","O"
Data "T","+","Q","X"
Data "A","R","E","W"
 
GridOffset:
Data 0,0,51
Data 0,51,0
Data 51,0,0
Data 0,0,-51
Data 0,-51,0
Data -51,0,0