// Parent spawner state
IfTimeOut
  // See if the board need to be cleared
  GetContent
  tmpx = tmpargument
  tmpy = 0
  IfXIsEqualToY
    tmpargument = 1
    SetContent

    // Reset the board...
    tmpx = 21 < 7
    tmpy = 35 < 7
    tmpargument = 187
    SetTileXY
    tmpx = tmpx + 128
    SetTileXY
    tmpx = tmpx + 128
    SetTileXY
    tmpx = tmpx + 128
    SetTileXY

    tmpx = 21 < 7
    tmpy = tmpy + 128
    tmpargument = 187
    SetTileXY
    tmpx = tmpx + 128
    SetTileXY
    tmpx = tmpx + 128
    SetTileXY
    tmpx = tmpx + 128
    SetTileXY

    tmpx = 21 < 7
    tmpy = tmpy + 128
    tmpargument = 187
    SetTileXY
    tmpx = tmpx + 128
    SetTileXY
    tmpx = tmpx + 128
    SetTileXY
    tmpx = tmpx + 128
    SetTileXY

    tmpx = 21 < 7
    tmpy = tmpy + 128
    tmpargument = 187
    SetTileXY
    tmpx = tmpx + 128
    SetTileXY
    tmpx = tmpx + 128
    SetTileXY
    tmpx = tmpx + 128
    SetTileXY

  tmpargument = 3
  SetTime

  SetTargetToNearestEnemy

  IfTargetIsAPlayer
    // See if the target is on the ground
    tmpx = targetaltitude
    tmpy = 20
    IfXIsLessThanY
      // See if the target is in the play area
      tmpx = targetx
      tmpy = 21 < 7
      IfXIsMoreThanY
        tmpy = 25 < 7
        IfXIsLessThanY
          tmpy = targety
          tmpx = 35 < 7
          IfYIsMoreThanX
            tmpx = 39 < 7
            IfYIsLessThanX
              // See if the target is standing in the center
              tmpx = targetx - 32 & 64
              tmpy = 0
              IfXIsEqualToY
                tmpx = targety - 32 & 64
                IfXIsEqualToY
                  // Change a tile
                  tmpx = targetx
                  tmpy = targety
                  GetTileXY
                  tmpx = tmpargument
                  tmpy = 187
                  IfXIsEqualToY
                    GetContent
                    tmpargument = tmpargument & 1 + 188
                    tmpx = targetx
                    tmpy = targety
                    SetTileXY

                    // Remember which ones have are Red
                    tmpx = tmpargument & 1
                    tmpy = 0
                    IfXIsEqualToY
                      tmpx = targetx > 7 - 21
                      tmpy = targety > 7 - 35 < 2
                      tmpx = tmpx + tmpy
                      tmpturn = 1 < tmpx
                      tmpargument = 0
                      GetXY
                      tmpx = tmpx + tmpturn
                      SetXY

                    // Increase the count
                    GetContent
                    tmpargument = tmpargument + 1
                    SetContent
                    tmpx = tmpargument
                    tmpy = 17
                    IfXIsEqualToY
                      // We are done...
                      tmpargument = 0
                      GetXY
                      tmpy = 38505
                      IfXIsEqualToY
                        // The player won...
                        tmpargument = 0
                        SendMessageNear

                        // Play the "found a secret" sound
                        tmpargument = 2
                        tmpdistance = 11025
                        PlaySound

                        // Open a master passage
                        tmpargument = passage
                        OpenPassage
                        GoPoof
                      Else
                        // The player lost...
                        tmpargument = rand & 3 + 1
                        SendMessageNear

                        // Play the buzzer sound
                        tmpargument = 1
                        tmpdistance = 10000
                        PlaySound

                        // Start it over in a second
                        tmpargument = 0
                        SetContent
                        tmpx = 0
                        SetXY
                        tmpargument = 50
                        SetTime
                    Else
                      // Play the button press sound
                      tmpargument = 0
                      tmpdistance = 11025
                      PlaySound

End					// Finished with this character
