📄 form1.frm
字号:
Caption = "Option1"
Height = 405
Left = -840
TabIndex = 2
Top = 4080
Width = 795
End
Begin VB.PictureBox VDot
AutoRedraw = -1 'True
AutoSize = -1 'True
BackColor = &H80000009&
BorderStyle = 0 'None
Height = 75
Left = 1200
Picture = "Form1.frx":555E
ScaleHeight = 75
ScaleWidth = 75
TabIndex = 1
Top = 7200
Visible = 0 'False
Width = 75
End
Begin VB.PictureBox Main
Align = 1 'Align Top
Appearance = 0 'Flat
AutoRedraw = -1 'True
BackColor = &H00000000&
BorderStyle = 0 'None
ForeColor = &H80000008&
Height = 5115
Left = 0
ScaleHeight = 341
ScaleMode = 3 'Pixel
ScaleWidth = 640
TabIndex = 0
Top = 0
Width = 9600
End
Begin MSComDlg.CommonDialog Cmd1
Left = 900
Top = 690
_ExtentX = 847
_ExtentY = 847
_Version = 393216
Filter = "*.botz|Bot Files|*.*|All Files"
End
Begin VB.Menu mnufile
Caption = "&File"
Begin VB.Menu mnuNew
Caption = "&New"
Shortcut = ^N
End
Begin VB.Menu mnuOpen
Caption = "&Open..."
Shortcut = ^O
End
Begin VB.Menu mnuSave
Caption = "&Save"
Shortcut = ^S
End
Begin VB.Menu mnuSaveAs
Caption = "Save &As..."
Shortcut = ^A
End
Begin VB.Menu mnudash
Caption = "-"
End
Begin VB.Menu mnuExit
Caption = "E&xit"
End
End
Begin VB.Menu mnuOpt
Caption = "&Options"
Begin VB.Menu mnuglobal
Caption = "Set Global Variables"
Shortcut = ^G
End
Begin VB.Menu mnuAutoRev
Caption = "Auto Reverse"
Checked = -1 'True
End
End
Begin VB.Menu mnuView
Caption = "&View"
Begin VB.Menu mnuVert
Caption = "&Vertices"
Checked = -1 'True
End
Begin VB.Menu mnuLink
Caption = "&Links"
Checked = -1 'True
End
Begin VB.Menu mnuhandl
Caption = "&Link Handles"
End
Begin VB.Menu line2
Caption = "-"
End
Begin VB.Menu fs
Caption = "Full Screen"
Shortcut = {F11}
End
End
Begin VB.Menu mnusel
Caption = "Vertex"
Begin VB.Menu mnuVertexDelete
Caption = "Delete Vertex"
End
Begin VB.Menu mnudash2
Caption = "-"
End
Begin VB.Menu mnuVertexAddwheel
Caption = "Add Wheel..."
Shortcut = ^W
End
Begin VB.Menu mnuVertexDeleteWheel
Caption = "Delete Wheel"
End
End
Begin VB.Menu mnulinkthing
Caption = "Link"
Begin VB.Menu mnuLinkDelete
Caption = "Delete Link Del"
End
Begin VB.Menu mnudash1
Caption = "-"
End
Begin VB.Menu mnuLinkLengthReset
Caption = "Reset Link Length"
End
Begin VB.Menu mnuDeleteMuscle
Caption = "Delete Muscle"
End
End
Begin VB.Menu mnuMode
Caption = "&Mode"
Begin VB.Menu mnuConstruct
Caption = "Construct"
Shortcut = {F2}
End
Begin VB.Menu mnuSimulate
Caption = "Simulate"
Shortcut = {F3}
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'--------------------------------------------------------------------------
'
' Botz 1.00
'
' I've done everything I can to make this code readable and understandable.
' Just about every procedure is thoroughly commented, and divided into
' nice, manageable segments to help with comprehension.
'
' Note: When the program is running, everything on the screen is flipped.
' That way, the 'floor' is at y-coordinate 0. VB usually has the
' top of an object as y=0. However I found that made things harder
' as I kept having to remember to reverse anything that was vertical.
'
' Anyways the point is that if you fiddle with the physics cycle,
' remember that y=0 is the floor, not the ceiling.
'
'
' You can do whatever you want to this code for non-commercial purposes.
' If you want to use some of this code for another project please let me
' know, and give me a little recognition.
'
' If you make improvements to this code please let me know so I can
' include it in future releases.
'
' If you need to contact me, my email addy is KevinLaity@Cadvision.com
' No bug reports unless the bug is important and can be replicated
'--------------------------------------------------------------------------
Dim vertex(200) As vertex_type
Const MaxVertices As Integer = 200
Const pi As Double = 3.14159265358979
'The maximum number of vertexes is 300, after 300 no more may be added
'By changing the dimensions of vertex and the value of MaxVertexs, you
'can change the maximum
Dim Link(200) As link_type
Const MaxLinks As Integer = 200
'The maximum number of links is also 300.
Dim MouseX, MouseY As Single
'Keep track of the mouse position on the main board.
Dim VertexCount As Integer
Dim LinkCount As Integer
'Keep track of how many links and vertices there are
Dim CycleTime As Integer
Const CycleSize As Integer = 200
Dim ClockPause As Boolean
'CycleTime - the current place in the muscle cycle
'CycleSize - the amount that the value of cycletime must reach before
' wrapping around.
'ClockPause - whether the muscle cycle is paused
'ClockSpeed - how fast the muscle cycle goes per turn
' --Defined in Declares.bas
Dim FS_Mode As Boolean 'Full screen mode
Dim mode As Byte
Dim SubMode As Byte
Dim SubModeData As Integer
'Mode 0 = Construction Mode
'Mode 1 = Simulation Mode
'SubMode 0 = Nothing. If in mode 0, ready to create a vertex.
'SubMode 1 = Creating a link
'SubMode 2 = Dragging a Vertex
'SubMode 4 = Link is selected
'SubModeData = Whatever needed data is relevant to the current submode
' eg. in SubMode 1, the location of the vertex to start
' the link from.
Dim SelVertex
Dim SelLink
Dim HoverVertex
Dim HoverLink As Integer
Dim DragDot As Integer
'Sel* - number of the vertex or link that is currently selected.
' (if any) 0 = none
'Hover* - The number of the vertex or link that the mouse is currently
' over (if any) 0 = none
'DragDot - which vertex is being dragged
Dim BoardX As Integer 'width
Dim BoardY As Integer 'height
Dim RightWall As Single
Dim Ceiling As Single
'These are the dimensions of the "playing field"
Dim AutoReverseCycle As Integer
Dim DrawColor, BGColor As Long
Dim CurrentPhase As Byte
Function AddLink(id1, id2) As Boolean
'This Subroutine adds a link between two vertices.
'The link will push or pull them to keep them at the same distance
'They were at when the link was created.
'This action is what makes it possible to make objects to stand up.
If id1 = id2 Then AddLink = False: Exit Function 'you can't link a vertex to itself
'Check to see if this link exists already --------------------------
For i = 1 To MaxLinks
With Link(i)
If .used = True Then
If .target1_id = id1 And .target2_id = id2 Then AddLink = False: Exit Function
If .target1_id = id2 And .target2_id = id1 Then AddLink = False: Exit Function
End If
End With
If id1 = id2 Then AddLink = False: Exit Function 'you can't link a vertex to itself
Next i
'--------------------------------------------------------------------
'Make the link-------------------------------------------------------
Dim CurLink As Integer
Dim XLen, YLen, Leng As Single
For i = 1 To 300 'Find a link number that is
If Link(i).used = False Then 'not being used. And use
CurLink = i 'Curlink'
Exit For
End If
Next i
With Link(CurLink)
.target1_id = id1 'Each Target_id is the number of one of the
.target2_id = id2 'vertices the link is attached to.
XLen = (vertex(.target2_id).X - vertex(.target1_id).X)
YLen = (vertex(.target2_id).y - vertex(.target1_id).y)
Leng = Sqr(Abs(XLen ^ 2 + YLen ^ 2))
'Calculate length.
.linklength = Leng
.used = True
.midx = vertex(.target2_id).X + ((vertex(.target1_id).X - vertex(.target2_id).X) / 2)
.midy = vertex(.target2_id).y + ((vertex(.target1_id).y - vertex(.target2_id).y) / 2)
.linktension = Tension
.pushstrength = 0
.pushtiming = 180
.pushspan = 40
.phase = CurrentPhase
End With
LinkCount = LinkCount + 1 'Count the new link.
AddLink = True 'Hey it worked.
'--------------------------------------------------------------------
End Function
Function AddLink2(id1, id2, Leng, Tens, pspan, pushr, stren, lastlen, timing, phase As Variant) As Boolean
'This Function is just like AddLink but it has more parameters.
'The extra parameters are needed when loading from a file.
'See Addlink for comments and explanations
If id1 = id2 Then AddLink2 = False: Exit Function
Dim CurLink As Integer
For i = 1 To 300
If Link(i).used = False Then
CurLink = i
Exit For
End If
Next i
LinkCount = LinkCount + 1
With Link(CurLink)
.target1_id = id1
.target2_id = id2
.linklength = Leng
.used = True
.linktension = Tens
.midx = vertex(.target2_id).X + ((vertex(.target1_id).X - vertex(.target2_id).X) / 2)
.midy = vertex(.target2_id).y + ((vertex(.target1_id).y - vertex(.target2_id).y) / 2)
.pushspan = pspan
.Push = pushr
.pushstrength = stren
.pushtiming = timing
.lastlen = lastlen
.phase = phase
'.Phase = 1
End With
AddLink2 = True
End Function
Function AddVertex(X, y, MomentX, MomentY, Radius, MomentC, Optional phase As Variant) As Integer
'MsgBox Phase
If phase = "" Then phase = 1
'This Subroutine adds a vertex.
'Find a vertex number thats not taken ------------------------------
For i = 1 To MaxVertices
If vertex(i).used = False Then
currentvertex = i
Exit For
End If
Next i
'-------------------------------------------------------------------
'Make the Vertex ---------------------------------------------------
With vertex(currentvertex)
.used = True
.X = X
.y = y
.momentum_x = MomentX
.momentum_y = MomentY
.momentum_c = MomentC
.heading = 0
SelVertex = currentvertex 'When a vertex is created it
VertexCount = VertexCount + 1 'is automatically selected
.Selected = True
If Radius > 0 Then 'For purposes of loading from
.wheel = True 'a file. By default a vertex
.Radius = Radius 'has no wheel attached.
Else
.wheel = False
.Radius = 0
End If
.phase = phase
End With
'-------------------------------------------------------------------
AddVertex = currentvertex 'return the number of the vertex
End Function
Sub AddWheel(vertx, Radius As Integer)
With vertex(vertx)
.wheel = True
.Radius = Radius
.heading = 0 'the default heading is arbitrarily 0
End With
'This should be pretty straightforward
End Sub
Sub Cycle_Botz(delay As Single)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -