home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 4_2005-2006.ISO / data / Zips / AntieLife_1976492262006.psc / AntieLife / formLife.frm < prev    next >
Text File  |  2006-02-25  |  25KB  |  769 lines

  1. VERSION 5.00
  2. Begin VB.Form formLife 
  3.    BackColor       =   &H00000000&
  4.    Caption         =   "Evolving Artificial Life"
  5.    ClientHeight    =   6150
  6.    ClientLeft      =   1170
  7.    ClientTop       =   915
  8.    ClientWidth     =   7680
  9.    FillColor       =   &H008080FF&
  10.    ForeColor       =   &H000000FF&
  11.    Icon            =   "formLife.frx":0000
  12.    LinkTopic       =   "formLife"
  13.    ScaleHeight     =   6150
  14.    ScaleWidth      =   7680
  15.    StartUpPosition =   2  'CenterScreen
  16.    Begin VB.CommandButton Command1 
  17.       Caption         =   "Remove Animals"
  18.       Height          =   492
  19.       Left            =   6240
  20.       TabIndex        =   9
  21.       Top             =   5520
  22.       Width           =   1092
  23.    End
  24.    Begin VB.CommandButton cmdDelPlants 
  25.       Caption         =   "Remove Plants"
  26.       Height          =   492
  27.       Left            =   360
  28.       TabIndex        =   5
  29.       Top             =   5520
  30.       Width           =   1092
  31.    End
  32.    Begin VB.Timer tmrMultiTask 
  33.       Enabled         =   0   'False
  34.       Interval        =   500
  35.       Left            =   120
  36.       Top             =   5040
  37.    End
  38.    Begin VB.PictureBox picLife 
  39.       AutoRedraw      =   -1  'True
  40.       BackColor       =   &H00000000&
  41.       Height          =   4812
  42.       Left            =   120
  43.       ScaleHeight     =   317
  44.       ScaleMode       =   3  'Pixel
  45.       ScaleWidth      =   493
  46.       TabIndex        =   4
  47.       Top             =   120
  48.       Width           =   7452
  49.    End
  50.    Begin VB.CommandButton cmdAddAnts 
  51.       Caption         =   "Add Animals"
  52.       Height          =   372
  53.       Left            =   4680
  54.       TabIndex        =   8
  55.       Top             =   5520
  56.       Width           =   1332
  57.    End
  58.    Begin VB.CommandButton cmdAddPlants 
  59.       Caption         =   "Add Plants"
  60.       Height          =   372
  61.       Left            =   1680
  62.       TabIndex        =   6
  63.       Top             =   5520
  64.       Width           =   1332
  65.    End
  66.    Begin VB.CommandButton cmdRestart 
  67.       Caption         =   "Restart"
  68.       Height          =   492
  69.       Left            =   3360
  70.       TabIndex        =   7
  71.       Top             =   5520
  72.       Width           =   972
  73.    End
  74.    Begin VB.Label lblAntCountLbl 
  75.       Alignment       =   1  'Right Justify
  76.       BackColor       =   &H00000000&
  77.       Caption         =   "Number of animals:"
  78.       ForeColor       =   &H00C0C0FF&
  79.       Height          =   252
  80.       Left            =   4200
  81.       TabIndex        =   3
  82.       Top             =   5160
  83.       Width           =   2052
  84.    End
  85.    Begin VB.Label lblPlantCountLbl 
  86.       Alignment       =   1  'Right Justify
  87.       BackColor       =   &H00000000&
  88.       Caption         =   "Number of plants:"
  89.       ForeColor       =   &H00C0C0FF&
  90.       Height          =   252
  91.       Left            =   360
  92.       TabIndex        =   2
  93.       Top             =   5160
  94.       Width           =   2052
  95.    End
  96.    Begin VB.Label lblAntCount 
  97.       BackColor       =   &H00000000&
  98.       Caption         =   "0"
  99.       ForeColor       =   &H00C0C0FF&
  100.       Height          =   252
  101.       Left            =   6360
  102.       TabIndex        =   1
  103.       Top             =   5160
  104.       Width           =   1212
  105.    End
  106.    Begin VB.Label lblPlantCount 
  107.       BackColor       =   &H00000000&
  108.       Caption         =   "0"
  109.       ForeColor       =   &H00C0C0FF&
  110.       Height          =   252
  111.       Left            =   2520
  112.       TabIndex        =   0
  113.       Top             =   5160
  114.       Width           =   1212
  115.    End
  116.    Begin VB.Menu mOptions 
  117.       Caption         =   "&Options"
  118.       Begin VB.Menu mChkEnableSounds 
  119.          Caption         =   "Enable sound effects"
  120.       End
  121.       Begin VB.Menu mChkInvertRed 
  122.          Caption         =   "Invert red level"
  123.       End
  124.       Begin VB.Menu mChkInvertGreen 
  125.          Caption         =   "Invert green level"
  126.       End
  127.       Begin VB.Menu mChkInvertBlue 
  128.          Caption         =   "Invert blue level"
  129.       End
  130.       Begin VB.Menu mChkNoFatalAge 
  131.          Caption         =   "Prohibit death by old age"
  132.       End
  133.       Begin VB.Menu mChkNoFatalHunger 
  134.          Caption         =   "Prohibit death by starvation"
  135.       End
  136.       Begin VB.Menu mChkNoCloneAnt 
  137.          Caption         =   "Prohibit self-reproducing animals"
  138.       End
  139.       Begin VB.Menu mChkNoClonePlant 
  140.          Caption         =   "Prohibit self-reproducing plants"
  141.       End
  142.       Begin VB.Menu mChkNoMateAntAnt 
  143.          Caption         =   "Prohibit animals from mating with animals"
  144.       End
  145.       Begin VB.Menu mChkNoMateAntPlant 
  146.          Caption         =   "Prohibit animals from mating with plants"
  147.       End
  148.       Begin VB.Menu mChkNoMatePlantAnt 
  149.          Caption         =   "Prohibit plants from mating with animals"
  150.       End
  151.       Begin VB.Menu mChkNoMatePlantPlant 
  152.          Caption         =   "Prohibit plants from mating with plants"
  153.       End
  154.       Begin VB.Menu mChkNoAntEatAnt 
  155.          Caption         =   "Prohibit animals from eating animals"
  156.       End
  157.       Begin VB.Menu mChkNoAntEatPlant 
  158.          Caption         =   "Prohibit animals from eating plants"
  159.       End
  160.       Begin VB.Menu mChkNoPlantEatAnt 
  161.          Caption         =   "Prohibit plants from eating animals"
  162.          Checked         =   -1  'True
  163.       End
  164.       Begin VB.Menu mChkNoPlantEatPlant 
  165.          Caption         =   "Prohibit plants from eating plants"
  166.          Checked         =   -1  'True
  167.       End
  168.       Begin VB.Menu mChkNoAntEatCarion 
  169.          Caption         =   "Prohibit animals from scavenging"
  170.       End
  171.       Begin VB.Menu mChkNoPlantEatCarion 
  172.          Caption         =   "Prohibit plants from scavenging"
  173.       End
  174.       Begin VB.Menu mChkNoAntEatDirt 
  175.          Caption         =   "Prohibit ambient feeding for animals"
  176.          Checked         =   -1  'True
  177.       End
  178.       Begin VB.Menu mChkAllowSpores 
  179.          Caption         =   "Allow animals to mate over a distance"
  180.       End
  181.       Begin VB.Menu mChkAllowPollen 
  182.          Caption         =   "Allow plants to mate over a distance"
  183.          Checked         =   -1  'True
  184.       End
  185.       Begin VB.Menu mChkAllowPlagues 
  186.          Caption         =   "Allow plagues"
  187.          Checked         =   -1  'True
  188.       End
  189.       Begin VB.Menu mChkQuickStart 
  190.          Caption         =   "Quick-start evolution"
  191.          Checked         =   -1  'True
  192.       End
  193.       Begin VB.Menu mChkFastEvolve 
  194.          Caption         =   "High rate of mutation"
  195.          Checked         =   -1  'True
  196.       End
  197.       Begin VB.Menu mChkBreakRules 
  198.          Caption         =   "Occasionally break selected rules"
  199.          Checked         =   -1  'True
  200.       End
  201.       Begin VB.Menu mChkZoomFactor 
  202.          Caption         =   "&Zoom Factor"
  203.          Checked         =   -1  'True
  204.       End
  205.    End
  206. End
  207. Attribute VB_Name = "formLife"
  208. Attribute VB_GlobalNameSpace = False
  209. Attribute VB_Creatable = False
  210. Attribute VB_PredeclaredId = True
  211. Attribute VB_Exposed = False
  212. Option Explicit
  213.  
  214. Private Declare Function GetTickCount Lib "kernel32" () As Long
  215.  
  216. Dim initialHeight As Single
  217. Dim initialWidth As Single
  218.  
  219. Private ExitForm As Boolean
  220.  
  221. Private Sub cmdAddAnts_Click()
  222.     'Add a user specified number of primateve live animals.
  223.     Dim s As String
  224.     Dim n
  225.     s = InputBox("Add how many random primative animals?" + vbCrLf + vbCrLf + "0 = cancel", "Add Animals", "1")
  226.     If s = "" Then Exit Sub
  227.     'On Error Resume Next
  228.     n = -Val(s)
  229.     'On Error GoTo 0
  230.     If n = 0 Then Exit Sub
  231.     firstLife n
  232. End Sub
  233.  
  234. Private Sub cmdAddPlants_Click()
  235.     'Add a user specified number of primateve live plants.
  236.     Dim s As String
  237.     Dim n
  238.     s = InputBox("Add how many primative plants?" + vbCrLf + vbCrLf + "0 = cancel", "Add Plants", "1")
  239.     If s = "" Then Exit Sub
  240.     'On Error Resume Next
  241.     n = Val(s)
  242.     'On Error GoTo 0
  243.     If n = 0 Then Exit Sub
  244.     firstLife n
  245. End Sub
  246.  
  247. Private Sub cmdDelPlants_Click()
  248.     'Delete a user specified number of plants.
  249.     Dim s As String
  250.     Dim n
  251.     s = InputBox("Remove how many plants?" + vbCrLf + vbCrLf + "0 = cancel", "Delete Plants", "1")
  252.     If s = "" Then Exit Sub
  253.     'On Error Resume Next
  254.     n = Val(s)
  255.     'On Error GoTo 0
  256.     If n = 0 Then Exit Sub
  257.     deleteLife n
  258. End Sub
  259.  
  260. Private Sub cmdRestart_Click()
  261.     'Start over with a user specified number of primateve live plants.  (choosing a negative number will start with animals.)
  262.     Dim s As String
  263.     Dim n
  264.     picLife.BorderStyle = 1 'show the pictureBox border.
  265.     s = InputBox("Restart with how many primative plants?" + vbCrLf + vbCrLf + "0 = random", "Restart", "1")
  266.     If s = "" Then
  267.         picLife.BorderStyle = 0 'hide the pictureBox border.
  268.         Exit Sub
  269.     End If
  270.     'On Error Resume Next
  271.     n = Val(s)
  272.     'On Error GoTo 0
  273.     If n = 0 Then n = Int(Rnd * (Rnd + 1) * 500 + 1) 'pick a random number of plants and finish re-initializing.
  274.     postInitialize n 're-initialize life form environment.
  275. End Sub
  276.  
  277. Private Sub Command1_Click()
  278.     'Delete a user specified number of Animals.
  279.     Dim s As String
  280.     Dim n
  281.     s = InputBox("Remove how many animals?" + vbCrLf + vbCrLf + "0 = cancel", "Delete Animals", "1")
  282.     If s = "" Then Exit Sub
  283.     'On Error Resume Next
  284.     n = Val(s)
  285.     'On Error GoTo 0
  286.     If n = 0 Then Exit Sub
  287.     deleteLife -n
  288. End Sub
  289.  
  290. Private Sub Form_Activate()
  291.     Static postinitialized As Boolean 'initially false
  292.     
  293.     'multitasking core.
  294.     Static timeOfLastRedraw As Single
  295.     Static taskNumber As Integer
  296.     Static X As Single
  297.     Static Y As Single
  298.     
  299.     Dim XX As Single
  300.     Dim YY As Single
  301.     Dim i As Integer 'loop counter
  302.     Dim lngLastTick As Long
  303.     
  304.     
  305.     If Not postinitialized Then
  306.         postInitialize Int(Rnd * Rnd * 500 + 1) 'pick a random number of plants and finish initializing.
  307.         postinitialized = True
  308.         
  309.         
  310.         Do
  311.             
  312.             
  313.             For i = 0 To 25 'arbitrary number of loops.  Low numbers are slower. High numbers are less responsive.
  314.                 taskNumber = taskNumber + 1
  315.                 If taskNumber > 8 Then taskNumber = 0
  316.                 If taskNumber <> 0 Then
  317.                     If Not ((X >= LowerX) And (X <= UpperX) And (Y >= LowerY) And (Y <= UpperY)) Then
  318.                         taskNumber = -1  'Do not process life forms out of the zoom area.
  319.                     End If
  320.                 End If
  321.                 Select Case taskNumber
  322.                 Case 0
  323.                     GetNextItemXY X, Y
  324.                 Case 1
  325.                     moveItemXY X, Y
  326.                 Case 2
  327.                     mateItemXY X, Y
  328.                 Case 3
  329.                     cloneItemXY X, Y
  330.                 Case 4
  331.                     feedItemXY X, Y
  332.                 Case 5
  333.                     ageItemXY X, Y
  334.                 Case 6
  335.                     healItemXY X, Y
  336.                 Case 7
  337.                     processNextGeneXY X, Y
  338.                 Case Else
  339.                     
  340.                     'If (Abs(timeOfLastRedraw - Timer) > 0.5) Then
  341.                     '**using Long as a data type is a lot faster than using Single
  342.                     If ((GetTickCount - lngLastTick) >= 500) Then
  343.                         
  344.                         '** all graphical drawing needs to be inside the IF statement, including the
  345.                         'DoEvents as this is one of the things that really kills an app when in a
  346.                         'loop
  347.                         DoEvents
  348.                         lngLastTick = GetTickCount
  349.                     End If
  350.                 End Select
  351.             Next i
  352.             If lifeCount < 1 Then 'Odds are "supposed to be" against all of this...
  353.                 'Simulate long term interactions of biochemicals in "lifeless" organic materials.
  354.                 If Grid(X, Y).Energy < 0 Then
  355.                     If Not Grid(X, Y).Alive Then
  356.                         XX = GetRndInt(RangeX - 1) + LowerX
  357.                         YY = GetRndInt(RangeY - 1) + LowerY
  358.                         If Sqr((XX - X) ^ 2 + (YY - Y) ^ 2) < Abs(Grid(X, Y).Energy) Then
  359.                             If (Grid(X, Y).RGB = Grid(XX, YY).RGB) And Not Grid(XX, YY).Alive Then
  360.                                 Grid(X, Y).Energy = -Grid(X, Y).Energy
  361.                                 BirthItemXY XX, YY
  362.                             End If
  363.                         End If
  364.                     End If
  365.                 End If
  366.             End If
  367.             If (mChkAllowPlagues.Checked Xor breakRules) Then
  368.                 If lifeCount > 200 Then 'Don't have plagues when the population is low.
  369.                     If neighborCount(X, Y) > 4 - Sgn(Grid(X, Y).Speed) Then '(over-crowded)
  370.                         plagueItemXY X, Y
  371.                     End If
  372.                 End If
  373.             End If
  374.         Loop Until ExitForm
  375.         Unload Me
  376.     End If
  377. End Sub
  378.  
  379. Sub postInitialize(n) 'Initialization of environment after the form has been initialized.
  380.     resetGrid 'Prepare the grid for life to grow in it.
  381.     picLife.Cls 'Clear the pictureBox.
  382.     picLife.BorderStyle = 0 'hide the pictureBox border.
  383.     firstLife n 'Seed first n primative life forms.
  384.     tmrMultiTask.Enabled = True 'Activate the multi-tasking core.
  385. End Sub
  386.  
  387. Private Sub Form_Initialize()
  388.     ZoomFactor = 1.5
  389.     mChkZoomFactor.Caption = "Zoom Factor = " + Trim(Str(ZoomFactor))
  390.     OffsetX = 0
  391.     OffsetY = 0
  392. End Sub
  393.  
  394. Private Sub Form_Load()
  395.     Dim ctrl As Control
  396.     Dim sTmp As String
  397.     
  398.     formLife.Caption = "AntieLife - v." + Trim(Str(App.Major)) + "." + Trim(Str(App.Minor)) + ".0." + Trim(Str(App.Revision)) + " - TechnoZeus"
  399.     initialHeight = formLife.ScaleHeight
  400.     initialWidth = formLife.ScaleWidth
  401.     
  402.     'On Error Resume Next
  403.     For Each ctrl In formLife.Controls
  404.         
  405.         '** why is this here?
  406.         If ctrl.Tag > "" Then Stop
  407.         
  408.         
  409.         'stop trying to read a timer control which does not have a run time interface
  410.         If (Not TypeOf ctrl Is Timer) And (Not TypeOf ctrl Is Menu) Then
  411.             sTmp = ""
  412.             sTmp = sTmp + CStr(ctrl.Top)
  413.             sTmp = sTmp + vbCrLf
  414.             sTmp = sTmp + CStr(ctrl.Left)
  415.             sTmp = sTmp + vbCrLf
  416.             sTmp = sTmp + CStr(ctrl.Height)
  417.             sTmp = sTmp + vbCrLf
  418.             sTmp = sTmp + CStr(ctrl.Width)
  419.             sTmp = sTmp + vbCrLf
  420.             sTmp = sTmp + CStr(ctrl.Font.Size)
  421.             ctrl.Tag = sTmp
  422.         End If
  423.     Next ctrl
  424.     Randomize
  425. End Sub
  426.  
  427. Sub drawGrid()
  428.     'draw all life forms.
  429.     Dim X As Single
  430.     Dim Y As Single
  431.     Dim LastX As Single
  432.     Dim LastY As Single
  433.     Dim W As Single
  434.     
  435.     GetNextItemXY LastX, LastY
  436.     lifeCount = 0
  437.     PlantCount = 0
  438.     AntCount = 0
  439.     
  440.     Do
  441.         GetNextItemXY X, Y
  442.         If (X >= LowerX) And (X <= UpperX) And (Y >= LowerY) And (Y <= UpperY) Then
  443.             DrawItemXY X, Y
  444.             If Grid(X, Y).Alive Then
  445.                 lifeCount = lifeCount + 1
  446.                 If Grid(X, Y).Speed > 0 Then
  447.                     AntCount = AntCount + 1
  448.                 Else
  449.                     PlantCount = PlantCount + 1
  450.                 End If
  451.             End If
  452.         End If
  453.     Loop Until (X = LastX) And (Y = LastY)
  454.     
  455.     lblPlantCount.Caption = Str(PlantCount)
  456.     lblAntCount.Caption = Str(AntCount)
  457. End Sub
  458.  
  459. Sub DrawItemXY(X As Single, Y As Single)
  460.     'draw a single life form.
  461.     Dim W As Single
  462.     
  463.     Call GridPos(X, Y)
  464.     
  465.     With Grid(X, Y)
  466.         If .Alive Then
  467.             W = .Width * ZoomFactor
  468.             If W < 1 Then W = 1
  469.             picLife.DrawWidth = W  ' Set DrawWidth.
  470.             picLife.PSet ((.NextX - LowerX) * mulX, (.NextY - LowerY) * mulY), .RGB
  471.             picLife.Line -((X - LowerX) * mulX, (Y - LowerY) * mulY), .RGB 'Draw to anchor point.
  472.         End If
  473.     End With
  474. End Sub
  475.  
  476. Private Sub Form_Paint()
  477.     'force a redraw when necessary
  478.     Call Form_Resize
  479. End Sub
  480.  
  481. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  482.     'exit the form
  483.     ExitForm = True
  484.     Unload Me
  485. End Sub
  486.  
  487. Private Sub Form_Resize()
  488.     'Make sure everything fits in the window.
  489.     Dim ctrl As Control
  490.     Dim tmpSa() As String
  491.     Dim tmpHeight As Single
  492.     Dim tmpWidth As Single
  493.     Dim tmpSize As Single
  494.     
  495.     tmpHeight = heightRatio * 0.97
  496.     tmpWidth = widthRatio * 0.99
  497.     
  498.     If tmpHeight < 0.25 Then tmpHeight = 0.25
  499.     If tmpWidth < 0.25 Then tmpWidth = 0.25
  500.     
  501.     tmpSize = lessNotZero(tmpHeight, tmpWidth)
  502.     
  503.     'On Error Resume Next
  504.     For Each ctrl In formLife.Controls
  505.         
  506.         'is there anything to process
  507.         If (ctrl.Tag <> "") And (Not TypeOf ctrl Is Timer) And (Not TypeOf ctrl Is Menu) Then
  508.             tmpSa() = Split(ctrl.Tag, vbCrLf)
  509.             ctrl.Top = (tmpHeight * Val(tmpSa(0)))
  510.             ctrl.Left = (tmpWidth * Val(tmpSa(1)))
  511.             ctrl.Height = (tmpHeight * Val(tmpSa(2)))
  512.             ctrl.Width = (tmpWidth * Val(tmpSa(3)))
  513.             ctrl.Font.Name = "Arial"
  514.             ctrl.Font.Size = (tmpSize * Val(tmpSa(4)))
  515.             ctrl.Refresh
  516.         End If
  517.     Next ctrl
  518.     'On Error GoTo 0
  519.     
  520.     mulX = picLife.ScaleWidth / GridSizeX * ZoomFactor
  521.     mulY = picLife.ScaleHeight / GridSizeY * ZoomFactor
  522.     LowerX = (GridSizeX / ZoomFactor * (ZoomFactor - 1)) / 2
  523.     UpperX = (GridSizeX - LowerX)
  524.     RangeX = (UpperX - LowerX)
  525.     LowerY = (GridSizeY / ZoomFactor * (ZoomFactor - 1)) / 2
  526.     UpperY = (GridSizeY - LowerY)
  527.     RangeY = (UpperY - LowerY)
  528.     
  529.     If Abs(OffsetX) > RangeX * 4 Then OffsetX = OffsetX * 0.85
  530.     If Abs(OffsetY) > RangeY * 4 Then OffsetY = OffsetY * 0.85
  531.     
  532.     LowerX = LowerX + OffsetX
  533.     LowerY = LowerY + OffsetY
  534.     UpperX = UpperX + OffsetX
  535.     UpperY = UpperY + OffsetY
  536.     
  537.     picLife.Cls
  538.     drawGrid
  539. End Sub
  540.  
  541. Private Sub mChkAllowPlagues_Click()
  542.     mChkAllowPlagues.Checked = Not mChkAllowPlagues.Checked
  543. End Sub
  544.  
  545. Private Sub mChkAllowPollen_Click()
  546.     mChkAllowPollen.Checked = Not mChkAllowPollen.Checked
  547. End Sub
  548.  
  549. Private Sub mChkAllowSpores_Click()
  550.     mChkAllowSpores.Checked = Not mChkAllowSpores.Checked
  551. End Sub
  552.  
  553. Private Sub mChkBreakRules_Click()
  554.     mChkBreakRules.Checked = Not mChkBreakRules.Checked
  555. End Sub
  556.  
  557. Private Sub mChkEnableSounds_Click()
  558.     mChkEnableSounds.Checked = Not mChkEnableSounds.Checked
  559. End Sub
  560.  
  561. Private Sub mChkFastEvolve_Click()
  562.     mChkFastEvolve.Checked = Not mChkFastEvolve.Checked
  563. End Sub
  564.  
  565. Private Sub mChkInvertGreen_Click()
  566.     mChkInvertGreen.Checked = Not mChkInvertGreen.Checked
  567.     setBackgroundColor
  568.     drawGrid
  569. End Sub
  570.  
  571. Private Sub mChkInvertBlue_Click()
  572.     mChkInvertBlue.Checked = Not mChkInvertBlue.Checked
  573.     setBackgroundColor
  574.     drawGrid
  575. End Sub
  576.  
  577. Private Sub mChkInvertRed_Click()
  578.     mChkInvertRed.Checked = Not mChkInvertRed.Checked
  579.     setBackgroundColor
  580.     drawGrid
  581. End Sub
  582.  
  583. Private Sub mChkNoAntEatAnt_Click()
  584.     mChkNoAntEatAnt.Checked = Not mChkNoAntEatAnt.Checked
  585. End Sub
  586.  
  587. Private Sub mChkNoAntEatCarion_Click()
  588.     mChkNoAntEatCarion.Checked = Not mChkNoAntEatCarion.Checked
  589. End Sub
  590.  
  591. Private Sub mChkNoAntEatDirt_Click()
  592.     mChkNoAntEatDirt.Checked = Not mChkNoAntEatDirt.Checked
  593. End Sub
  594.  
  595. Private Sub mChkNoAntEatPlant_Click()
  596.     mChkNoAntEatPlant.Checked = Not mChkNoAntEatPlant.Checked
  597. End Sub
  598.  
  599. Private Sub mChkNoCloneAnt_Click()
  600.     mChkNoCloneAnt.Checked = Not mChkNoCloneAnt.Checked
  601. End Sub
  602.  
  603. Private Sub mChkNoClonePlant_Click()
  604.     mChkNoClonePlant.Checked = Not mChkNoClonePlant.Checked
  605. End Sub
  606.  
  607. Private Sub mChkNoFatalAge_Click()
  608.     mChkNoFatalAge.Checked = Not mChkNoFatalAge.Checked
  609. End Sub
  610.  
  611. Private Sub mChkNoFatalHunger_Click()
  612.     mChkNoFatalHunger.Checked = Not mChkNoFatalHunger.Checked
  613. End Sub
  614.  
  615. Private Sub mChkNoMateAntAnt_Click()
  616.     mChkNoMateAntAnt.Checked = Not mChkNoMateAntAnt.Checked
  617. End Sub
  618.  
  619. Private Sub mChkNoMateAntPlant_Click()
  620.     mChkNoMateAntPlant.Checked = Not mChkNoMateAntPlant.Checked
  621. End Sub
  622.  
  623. Private Sub mChkNoMatePlantAnt_Click()
  624.     mChkNoMatePlantAnt.Checked = Not mChkNoMatePlantAnt.Checked
  625. End Sub
  626.  
  627. Private Sub mChkNoMatePlantPlant_Click()
  628.     mChkNoMatePlantPlant.Checked = Not mChkNoMatePlantPlant.Checked
  629. End Sub
  630.  
  631. Private Sub mChkNoPlantEatAnt_Click()
  632.     mChkNoPlantEatAnt.Checked = Not mChkNoPlantEatAnt.Checked
  633. End Sub
  634.  
  635. Private Sub mChkNoPlantEatCarion_Click()
  636.     mChkNoPlantEatCarion.Checked = Not mChkNoPlantEatCarion.Checked
  637. End Sub
  638.  
  639. Private Sub mChkNoPlantEatPlant_Click()
  640.     mChkNoPlantEatPlant.Checked = Not mChkNoPlantEatPlant.Checked
  641. End Sub
  642.  
  643. Private Sub mChkQuickStart_Click()
  644.     mChkQuickStart.Checked = Not mChkQuickStart.Checked
  645. End Sub
  646.  
  647. Private Sub mChkZoomFactor_Click()
  648.     Dim s As String
  649.     Dim c As String
  650.     'On Error Resume Next
  651.     If ZoomFactor = 1 Then
  652.         c = "You may choose to zoom in on the center, but note that life-forms outside of the area displayed will be suspended in time until you zoom back out."
  653.         c = c + vbCrLf + vbCrLf + "Please enter the desired zoom factor, in the range of 1 to 20"
  654.         s = InputBox(c, "Set Zoom Factor", "2")
  655.         ZoomFactor = Val(s)
  656.         If (ZoomFactor < 1) Or (ZoomFactor > 20) Then ZoomFactor = 1
  657.     Else
  658.         ZoomFactor = 1
  659.     End If
  660.     'On Error GoTo 0
  661.     mChkZoomFactor.Checked = (ZoomFactor <> 1)
  662.     
  663.     If mChkZoomFactor.Checked Then
  664.         mChkZoomFactor.Caption = "Zoom Factor = " + Trim(Str(ZoomFactor))
  665.     Else
  666.         mChkZoomFactor.Caption = "Zoom In (normal = 1)"
  667.     End If
  668.     Form_Resize
  669. End Sub
  670.  
  671.  
  672. Private Sub picLife_KeyDown(KeyCode As Integer, Shift As Integer)
  673.     Select Case KeyCode
  674.     Case 97
  675.         OffsetX = OffsetX - RangeX / 10
  676.         OffsetY = OffsetY + RangeY / 10
  677.     Case 98, 40 'Down
  678.         OffsetY = OffsetY + RangeY / 10
  679.     Case 99
  680.         OffsetX = OffsetX + RangeX / 10
  681.         OffsetY = OffsetY + RangeY / 10
  682.     Case 100, 37 'Left
  683.         OffsetX = OffsetX - RangeX / 10
  684.     Case 101
  685.         OffsetX = 0
  686.         OffsetY = 0
  687.     Case 102, 39 'Right
  688.         OffsetX = OffsetX + RangeX / 10
  689.     Case 103
  690.         OffsetX = OffsetX - RangeX / 10
  691.         OffsetY = OffsetY - RangeY / 10
  692.     Case 104, 38 'Up
  693.         OffsetY = OffsetY - RangeY / 10
  694.     Case 105
  695.         OffsetX = OffsetX + RangeX / 10
  696.         OffsetY = OffsetY - RangeY / 10
  697.     Case 107, 187 'Plus
  698.         ZoomFactor = ZoomFactor * 1.01 + 0.1
  699.     Case 109, 189 'Minus
  700.         ZoomFactor = (ZoomFactor - 0.1) / 1.01
  701.     End Select
  702.     If ZoomFactor < 0.1 Then ZoomFactor = 0.1
  703.     If ZoomFactor > 50 Then ZoomFactor = 50
  704.     mChkZoomFactor.Checked = (ZoomFactor <> 1)
  705.     If mChkZoomFactor.Checked Then
  706.         mChkZoomFactor.Caption = "Zoom Factor = " + Trim(Str(ZoomFactor))
  707.     Else
  708.         mChkZoomFactor.Caption = "Zoom In (normal = 1)"
  709.     End If
  710.     Form_Resize
  711. End Sub
  712.  
  713. Private Sub picLife_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  714.     Static Lf As Creature
  715.     Dim XX As Single
  716.     Dim YY As Single
  717.     
  718.     XX = CLng(LowerX + X / mulX)
  719.     YY = CLng(LowerY + Y / mulY)
  720.     
  721.     'On Error Resume Next 'To avoid errors while scrolling the display
  722.     
  723.     If Button = vbRightButton Then
  724.         If Not Grid(XX, YY).Alive Then
  725.             GetNearestLiveNeighborXY XX, YY, False, False, True, True, True
  726.         End If
  727.         If Grid(XX, YY).Alive Then
  728.             Lf = Grid(XX, YY)
  729.             killItemXY XX, YY
  730.         End If
  731.     
  732.     ElseIf Button = vbLeftButton Then
  733.         If Not Grid(XX, YY).Alive Then
  734.             Grid(XX, YY) = Lf
  735.             BirthItemXY XX, YY
  736.             Grid(XX, YY).Energy = Abs(Grid(XX, YY).Energy) + 0.3 * Rnd
  737.             Grid(XX, YY).redEnergy = Grid(XX, YY).redEnergy + 0.2 * Rnd
  738.             Grid(XX, YY).greenEnergy = Grid(XX, YY).greenEnergy + 0.2 * Rnd
  739.             Grid(XX, YY).blueEnergy = Grid(XX, YY).blueEnergy + 0.2 * Rnd
  740.         End If
  741.     End If
  742.     
  743.     'On Error GoTo 0
  744. End Sub
  745.  
  746. Private Sub tmrMultiTask_Timer()
  747.     'update the display
  748.     lblPlantCount.Caption = Str(PlantCount)
  749.     lblAntCount.Caption = Str(AntCount)
  750.     picLife.Cls
  751.     Call drawGrid
  752. End Sub
  753.  
  754. Function heightRatio() As Double
  755.     heightRatio = formLife.ScaleHeight / initialHeight
  756. End Function
  757.  
  758. Function widthRatio() As Double
  759.     widthRatio = formLife.ScaleWidth / initialWidth
  760. End Function
  761.  
  762. Function lessNotZero(ByVal A, ByVal b)
  763.     'returns the lesser value, provided that value is not zero.
  764.     'returns zero only if both values provided are zero.
  765.     If (A = 0) Or ((b < A) And (b <> 0)) Then A = b
  766.     lessNotZero = A
  767. End Function
  768.  
  769.