IfOrdered
  tmpx = selforder
  tmpy = [WAVE]
  IfXIsEqualToY
    tmpdistance = selfz + 300
  
    //Wave 0 - Grub Bugs
    IfStateIs0
      tmpargument = 38
      tmpx = selfx
      tmpy = selfy
      SpawnExactCharacterXYZ
  
    //Wave 1 - Crabs
    IfStateIs1
      tmpargument = 41
      tmpx = selfx
      tmpy = selfy
      SpawnExactCharacterXYZ

    //Wave 2 - Tranches
    IfStateIs2
      tmpargument = 42
      tmpx = selfx
      tmpy = selfy
      SpawnExactCharacterXYZ
      
    //--------------------------
    //Wave 3 - PAUSE AND RESTING
    //--------------------------

    //Wave 4 - Zombis!
    IfStateIs4
      tmpargument = 71
      tmpx = selfx
      tmpy = selfy
      SpawnExactCharacterXYZ
      
      //Give him a weapon
      SetTargetToChild
      tmpx = rand % 7
      tmpy = 0
      IfXIsEqualToY
        tmpargument = 83          //Trident
      tmpy = 1
      IfXIsEqualToY
        tmpargument = 72          //Spear
      tmpy = 2
      IfXIsEqualToY
        tmpargument = 87          //Cinqueda
      tmpy = 3
      IfXIsEqualToY
        tmpargument = 81          //Hatchet
      tmpy = 4
      IfXIsEqualToY
        tmpargument = 82          //Mace
      tmpy = 5
      IfXIsEqualToY
        tmpargument = 88          //Battleaxes
      tmpy = 6
      IfXIsEqualToY
        tmpargument = 79          //Claw
      tmpdistance = RIGHT
      SpawnAttachedCharacter

    //Wave 5 - Fire Lizards
    IfStateIs5
      tmpargument = 73
      tmpx = selfx
      tmpy = selfy
      SpawnExactCharacterXYZ
      
    //Wave 6 - Angry Lumpkins!
    IfStateIs6
      tmpargument = 74
      tmpx = selfx
      tmpy = selfy
      SpawnExactCharacterXYZ      

      //Give him a weapon
      SetTargetToChild
      tmpx = rand & 1
      tmpy = 0
      IfXIsEqualToY
        tmpargument = 75          //Gonne
      Else
        tmpargument = 79          //Claw
      tmpdistance = RIGHT
      SpawnAttachedCharacter

    //--------------------------
    //Wave 7 - PAUSE AND RESTING
    //--------------------------

    //Wave 8 - Assassins!
    IfStateIs8
      tmpargument = 76
      tmpx = selfx
      tmpy = selfy
      SpawnExactCharacterXYZ      

      //Give him a weapon
      SetTargetToChild
      tmpx = rand & 1
      tmpy = 0
      IfXIsEqualToY
        tmpargument = 77          //Stiletto
      Else
        tmpargument = 78          //Poisoned X-bow
      tmpdistance = RIGHT
      SpawnAttachedCharacter

    //Wave 9 - Minotores
    IfStateIs9
      tmpargument = 80
      tmpx = selfx
      tmpy = selfy
      SpawnExactCharacterXYZ      

      //Give him a weapon
      SetTargetToChild
      tmpx = rand & 2
      tmpy = 0
      IfXIsEqualToY
        tmpargument = 81          //Hatchet
      tmpy = 1
      IfXIsEqualToY
        tmpargument = 82          //Mace
      tmpy = 2
      IfXIsEqualToY
        tmpargument = 88          //Battleaxes
      
      tmpdistance = RIGHT
      SpawnAttachedCharacter
      
    //Wave 10 - Boss Fight!
    IfStateIs10
      tmpargument = 38            //Grubb swarm
      tmpx = selfx
      tmpy = selfy
      SpawnExactCharacterXYZ
      SpawnExactCharacterXYZ
      SpawnExactCharacterXYZ
      SpawnExactCharacterXYZ
      SpawnExactCharacterXYZ
      
      tmpargument = 90              //King Crabs
      SpawnExactCharacterXYZ
      SpawnExactCharacterXYZ
      
      tmpargument = 1
      SetContent
      
    //Next Wave
    tmpargument = selfstate + 1
    SetState
  
//Special undefeatable last boss ending
tmpx = selfcontent
tmpy = 0
IfXIsMoreThanY
  tmpargument = selfcontent + 1
  SetContent
  tmpturn = difficulty*75       //-1.5 second per difficulity level
  tmpy = 700-tmpturn
  IfXIsEqualToY
    tmpargument = 91            //Gigantic Gelfeet
    tmpx = selfx
    tmpy = selfy
    SpawnExactCharacterXYZ
    GoPoof

//------------------------------------------------------------------------------------
End					// All done
//------------------------------------------------------------------------------------
