

    '***********************************************************
    '   Official website : www.atomose.fr                      '
    '   LibertyBasic 4.51 pro licence                          '
    '   Tower Defense © (all copyrights reserved)              '
    '   By Alexandre Lomuto (Atomose Studio) - 2026            '
    '***********************************************************

    nomainwin
  '  dir$ = "" : file$ = "licence.txt"
  '  if fileExist(dir$,file$) = 0 then NOlicence = 1

    ' secu test -----------
    on error goto [noSav]
    open "secu.txt" for input as #secu
    input #secu, pass$
    close #secu
    if pass$ = "1" then end
    pass$ = "1"
    open "secu.txt" for output as #secu
    print #secu, pass$
    close #secu
    '---------------------

    dir$ = "" : file$ = "data.txt"
  '  if fileExist(dir$,file$) = 1 then
    loaded = 1
    gosub [input]
    if lifeTOTA <> int(gold*4587953+Nvague*141254867) then notice " " + chr$(13) +  "Il a été détecté que le système de sauvegarde à été modifié et corrompue. Supression de l'ancienne sauvegarde." : kill "data.txt" : end
    if goldTOTA <> int(Nvague*56458487+45879*life) then notice " " + chr$(13) +  "Il a été détecté que le système de sauvegarde à été modifié et corrompue. Supression de l'ancienne sauvegarde." : kill "data.txt" : end

    [noSav]
    pass$ = "1" : if loaded = 0 then life = 20 : gold = 40 : Nvague = 1 : gosub [print]
    open "secu.txt" for output as #secu
    print #secu, pass$
    close #secu

    GameVersion = 1.17 : Version$ = "Version 1.17" : version = 1
    loadbmp "screen", "data\screen.bmp"
    loadbmp "tuto", "data\tuto.bmp"
    loadbmp "king", "data\king.bmp"

    [INITIAL]
    WindowWidth=817 : WindowHeight=640 : UpperLeftX=int((DisplayWidth-WindowWidth)/2) : UpperLeftY=int((DisplayHeight-WindowHeight)/2)
    TIMERBOUCLE = 50 : bruitage = 0
    graphicbox #ini.main, 0, 0, 811, 611

    if version = 1 then bmpbutton #ini.b1, "data\button1fr.bmp", [INITIAL2], UL, 450,180 : bmpbutton #ini.b5, "data\button2fr.bmp", [web], UL, 450,220 : bmpbutton #ini.b4, "data\button1.bmp", [about], UL, 450,260
    if version = 2 then bmpbutton #ini.b1, "data\button1en.bmp", [INITIAL2], UL, 450,180 : bmpbutton #ini.b5, "data\button2en.bmp", [web], UL, 450,220 : bmpbutton #ini.b4, "data\button1.bmp", [about], UL, 450,260

    bmpbutton #ini.b2, "data\fr.bmp", [fr], UL, 20,10
    bmpbutton #ini.b3, "data\eng.bmp", [eng], UL, 50,10
    open "" for window_nf as #ini
    #ini, "trapclose [quit2]"
    #ini.main "down; fill black"
    #ini.main "drawbmp screen 0 0; background screen"
    #ini, "font ink_free 11"

    handle = hwnd(#ini)
    hTip=CreateTooltip(handle)
    if version = 1 then
        Call AddToolTip Hwnd(#ini.b1), hTip , "Lancement du jeu"
        Call AddToolTip Hwnd(#ini.b2), hTip , "Met le jeu en langue Française"
        Call AddToolTip Hwnd(#ini.b3), hTip , "Met le jeu en langue Anglaise"
        Call AddToolTip Hwnd(#ini.b4), hTip , "Permet de vérifier si une nouvelle mise à jour est disponible"
        Call AddToolTip Hwnd(#ini.b5), hTip , "Tous nos jeux disponibles sur notre site"
    end if
    if version = 2 then
        Call AddToolTip Hwnd(#ini.b1), hTip , "Launching the game"
        Call AddToolTip Hwnd(#ini.b2), hTip , "Put the game in French language"
        Call AddToolTip Hwnd(#ini.b3), hTip , "Put the game in English language"
        Call AddToolTip Hwnd(#ini.b4), hTip , "Allows you to check if a new update is available"
        Call AddToolTip Hwnd(#ini.b5), hTip , "All our games available on our website"
    end if
    GameActivation = 0
    #ini.main "flush"
    wait
    [INITIALb]
    close #ini : nocheat = 0 : call Sleep 100 : goto [INITIAL]

    [INITIAL2]
    timer 0
    close #ini

    [INITIAL3]
    on error goto [noticeERROR]
    timer 0 : nocheat = 0 : pause = 0
    if loaded = 1 and life >0 then goto [loaded]

    global fermage, forge
    fermage = 0 : forge = 0 : mapCHOICE = 1
    lands$ = "mini0 mini1 mini2 mini3 mini4 mini5 mini6 mini7 mini8 mini9 mini10 mini11 mini12 selectMAP"
    for s = 1 to 14
        loadbmp word$(lands$,s), "data\"+word$(lands$,s)+".bmp"
    next


    WindowWidth=817 : WindowHeight=640 : UpperLeftX=int((DisplayWidth-WindowWidth)/2) : UpperLeftY=int((DisplayHeight-WindowHeight)/2)
    graphicbox #ini.main, 0, 0, 811, 611

    if version = 1 then bmpbutton #ini.b1, "data\button1fr.bmp", [tuto], UL, 420,550 : bmpbutton #ini.b5, "data\button0fr.bmp", [INITIALb], UL, 250,550
    if version = 2 then bmpbutton #ini.b1, "data\button1en.bmp", [tuto], UL, 420,550 : bmpbutton #ini.b5, "data\button0en.bmp", [INITIALb], UL, 250,550

    open "" for window_nf as #ini
    #ini, "trapclose [INITIALb]"

    #ini.main "down; fill ";70;" ";136;" ";223
    #ini.main, "when leftButtonDown [selectMAP]"
    #ini.main "drawbmp selectMAP 38 50"
    #ini.main "drawbmp mini1 100 140" : #ini.main "drawbmp mini2 260 140" : #ini.main "drawbmp mini3 420 140" : #ini.main "drawbmp mini4 580 140"
    #ini.main "drawbmp mini5 100 260" : #ini.main "drawbmp mini6 260 260" : #ini.main "drawbmp mini7 420 260" : #ini.main "drawbmp mini8 580 260"
    #ini.main "drawbmp mini9 100 380" : #ini.main "drawbmp mini10 260 380" : #ini.main "drawbmp mini11 420 380" : #ini.main "drawbmp mini12 580 380"
    #ini.main "font ink_free 15 bold; color black; backcolor ";182;" ";111;" ";42
    if version = 1 then #ini.main "place 255 105 ;\"; "SÉLECTIONNEZ UNE CARTE"
    if version = 2 then #ini.main "place 330 105 ;\"; "SELECT A MAP"
    print #ini.main, "size 2; color black" : print #ini.main, "line "; 90; " "; 140; " "; 90; " "; 220 : print #ini.main, "line "; 230; " "; 140; " "; 230; " "; 220
    #ini.main "flush"
    wait

    [selectMAP]
    mX = MouseX : mY = MouseY
    'notice mX; " : ";mY
    if mX >100 and mX< 220 and mY >140 and mY < 220 then mapCHOICE = 1 : gosub [restorMAP] : print #ini.main, "line "; 90; " "; 140; " "; 90; " "; 220 : print #ini.main, "line "; 230; " "; 140; " "; 230; " "; 220
    if mX >260 and mX< 380 and mY >140 and mY < 220 then mapCHOICE = 2 : gosub [restorMAP] : print #ini.main, "line "; 250; " "; 140; " "; 250; " "; 220 : print #ini.main, "line "; 390; " "; 140; " "; 390; " "; 220
    if mX >420 and mX< 540 and mY >140 and mY < 220 then mapCHOICE = 3 : gosub [restorMAP] : print #ini.main, "line "; 410; " "; 140; " "; 410; " "; 220 : print #ini.main, "line "; 550; " "; 140; " "; 550; " "; 220
    if mX >580 and mX< 700 and mY >140 and mY < 220 then mapCHOICE = 4 : gosub [restorMAP] : print #ini.main, "line "; 570; " "; 140; " "; 570; " "; 220 : print #ini.main, "line "; 710; " "; 140; " "; 710; " "; 220
    if mX >100 and mX< 220 and mY >260 and mY < 340 then mapCHOICE = 5 : gosub [restorMAP] : print #ini.main, "line "; 90; " "; 260; " "; 90; " "; 340 : print #ini.main, "line "; 230; " "; 260; " "; 230; " "; 340
    if mX >260 and mX< 380 and mY >260 and mY < 340 then mapCHOICE = 6 : gosub [restorMAP] : print #ini.main, "line "; 250; " "; 260; " "; 250; " "; 340 : print #ini.main, "line "; 390; " "; 260; " "; 390; " "; 340
    if mX >420 and mX< 540 and mY >260 and mY < 340 then mapCHOICE = 7 : gosub [restorMAP] : print #ini.main, "line "; 410; " "; 260; " "; 410; " "; 340 : print #ini.main, "line "; 550; " "; 260; " "; 550; " "; 340
    if mX >580 and mX< 700 and mY >260 and mY < 340 then mapCHOICE = 8 : gosub [restorMAP] : print #ini.main, "line "; 570; " "; 260; " "; 570; " "; 340 : print #ini.main, "line "; 710; " "; 260; " "; 710; " "; 340
    if mX >100 and mX< 220 and mY >380 and mY < 460 then mapCHOICE = 9 : gosub [restorMAP] : print #ini.main, "line "; 90; " "; 380; " "; 90; " "; 460 : print #ini.main, "line "; 230; " "; 380; " "; 230; " "; 460
    if mX >260 and mX< 380 and mY >380 and mY < 460 then mapCHOICE = 10 : gosub [restorMAP] : print #ini.main, "line "; 250; " "; 380; " "; 250; " "; 460 : print #ini.main, "line "; 390; " "; 380; " "; 390; " "; 460
    if mX >420 and mX< 540 and mY >380 and mY < 460 then mapCHOICE = 11 : gosub [restorMAP] : print #ini.main, "line "; 410; " "; 380; " "; 410; " "; 460 : print #ini.main, "line "; 550; " "; 380; " "; 550; " "; 460
    if mX >580 and mX< 700 and mY >380 and mY < 460 then mapCHOICE = 12 : gosub [restorMAP] : print #ini.main, "line "; 570; " "; 380; " "; 570; " "; 460 : print #ini.main, "line "; 710; " "; 380; " "; 710; " "; 460
    wait

    [restorMAP]
    print #ini.main, "size 2; color ";182;" ";111;" ";42
    print #ini.main, "line "; 90; " "; 140; " "; 90; " "; 220 : print #ini.main, "line "; 230; " "; 140; " "; 230; " "; 220
    print #ini.main, "line "; 250; " "; 140; " "; 250; " "; 220 : print #ini.main, "line "; 390; " "; 140; " "; 390; " "; 220
    print #ini.main, "line "; 410; " "; 140; " "; 410; " "; 220 : print #ini.main, "line "; 550; " "; 140; " "; 550; " "; 220
    print #ini.main, "line "; 570; " "; 140; " "; 570; " "; 220 : print #ini.main, "line "; 710; " "; 140; " "; 710; " "; 220
    print #ini.main, "line "; 90; " "; 260; " "; 90; " "; 340 : print #ini.main, "line "; 230; " "; 260; " "; 230; " "; 340
    print #ini.main, "line "; 250; " "; 260; " "; 250; " "; 340 : print #ini.main, "line "; 390; " "; 260; " "; 390; " "; 340
    print #ini.main, "line "; 410; " "; 260; " "; 410; " "; 340 : print #ini.main, "line "; 550; " "; 260; " "; 550; " "; 340
    print #ini.main, "line "; 570; " "; 260; " "; 570; " "; 340 : print #ini.main, "line "; 710; " "; 260; " "; 710; " "; 340
    print #ini.main, "line "; 90; " "; 380; " "; 90; " "; 460 : print #ini.main, "line "; 230; " "; 380; " "; 230; " "; 460
    print #ini.main, "line "; 250; " "; 380; " "; 250; " "; 460 : print #ini.main, "line "; 390; " "; 380; " "; 390; " "; 460
    print #ini.main, "line "; 410; " "; 380; " "; 410; " "; 460 : print #ini.main, "line "; 550; " "; 380; " "; 550; " "; 460
    print #ini.main, "line "; 570; " "; 380; " "; 570; " "; 460 : print #ini.main, "line "; 710; " "; 380; " "; 710; " "; 460
    print #ini.main, "size 2; color black"
    return

    [noticeERROR]
  '  notice "error"
    wait

'    open "wininet.dll" for dll as #inet
'    callDll #inet, "InternetCheckConnectionA", "http://www.google.com/" as ptr,1 as long,_
'       dwReserved as long,_
'       result as long
'    close #inet

'    print result ' 1 = online ...... 0 = offline

    [about]
    WindowWidth=450 : WindowHeight=200
    UpperLeftX=int((DisplayWidth-WindowWidth)/2) : UpperLeftY=int((DisplayHeight-WindowHeight)/2)
    if about = 1 then close #about
    about = 1
    graphicbox #about.map, 1, 1, WindowWidth-7, WindowHeight-30
    if version = 1 then button #about.b1, "Vérifier les mises à jour disponibles en ligne", [maj], UL, 15, 123,415,30 ': button #about.b2, "Site officiel", [web], UL, 63, 123,100,30
    if version = 2 then button #about.b1, "Check for upgrade available on web", [maj], UL, 15, 123,415,30' : button #about.b2, "Web site", [web], UL, 63, 123,100,30
    open "" for window_nf as #about
    #about, "trapclose [about2]"
    #about.map, "cls;down;fill white"
    print #about.map, "font Cascadia_Code 10; color black;backcolor white"
    [refreshCO]

    open "wininet" for dll as #internet
    callDll #internet, "InternetCheckConnectionA", "http://www.google.com/" as ptr,1 as long,_
        dwReserved as long,_
        checkInet as long
    close #internet

  '  Open "wininet" For DLL As #wininet
  '  CallDLL #wininet, "InternetCheckConnectionA", "http://www.google.com"   As ptr,_
  '                                                    1                         As long, _
  '                                                    0                         As long, _
  '                                                    checkInet                 As long
   '   close #wininet

    If checkInet  = 1 Then
        if version = 1 then checkInet$ = "Votre connexion internet est stable.          "
        if version = 2 then checkInet$ = "Your internet connection is good.          "
    end if
    If checkInet <> 1 Then
        if version = 1 then checkInet$ = "Votre connexion internet est coupée.          "
        if version = 2 then checkInet$ = "Your internet connexion is over.          "
    end if


    if version = 1 then print #about.map, "place 15 30 ;\"; "Tower Defense Re-evolution ";Version$;"\Créé par Atomose Studio ® \Liberty Basic 4.51 pro\\    ";checkInet$
    if version = 2 then print #about.map, "place 15 30 ;\"; "Arena Re-evolution ";Version$;"\Creat by Atomose Studio ® \Liberty Basic 4.51 pro\\    ";checkInet$
    #about, "font ink_free 11"
    if checkInet  = 1 then print #about.map, "size 10; color green" : print #about.map, "set ";25;" ";94
    if checkInet  <> 1 then print #about.map, "size 10; color red" : print #about.map, "set ";25;" ";94
    print #about.map, "color black"
    timer 500, [refreshCO]
    wait
    [about2]
    timer 0
    close #about : about = 0 : wait
    [web]
    run "explorer.exe https://www.atomose.fr" : wait

    [quit2]
    pass$ = "0"
    if about = 1 then close #about
    open "secu.txt" for output as #secu
    print #secu, pass$
    close #secu
    close #ini : end
    [fr]
    version = 1 : close #ini : goto [INITIAL]
    [eng]
    version = 2 : close #ini : goto [INITIAL]

    [maj]
    timer 0
    run "explorer.exe https://www.atomose.fr/la-bibliotheque" : wait


    on error goto [error]
    htmlText$ = httpget$("https://www.petit-fichier.fr/2022/12/07/majtdre/")
    if htmlText$ <> "" then run "curl -O https://www.petit-fichier.fr/2022/12/07/majtdre/majtdre.txt"
    if htmlText$ = "" and version =1 then notice " " + chr$(13) +  "Serveur indisponible" : wait
    if htmlText$ = "" and version =2 then notice " " + chr$(13) +  "Server unavailable" : wait
    htmlText$ =""
    call Sleep 1000 : goto [maj2]
    [maj2]
    open "majtdre.txt" for input as #secu
    input #secu, GameVersionNEW
    input #secu, LinkDownloadNewVersion$
    close #secu
    call Sleep 500 : goto [maj3]
    [maj3]
    q$=chr$(34)
    versionTXT1$ = "    Vous avez la version ";GameVersion;"."
    versionTXT2$ = "    La dernière version en ligne est la ";GameVersionNEW
    versionTXT3$ = "    You have version ";GameVersion;"."
    versionTXT4$ = "    The last available version is ";GameVersionNEW
    if version = 1 then confirm " " + chr$(13) +  versionTXT1$ + chr$(13) +  versionTXT2$+ chr$(13) + chr$(13) +"    Voulez-vous télécharger la version en ligne ?"; confirmation$
    if version = 2 then confirm " " + chr$(13) +  versionTXT3$ + chr$(13) +  versionTXT4$+ chr$(13) + chr$(13) +"    Do you want to download the online version?"; confirmation$
    if confirmation$ = "no" then goto [error]
    run "curl -O ";q$;LinkDownloadNewVersion$;q$
    call Sleep 200
    dir$ = "" : file$ = "majtdre.txt"
    if fileExist(dir$,file$) = 1 then kill "majtdre.txt"
    call Sleep 200
    if version = 1 then confirm " " + chr$(13) +  "Téléchargement terminé." + chr$(13) + "La nouvelle version est disponible dans le dossier du jeu." + chr$(13) + chr$(13) + "Voulez-vous fermer la version actuelle ?";confirmation$
    if version = 2 then confirm " " + chr$(13) +  "Download complete." + chr$(13) + "The new version is available in the game folder." + chr$(13) + chr$(13) + "Do you want to close the current version ?";confirmation$
    if confirmation$ = "no" then goto [error]
    close #ini : close #about : end
    [error]
    dir$ = "" : file$ = "majtdre.txt"
    if fileExist(dir$,file$) = 1 then kill "majtdre.txt"
    wait

    [tuto]
    if about = 1 then close #about : about = 0
    if bossKILLED = 1 then close #ini : goto [ini]
    if mapCHOICE = 0 then mapCHOICE = 1
    close #ini
    WindowWidth=817 : WindowHeight=640 : UpperLeftX=int((DisplayWidth-WindowWidth)/2) : UpperLeftY=int((DisplayHeight-WindowHeight)/2)
    graphicbox #tuto.main, 0, 0, 811, 611
    if version = 1 then button #tuto.b1, "AU COMBAT !", [ini0], UL, 470, 530,230,30
    if version = 2 then button #tuto.b1, "LET'S FIGHT !", [ini0], UL, 470, 530,230,30
    open "" for window_nf as #tuto
    #tuto, "trapclose [Noquit]"
    #tuto.main "down; fill white"
    #tuto, "font ink_free 8"
    #tuto.main "drawbmp tuto 160 160; background tuto"
   ' #tuto.main "drawbmp king 515 470"
    #tuto.main "font ink_free 30 bold; backcolor white"
    #tuto.b1 "!font ink_free 10 bold"
    #tuto.main "place 60 80 ;\"; "TUTO !"
    #tuto.main "font ink_free 10 bold"
    if version = 1 then
        #tuto.main "place 480 470 ;\"; "''C'est bon t'es prêt ?! ''"
        #tuto.main "place 290 140 ;\"; "Sens de marche des ennemis"
        #tuto.main "place 110 188 ;\"; "Point de départ \   des ennemis"
        #tuto.main "place 550 182 ;\"; "Point d'arrivé. Chaque \ennemi qui y passe \vous retire 1 vie."
        #tuto.main "place 100 295 ;\"; "Cliquez sur une zone d'herbe\ pour construire vos tours."
       ' #tuto.main "place 435 335 ;\"; "L'indicateur de niveau est à droite \de la tour !"
        #tuto.main "place 320 295 ;\"; "Pour évoluer vos tours, cliquez dessus une seconde fois. Il faut \avoir l'argent demandé pour que l'amélioration soit faite."
        #tuto.main "place 475 345 ;\"; "Un clic droit sur la tour vous donne \ses caractéristiques !"
    end if
    if version = 2 then
        #tuto.main "place 360 460 ;\"; "''Alright, are you ready?! ''"
        #tuto.main "place 300 100 ;\"; "Direction of enemies"
        #tuto.main "place 115 148 ;\"; "Starting point of \enemies"
        #tuto.main "place 510 142 ;\"; "Arrival point. Each enemy \that passes through it \removes 1 life from you."
        #tuto.main "place 105 255 ;\"; "Click on a grass area to \build your towers."
     '   #tuto.main "place 435 335 ;\"; "The level indicator is to the right \of the tower!"
        #tuto.main "place 290 255 ;\"; "To upgrade your towers, click on it a second time. You have to \have the money requested for the improvement to be made."
        #tuto.main "place 435 305 ;\"; "A right click on the tower gives you its \characteristics!"
    end if
    #tuto.main "flush"
    wait

    [quit4]
    close #tuto : pass$ = "0" : gosub [print] : end

    [ini0]
    close #tuto
    if loaded = 1 and life >0 then goto [loaded]
    [ini]
    bossKILLED = 0
    global towers, life, Nvague, gold, compteurBOSS, compteurSUPERboss, lvlGOLD
    Nvague = 1 : towers = 0 : life = 20 : gold = 40 : compteurBOSS = 4 : compteurSUPERboss = 14 : lvlARM = 0 : lvlGOLD = 0 : EVEN = 0 : viseur = 0 : drapeau = 0

    [rmk]
    lastWave = 1 : lastWave2 = 0
   '  mapCHOICE = 12
    if mapCHOICE = 1 then goto [map1]
    if mapCHOICE = 2 then goto [map2]
    if mapCHOICE = 3 then goto [map3]
    if mapCHOICE = 4 then goto [map4]
    if mapCHOICE = 5 then goto [map5]
    if mapCHOICE = 6 then goto [map6]
    if mapCHOICE = 7 then goto [map7]
    if mapCHOICE = 8 then goto [map8]
    if mapCHOICE = 9 then goto [map9]
    if mapCHOICE = 10 then goto [map10]
    if mapCHOICE = 11 then goto [map11]
    if mapCHOICE = 12 then goto [map12]
    [map1]
    map$ = "éééàéééééééééééééééé";_
           "ééààààéàééééààààééàé";_
           "ééé¤éà  àéàà  è à àé";_
           "ééàààà&ABCDEFGHI  éé";_
           "à  èé  èè   à¤ J àéé";_
           "éàutsrqponml é Kéààé";_
           "éàvà -éà   kéàèL ééé";_
           "é w cdefghijàààMé_àé";_
           "à x b  éà   $è Néàéé";_
           "/zy a]\[ZYX éà O ààé";_
           "à àèè  è  W   éP àéé";_
           "éà àà  ¤àéVUTSRQéèéé";_
           "éà%ééàààééà éà  àééé";_
           "ééàééàéééééàééààéééé"
    goto [loaded]
    [map2]
    map$ = "ééééàééààéééééààéééé";_
           "ééàà àà  àééàà  àééé";_
           "éé ba]\[ZYXWVUTS àéé";_
           "éà c à  èéé    R  àé";_
           "é  d éà    éé¤ Q àéé";_
           "éà efghijk _àéàP ààé";_
           "é¤à   é  l àééèO àéé";_
           "é-à èqponm $àé N ééé";_
           "ééà  r è   è   M àéé";_
           "é èà s à FGHIJKL ééé";_
           "/zà  t   E  àèé àééé";_
           "éyxwvu é¤DCBA&àààééé";_
           "ééà  à%éééà ààéééééé";_
           "éééàéééééééàééééééàà"
    goto [loaded]
    [map3]
    map$ = "éééà/éééééàéééàééàéé";_
           "éàà zàééà  àéà-àà_éé";_
           "à¤èxyé   é¤àéééààééé";_
           "à  w  à   à   à àééé";_
           "éà vutsrqponmlk   àé";_
           "éàà      è    jè  àà";_
           "&ABCDEFGHIJ à i  àéé";_
           "   èéà    Kàéàh   àé";_
           "éà  à   è¤L à g à%éé";_
           "à  TSRQPONM   fàéééé";_
           "éà U é   èà   e àééé";_
           "ééàVWXYZ[\]abcdè àéé";_
           "éà àà$à àéà àà àéééé";_
           "éééàéééàéééééééééééé"
    goto [loaded]
    [map4]
    map$ = "é¤ééééééééééé/ àéééé";_
           "éééààààèéééé z  ààéé";_
           "éé¤IHGFEDèà  yxwvuté";_
           "éè J  èà  èà  é   éé";_
           "éà K ésrqpoé CBA& éé";_
           "é  L  èé¤  èé-   à¤é";_
           "éé MNOPQRS  nmé éééé";_
           "é$à éà   T  àlkj àéé";_
           "éééé  ¤WVU ééà   ééé";_
           "ééé  é   à  ihgfe àé";_
           "ééà YX  àéé   _¤  éé";_
           "ééééZ[\]abcdàé  àèéé";_
           "éééàéé%  àéééààééééé";_
           "ééà   àéééééà  àéééé"
    goto [loaded]
    [map5]
    map$ = "éééàééé  éà¤ èééé/éé";_
           "éà- PONMLKJIHG ¤èzéé";_
           "éà  Q   ééà éFé àyéé";_
           "éé èR àéèèé  Eàé xàé";_
           "ééé Sè  ¤&ABCD  éwàé";_
           "ééàéTà éà¤ ééé   véé";_
           "é¤é Uè ¤éà èpqrstuéé";_
           "éà  V àéé_à$o  éà àé";_
           "éééàW  àé¤  nmlkj éé";_
           "éèééX è àà  àéà i ¤é";_
           "ééà YZ[\]abcdefgh èé";_
           "éà   àééà    àéééààé";_
           "éééàéé%ééà     àéééé";_
           "ééààéééééééàààéééééé"
    goto [loaded]
    [map6]
    map$ = "µµ}éééàéééééààéééééé";_
           "µµ}YZ[\]abcdefghéààé";_
           "µµ}X  àéè    àéi àéé";_
           "²²çWVUTSRQPON¤ jé àé";_
           "éééé  àè    M ékà _¢";_
           "éééà EFGHIJKLééléà §";_
           "éà  éD ¢^^^£èé mé  §";_
           "ééà éC §µµµ}é  n  $§";_
           "ééà¤ B §µµµ}à éo àé{";_
           "ééé àAé{²²²çéà p  éé";_
           "éà àè&à  éà   àq ààé";_
           "é-àèéà èyxwvutsrè éé";_
           "éééééé% zàééà   àééà";_
           "éééééééà/éééé   ééà¢"
    goto [loaded]
    [map7]
    map$ = "ééééààéà{²²²çàéè àéé";_
           "éééà  FGHIJKLMNOP àé";_
           "éèà à E  éèà  é Qè à";_
           "éà&ABCDéàèèWVUTSR àé";_
           "^^^^^^^^^^^^^^^^^^^^";_
           "²²²²²²²²²²²²²²²²²²²²";_
           "ééà[ZYXèénopqrstàèàà";_
           "ééà\ àèà m $à  u àéé";_
           "éà ] éijkl àéà v ééé";_
           "àà aà h é  é¤_ wxyz/";_
           "éà bé gè -àéàèà  àéà";_
           "éé cdef  àéà àééàééé";_
           "éàà  à%ààéééààéééééà";_
           "éééàééééééééà àéééàà"
    goto [loaded]
    [map8]
    map$ = "éééééé-àéé&ééé/ééééé";_
           "ééàéééà àéAéèyz éééé";_
           "éè SRQPé  Bééx   àéé";_
           "éà T  O àéC éwééà éé";_
           "éà U éNàééD  vutsééé";_
           "éé V  M àéEéà  éràéé";_
           "ééàWé Lé  Fééà  q éé";_
           "éééX  KJIHG$à  ép éé";_
           "éé Yè àéà  è    oééé";_
           "ééèZ  ééé èijklmn¤éé";_
           "éà [  àéà  h éè   àé";_
           "ééé\]abcdefgàéé_éààé";_
           "éà  àé%éé  ééééà  àé";_
           "éééàéééééééééééééàéé"
    goto [loaded]
    [map9]
    map$ = "µµµµµ}èééW&ééé§µµµµµ";_
           "µµµµµ}éàèVA èé§µµµµµ";_
           "µµµµµ}é àUB  é§µµµµµ";_
           "µµµµµ}àà TC éé§µµµµµ";_
           "µµµµµ}é  SD  é§µµµµµ";_
           "µµµµµ}éà REè à§µµµµµ";_
           "µµµµµ}é  QF  é§µµµµµ";_
           "µµµµµ}à èPG  $§µµµµµ";_
           "µµµµµ}é  OH  à§µµµµµ";_
           "µµµµµ}àà NI à_§µµµµµ";_
           "µµµµµ}-é MJ éè§µµµµµ";_
           "µµµµµ}éééLKéàé§µµµµµ";_
           "µµµµµ}é% é   é§µµµµµ";_
           "µµµµµµ^^^^^^^^µµµµµµ"
    goto [loaded]
    [map10]
    map$ = "éééé/àéééééààééééééé";_
           "ééééz  àéé    ééééàé";_
           "éééàyèà èéééààéàèèàà";_
           "éàà xw  àèà GFEDCBA&";_
           "éèè  v  àèà H      à";_
           "éà stu éàèè I èà  àé";_
           "àà r èéèàèà JKLMN àé";_
           "^^^q^£ éàèà$èà  O éé";_
           "µµµpµ} -à_é TSRQP àé";_
           "²²²o²ç àèà  U  àèèèé";_
           "éà n àèèèà  VWXYZàèé";_
           "éé m  à àèè     [ éé";_
           "éèàlkjihgfedcba]\ààé";_
           "ééééàà%ééàéèèèèéààéé"
    goto [loaded]
    [map11]
    map$ = "²²²²²²²çàéééà à/éééé";_
           "&ABCDEFGHIJKL  zyxéé";_
           "èéà  à  à  èMé  àééà";_
           "éé  à  àéé  N    é  ";_
           "à hijklmné$àOèà àééé";_
           "éàg  é  oà  P àééàéé";_
           "à f èéà p  éQà  àééà";_
           "_ e àé  qéà R éééà  ";_
           "é d  utsr   S  é ééà";_
           "ééc ééà    àT é wvéé";_
           "à ba]\[ZYXWVUè à àéé";_
           "éà  ààééàààéà  àé-¤é";_
           "ééèàéééé%àééééàééààé";_
           "éééééééééééééééééééà"
    goto [loaded]
    [map12]
    map$ = "éééèèéààéààééééèè§µµ";_
           "éééààèééé¤éééèàéè§µµ";_
           "éé$éàà%ééà-àà_àéé§µµ";_
           "ééà    àà      àà§µµ";_
           "èàhgfedcba]\[Z  à§µµ";_
           "éàié    éà   Yà è§µµ";_
           "é j  HGFEDC éX àè§µµ";_
           "é kà I èà BàéW   §µµ";_
           "à lè J éè&A éVé à§µµ";_
           "à m éKé  à   Uéà §µµ";_
           "é n  LMNOPQRSTé  §µµ";_
           "é oé     àà éé à §µµ";_
           "éépqrstuvwxyzàéé §µµ";_
           "ééééà àééééé/éééé§µµ"

' case "¢","^","£","§","µ","}","{","²","ç","~","","¤"


  '  map$ = "ééééééééééééééééééééééééééééééé";_     90 posibilités de marche
  '         "é                             é";_     if v>=36 and v<=126 then index = v-36 : pathX(index)=x : pathY(index)=y
  '         "é    $%&'()*+,-./01234567     é";_
  '         "é                       8     é";_
  '         "é  hijklmnopqrstuvwxy   9     é";_
  '         "é  g                z   :     é";_
  '         "é  f                {   ;     é";_
  '         "é  e                |   <     é";_
  '         "é  d                }   =     é";_
  '         "é  c                ~   >     é";_
  '         "é  b                    ?     é";_
  '         "é  a                    @     é";_
  '         "é  `                    A     é";_
  '         "é  _                    B     é";_
  '         "é  ^                    C     é";_
  '         "é  ]                    D     é";_
  '         "é  \                    E     é";_
  '         "é  [ZYXWVUTSRQPONMLKJIHGF     é";_
  '         "é                             é";_
  '         "ééééééééééééééééééééééééééééééé"


    [loaded]
    if about = 1 then close #about : about = 0
    mapCHOICEinGAME = mapCHOICE
    GameActivation = 1 : WindowWidth=817 : WindowHeight=640 : UpperLeftX=int((DisplayWidth-WindowWidth)/2) : UpperLeftY=int((DisplayHeight-WindowHeight)/2)
    global map$, pause, lvlARM, lastWave, lastWave2, bossKILLED, SELLmode, infoTOWERx, infoTOWERy, infoTOWERgold, fermage, forge, lvlGOLD, viseur, drapeau, towerLVLinfo
    if lastWave = 0 then lastWave = 1 : lastWave2 = 0 : bossKILLED = 0 : SELLmode = 0 : infoTOWERgold = 0

    dim pathX(73) : dim pathY(73)
    for x = 1 to 20
        for y = 1 to 14
            v = asc(mid$(map$, x+(y-1)*20, 1))
            if v>=47 and v<=64 then index=v-46+55 : pathX(index)=x : pathY(index)=y '3
            if v>=65 and v<=93 then index=v-64 : pathX(index)=x : pathY(index)=y '1
            if v>=97 and v<=122 then index=v-96+29 : pathX(index)=x : pathY(index)=y '2
        next y
    next x

    sprites$ = "bat4 bat4b bat3 bat3b flamme1a flamme1b flamme1c forge forge2 ferme ferme2 emplacement emplacement2 emplacement3 emplacement4 emplacement5 emplacement6 emplacement7 emplacement8 pause play sell tp1 tp2 tp3 king towerAa towerBb waveINFO boss arbre arbre2 rocher grass road roadB road2 road2B road3 road4 road5 road6 door1 door2 door3 door4 trou trou2 trou3 trou4 creep creep2 creepB creepC creepC2 creepC3 creepC4 towerA towerB towerC towerD towerE towerF towerG towerH towerI towerJ towerK towerL towerM towerN towerO towerP towerQ towerR towerS towerT bullet eau1 eau2 eau3 eau4 eau5 eau6 eau7 eau8 eau9 eau10 eau11 eau12"
    for s = 1 to 90
        loadbmp word$(sprites$,s), "data\"+word$(sprites$,s)+".bmp"
    next

    bmpbutton #td.b7, "data\pause.bmp", [pause], UL, 43,14
    bmpbutton #td.b6, "data\vie.bmp", [w], UL, 210,13
    bmpbutton #td.b4, "data\sons.bmp", [bruitage], UL, 740,13
    bmpbutton #td.b9, "data\sons2.bmp", [bruitage], UL, 740,13
    bmpbutton #td.b5, "data\aide.bmp", [RESET], UL, 770,13
    bmpbutton #td.b10, "data\argent.bmp", [w], UL, 270,13
    bmpbutton #td.x1, "data\x1.bmp", [vitesse], UL, 15,14
    bmpbutton #td.x2, "data\x2.bmp", [vitesse], UL, 15,14
    bmpbutton #td.x3, "data\x3.bmp", [vitesse], UL, 15,14
    bmpbutton #td.x4, "data\x4.bmp", [vitesse], UL, 15,14
    bmpbutton #td.x5, "data\x5.bmp", [vitesse], UL, 15,14
    bmpbutton #td.b2, "data\fr.bmp", [fr2], UL, 680,14
    bmpbutton #td.b3, "data\eng.bmp", [eng2], UL, 710,14
    graphicbox #td.main, 6, 45, 800, 562
    graphicbox #td.main2, 6, 5, 800, 40
    open "TD Re-Evolution ®" for window_nf as #td
    #td "trapclose [quit]"
    #td.main "down"

    handle = hwnd(#td)
    hTip=CreateTooltip(handle)
    if version = 1 then
        Call AddToolTip Hwnd(#td.b2), hTip , "Met la langue du jeu en français."
        Call AddToolTip Hwnd(#td.b3), hTip , "Met la langue du jeu en anglais."
        Call AddToolTip Hwnd(#td.b4), hTip , "Active ou désactive les bruitages en jeu."
        Call AddToolTip Hwnd(#td.b5), hTip , "Menu du jeu"
        Call AddToolTip Hwnd(#td.b6), hTip , "Vie(s) restante(s)"
        Call AddToolTip Hwnd(#td.b7), hTip , "Mettre le jeu en pause, cliquez une seconde fois pour relancer le jeu"
        Call AddToolTip Hwnd(#td.b10), hTip , "Représente votre stock d'or."
        Call AddToolTip Hwnd(#td.x1), hTip , "vitesse du jeu : 1"
        Call AddToolTip Hwnd(#td.x2), hTip , "vitesse du jeu : 2"
        Call AddToolTip Hwnd(#td.x3), hTip , "vitesse du jeu : 3"
        Call AddToolTip Hwnd(#td.x4), hTip , "vitesse du jeu : 4"
        Call AddToolTip Hwnd(#td.x5), hTip , "vitesse du jeu : dépend de votre pc ;)"
    end if
    if version = 2 then
        Call AddToolTip Hwnd(#td.b2), hTip , "Set the game language to French."
        Call AddToolTip Hwnd(#td.b3), hTip , "Set the game language to English."
        Call AddToolTip Hwnd(#td.b4), hTip , "Enable or disable sound effects in the game."
        Call AddToolTip Hwnd(#td.b5), hTip , "Game's menu"
        Call AddToolTip Hwnd(#td.b6), hTip , "Represents your remaining life."
        Call AddToolTip Hwnd(#td.b7), hTip , "Pause the game, click a second time to restart the game"
        Call AddToolTip Hwnd(#td.b10), hTip , "Represents your gold stock."
        Call AddToolTip Hwnd(#td.x1), hTip , "game speed : 1"
        Call AddToolTip Hwnd(#td.x2), hTip , "game speed : 2"
        Call AddToolTip Hwnd(#td.x3), hTip , "game speed : 3"
        Call AddToolTip Hwnd(#td.x4), hTip , "game speed : 4"
        Call AddToolTip Hwnd(#td.x5), hTip , "game speed : depends on your pc ;)"
    end if

    global maxTowers, towerGold, UPGRADE, dialBOSS, play, txt1$, txt2$, txt3$, towerRemoove$, RemooveX, RemooveY, remoovable
    maxTowers = 1000 : towerGold = 5 : UPGRADE = 0 : dialBOSS = 0
    if version = 1 then txt1$ = "Attaque : " :txt2$ = "Portée : " : txt3$ = "Vitèsse : "
    if version = 2 then txt1$ = "Attack : " :txt2$ = "Range : " : txt3$ = "Speed : "
    dim towerX(maxTowers), towerY(maxTowers), towerSpeed(maxTowers), towerRange(maxTowers), towerDamage(maxTowers), towerTime(maxTowers), bulletX(maxTowers), bulletY(maxTowers), towerLVL(maxTowers)

    for x = 1 to 20
        for y = 1 to 14
            char$ = mid$(map$, x+(y-1)*20, 1)
            #td.main "place ";(x-1)*40;" ";(y-1)*40
            select case char$
                case " ","ì","í","î","ô","õ","ö","÷","ø","ù","ú","û","ü","ý","þ","ÿ","ñ","ò","¶","ß","©"
                    #td.main "drawbmp grass"
                case "¢"
                    #td.main "drawbmp eau1"
                case "^"
                    #td.main "drawbmp eau2"
                case "£"
                    #td.main "drawbmp eau3"
                case "§"
                    #td.main "drawbmp eau4"
                case "µ"
                    #td.main "drawbmp eau5"
                case "}"
                    #td.main "drawbmp eau6"
                case "{"
                    #td.main "drawbmp eau7"
                case "²"
                    #td.main "drawbmp eau8"
                case "ç"
                    #td.main "drawbmp eau9"
                case "~"
                    #td.main "drawbmp eau10"
                case ""
                    #td.main "drawbmp eau11"
                case "¤"
                    #td.main "drawbmp eau12"
                case "é"
                    #td.main "drawbmp arbre"
                case "à"
                    #td.main "drawbmp arbre2"
                case "è"
                    #td.main "drawbmp rocher"
                case "-"
                    if fermage = 1 then #td.main "drawbmp ferme2"
                case "_"
                    if forge = 1 then #td.main "drawbmp forge2"
                case "$"
                    if viseur = 1 then #td.main "drawbmp bat3b"
                case "%"
                    if drapeau = 1 then #td.main "drawbmp bat4b"
                end select
            if mapCHOICE = 1 then
                #td.main "addsprite flamme flamme1a flamme1a flamme1b flamme1b flamme1c flamme1c flamme1c; spriteXY flamme 252 132 ;spritevisible flamme on"
                if fermage = 0 then #td.main "addsprite emplacement1 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement1 200 240 ;spritevisible emplacement1 on"
                if forge = 0 then #td.main "addsprite emplacement2 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement2 680 280 ;spritevisible emplacement2 on"
                if viseur = 0 then #td.main "addsprite emplacement3 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement3 480 320 ;spritevisible emplacement3 on"
                if drapeau = 0 then #td.main "addsprite emplacement4 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement4 80 480 ;spritevisible emplacement4 on"
                select case char$
                case "J","K","L","M","N","O","P","W","b","k","v","w","x"
                    #td.main "drawbmp road"
                case "A","B","C","D","E","F","G","H","R","S","T","U","Y","Z","[","\","]","d","e","f","g","h","i","m","n","o","p","q","r","s","t","z"
                    #td.main "drawbmp road2"
                case "c","u"
                    #td.main "drawbmp road3"
                case "I","X","l"
                    #td.main "drawbmp road4"
                case "Q","j","y"
                    #td.main "drawbmp road5"
                case "V","a"
                    #td.main "drawbmp road6"
                case "/"
                    #td.main "drawbmp door2"
                case "&"
                    #td.main "drawbmp trou"
                end select
            end if
            if mapCHOICE = 2 then
                #td.main "addsprite flamme flamme1a flamme1a flamme1b flamme1b flamme1c flamme1c flamme1c; spriteXY flamme 533 453 ;spritevisible flamme on"
                if fermage = 0 then #td.main "addsprite emplacement1 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement1 40 280 ;spritevisible emplacement1 on"
                if forge = 0 then #td.main "addsprite emplacement2 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement2 440 200 ;spritevisible emplacement2 on"
                if viseur = 0 then #td.main "addsprite emplacement3 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement3 440 280 ;spritevisible emplacement3 on"
                if drapeau = 0 then #td.main "addsprite emplacement4 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement4 240 480 ;spritevisible emplacement4 on"
                select case char$
                case "E","M","N","O","P","Q","R","c","d","l","r","s","t"
                    #td.main "drawbmp road"
                case "A","B","C","G","H","I","J","K","T","U","V","W","X","Y","Z","[","\","]","a","f","g","h","i","j","n","o","p","v","w","x"
                    #td.main "drawbmp road2"
                case "F","b","q"
                    #td.main "drawbmp road3"
                case "S","k","z"
                    #td.main "drawbmp road4"
                case "L","m","u"
                    #td.main "drawbmp road5"
                case "D","e","y"
                    #td.main "drawbmp road6"
                case "/"
                    #td.main "drawbmp door2"
                case "&"
                    #td.main "drawbmp trou2"
                end select
            end if
            if mapCHOICE = 3 then
                #td.main "addsprite flamme flamme1a flamme1a flamme1b flamme1b flamme1c flamme1c flamme1c; spriteXY flamme 12 252 ;spritevisible flamme on"
                if fermage = 0 then #td.main "addsprite emplacement1 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement1 560 40 ;spritevisible emplacement1 on"
                if forge = 0 then #td.main "addsprite emplacement2 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement2 680 40 ;spritevisible emplacement2 on"
                if viseur = 0 then #td.main "addsprite emplacement3 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement3 200 480  ;spritevisible emplacement3 on"
                if drapeau = 0 then #td.main "addsprite emplacement4 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement4 680 320 ;spritevisible emplacement4 on"
                select case char$
                case "K","L","U","e","f","g","h","i","j","w","z"
                    #td.main "drawbmp road"
                case "A","B","C","D","E","F","G","H","I","N","O","P","Q","R","S","W","X","Y","Z","[","\","]","a","b","c","l","m","n","o","p","q","r","s","t","u"
                    #td.main "drawbmp road2"
                case "T","x"
                    #td.main "drawbmp road3"
                case "J","k"
                    #td.main "drawbmp road4"
                case "M","d","y"
                    #td.main "drawbmp road5"
                case "V","v"
                    #td.main "drawbmp road6"
                case "/"
                    #td.main "drawbmp door4"
                case "&"
                    #td.main "drawbmp trou"
                end select
            end if
            if mapCHOICE = 4 then
                #td.main "addsprite flamme flamme1a flamme1a flamme1b flamme1b flamme1c flamme1c flamme1c; spriteXY flamme 652 172 ;spritevisible flamme on"
                if fermage = 0 then #td.main "addsprite emplacement1 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement1 520 200 ;spritevisible emplacement1 on"
                if forge = 0 then #td.main "addsprite emplacement2 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement2 560 400 ;spritevisible emplacement2 on"
                if viseur = 0 then #td.main "addsprite emplacement3 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement3 40 280 ;spritevisible emplacement3 on"
                if drapeau = 0 then #td.main "addsprite emplacement4 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement4 240 480 ;spritevisible emplacement4 on"
                select case char$
                case "J","K","L","T","z"
                    #td.main "drawbmp road"
                case "A","B","E","F","G","H","N","O","P","Q","R","V","[","\","]","a","b","c","f","g","h","k","p","q","r","u","v","w","x"
                    #td.main "drawbmp road2"
                case "I","Y"
                    #td.main "drawbmp road3"
                case "S","m"
                    #td.main "drawbmp road4"
                case "U"
                    #td.main "drawbmp road5"
                case "M","Z","l","y"
                    #td.main "drawbmp road6"
                case "D","X","e","j","t","o"
                    #td.main "drawbmp tp1"
                case "C","W","e","i","n","s"
                    #td.main "drawbmp tp2"
                case "d"
                    #td.main "drawbmp tp3"
                case "/"
                    #td.main "drawbmp door4"
                case "&"
                    #td.main "drawbmp trou2"
                end select
            end if
            if mapCHOICE = 5 then
                #td.main "addsprite flamme flamme1a flamme1a flamme1b flamme1b flamme1c flamme1c flamme1c; spriteXY flamme 370 172 ;spritevisible flamme on"
                if fermage = 0 then #td.main "addsprite emplacement1 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement1 80 40 ;spritevisible emplacement1 on"
                if forge = 0 then #td.main "addsprite emplacement2 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement2 360 280 ;spritevisible emplacement2 on"
                if viseur = 0 then #td.main "addsprite emplacement3 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement3 440 280 ;spritevisible emplacement3 on"
                if drapeau = 0 then #td.main "addsprite emplacement4 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement4 240 480 ;spritevisible emplacement4 on"
                select case char$
                case "E","F","Q","R","S","T","U","V","W","X","i","o","v","w","x","y","z"
                    #td.main "drawbmp road"
                case "A","B","C","H","I","J","K","L","M","N","O","Z","[","\","]","a","b","c","d","e","f","g","k","l","m","q","r","s","t"
                    #td.main "drawbmp road2"
                case "P","p"
                    #td.main "drawbmp road3"
                case "G","j"
                    #td.main "drawbmp road4"
                case "D","h","u"
                    #td.main "drawbmp road5"
                case "Y","n"
                    #td.main "drawbmp road6"
                case "/"
                    #td.main "drawbmp door4"
                case "&"
                    #td.main "drawbmp trou"
                end select
            end if
            if mapCHOICE = 6 then
                #td.main "addsprite flamme flamme1a flamme1a flamme1b flamme1b flamme1c flamme1c flamme1c; spriteXY flamme 212 412 ;spritevisible flamme on"
                if fermage = 0 then #td.main "addsprite emplacement1 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement1 40 440 ;spritevisible emplacement1 on"
                if forge = 0 then #td.main "addsprite emplacement2 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement2 720 160 ;spritevisible emplacement2 on"
                if viseur = 0 then #td.main "addsprite emplacement3 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement3 720 280 ;spritevisible emplacement3 on"
                if drapeau = 0 then #td.main "addsprite emplacement4 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement4 240 480 ;spritevisible emplacement4 on"
                select case char$
                case "A","B","C","D","M","X","i","j","k","l","m","n","o","p","q","z"
                    #td.main "drawbmp road"
                case "F","G","H","I","J","K","O","P","Q","R","S","T","U","V","Z","a","b","c","d","e","f","g","i","j","s","[","\","]","t","u","v","w","x"
                    #td.main "drawbmp road2"
                case "E","Y","y"
                    #td.main "drawbmp road3"
                case "N","h"
                    #td.main "drawbmp road4"
                case "L","r"
                    #td.main "drawbmp road5"
                case "W"
                    #td.main "drawbmp road6"
                case "/"
                    #td.main "drawbmp door4"
                case "&"
                    #td.main "drawbmp trou4"
                end select
            end if
            if mapCHOICE = 7 then
                #td.main "addsprite flamme flamme1a flamme1a flamme1b flamme1b flamme1c flamme1c flamme1c; spriteXY flamme 93 133 ;spritevisible flamme on"
                if fermage = 0 then #td.main "addsprite emplacement1 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement1 360 400 ;spritevisible emplacement1 on"
                if forge = 0 then #td.main "addsprite emplacement2 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement2 520 360 ;spritevisible emplacement2 on"
                if viseur = 0 then #td.main "addsprite emplacement3 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement3 440 280 ;spritevisible emplacement3 on"
                if drapeau = 0 then #td.main "addsprite emplacement4 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement4 240 480 ;spritevisible emplacement4 on"
                select case char$
                case "E","Q","\","]","a","b","g","h","m","u","v"
                    #td.main "drawbmp road"
                case "A","B","C","G","H","I","J","K","L","M","N","O","S","T","U","V","Y","Z","d","e","j","k","o","p","q","r","s","y","z","x"
                    #td.main "drawbmp road2"
                case "F","[","i","n"
                    #td.main "drawbmp road3"
                case "t","P"
                    #td.main "drawbmp road4"
                case "D","R","f","l"
                    #td.main "drawbmp road5"
                case "c","w"
                    #td.main "drawbmp road6"
                case "/"
                    #td.main "drawbmp door3"
                case "&"
                    #td.main "drawbmp trou"
                case "X"
                    #td.main "drawbmp tp1"
                case "W"
                    #td.main "drawbmp tp2"
                end select
            end if
            if mapCHOICE = 8 then
                #td.main "addsprite flamme flamme1a flamme1a flamme1b flamme1b flamme1c flamme1c flamme1c; spriteXY flamme 412 12 ;spritevisible flamme on"
                if fermage = 0 then #td.main "addsprite emplacement1 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement1 240 0 ;spritevisible emplacement1 on"
                if forge = 0 then #td.main "addsprite emplacement2 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement2 600 440 ;spritevisible emplacement2 on"
                if viseur = 0 then #td.main "addsprite emplacement3 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement3 440 280 ;spritevisible emplacement3 on"
                if drapeau = 0 then #td.main "addsprite emplacement4 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement4 240 480 ;spritevisible emplacement4 on"
                select case char$
                case "A","B","C","D","E","F","L","M","N","O","T","U","V","W","X","Y","Z","[","h","o","p","q","r","w","x"
                    #td.main "drawbmp road"
                case "H","I","J","Q","R","]","a","b","c","d","e","f","j","k","l","m","t","u"
                    #td.main "drawbmp road2"
                case "S","i","y"
                    #td.main "drawbmp road3"
                case "P","s"
                    #td.main "drawbmp road4"
                case "G","n","g","z"
                    #td.main "drawbmp road5"
                case "\","K","v"
                    #td.main "drawbmp road6"
                case "/"
                    #td.main "drawbmp door4"
                case "&"
                    #td.main "drawbmp trou3"
                end select
            end if
            if mapCHOICE = 9 then
                #td.main "addsprite flamme flamme1a flamme1a flamme1b flamme1b flamme1c flamme1c flamme1c; spriteXY flamme 412 12 ;spritevisible flamme on"
                if fermage = 0 then #td.main "addsprite emplacement1 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement1 240 400 ;spritevisible emplacement1 on"
                if forge = 0 then #td.main "addsprite emplacement2 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement2 520 360 ;spritevisible emplacement2 on"
                if viseur = 0 then #td.main "addsprite emplacement3 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement3 520 280 ;spritevisible emplacement3 on"
                if drapeau = 0 then #td.main "addsprite emplacement4 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement4 280 480 ;spritevisible emplacement4 on"
                select case char$
                case "A","B","C","D","E","F","G","H","I","J","M","N","O","P","Q","R","S","T","U","V"
                    #td.main "drawbmp road"
                case "K"
                    #td.main "drawbmp road5"
                case "L"
                    #td.main "drawbmp road6"
                case "W"
                    #td.main "drawbmp door4"
                case "&"
                    #td.main "drawbmp trou3"
                end select
            end if
            if mapCHOICE = 10 then
                #td.main "addsprite flamme flamme1a flamme1a flamme1b flamme1b flamme1c flamme1c flamme1c; spriteXY flamme 771 132 ;spritevisible flamme on"
                if fermage = 0 then #td.main "addsprite emplacement1 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement1 280 320 ;spritevisible emplacement1 on"
                if forge = 0 then #td.main "addsprite emplacement2 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement2 360 320 ;spritevisible emplacement2 on"
                if viseur = 0 then #td.main "addsprite emplacement3 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement3 440 280 ;spritevisible emplacement3 on"
                if drapeau = 0 then #td.main "addsprite emplacement4 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement4 240 520 ;spritevisible emplacement4 on"
                select case char$
                case "H","I","O","U","[","m","n","r","v","y","z"
                    #td.main "drawbmp road"
                case "o","p","q"
                    #td.main "drawbmp roadB"
                case "A","B","C","D","E","F","K","L","M","Q","R","S","W","X","Y","]","a","b","c","d","e","f","g","h","i","j","k","t"
                    #td.main "drawbmp road2"
                case "G","T","s"
                    #td.main "drawbmp road3"
                case "N","Z","w"
                    #td.main "drawbmp road4"
                case "P","\","u"
                    #td.main "drawbmp road5"
                case "J","V","l","x"
                    #td.main "drawbmp road6"
                case "/"
                    #td.main "drawbmp door4"
                case "&"
                    #td.main "drawbmp trou2"
                end select
            end if
            if mapCHOICE = 11 then
                #td.main "addsprite flamme flamme1a flamme1a flamme1b flamme1b flamme1c flamme1c flamme1c; spriteXY flamme 12 53 ;spritevisible flamme on"
                if fermage = 0 then #td.main "addsprite emplacement1 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement1 680 440 ;spritevisible emplacement1 on"
                if forge = 0 then #td.main "addsprite emplacement2 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement2 0 280 ;spritevisible emplacement2 on"
                if viseur = 0 then #td.main "addsprite emplacement3 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement3 400 160 ;spritevisible emplacement3 on"
                if drapeau = 0 then #td.main "addsprite emplacement4 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement4 320 480 ;spritevisible emplacement4 on"
                select case char$
                case "M","N","O","P","Q","R","S","T","c","d","e","f","g","o","p","q"
                    #td.main "drawbmp road"
                case "A","B","C","D","E","F","G","H","I","J","K","V","W","X","Y","Z","[","\","]","a","i","j","k","l","m","s","t","y"
                    #td.main "drawbmp road2"
                case "h"
                    #td.main "drawbmp road3"
                case "L","n"
                    #td.main "drawbmp road4"
                case "U","r"
                    #td.main "drawbmp road5"
                case "b","z"
                    #td.main "drawbmp road6"
                case "v","x"
                    #td.main "drawbmp tp1"
                case "u","w"
                    #td.main "drawbmp tp2"
                case "/"
                    #td.main "drawbmp door4"
                case "&"
                    #td.main "drawbmp trou"
                end select
            end if
            if mapCHOICE = 12 then
                #td.main "addsprite flamme flamme1a flamme1a flamme1b flamme1b flamme1c flamme1c flamme1c; spriteXY flamme 371 332 ;spritevisible flamme on"
                if fermage = 0 then #td.main "addsprite emplacement1 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement1 400 80 ;spritevisible emplacement1 on"
                if forge = 0 then #td.main "addsprite emplacement2 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement2 520 80 ;spritevisible emplacement2 on"
                if viseur = 0 then #td.main "addsprite emplacement3 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement3 80 80 ;spritevisible emplacement3 on"
                if drapeau = 0 then #td.main "addsprite emplacement4 emplacement emplacement emplacement2 emplacement2 emplacement3 emplacement3 emplacement4 emplacement4 emplacement5 emplacement5 emplacement6 emplacement6 emplacement7 emplacement7 emplacement8 emplacement8; spriteXY emplacement4 240 80 ;spritevisible emplacement4 on"
                select case char$
                case "B","I","J","K","U","V","W","X","Y","i","j","k","l","m","n","o"
                    #td.main "drawbmp road"
                case "D","E","F","G","M","N","O","P","Q","R","S","[","\","]","a","b","c","d","e","f","g","q","r","s","t","u","v","w","x","y"
                    #td.main "drawbmp road2"
                case "H","h"
                    #td.main "drawbmp road3"
                case "C","Z","z"
                    #td.main "drawbmp road4"
                case "A","T"
                    #td.main "drawbmp road5"
                case "L","p"
                    #td.main "drawbmp road6"
                case "/"
                    #td.main "drawbmp door1"
                case "&"
                    #td.main "drawbmp trou"
                end select
            end if
        next y
    next x

    call RemooveOldTower x, y
    #td.main "getbmp background 0 0 800, 562; background background"
    #td.main "drawsprites"
    print #td.x2, "hide"
    print #td.x3, "hide"
    print #td.x4, "hide"
    print #td.x5, "hide"
    if bruitage = 1 then print #td.b9, "hide"
    if bruitage = 0 then print #td.b4, "hide"
    print #td.x1, "show"

    f$ = chr$(34) + "data\laser.wav" + chr$(34)
    r$ = mcisend$("open " + f$ + " type waveaudio alias laser")

    [nextLevel]
    global eliteWave, play, version, bruitage
    if (Nvague = 50 or Nvague = 100 or Nvague = 150 or Nvague = 200 or Nvague = 250 or Nvague = 300 or Nvague = 350 or Nvague = 400 or Nvague = 450 or Nvague = 500) then compteurBOSS = 5 : compteurSUPERboss = 15 : eliteWave = 1
    nocheat = 1 : switchSPRITES = 0 : SELLmode = 0
    vitesseSprite = int(rnd(1)*(30)+15)
    if Nvague <= 10 then vitesseSprite = 15
    if Nvague <15 and vitesseSprite >25 then vitesseSprite =25

    if version = 1 then
        if vitesseSprite <=15 then vitesse$ = "Normale"
        if vitesseSprite >15 and vitesseSprite <=30 then vitesse$ = "Rapide"
        if vitesseSprite >30 then vitesse$ = "Très Rapide"
    end if

    if version = 2 then
        if vitesseSprite <=15 then vitesse$ = "Normal"
        if vitesseSprite >15 and vitesseSprite <=30 then vitesse$ = "Fast"
        if vitesseSprite >30 then vitesse$ = "Very fast"
    end if

    #td.main "when leftButtonDown NOclick; when rightButtonDown NOclick2"
    #td.main "drawbmp waveINFO 215 170"
    #td.main "font Cascadia_Code 16 bold"

    if compteurSUPERboss = 0 then EVEN = 1

    select case EVEN
        case 0
            if version = 1 then
                #td.main "place 325 225 ;\"; "Vague N° ";Nvague
                #td.main "font Cascadia_Code 10; color black"
                if eliteWave = 0 then #td.main "place 310 260 ;\"; "Nombre ennemis : ";40;"\Pv ennemis : ";int(5*Nvague);" - ";int(13*Nvague);"    \Vitesse : ";vitesse$ ;"   "
                if eliteWave > 0 then #td.main "place 310 260 ;\"; "Nombre ennemis : ";40;"\  Pv ennemis : ";int(22*Nvague);"     \Vitesse : Normale      "
                if lastWave2 = lastWave then #td.main "font Cascadia_Code 9 underscore; color red" : #td.main "place 290 330 ;\"; "Pas d'or pendant cette vague !"
                if lastWave2 <> lastWave then #td.main "font Cascadia_Code 9 bold; color darkgreen" : #td.main "place 290 330 ;\"; "Récompense : ";int(1+(Nvague/80)+1);" - ";int(1+(Nvague/15)+1);"$ / ennemis"
            end if
            if version = 2 then
                #td.main "place 330 225 ;\"; "Wave N° ";Nvague
                #td.main "font Cascadia_Code 10; color black"
                if eliteWave = 0 then #td.main "place 300 260 ;\"; "Ennemies Number : ";40;"\Ennemies HP : ";int(5*Nvague);" - ";int(13*Nvague);"   \Ennemies Speed : ";vitesse$ ;"   "
                if eliteWave > 0 then #td.main "place 300 260 ;\"; "Ennemies Number : ";40;"\  Ennemies HP : ";int(22*Nvague);"     \Ennemies Speed : Normal      "
                if lastWave2 = lastWave then #td.main "font Cascadia_Code 9 underscore; color red" : #td.main "place 300 330 ;\"; "No gold during this wave !"
                if lastWave2 <> lastWave then #td.main "font Cascadia_Code 9 bold; color darkgreen" : #td.main "place 310 330 ;\"; "Reward : ";int(1+(Nvague/80)+1);"-";int(1+(Nvague/15)+1);"$ / enemies"
            end if
            UPGRADE = 0 : call RemooveOldTower x, y
            timer 2000, [next] : wait
        case 1
            #td.main "drawbmp king 240 215"
            #td.main "font Cascadia_Code 14"
            if version = 1 then
                if dialBOSS = 0 then #td.main "place 320 255 ;\"; "Alors, c'est toi \qui ose me défier ?!"
                if dialBOSS = 1 then #td.main "place 320 255 ;\"; "C'est encore moi !\Tu t'es endormi ?!"
                if dialBOSS = 2 then #td.main "place 320 255 ;\"; "Tu pense vraiment\me battre ? haha ?!"
                if dialBOSS = 3 then #td.main "place 320 255 ;\"; "T'es nul ! ZzzZzz\T'es encore la ?"
                if dialBOSS = 4 then #td.main "place 320 255 ;\"; "Je tourne en rond\avec toi ... XD !"
                if dialBOSS = 5 then #td.main "place 320 265 ;\"; "Fait un effort !!! "
                if dialBOSS >= 6 then #td.main "place 320 255 ;\"; "Et c'est reparti \pour un tour !"
                #td.main "font Cascadia_Code 8 italic; color black"
                #td.main "place 300 335 ;\"; " - Tuez le Boss pour gagner ! - "
            end if
            if version = 2 then
                if dialBOSS = 0 then #td.main "place 320 240 ;\"; "So, are you the one \who dares to \challenge me?!"
                if dialBOSS = 1 then #td.main "place 320 255 ;\"; "It's me again ! \You fell asleep ?!"
                if dialBOSS = 2 then #td.main "place 320 255 ;\"; "Do you really think \you'll beat me? haha?!"
                if dialBOSS = 3 then #td.main "place 320 255 ;\"; "You're useless ! \ZzzZzz\Are you still there?"
                if dialBOSS = 4 then #td.main "place 320 255 ;\"; "I'm going in circles\with you... XD!"
                if dialBOSS = 5 then #td.main "place 320 265 ;\"; "Make an effort !!! "
                if dialBOSS >= 6 then #td.main "place 320 255 ;\"; "And here we go again \for a ride!"
                #td.main "font Cascadia_Code 8 italic; color black"
                #td.main "place 305 335 ;\"; " - kill the Boss to win ! - "
            end if
            UPGRADE = 0 : call RemooveOldTower x, y
            timer 3500, [next] : wait
    end select


    [next]
    timer 0
    global creeps, maxCreeps, lastWave, lastWave2, vitesseSprite, TIMERBOUCLE, mapCHOICE, forgeActivation, shootTOWER
    maxCreeps = 80 : creeps = 80 : UPGRADE = 0 : forgeActivation = 0
    dim creepPosX(maxCreeps), creepPosY(maxCreeps), creepHealth(maxCreeps), creepSpeed(maxCreeps), creepTime(maxCreeps)

    for c = 1 to 40
        select case eliteWave
            case 0
                if c > 1 and switchSPRITES = 0 then switchSPRITES = 1 : #td.main "addsprite creep";c;" creepB; spriteXY creep";c;" ";-20;" ";-20;";spritevisible creep";c;" on" : creepHealth(c)= int(rnd(1)*(11*Nvague)+(5*Nvague)) : creepSpeed(c)=vitesseSprite : creepTime(c)=150*c : goto [switchSPRITES]
                if c > 1 and switchSPRITES = 1 then switchSPRITES = 0 : #td.main "addsprite creep";c;" creep; spriteXY creep";c;" ";-20;" ";-20;";spritevisible creep";c;" on" : creepHealth(c)= int(rnd(1)*(11*Nvague)+(5*Nvague)) : creepSpeed(c)=vitesseSprite : creepTime(c)=150*c : goto [switchSPRITES]
                if compteurBOSS > 0 and compteurSUPERboss > 0 then  #td.main "addsprite creep";c;" creepC creepC creepC creepC2 creepC2 creepC2 creepC3 creepC3 creepC3 creepC4 creepC4 creepC4; spriteXY creep";c;" ";-20;" ";-20;"; spritevisible creep";c;" on" : creepHealth(c)= int(rnd(1)*(40*Nvague)+(40*Nvague)) : creepSpeed(c)=vitesseSprite : creepTime(c)=150*c
                if c = 1 and compteurBOSS = 0 then #td.main "addsprite creep";c;" creep2; spriteXY creep";c;" ";-50;" ";-50;"; spritevisible creep";c;" on" : creepHealth(c)= int(131*Nvague) : creepSpeed(c)=vitesseSprite : creepTime(c)=150*c
                if c = 1 and compteurSUPERboss = 0 then #td.main "addsprite creep";c;" boss; spriteXY creep";c;" ";-150;" ";-150;"; spritevisible creep";c;" on" : creepHealth(c)= int(800*Nvague) : creepSpeed(c)=10 :  creepTime(c)=150*c
            case 1
                #td.main "addsprite creep";c;" creep2; spriteXY creep";c;" ";-50;" ";-50;";spritevisible creep";c;" on" : creepHealth(c)= int(60*Nvague) : creepSpeed(c)=15 : creepTime(c)=150*c
        end select
    [switchSPRITES]
    next c

    #td.main "addsprite sell sell; spriteXY sell ";-100;" ";-100
    #td.main "when leftButtonDown click"
    #td.main "when rightButtonDown click2"
    #td.main2 "down; fill white; font ink_free 8"

    ' supprime le backcolor pour texte transparent
        hGBox = hwnd(#td.main)
        CallDLL #user32, "GetDC",_
        hGBox As ulong,_  'handle of graphicbox
        gDC As ulong      'device context
        CallDLL #gdi32, "SetBkMode",_
        gDC As ulong,_          'handle of graphicbox
        _TRANSPARENT As long,_  'flag for transparent background 'OPAQUE
        result As long          'previous bkmode
        CallDLL#user32,"ReleaseDC",_
        hGBox As ulong,_    'graphicbox handle
        gDC As ulong,_      'device context
        result As long

    #td.main2 "flush"
    nocheat = 0

'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    [boucle]
    on error goto [ERRORnotif]
    scan
    #td.main "discard"
    call advanceCreeps

    #td.main "cyclesprite flamme 1 once"
    if fermage = 0 then #td.main "cyclesprite emplacement1 1 once"
    if forge = 0 then #td.main "cyclesprite emplacement2 1 once"
    if viseur = 0 then #td.main "cyclesprite emplacement3 1 once"
    if drapeau = 0 then #td.main "cyclesprite emplacement4 1 once"
    if creepHealth(1) <0 then creepHealth(1) = 0

    select case version
        case 1
            #td.main2 "font Cascadia_Code 8"
            #td.main2 "place 70 15 ;\"; "Vague : ";Nvague;" (";int(creeps-40);")      "
            if compteurBOSS > 0 and compteurSUPERboss > 0 then #td.main2 "place 70 30 ;\"; "Ennemis basiques       "
            if compteurBOSS = 0 then #td.main2 "place 70 30 ;\"; "ÉLITE : ";creepHealth(1);"           "
            if compteurSUPERboss = 0 then #td.main2 "place 70 30 ;\"; "BOSS : ";creepHealth(1);"            "
            #td.main2 "place 232 22 ;\"; life;"    "
            #td.main2 "place 293 22 ;\"; gold;"    "
        case 2
            #td.main2 "font Cascadia_Code 8"
            #td.main2 "place 70 15 ;\"; "Wave : ";Nvague;" (";int(creeps-40);")      "
            if compteurBOSS > 0 and compteurSUPERboss > 0 then #td.main2 "place 70 30 ;\"; "Basic enemies       "
            if compteurBOSS = 0 then #td.main2 "place 70 30 ;\"; "ELITE : ";creepHealth(1);"           "
            if compteurSUPERboss = 0 then #td.main2 "place 70 30 ;\"; "BOSS : ";creepHealth(1);"            "
            #td.main2 "place 232 22 ;\"; life;"    "
            #td.main2 "place 293 22 ;\"; gold;"    "

       end select

    select case bossKILLED
        case 1
            close #td
            dir$ = "" : file$ = "data.txt"
            if fileExist(dir$,file$) = 1 then kill "data.txt"
            pass$ = "1" : compteurBOSS = 4 : compteurSUPERboss = 14 : towers = 0 : lastWave = 1 : lastWave2 = 0 : bossKILLED = 0 : dialBOSS = 0 : lastWave = 1 : lastWave2 = 0 : loaded = 0
            Nvague = 1 : towers = 0 : life = 20 : gold = 40 : compteurBOSS = 4 : compteurSUPERboss = 14 : lvlARM = 0 : lvlGOLD = 0 : EVEN = 0 : fermage = 0 : forge = 0 : mapCHOICE = 1 : TIMERBOUCLE = 50
            call Sleep TIMERBOUCLE : goto [INITIAL]
    end select

    select case life
        case 0
        [cheater]
        close #td
        graphicbox #quit.main, 0, 0, 811, 611
        open "" for window_nf as #quit
        #quit, "trapclose [Noquit]"
        #quit.main "down; fill white; font Cascadia_Code 40 bold; color red"
        #quit.main "place 270 270 ;\"; "GAME OVER"
        #quit.main "font ink_free 10 italic bold; color black"
        if version = 1 then #quit.main "place 285 370 ;\"; "(Faudra mieux faire la prochaine fois)"
        if version = 2 then #quit.main "place 300 370 ;\"; "(Will have to do better next time)"
        #quit.main "flush"
        on error goto [remakeGAME1]
        dir$ = "" : file$ = "data.txt"
        if fileExist(dir$,file$) = 1 then kill "data.txt"
        timer 2000, [remakeGAME1] : wait
        [remakeGAME1]
        timer 0 : close #quit
        pass$ = "1" : compteurBOSS = 4 : compteurSUPERboss = 14 : towers = 0 : lastWave = 1 : lastWave2 = 0 : bossKILLED = 0 : dialBOSS = 0 : lastWave = 1 : lastWave2 = 0 : loaded = 0
        Nvague = 1 : towers = 0 : life = 20 : gold = 40 : compteurBOSS = 4 : compteurSUPERboss = 14 : lvlARM = 0 : lvlGOLD = 0 : EVEN = 0 : fermage = 0 : forge = 0 : mapCHOICE = 1 : TIMERBOUCLE = 50
        goto [INITIAL]
    end select

    select case int(creeps-40)
        case 0
            EVEN = 0
            Nvague = Nvague + 1 : lastWave2 = 0 : lastWave = Nvague
            if compteurSUPERboss = 0 then dialBOSS = dialBOSS + 1 : compteurSUPERboss = 15
            if eliteWave = 1 then eliteWave = 0
            gold = gold + 10 + lvlGOLD : compteurBOSS = compteurBOSS -1 : compteurSUPERboss = compteurSUPERboss - 1 : secuBOSS = 0
            if compteurBOSS <0 then compteurBOSS = 4
            if compteurSUPERboss = 0 then compteurBOSS =5 : EVEN = 1
            if (Nvague = 50 or Nvague = 100 or Nvague = 150 or Nvague = 200 or Nvague = 250 or Nvague = 300 or Nvague = 350 or Nvague = 400 or Nvague = 450 or Nvague = 500) then compteurBOSS = 5 : compteurSUPERboss = 15 : eliteWave = 1
            goto [nextLevel]
    end select

    #td.main "drawsprites"
    call Sleep TIMERBOUCLE : goto [boucle]

'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    [w]
    if nocheat = 1 or pause = 1 then wait
    goto [boucle]
    [Noquit]
    wait
    [ERRORnotif]
    call Sleep TIMERBOUCLE : goto [boucle]

    [fr2]
    if nocheat = 1 then wait
    version = 1
        Call AddToolTip Hwnd(#td.b2), hTip , "Met la langue du jeu en français."
        Call AddToolTip Hwnd(#td.b3), hTip , "Met la langue du jeu en anglais."
        Call AddToolTip Hwnd(#td.b4), hTip , "Active ou désactive les bruitages en jeu."
        Call AddToolTip Hwnd(#td.b5), hTip , "Menu du jeu"
        Call AddToolTip Hwnd(#td.b6), hTip , "Vie(s) restante(s)"
        Call AddToolTip Hwnd(#td.b7), hTip , "Mettre le jeu en pause, cliquez une seconde fois pour relancer le jeu"
        Call AddToolTip Hwnd(#td.b10), hTip , "Représente votre stock d'or."
        Call AddToolTip Hwnd(#td.x1), hTip , "vitesse du jeu : 1"
        Call AddToolTip Hwnd(#td.x2), hTip , "vitesse du jeu : 2"
        Call AddToolTip Hwnd(#td.x3), hTip , "vitesse du jeu : 3"
        Call AddToolTip Hwnd(#td.x4), hTip , "vitesse du jeu : 4"
        Call AddToolTip Hwnd(#td.x5), hTip , "vitesse du jeu : dépend de votre pc ;)"
        txt1$ = "Attaque : " :txt2$ = "Portée : " : txt3$ = "Vitèsse : "

    goto [boucle]
    [eng2]
    if nocheat = 1 then wait
    version = 2
        Call AddToolTip Hwnd(#td.b2), hTip , "Set the game language to French."
        Call AddToolTip Hwnd(#td.b3), hTip , "Set the game language to English."
        Call AddToolTip Hwnd(#td.b4), hTip , "Enable or disable sound effects in the game."
        Call AddToolTip Hwnd(#td.b5), hTip , "Game's menu"
        Call AddToolTip Hwnd(#td.b6), hTip , "Represents your remaining life."
        Call AddToolTip Hwnd(#td.b7), hTip , "Pause the game, click a second time to restart the game"
        Call AddToolTip Hwnd(#td.b10), hTip , "Represents your gold stock."
        Call AddToolTip Hwnd(#td.x1), hTip , "game speed : 1"
        Call AddToolTip Hwnd(#td.x2), hTip , "game speed : 2"
        Call AddToolTip Hwnd(#td.x3), hTip , "game speed : 3"
        Call AddToolTip Hwnd(#td.x4), hTip , "game speed : 4"
        Call AddToolTip Hwnd(#td.x5), hTip , "game speed : depends on your pc ;)"
        txt1$ = "Attack : " :txt2$ = "Range : " : txt3$ = "Speed : "
    goto [boucle]


    [vitesse]
    if nocheat = 1 or pause = 1 then wait
    if TIMERBOUCLE = 0 then TIMERBOUCLE = 50 : print #td.x5, "hide" : print #td.x1, "show" : goto [boucle]
    if TIMERBOUCLE = 13 then TIMERBOUCLE = 0 : bruitage = 0 : print #td.b9, "show" : print #td.b4, "hide" : print #td.x4, "hide" : print #td.x5, "show" : goto [boucle]
    if TIMERBOUCLE = 17 then TIMERBOUCLE = 13 : print #td.x3, "hide" : print #td.x4, "show" : goto [boucle]
    if TIMERBOUCLE = 25 then TIMERBOUCLE = 17 : print #td.x2, "hide" : print #td.x3, "show" : goto [boucle]
    if TIMERBOUCLE = 50 then TIMERBOUCLE = 25 : print #td.x1, "hide" : print #td.x2, "show" : goto [boucle]
    goto [boucle]


    [site]
    if nocheat = 1 then wait
    run "explorer.exe https://www.atomose.fr" : pause = 0 : goto [pause]

    [help]
    loadbmp "tuto", "data\tuto.bmp"
    if nocheat = 1 then wait
    if help = 1 then close #help
    help = 1
    pause = 1 : print #td.b7, "bitmap play"
    graphicbox #help.main,  0, 0, 731, 531
    open "" for window_nf as #help
    #help, "trapclose [help2]"
    #help.main "down; fill white; setfocus"
    #help.main "drawbmp tuto 140 150"
    if version = 1 then
        #help.main "font ink_free 20 bold"
        #help.main "place 40 50 ;\"; "MENU AIDE"
        #help.main "font Cascadia_Code 9"
        #help.main "place 270 130 ;\"; "Sens de marche des ennemis"
        #help.main "place 95 178 ;\"; "Point de départ \   des ennemis"
        #help.main "place 510 172 ;\"; "Point d'arrivé. Chaque \ennemi qui y passe \vous retire 1 vie."
        #help.main "place 70 260 ;\"; "Cliquez sur une zone d'herbe\ pour construire vos tours."
        #help.main "place 435 335 ;\"; "L'indicateur de niveau est a droite \de la tour !"
        #help.main "place 290 260 ;\"; "Pour evoluer vos tours, cliquez dessus une seconde fois. \Il faut avoir suffisamment d'argent pour que l'amelioration \soit faite."
        #help.main "place 115 480 ;\"; "Remarque : Un clic droit sur la tour vous donne ses caractéristiques !"
    end if
    if version = 2 then
        #help.main "font ink_free 20 bold"
        #help.main "place 40 50 ;\"; "HELP MENU"
        #help.main "font Cascadia_Code 9"
        #help.main "place 280 130 ;\"; "Direction of enemies"
        #help.main "place 70 178 ;\"; "Starting point of \enemies"
        #help.main "place 510 172 ;\"; "Arrival point. Each enemy \that passes through it \removes 1 life from you."
        #help.main "place 70 260 ;\"; "Click on a grass area to \build your towers."
        #help.main "place 435 335 ;\"; "The level indicator is to the right \of the tower!"
        #help.main "place 300 260 ;\"; "To upgrade your towers, click on it a second time. \You have to have the money requested for the \improvement to be made."
        #help.main "place 120 480 ;\"; "trick : A right click on the tower gives you its characteristics!"
    end if
    #td.main "flush" : #help.main "flush" : wait
    [help2]
    close #help : help = 0 : wait

    [pause]
    if nocheat = 1 then wait

    if pause = 1 then pause = 0 : print #td.b7, "setfocus" : print #td.b7, "bitmap pause" : goto [boucle]
    if pause = 0 then
        pause = 1 : print #td.b7, "setfocus" : print #td.b7, "bitmap play"
        ' supprime le backcolor pour texte transparent
        hGBox = hwnd(#td.main)
        CallDLL #user32, "GetDC",_
        hGBox As ulong,_  'handle of graphicbox
        gDC As ulong      'device context
        CallDLL #gdi32, "SetBkMode",_
        gDC As ulong,_          'handle of graphicbox
        _TRANSPARENT As long,_  'flag for transparent background
        result As long          'previous bkmode
        CallDLL#user32,"ReleaseDC",_
        hGBox As ulong,_    'graphicbox handle
        gDC As ulong,_      'device context
        result As long
        #td.main "font Cascadia_Code 24 bold; color black"
        if version = 1 then #td.main "place 280 290 ;\"; "JEU EN PAUSE"
        if version = 2 then #td.main "place 290 290 ;\"; "PAUSED GAME"
        wait
    end if

    [print]
    lastWave = Nvague
    lastWave2 = lastWave
    global map$ 
    'antiCHEATsystem 1.0
    lifeTOTA = int(gold*4587953+Nvague*141254867)
    goldTOTA = int(Nvague*56458487+45879*life)
    '-------------------
    open "data.txt" for output as #secu
    print #secu, life
    print #secu, lifeTOTA
    print #secu, Nvague
    print #secu, gold
    print #secu, goldTOTA
    print #secu, compteurBOSS
    print #secu, compteurSUPERboss
    print #secu, towers
    print #secu, map$
    print #secu, mapCHOICE
    print #secu, lvlARM
    print #secu, lvlGOLD
    print #secu, lastWave
    print #secu, lastWave2
    print #secu, dialBOSS
    print #secu, fermage
    print #secu, forge
    print #secu, viseur
    print #secu, drapeau
    close #secu
    'if bossKILLED = 1 then goto [remakeGAME3]
    if GameActivation = 1 then call Sleep 100 : goto [boucle]
    if map$ = "  " or map$ = " " or map$ = "" then kill "data.txt"
    return

    [input]
    open "data.txt" for input as #secu
    input #secu, life
    input #secu, lifeTOTA
    input #secu, Nvague
    input #secu, gold
    input #secu, goldTOTA
    input #secu, compteurBOSS
    input #secu, compteurSUPERboss
    input #secu, towers
    input #secu, map$
    input #secu, mapCHOICE
    input #secu, lvlARM
    input #secu, lvlGOLD
    input #secu, lastWave
    input #secu, lastWave2
    input #secu, dialBOSS
    input #secu, fermage
    input #secu, forge
    input #secu, viseur
    input #secu, drapeau
    close #secu
    return


    [RESET]
    if version = 1 then confirm "Voulez-vous vraiment recommencer sur une nouvelle carte ?";text$
    if version = 2 then confirm "Are you sure you want to start again on a new map ?";text$
    if text$ = "no" then
        if pause = 1 then wait
        if pause = 0 then goto [boucle]
    end if
    close #td : timer 0 : call Sleep 100 : TIMERBOUCLE = 50 : loaded = 0 : life = 20 : goto [INITIAL3]

    sub NOclick handle$, mx, my
        if nocheat = 1 then wait
    end sub
    sub NOclick2 handle$, mx, my
        if nocheat = 1 then wait
    end sub

    sub click handle$, mx, my
    forgeActivation = 0
    if nocheat = 1 then wait
        if help = 1 then close #help : help = 0
        x = int(mx/40)+1  :  y = int(my/40)+1
        if SELLmode = 0 then
            if mid$(map$, x+(y-1)*20, 1) = "ß" and gold >= 80000 and pause = 0 then UPGRADE = 1 : #td.main "removesprite towerX";x;"Y";y : map$=mid$(map$,1,x+(y-1)*20-1) ; "©" ; mid$(map$, x+(y-1)*20+1) : gold = gold - 80000 : towers = towers - 1 : call RemooveOldTower x, y
            if mid$(map$, x+(y-1)*20, 1) = "¶" and gold >= 70000 and pause = 0 then UPGRADE = 1 : #td.main "removesprite towerX";x;"Y";y : map$=mid$(map$,1,x+(y-1)*20-1) ; "ß" ; mid$(map$, x+(y-1)*20+1) : gold = gold - 70000 : towers = towers - 1 : call RemooveOldTower x, y
            if mid$(map$, x+(y-1)*20, 1) = "ò" and gold >= 60000 and pause = 0 then UPGRADE = 1 : #td.main "removesprite towerX";x;"Y";y : map$=mid$(map$,1,x+(y-1)*20-1) ; "¶" ; mid$(map$, x+(y-1)*20+1) : gold = gold - 60000 : towers = towers - 1 : call RemooveOldTower x, y
            if mid$(map$, x+(y-1)*20, 1) = "ñ" and gold >= 50000 and pause = 0 then UPGRADE = 1 : #td.main "removesprite towerX";x;"Y";y : map$=mid$(map$,1,x+(y-1)*20-1) ; "ò" ; mid$(map$, x+(y-1)*20+1) : gold = gold - 50000 : towers = towers - 1 : call RemooveOldTower x, y
            if mid$(map$, x+(y-1)*20, 1) = "ì" and gold >= 40000 and pause = 0 then UPGRADE = 1 : #td.main "removesprite towerX";x;"Y";y : map$=mid$(map$,1,x+(y-1)*20-1) ; "ñ" ; mid$(map$, x+(y-1)*20+1) : gold = gold - 40000 : towers = towers - 1 : call RemooveOldTower x, y
            if mid$(map$, x+(y-1)*20, 1) = "í" and gold >= 30000 and pause = 0 then UPGRADE = 1 : #td.main "removesprite towerX";x;"Y";y : map$=mid$(map$,1,x+(y-1)*20-1) ; "ì" ; mid$(map$, x+(y-1)*20+1) : gold = gold - 30000 : towers = towers - 1 : call RemooveOldTower x, y
            if mid$(map$, x+(y-1)*20, 1) = "î" and gold >= 20000 and pause = 0 then UPGRADE = 1 : #td.main "removesprite towerX";x;"Y";y : map$=mid$(map$,1,x+(y-1)*20-1) ; "í" ; mid$(map$, x+(y-1)*20+1) : gold = gold - 20000 : towers = towers - 1 : call RemooveOldTower x, y
            if mid$(map$, x+(y-1)*20, 1) = "ô" and gold >= 10000 and pause = 0 then UPGRADE = 1 : #td.main "removesprite towerX";x;"Y";y : map$=mid$(map$,1,x+(y-1)*20-1) ; "î" ; mid$(map$, x+(y-1)*20+1) : gold = gold - 10000 : towers = towers - 1 : call RemooveOldTower x, y
            if mid$(map$, x+(y-1)*20, 1) = "õ" and gold >= 6000 and pause = 0 then UPGRADE = 1 : #td.main "removesprite towerX";x;"Y";y : map$=mid$(map$,1,x+(y-1)*20-1) ; "ô" ; mid$(map$, x+(y-1)*20+1) : gold = gold - 6000 : towers = towers - 1 : call RemooveOldTower x, y
            if mid$(map$, x+(y-1)*20, 1) = "ö" and gold >= 3500 and pause = 0 then UPGRADE = 1 : #td.main "removesprite towerX";x;"Y";y : map$=mid$(map$,1,x+(y-1)*20-1) ; "õ" ; mid$(map$, x+(y-1)*20+1) : gold = gold - 3500 : towers = towers - 1 : call RemooveOldTower x, y
            if mid$(map$, x+(y-1)*20, 1) = "÷" and gold >= 2000 and pause = 0 then UPGRADE = 1 : #td.main "removesprite towerX";x;"Y";y : map$=mid$(map$,1,x+(y-1)*20-1) ; "ö" ; mid$(map$, x+(y-1)*20+1) : gold = gold - 2000 : towers = towers - 1 : call RemooveOldTower x, y
            if mid$(map$, x+(y-1)*20, 1) = "ø" and gold >= 1000 and pause = 0 then UPGRADE = 1 : #td.main "removesprite towerX";x;"Y";y : map$=mid$(map$,1,x+(y-1)*20-1) ; "÷" ; mid$(map$, x+(y-1)*20+1) : gold = gold - 1000 : towers = towers - 1 : call RemooveOldTower x, y
            if mid$(map$, x+(y-1)*20, 1) = "ù" and gold >= 500 and pause = 0 then UPGRADE = 1 : #td.main "removesprite towerX";x;"Y";y : map$=mid$(map$,1,x+(y-1)*20-1) ; "ø" ; mid$(map$, x+(y-1)*20+1) : gold = gold - 500 : towers = towers - 1 : call RemooveOldTower x, y
            if mid$(map$, x+(y-1)*20, 1) = "ú" and gold >= 320 and pause = 0 then UPGRADE = 1 : #td.main "removesprite towerX";x;"Y";y : map$=mid$(map$,1,x+(y-1)*20-1) ; "ù" ; mid$(map$, x+(y-1)*20+1) : gold = gold - 320 : towers = towers - 1 : call RemooveOldTower x, y
            if mid$(map$, x+(y-1)*20, 1) = "û" and gold >= 160 and pause = 0 then UPGRADE = 1 : #td.main "removesprite towerX";x;"Y";y : map$=mid$(map$,1,x+(y-1)*20-1) ; "ú" ; mid$(map$, x+(y-1)*20+1) : gold = gold - 160 : towers = towers - 1 : call RemooveOldTower x, y
            if mid$(map$, x+(y-1)*20, 1) = "ü" and gold >= 80 and pause = 0 then UPGRADE = 1 : #td.main "removesprite towerX";x;"Y";y : map$=mid$(map$,1,x+(y-1)*20-1) ; "û" ; mid$(map$, x+(y-1)*20+1) : gold = gold - 80 : towers = towers - 1 : call RemooveOldTower x, y
            if mid$(map$, x+(y-1)*20, 1) = "ý" and gold >= 40 and pause = 0 then UPGRADE = 1 : #td.main "removesprite towerX";x;"Y";y : map$=mid$(map$,1,x+(y-1)*20-1) ; "ü" ; mid$(map$, x+(y-1)*20+1) : gold = gold - 40 : towers = towers - 1 : call RemooveOldTower x, y
            if mid$(map$, x+(y-1)*20, 1) = "þ" and gold >= 20 and pause = 0 then UPGRADE = 1 : #td.main "removesprite towerX";x;"Y";y : map$=mid$(map$,1,x+(y-1)*20-1) ; "ý" ; mid$(map$, x+(y-1)*20+1) : gold = gold - 20 : towers = towers - 1 : call RemooveOldTower x, y
            if mid$(map$, x+(y-1)*20, 1) = "ÿ" and gold >= 10 and pause = 0 then UPGRADE = 1 : #td.main "removesprite towerX";x;"Y";y : map$=mid$(map$,1,x+(y-1)*20-1) ; "þ" ; mid$(map$, x+(y-1)*20+1) : gold = gold - 10 : towers = towers - 1 : call RemooveOldTower x, y
            if mid$(map$, x+(y-1)*20, 1) = " " and gold >= 5 and pause = 0 then gold = gold - 5 : call placeTower1 x, y
            if mid$(map$, x+(y-1)*20, 1) = "-" and pause = 0 then
                if version = 1 and fermage = 0 and gold < 380 then notice " " + chr$(13) +  "Ferme : La ferme augmente vos revenues de 50 pièces d'or à la fin de chaque vagues. il vous faut 380 d'or pour construire ce bâtiment." : goto [boucle]
                if version = 2 and fermage = 0 and gold < 380 then notice " " + chr$(13) +  "Ferme : The farm increases your income by 50 gold at the end of each wave. You need 380 gold to build this building." : goto [boucle]
                if fermage = 0 and gold >= 380 then
                    if version = 1 then demande$ = "La ferme augmente vos revenues de 50 pièces d'or à la fin de chaque vagues. Voulez vous construire une ferme pour 380 d'or ?"
                    if version = 2 then demande$ = "The farm increases your income by 50 gold at the end of each wave. Want to build a farm for 380 gold?"
                    confirm demande$;text$
                    if text$ = "no" then goto [boucle]
                    gold = gold - 380 : lvlGOLD = 50
                    call buildFERME x, y
                    goto [boucle]
                end if
                if version = 1 and fermage = 1 then notice "Fermage" + chr$(13) + "La ferme augmente vos revenues de 50 pièces d'or à la fin de chaque vagues." + chr$(13) + chr$(13) + "(déjà construit)"
                if version = 2 and fermage = 1 then notice "Farm" + chr$(13) + "The farm increases your income by 50 gold at the end of each wave." + chr$(13) + chr$(13) + "(already built)"
            end if
            if mid$(map$, x+(y-1)*20, 1) = "_" and pause = 0 then
                if version = 1 and forge = 0 and gold < 1440 then notice " " + chr$(13) +  "Forge : La forge augmente la valeur offensive de toutes vos tours de 30%. il vous faut 1440 d'or pour construire ce bâtiment." : goto [boucle]
                if version = 2 and forge = 0 and gold < 1440 then notice " " + chr$(13) +  "Forge : The forge increases the offensive value of all your towers by 30%. You need 1440 gold to build this building." : goto [boucle]
                if forge = 0 and gold >= 1440 then
                    if version = 1 then demande$ = "La forge augmente la valeur offensive de toutes vos tours de 30%. Voulez vous construire une forge pour 1440 d'or ?"
                    if version = 2 then demande$ = "The forge increases the offensive value of all your towers by 30%. Want to build a forge for 1440 gold?"
                    confirm demande$;text$
                    if text$ = "no" then goto [boucle]
                    gold = gold - 1440
                    call buildFORGE x, y
                    goto [boucle]
                end if
                if version = 1 and forge = 1 then notice "Forge" + chr$(13) + "La forge augmente la valeur offensive de toutes vos tours de 30%." + chr$(13) + chr$(13) + "(déjà construit)"
                if version = 2 and forge = 1 then notice "Forge" + chr$(13) + "The forge increases the offensive value of all your towers by 30%." + chr$(13) + chr$(13) + "(already built)"
            end if
            if mid$(map$, x+(y-1)*20, 1) = "$" and pause = 0 then
                if version = 1 and viseur = 0 and gold < 900 then notice " " + chr$(13) +  "Viseur : Le viseur augmente la portée de la totalité de vos tour de 1 case. il vous faut 900 d'or pour construire ce bâtiment." : goto [boucle]
                if version = 2 and viseur = 0 and gold < 900 then notice " " + chr$(13) +  "Viewfinder : The viewfinder increases the range of all your towers by 1 tile. You need 900 gold to build this building." : goto [boucle]
                if viseur = 0 and gold >= 900 then
                    if version = 1 then demande$ = "Le viseur augmente la portée de la totalité de vos tour de 1 case. Voulez vous construire le viseur pour 900 d'or ?"
                    if version = 2 then demande$ = "The viewfinder increases the range of all your towers by 1 tile. Want to build the sight for 900 gold ?"
                    confirm demande$;text$
                    if text$ = "no" then goto [boucle]
                    gold = gold - 900
                    call buildVISEUR x, y
                    goto [boucle]
                end if
                if version = 1 and viseur = 1 then notice "Viseur" + chr$(13) + "Le viseur augmente la portée de la totalité de vos tour de 1 case." + chr$(13) + chr$(13) + "(déjà construit)"
                if version = 2 and viseur = 1 then notice "Viewfinder" + chr$(13) + "The viewfinder increases the range of all your towers by 1 tile." + chr$(13) + chr$(13) + "(already built)"
            end if
            if mid$(map$, x+(y-1)*20, 1) = "%" and pause = 0 then
                if version = 1 and drapeau = 0 and gold < 500 then notice " " + chr$(13) +  "Industrie : L'industrie augmente la cadence de fabrique de flèche permettant à vos tour de tirer plus rapidement. il vous faut 500 d'or pour construire ce bâtiment." : goto [boucle]
                if version = 2 and drapeau = 0 and gold < 500 then notice " " + chr$(13) +  "Industry : Industry increases the rate of arrow manufacturing allowing your towers to fire faster. You need 500 gold to build this building." : goto [boucle]
                if drapeau = 0 and gold >= 500 then
                    if version = 1 then demande$ = "L'industrie augmente la vitesse de vos tours de 1. Voulez vous construire le viseur pour 500 d'or ?"
                    if version = 2 then demande$ = "Industry increases your turn speed by 1. Want to build the sight for 500 gold ?"
                    confirm demande$;text$
                    if text$ = "no" then goto [boucle]
                    gold = gold - 500
                    call buildINDUSTRIE x, y
                    goto [boucle]
                end if
                if version = 1 and drapeau = 1 then notice "Industrie" + chr$(13) + "L'industrie augmente la vitesse de vos tours de 1." + chr$(13) + chr$(13) + "(déjà construit)"
                if version = 2 and drapeau = 1 then notice "Industrie" + chr$(13) + "Industry increases your turn speed by 1." + chr$(13) + chr$(13) + "(already built)"
            end if
        end if

        if infoTOWERx = x and infoTOWERy = y then
            if SELLmode = 1 and (mid$(map$, x+(y-1)*20, 1) = "©" or mid$(map$, x+(y-1)*20, 1) = "ß" or mid$(map$, x+(y-1)*20, 1) = "¶" or mid$(map$, x+(y-1)*20, 1) = "ò" or mid$(map$, x+(y-1)*20, 1) = "ñ" or mid$(map$, x+(y-1)*20, 1) = "ì" or mid$(map$, x+(y-1)*20, 1) = "í" or mid$(map$, x+(y-1)*20, 1) = "î" or mid$(map$, x+(y-1)*20, 1) = "ô" or mid$(map$, x+(y-1)*20, 1) = "õ" or mid$(map$, x+(y-1)*20, 1) = "ö" or mid$(map$, x+(y-1)*20, 1) = "÷" or mid$(map$, x+(y-1)*20, 1) = "ø" or mid$(map$, x+(y-1)*20, 1) = "ù" or mid$(map$, x+(y-1)*20, 1) = "ú" or mid$(map$, x+(y-1)*20, 1) = "û" or mid$(map$, x+(y-1)*20, 1) = "ü" or mid$(map$, x+(y-1)*20, 1) = "ý" or mid$(map$, x+(y-1)*20, 1) = "þ" or mid$(map$, x+(y-1)*20, 1) = "ÿ") and pause = 0 then call click3 : UPGRADE = 0 : call RemooveOldTower x, y
            if SELLmode = 1 and (mid$(map$, x+(y-1)*20, 1) = " " or mid$(map$, x+(y-1)*20, 1) = "é" or mid$(map$, x+(y-1)*20, 1) = "è" or mid$(map$, x+(y-1)*20, 1) = "¤" or mid$(map$, x+(y-1)*20, 1) = "à") then SELLmode = 0 : #td.main "spritevisible sell off" : #td.main2 "place 380 10 ;\"; "                                         \                                         \                                          "
        end if
        if SELLmode = 1 then SELLmode = 0 : #td.main "spritevisible sell off" : #td.main2 "place 380 10 ;\"; "                                                       \                                                       \                                                       "
    end sub

    sub click2 handle$, mx, my
    if nocheat = 1 then wait
        x = int(mx/40)+1  :  y = int(my/40)+1
        if mid$(map$, x+(y-1)*20, 1) = "©" then
            DamageInfo = 40000 : RangeInfo = 7 : SpeedInfo = 13 : SELLmode = 1 : infoTOWERx = x : infoTOWERy = y : infoTOWERgold = 80000 : #td.main "spriteXY sell ";(x*40)-30;" ";(y*40)-25;"; spritetofront sell; spritevisible sell on" : #td.main2 "drawbmp towerBb 520 4"
            if forge = 1 then DamageInfo = 52000
            if drapeau = 1 then SpeedInfo = 14
            if viseur = 1 then RangeInfo = 8
            #td.main2 "font Cascadia_Code 7 bold; place 550 10 ;\"; txt1$;DamageInfo;"     \";txt2$;RangeInfo;"     \";txt3$;SpeedInfo;"      "
        end if
        if mid$(map$, x+(y-1)*20, 1) = "ß" then
            DamageInfo = 25000 : RangeInfo = 6 : SpeedInfo = 12 : SELLmode = 1 : infoTOWERx = x : infoTOWERy = y : infoTOWERgold = 70000 : #td.main "spriteXY sell ";(x*40)-30;" ";(y*40)-25;"; spritetofront sell; spritevisible sell on" : #td.main2 "drawbmp towerBb 520 4"
            if forge = 1 then DamageInfo = 32500
            if drapeau = 1 then SpeedInfo = 13
            if viseur = 1 then RangeInfo = 7
            #td.main2 "font Cascadia_Code 7 bold; place 550 10 ;\"; txt1$;DamageInfo;"     \";txt2$;RangeInfo;"     \";txt3$;SpeedInfo;"      "
        end if
        if mid$(map$, x+(y-1)*20, 1) = "¶" then
            DamageInfo = 20000 : RangeInfo = 6 : SpeedInfo = 11 : SELLmode = 1 : infoTOWERx = x : infoTOWERy = y : infoTOWERgold = 60000 : #td.main "spriteXY sell ";(x*40)-30;" ";(y*40)-25;"; spritetofront sell; spritevisible sell on" : #td.main2 "drawbmp towerBb 520 4"
            if forge = 1 then DamageInfo = 26000
            if drapeau = 1 then SpeedInfo = 12
            if viseur = 1 then RangeInfo = 7
            #td.main2 "font Cascadia_Code 7 bold; place 550 10 ;\"; txt1$;DamageInfo;"     \";txt2$;RangeInfo;"     \";txt3$;SpeedInfo;"      "
        end if
        if mid$(map$, x+(y-1)*20, 1) = "ò" then
            DamageInfo = 15000 : RangeInfo = 5 : SpeedInfo = 11 : SELLmode = 1 : infoTOWERx = x : infoTOWERy = y : infoTOWERgold = 50000 : #td.main "spriteXY sell ";(x*40)-30;" ";(y*40)-25;"; spritetofront sell; spritevisible sell on" : #td.main2 "drawbmp towerBb 520 4"
            if forge = 1 then DamageInfo = 18500
            if drapeau = 1 then SpeedInfo = 12
            if viseur = 1 then RangeInfo = 6
            #td.main2 "font Cascadia_Code 7 bold; place 550 10 ;\"; txt1$;DamageInfo;"     \";txt2$;RangeInfo;"     \";txt3$;SpeedInfo;"      "
        end if
        if mid$(map$, x+(y-1)*20, 1) = "ñ" then
            DamageInfo = 11000 : RangeInfo = 5 : SpeedInfo = 10 : SELLmode = 1 : infoTOWERx = x : infoTOWERy = y : infoTOWERgold = 40000 : #td.main "spriteXY sell ";(x*40)-30;" ";(y*40)-25;"; spritetofront sell; spritevisible sell on" : #td.main2 "drawbmp towerBb 520 4"
            if forge = 1 then DamageInfo = 14300
            if drapeau = 1 then SpeedInfo = 11
            if viseur = 1 then RangeInfo = 6
            #td.main2 "font Cascadia_Code 7 bold; place 550 10 ;\"; txt1$;DamageInfo;"     \";txt2$;RangeInfo;"     \";txt3$;SpeedInfo;"      "
        end if
        if mid$(map$, x+(y-1)*20, 1) = "ì" then
            DamageInfo = 8000 : RangeInfo = 5 : SpeedInfo = 10 : SELLmode = 1 : infoTOWERx = x : infoTOWERy = y : infoTOWERgold = 30000 : #td.main "spriteXY sell ";(x*40)-30;" ";(y*40)-25;"; spritetofront sell; spritevisible sell on" : #td.main2 "drawbmp towerBb 520 4"
            if forge = 1 then DamageInfo = 10400
            if drapeau = 1 then SpeedInfo = 11
            if viseur = 1 then RangeInfo = 6
            #td.main2 "font Cascadia_Code 7 bold; place 550 10 ;\"; txt1$;DamageInfo;"     \";txt2$;RangeInfo;"     \";txt3$;SpeedInfo;"      "
        end if
        if mid$(map$, x+(y-1)*20, 1) = "í" then
            DamageInfo = 6300 : RangeInfo = 4 : SpeedInfo = 10 : SELLmode = 1 : infoTOWERx = x : infoTOWERy = y : infoTOWERgold = 20000 : #td.main "spriteXY sell ";(x*40)-30;" ";(y*40)-25;"; spritetofront sell; spritevisible sell on" : #td.main2 "drawbmp towerBb 520 4"
            if forge = 1 then DamageInfo = 8190
            if drapeau = 1 then SpeedInfo = 11
            if viseur = 1 then RangeInfo = 5
            #td.main2 "font Cascadia_Code 7 bold; place 550 10 ;\"; txt1$;DamageInfo;"     \";txt2$;RangeInfo;"     \";txt3$;SpeedInfo;"      "
        end if
        if mid$(map$, x+(y-1)*20, 1) = "î" then
            DamageInfo = 3900 : RangeInfo = 4 : SpeedInfo = 9 : SELLmode = 1 : infoTOWERx = x : infoTOWERy = y : infoTOWERgold = 10000 : #td.main "spriteXY sell ";(x*40)-30;" ";(y*40)-25;"; spritetofront sell; spritevisible sell on" : #td.main2 "drawbmp towerBb 520 4"
            if forge = 1 then DamageInfo = 5070
            if drapeau = 1 then SpeedInfo = 10
            if viseur = 1 then RangeInfo = 5
            #td.main2 "font Cascadia_Code 7 bold; place 550 10 ;\"; txt1$;DamageInfo;"     \";txt2$;RangeInfo;"     \";txt3$;SpeedInfo;"      "
        end if
        if mid$(map$, x+(y-1)*20, 1) = "ô" then
            DamageInfo = 2400 : RangeInfo = 4 : SpeedInfo = 9 : SELLmode = 1 : infoTOWERx = x : infoTOWERy = y : infoTOWERgold = 6000 : #td.main "spriteXY sell ";(x*40)-30;" ";(y*40)-25;"; spritetofront sell; spritevisible sell on" : #td.main2 "drawbmp towerBb 520 4"
            if forge = 1 then DamageInfo = 3120
            if drapeau = 1 then SpeedInfo = 10
            if viseur = 1 then RangeInfo = 5
            #td.main2 "font Cascadia_Code 7 bold; place 550 10 ;\"; txt1$;DamageInfo;"     \";txt2$;RangeInfo;"     \";txt3$;SpeedInfo;"      "
        end if
        if mid$(map$, x+(y-1)*20, 1) = "õ" then
            DamageInfo = 1500 : RangeInfo = 4 : SpeedInfo = 8 : SELLmode = 1 : infoTOWERx = x : infoTOWERy = y : infoTOWERgold = 3500 : #td.main "spriteXY sell ";(x*40)-30;" ";(y*40)-25;"; spritetofront sell; spritevisible sell on" : #td.main2 "drawbmp towerBb 520 4"
            if forge = 1 then DamageInfo = 1850
            if drapeau = 1 then SpeedInfo = 9
            if viseur = 1 then RangeInfo = 5
            #td.main2 "font Cascadia_Code 7 bold; place 550 10 ;\"; txt1$;DamageInfo;"     \";txt2$;RangeInfo;"     \";txt3$;SpeedInfo;"      "
        end if
        if mid$(map$, x+(y-1)*20, 1) = "ö" then
            DamageInfo = 1100 : RangeInfo = 4 : SpeedInfo = 8 : SELLmode = 1 : infoTOWERx = x : infoTOWERy = y : infoTOWERgold = 2000 : #td.main "spriteXY sell ";(x*40)-30;" ";(y*40)-25;"; spritetofront sell; spritevisible sell on" : #td.main2 "drawbmp towerBb 520 4"
            if forge = 1 then DamageInfo = 1430
            if drapeau = 1 then SpeedInfo = 9
            if viseur = 1 then RangeInfo = 5
            #td.main2 "font Cascadia_Code 7 bold; place 550 10 ;\"; txt1$;DamageInfo;"     \";txt2$;RangeInfo;"     \";txt3$;SpeedInfo;"      "
        end if
        if mid$(map$, x+(y-1)*20, 1) = "÷" then
            DamageInfo = 880 : RangeInfo = 4 : SpeedInfo = 7 : SELLmode = 1 : infoTOWERx = x : infoTOWERy = y : infoTOWERgold = 1000 : #td.main "spriteXY sell ";(x*40)-30;" ";(y*40)-25;"; spritetofront sell; spritevisible sell on" : #td.main2 "drawbmp towerBb 520 4"
            if forge = 1 then DamageInfo = 1144
            if drapeau = 1 then SpeedInfo = 8
            if viseur = 1 then RangeInfo = 5
            #td.main2 "font Cascadia_Code 7 bold; place 550 10 ;\"; txt1$;DamageInfo;"     \";txt2$;RangeInfo;"     \";txt3$;SpeedInfo;"      "
        end if
        if mid$(map$, x+(y-1)*20, 1) = "ø" then
            DamageInfo = 640 : RangeInfo = 3 : SpeedInfo = 7 : SELLmode = 1 : infoTOWERx = x : infoTOWERy = y : infoTOWERgold = 500 : #td.main "spriteXY sell ";(x*40)-30;" ";(y*40)-25;"; spritetofront sell; spritevisible sell on" : #td.main2 "drawbmp towerBb 520 4"
            if forge = 1 then DamageInfo = 832
            if drapeau = 1 then SpeedInfo = 8
            if viseur = 1 then RangeInfo = 4
            #td.main2 "font Cascadia_Code 7 bold; place 550 10 ;\"; txt1$;DamageInfo;"     \";txt2$;RangeInfo;"     \";txt3$;SpeedInfo;"      "
        end if
        if mid$(map$, x+(y-1)*20, 1) = "ù" then
            DamageInfo = 372 : RangeInfo = 3 : SpeedInfo = 7 : SELLmode = 1 : infoTOWERx = x : infoTOWERy = y : infoTOWERgold = 320 : #td.main "spriteXY sell ";(x*40)-30;" ";(y*40)-25;"; spritetofront sell; spritevisible sell on" : #td.main2 "drawbmp towerBb 520 4"
            if forge = 1 then DamageInfo = 484
            if drapeau = 1 then SpeedInfo = 8
            if viseur = 1 then RangeInfo = 4
            #td.main2 "font Cascadia_Code 7 bold; place 550 10 ;\"; txt1$;DamageInfo;"     \";txt2$;RangeInfo;"     \";txt3$;SpeedInfo;"      "
        end if
        if mid$(map$, x+(y-1)*20, 1) = "ú" then
            DamageInfo = 220 : RangeInfo = 3 : SpeedInfo = 6 : SELLmode = 1 : infoTOWERx = x : infoTOWERy = y : infoTOWERgold = 160 : #td.main "spriteXY sell ";(x*40)-30;" ";(y*40)-25;"; spritetofront sell; spritevisible sell on" : #td.main2 "drawbmp towerAa 520 4"
            if forge = 1 then DamageInfo = 286
            if drapeau = 1 then SpeedInfo = 7
            if viseur = 1 then RangeInfo = 4
            #td.main2 "font Cascadia_Code 7 bold; place 550 10 ;\"; txt1$;DamageInfo;"     \";txt2$;RangeInfo;"     \";txt3$;SpeedInfo;"      "
        end if
        if mid$(map$, x+(y-1)*20, 1) = "û" then
            DamageInfo = 100 : RangeInfo = 3 : SpeedInfo = 6 : SELLmode = 1 : infoTOWERx = x : infoTOWERy = y : infoTOWERgold = 80 : #td.main "spriteXY sell ";(x*40)-30;" ";(y*40)-25;"; spritetofront sell; spritevisible sell on" : #td.main2 "drawbmp towerAa 520 4"
            if forge = 1 then DamageInfo = 130
            if drapeau = 1 then SpeedInfo = 7
            if viseur = 1 then RangeInfo = 4
            #td.main2 "font Cascadia_Code 7 bold; place 550 10 ;\"; txt1$;DamageInfo;"     \";txt2$;RangeInfo;"     \";txt3$;SpeedInfo;"      "
        end if
        if mid$(map$, x+(y-1)*20, 1) = "ü" then
            DamageInfo = 60 : RangeInfo = 3 : SpeedInfo = 5 : SELLmode = 1 : infoTOWERx = x : infoTOWERy = y : infoTOWERgold = 40 : #td.main "spriteXY sell ";(x*40)-30;" ";(y*40)-25;"; spritetofront sell; spritevisible sell on" : #td.main2 "drawbmp towerAa 520 4"
            if forge = 1 then DamageInfo = 78
            if drapeau = 1 then SpeedInfo = 6
            if viseur = 1 then RangeInfo = 4
            #td.main2 "font Cascadia_Code 7 bold; place 550 10 ;\"; txt1$;DamageInfo;"     \";txt2$;RangeInfo;"     \";txt3$;SpeedInfo;"      "
        end if
        if mid$(map$, x+(y-1)*20, 1) = "ý" then
            DamageInfo = 35 : RangeInfo = 2 : SpeedInfo = 5 : SELLmode = 1 : infoTOWERx = x : infoTOWERy = y : infoTOWERgold = 20 : #td.main "spriteXY sell ";(x*40)-30;" ";(y*40)-25;"; spritetofront sell; spritevisible sell on" : #td.main2 "drawbmp towerAa 520 4"
            if forge = 1 then DamageInfo = 46
            if drapeau = 1 then SpeedInfo = 6
            if viseur = 1 then RangeInfo = 3
            #td.main2 "font Cascadia_Code 7 bold; place 550 10 ;\"; txt1$;DamageInfo;"     \";txt2$;RangeInfo;"     \";txt3$;SpeedInfo;"      "
        end if
        if mid$(map$, x+(y-1)*20, 1) = "þ" then
            DamageInfo = 18 : RangeInfo = 2 : SpeedInfo = 4 : SELLmode = 1 : infoTOWERx = x : infoTOWERy = y : infoTOWERgold = 10 : #td.main "spriteXY sell ";(x*40)-30;" ";(y*40)-25;"; spritetofront sell; spritevisible sell on" : #td.main2 "drawbmp towerAa 520 4"
            if forge = 1 then DamageInfo = 24
            if drapeau = 1 then SpeedInfo = 5
            if viseur = 1 then RangeInfo = 3
            #td.main2 "font Cascadia_Code 7 bold; place 550 10 ;\"; txt1$;DamageInfo;"     \";txt2$;RangeInfo;"     \";txt3$;SpeedInfo;"      "
        end if
        if mid$(map$, x+(y-1)*20, 1) = "ÿ" then
            DamageInfo = 7 : RangeInfo = 2 : SpeedInfo = 4 : SELLmode = 1 : infoTOWERx = x : infoTOWERy = y : infoTOWERgold = 5 : #td.main "spriteXY sell ";(x*40)-30;" ";(y*40)-25;"; spritetofront sell; spritevisible sell on" : #td.main2 "drawbmp towerAa 520 4"
            if forge = 1 then DamageInfo = 9
            if drapeau = 1 then SpeedInfo = 5
            if viseur = 1 then RangeInfo = 3
            #td.main2 "font Cascadia_Code 7 bold; place 550 10 ;\"; txt1$;DamageInfo;"     \";txt2$;RangeInfo;"     \";txt3$;SpeedInfo;"      "
        end if
        if mid$(map$, x+(y-1)*20, 1) = " " or mid$(map$, x+(y-1)*20, 1) = "é" or mid$(map$, x+(y-1)*20, 1) = "è" or mid$(map$, x+(y-1)*20, 1) = "¤" or mid$(map$, x+(y-1)*20, 1) = "à" then SELLmode = 0 : #td.main "spritevisible sell off" : #td.main2 "place 510 10 ;\"; "                                        \                                        \                                         "
    end sub

    sub click3
        if version = 1 then demande$ = "Voulez vous revendre cette tour pour ";infoTOWERgold;" d'or ?"
        if version = 2 then demande$ = "Do you want to sell this tower for ";infoTOWERgold;" gold ?"
        confirm demande$;text$
        if text$ = "no" then SELLmode = 0 : #td.main "spritevisible sell off" : #td.main2 "place 380 10 ;\"; "                                                       \                                                       \                                                       " : goto [boucle]
        gold = gold + infoTOWERgold
        SELLmode = 0
        #td.main2 "place 380 10 ;\"; "                                                       \                                                       \                                                       "
        #td.main "removesprite towerX";infoTOWERx;"Y";infoTOWERy
        #td.main "removesprite bulletX";infoTOWERx;"Y";infoTOWERy
        #td.main "spritevisible sell off"
        towers=towers-1
        map$=mid$(map$,1,infoTOWERx+(infoTOWERy-1)*20-1) ; " " ; mid$(map$, infoTOWERx+(infoTOWERy-1)*20+1)
    end sub

    sub advanceCreeps
        for thisCreep = 1 to creeps
            if creepHealth(thisCreep)>0 then
                creepTime(thisCreep)=creepTime(thisCreep)-creepSpeed(thisCreep)
                if creepTime(thisCreep)<=0 then
                    creepTime(thisCreep)=100
                    if creepPosX(thisCreep)=0 then
                        creepPosX(thisCreep)=pathX(1) : creepPosY(thisCreep)=pathY(1)
                        if eliteWave = 1 then #td.main "spriteXY creep";thisCreep;" ";(creepPosX(thisCreep)-1)*40+5;" ";(creepPosY(thisCreep)-1)*40+3;"; spritetofront creep";thisCreep;""
                        if thisCreep >1 and eliteWave = 0 then #td.main "spriteXY creep";thisCreep;" ";(creepPosX(thisCreep)-1)*40+10;" ";(creepPosY(thisCreep)-1)*40+10
                        if compteurBOSS = 0 and thisCreep = 1 and eliteWave = 0 then #td.main "spriteXY creep";thisCreep;" ";(creepPosX(thisCreep)-1)*40;" ";(creepPosY(thisCreep)-1)*40+3;"; spritetofront creep";thisCreep;""
                        if compteurSUPERboss = 0 and thisCreep = 1 and eliteWave = 0 then #td.main "spriteXY creep";thisCreep;" ";(creepPosX(thisCreep)-1)*40-17;" ";(creepPosY(thisCreep)-1)*40-40;"; spritetofront creep";thisCreep;""
                        if compteurBOSS > 0 and compteurSUPERboss > 0 and thisCreep = 1 and eliteWave = 0 then #td.main "spriteXY creep";thisCreep;" ";(creepPosX(thisCreep)-1)*40+8;" ";(creepPosY(thisCreep)-1)*40+10
                        exit sub
                    end if
                    if creepPosX(thisCreep)>0 then
                        for index = 1 to 56
                            if creepPosX(thisCreep)=pathX(index) AND creepPosY(thisCreep)=pathY(index) then creepPosX(thisCreep)=pathX(index+1) : creepPosY(thisCreep)=pathY(index+1) : exit for
                        next index
                        if mapCHOICE = 9 and index>22 then life = life - 1 : creeps = creeps - 1 : creepPosX(thisCreep)=0 : creepPosY(thisCreep)=0 : creepHealth(thisCreep)=0
                        if index>55 then life = life - 1 : creeps = creeps - 1 : creepPosX(thisCreep)=0 : creepPosY(thisCreep)=0 : creepHealth(thisCreep)=0
                        if eliteWave = 1 then #td.main "spriteXY creep";thisCreep;" ";(creepPosX(thisCreep)-1)*40+5;" ";(creepPosY(thisCreep)-1)*40+3;"; spritetofront creep";thisCreep;""
                        if thisCreep >1 and eliteWave = 0 then #td.main "spriteXY creep";thisCreep;" ";(creepPosX(thisCreep)-1)*40+10;" ";(creepPosY(thisCreep)-1)*40+10
                        if thisCreep =1 and eliteWave = 0 then
                            select case compteurSUPERboss
                                case 0
                                    #td.main "spriteXY creep";thisCreep;" ";(creepPosX(thisCreep)-1)*40-17;" ";(creepPosY(thisCreep)-1)*40-40;"; spritetofront creep";thisCreep;""
                                case else
                                    if compteurBOSS = 0 then #td.main "spriteXY creep";thisCreep;" ";(creepPosX(thisCreep)-1)*40;" ";(creepPosY(thisCreep)-1)*40+3;"; spritetofront creep";thisCreep
                                    if compteurBOSS > 0 then #td.main "spriteXY creep";thisCreep;" ";(creepPosX(thisCreep)-1)*40+8;" ";(creepPosY(thisCreep)-1)*40+10 : #td.main,"cyclesprite creep";thisCreep;" 1 once"
                            end select
                        end if
                    end if
                end if
            end if
        next thisCreep
        for t = 1 to towers
            on error goto [nextTower]
            if towerTime(t)<=0 then
                for c = 1 to creeps
                    if creepHealth(c) <= 0 then goto [skipCreep]
                    cx=creepPosX(c) : cy=creepPosY(c) : tx=towerX(t) : ty=towerY(t) : dist = sqr( abs(tx-cx)*abs(tx-cx) + abs(ty-cy)*abs(ty-cy) )
                    if dist<towerRange(t) then
                        r$ = mcisend$("pause laser")
                        #td.main "spritevisible bulletX";tx;"Y";ty;" on"
                        x = (tx-1) * 40+10 : y = (ty-1) * 40+10 : cx = (cx-1) * 40 +10 : cy = (cy-1) * 40
                        if fermage = 0 then #td.main "cyclesprite emplacement1 0"
                        if forge = 0 then #td.main "cyclesprite emplacement2 0"
                        if viseur = 0 then #td.main "cyclesprite emplacement3 0"
                        if drapeau = 0 then #td.main "cyclesprite emplacement4 0"
                        #td.main "cyclesprite flamme 0"
                        while (x>cx+3 or x<cx-3) and (y>cy+3 or y<cy-3)
                            #td.main "spritexy bulletX";tx;"Y";ty;" ";x+5;" ";y+10 : #td.main "drawsprites"
                            if x<cx-2 then x=x+2
                            if x>cx+2 then x=x-2
                            if y<cy-2 then y=y+2
                            if y>cy+2 then y=y-2
                        wend
                        if fermage = 0 then #td.main "cyclesprite emplacement1 1 once"
                        if forge = 0 then #td.main "cyclesprite emplacement2 1 once"
                        if viseur = 0 then #td.main "cyclesprite emplacement3 1 once"
                        if drapeau = 0 then #td.main "cyclesprite emplacement4 1 once"
                        #td.main "cyclesprite flamme 1"
                        #td.main "spritevisible bulletX";tx;"Y";ty;" off"
                        creepHealth(c)=creepHealth(c)-towerDamage(t) : towerTime(t)=100
                        if bruitage = 1 then r$ = mcisend$("play laser from 0")
                        if creepHealth(c)<=0 then
                            #td.main "removesprite creep";c
                            select case eliteWave
                                case 1
                                    creeps = creeps - 1
                                    if lastWave2 <> lastWave then gold = gold + Nvague
                                case 0
                                    creeps = creeps - 1 : ENNEMIgold = int(rnd(1)*((1+(Nvague/15))-(Nvague/80))+(2+(Nvague/80)))
                                    if lastWave2 <> lastWave then gold = gold +  ENNEMIgold
                                    if c = 1 and compteurBOSS = 0 and lastWave2 <> lastWave then life = life + 3 : gold = gold + (10*Nvague)
                                    if c = 1 and compteurSUPERboss = 0 then
                                        life = life + 10 : gold = gold + (20*Nvague)
                                        if version = 1 then confirm "Bravo, tu m'as eu ... tu veux remettre ca ? (Vous pouvez continuer en appuyant sur OUI ou quitter la partie en appuyant sur NON. Si vous quittez, la partie sera automatiquement effacée.)"; rp$
                                        if version = 2 then confirm "Well done, you got me... do you want to do that again? (You can continue by pressing YES or exit the game by pressing NO. If you exit, the game will be automatically cleared.)"; rp$
                                        if rp$ = "no" then bossKILLED = 1
                                    end if
                            end select
                        end if
                        exit for
                    end if
                    [skipCreep]
                next c
            else
                towerTime(t)=towerTime(t)-towerSpeed(t)
            end if
            [nextTower]
        next t
    end sub

    sub buildFERME x, y
        map$=mid$(map$,1,x+(y-1)*20-1) ; "-" ; mid$(map$, x+(y-1)*20+1)
        fermage = 1
        #td.main "addsprite ferme ferme; spritexy ferme ";(x-1)*40;" ";(y-1)*40
    end sub
    sub buildFORGE x, y
        map$=mid$(map$,1,x+(y-1)*20-1) ; "_" ; mid$(map$, x+(y-1)*20+1)
        forge = 1
        #td.main "addsprite forge forge; spritexy forge ";(x-1)*40;" ";(y-1)*40
    end sub
    sub buildVISEUR x, y
        map$=mid$(map$,1,x+(y-1)*20-1) ; "$" ; mid$(map$, x+(y-1)*20+1)
        viseur = 1
        #td.main "addsprite bat3 bat3; spritexy bat3 ";(x-1)*40;" ";(y-1)*40
    end sub
    sub buildINDUSTRIE x, y
        map$=mid$(map$,1,x+(y-1)*20-1) ; "%" ; mid$(map$, x+(y-1)*20+1)
        drapeau = 1
        #td.main "addsprite bat4 bat4; spritexy bat4 ";(x-1)*40;" ";(y-1)*40
    end sub

    sub placeTower1 x, y
        map$=mid$(map$,1,x+(y-1)*20-1) ; "ÿ" ; mid$(map$, x+(y-1)*20+1)
        towers=towers+1
        towerX(towers)=x
        towerY(towers)=y
        towerSpeed(towers)=4
        towerRange(towers)=2
        towerDamage(towers)=7
        towerLVL(towers) = 1
        towerTime(towers)=100
        if forge = 1 then towerDamage(towers)= 9
        if drapeau = 1 then towerSpeed(towers)= 5
        if viseur = 1 then towerRange(towers)= 3
        #td.main "addsprite towerX";x;"Y";y;" towerA; spritexy towerX";x;"Y";y;" ";(x-1)*40;" ";(y-1)*40
        bulletX(towers) = x : bulletY(towers) = y
        #td.main "addsprite bulletX";x;"Y";y;" bullet; spritexy bulletX";x;"Y";y;" ";(x-1)*40+5;" ";(y-1)*40+5 : #td.main "spritevisible bulletX";x;"Y";y;" off"
    end sub
    sub placeTower2 x, y
        map$=mid$(map$,1,x+(y-1)*20-1) ; "þ" ; mid$(map$, x+(y-1)*20+1)
        towers=towers+1
        towerX(towers)=x
        towerY(towers)=y
        towerSpeed(towers)=4
        towerRange(towers)=2
        towerDamage(towers)=18
        towerLVL(towers) = 2
        towerTime(towers)=100
        if forge = 1 then towerDamage(towers)= 24
        if drapeau = 1 then towerSpeed(towers)= 5
        if viseur = 1 then towerRange(towers)= 3
        #td.main "addsprite towerX";x;"Y";y;" towerB; spritexy towerX";x;"Y";y;" ";(x-1)*40;" ";(y-1)*40
        bulletX(towers) = x : bulletY(towers) = y
        #td.main "addsprite bulletX";x;"Y";y;" bullet; spritexy bulletX";x;"Y";y;" ";(x-1)*40+5;" ";(y-1)*40+5 : #td.main "spritevisible bulletX";x;"Y";y;" off"
    end sub
    sub placeTower3 x, y
        map$=mid$(map$,1,x+(y-1)*20-1) ; "ý" ; mid$(map$, x+(y-1)*20+1)
        towers=towers+1
        towerX(towers)=x
        towerY(towers)=y
        towerSpeed(towers)=5
        towerRange(towers)=2
        towerDamage(towers)=35
        towerLVL(towers) = 3
        towerTime(towers)=100
        if forge = 1 then towerDamage(towers)= 46
        if drapeau = 1 then towerSpeed(towers)= 6
        if viseur = 1 then towerRange(towers)= 3
        #td.main "addsprite towerX";x;"Y";y;" towerC; spritexy towerX";x;"Y";y;" ";(x-1)*40;" ";(y-1)*40
        bulletX(towers) = x : bulletY(towers) = y
        #td.main "addsprite bulletX";x;"Y";y;" bullet; spritexy bulletX";x;"Y";y;" ";(x-1)*20+5;" ";(y-1)*20+1 : #td.main "spritevisible bulletX";x;"Y";y;" off"
    end sub
    sub placeTower4 x, y
        map$=mid$(map$,1,x+(y-1)*20-1) ; "ü" ; mid$(map$, x+(y-1)*20+1)
        towers=towers+1
        towerX(towers)=x
        towerY(towers)=y
        towerSpeed(towers)=5
        towerRange(towers)=3
        towerDamage(towers)=60
        towerLVL(towers) = 4
        towerTime(towers)=100
        if forge = 1 then towerDamage(towers)= 78
        if drapeau = 1 then towerSpeed(towers)= 6
        if viseur = 1 then towerRange(towers)= 4
        #td.main "addsprite towerX";x;"Y";y;" towerD; spritexy towerX";x;"Y";y;" ";(x-1)*40;" ";(y-1)*40
        bulletX(towers) = x : bulletY(towers) = y
        #td.main "addsprite bulletX";x;"Y";y;" bullet; spritexy bulletX";x;"Y";y;" ";(x-1)*20+5;" ";(y-1)*20+1 : #td.main "spritevisible bulletX";x;"Y";y;" off"
    end sub
    sub placeTower5 x, y
        map$=mid$(map$,1,x+(y-1)*20-1) ; "û" ; mid$(map$, x+(y-1)*20+1)
        towers=towers+1
        towerX(towers)=x
        towerY(towers)=y
        towerSpeed(towers)=6
        towerRange(towers)=3
        towerDamage(towers)=100
        towerLVL(towers) = 5
        towerTime(towers)=100
        if forge = 1 then towerDamage(towers)= 130
        if drapeau = 1 then towerSpeed(towers)= 7
        if viseur = 1 then towerRange(towers)= 4
        #td.main "addsprite towerX";x;"Y";y;" towerE; spritexy towerX";x;"Y";y;" ";(x-1)*40;" ";(y-1)*40
        bulletX(towers) = x : bulletY(towers) = y
        #td.main "addsprite bulletX";x;"Y";y;" bullet; spritexy bulletX";x;"Y";y;" ";(x-1)*20+5;" ";(y-1)*20+1 : #td.main "spritevisible bulletX";x;"Y";y;" off"
    end sub
    sub placeTower6 x, y
        map$=mid$(map$,1,x+(y-1)*20-1) ; "ú" ; mid$(map$, x+(y-1)*20+1)
        towers=towers+1
        towerX(towers)=x
        towerY(towers)=y
        towerSpeed(towers)=6
        towerRange(towers)=3
        towerDamage(towers)=220
        towerLVL(towers) = 6
        towerTime(towers)=100
        if forge = 1 then towerDamage(towers)= 286
        if drapeau = 1 then towerSpeed(towers)= 7
        if viseur = 1 then towerRange(towers)= 4
        #td.main "addsprite towerX";x;"Y";y;" towerF; spritexy towerX";x;"Y";y;" ";(x-1)*40;" ";(y-1)*40
        bulletX(towers) = x : bulletY(towers) = y
        #td.main "addsprite bulletX";x;"Y";y;" bullet; spritexy bulletX";x;"Y";y;" ";(x-1)*40+5;" ";(y-1)*40+1 : #td.main "spritevisible bulletX";x;"Y";y;" off"
    end sub
    sub placeTower7 x, y
        map$=mid$(map$,1,x+(y-1)*20-1) ; "ù" ; mid$(map$, x+(y-1)*20+1)
        towers=towers+1
        towerX(towers)=x
        towerY(towers)=y
        towerSpeed(towers)=7
        towerRange(towers)=3
        towerDamage(towers)=372
        towerLVL(towers) = 7
        towerTime(towers)=100
        if forge = 1 then towerDamage(towers)= 484
        if drapeau = 1 then towerSpeed(towers)= 8
        if viseur = 1 then towerRange(towers)= 4
        #td.main "addsprite towerX";x;"Y";y;" towerG; spritexy towerX";x;"Y";y;" ";(x-1)*40;" ";(y-1)*40
        bulletX(towers) = x : bulletY(towers) = y
        #td.main "addsprite bulletX";x;"Y";y;" bullet; spritexy bulletX";x;"Y";y;" ";(x-1)*20+5;" ";(y-1)*20+1 : #td.main "spritevisible bulletX";x;"Y";y;" off"
    end sub
    sub placeTower8 x, y
        map$=mid$(map$,1,x+(y-1)*20-1) ; "ø" ; mid$(map$, x+(y-1)*20+1)
        towers=towers+1
        towerX(towers)=x
        towerY(towers)=y
        towerSpeed(towers)=7
        towerRange(towers)=3
        towerDamage(towers)=640
        towerLVL(towers) = 8
        towerTime(towers)=100
        if forge = 1 then towerDamage(towers)= 832
        if drapeau = 1 then towerSpeed(towers)= 8
        if viseur = 1 then towerRange(towers)= 4
        #td.main "addsprite towerX";x;"Y";y;" towerH; spritexy towerX";x;"Y";y;" ";(x-1)*40;" ";(y-1)*40
        bulletX(towers) = x : bulletY(towers) = y
        #td.main "addsprite bulletX";x;"Y";y;" bullet; spritexy bulletX";x;"Y";y;" ";(x-1)*20+5;" ";(y-1)*20+1 : #td.main "spritevisible bulletX";x;"Y";y;" off"
    end sub
    sub placeTower9 x, y
        map$=mid$(map$,1,x+(y-1)*20-1) ; "÷" ; mid$(map$, x+(y-1)*20+1)
        towers=towers+1
        towerX(towers)=x
        towerY(towers)=y
        towerSpeed(towers)=7
        towerRange(towers)=4
        towerDamage(towers)=880
        towerLVL(towers) = 9
        towerTime(towers)=100
        if forge = 1 then towerDamage(towers)= 1144
        if drapeau = 1 then towerSpeed(towers)= 8
        if viseur = 1 then towerRange(towers)= 5
        #td.main "addsprite towerX";x;"Y";y;" towerI; spritexy towerX";x;"Y";y;" ";(x-1)*40;" ";(y-1)*40
        bulletX(towers) = x : bulletY(towers) = y
        #td.main "addsprite bulletX";x;"Y";y;" bullet; spritexy bulletX";x;"Y";y;" ";(x-1)*20+5;" ";(y-1)*20+1 : #td.main "spritevisible bulletX";x;"Y";y;" off"
    end sub
    sub placeTower10 x, y
        map$=mid$(map$,1,x+(y-1)*20-1) ; "ö" ; mid$(map$, x+(y-1)*20+1)
        towers=towers+1
        towerX(towers)=x
        towerY(towers)=y
        towerSpeed(towers)=8
        towerRange(towers)=4
        towerDamage(towers)=1100
        towerLVL(towers) = 10
        towerTime(towers)=100
        if forge = 1 then towerDamage(towers)= 1430
        if drapeau = 1 then towerSpeed(towers)= 9
        if viseur = 1 then towerRange(towers)= 5
        #td.main "addsprite towerX";x;"Y";y;" towerJ; spritexy towerX";x;"Y";y;" ";(x-1)*40;" ";(y-1)*40
        bulletX(towers) = x : bulletY(towers) = y
        #td.main "addsprite bulletX";x;"Y";y;" bullet; spritexy bulletX";x;"Y";y;" ";(x-1)*20+5;" ";(y-1)*20+1 : #td.main "spritevisible bulletX";x;"Y";y;" off"
    end sub
    sub placeTower11 x, y
        map$=mid$(map$,1,x+(y-1)*20-1) ; "õ" ; mid$(map$, x+(y-1)*20+1)
        towers=towers+1
        towerX(towers)=x
        towerY(towers)=y
        towerSpeed(towers)=8
        towerRange(towers)=4
        towerDamage(towers)=1500
        towerLVL(towers) = 11
        towerTime(towers)=100
        if forge = 1 then towerDamage(towers)= 1850
        if drapeau = 1 then towerSpeed(towers)= 9
        if viseur = 1 then towerRange(towers)= 5
        #td.main "addsprite towerX";x;"Y";y;" towerK; spritexy towerX";x;"Y";y;" ";(x-1)*40;" ";(y-1)*40
        bulletX(towers) = x : bulletY(towers) = y
        #td.main "addsprite bulletX";x;"Y";y;" bullet; spritexy bulletX";x;"Y";y;" ";(x-1)*20+5;" ";(y-1)*20+1 : #td.main "spritevisible bulletX";x;"Y";y;" off"
    end sub
    sub placeTower12 x, y
        map$=mid$(map$,1,x+(y-1)*20-1) ; "ô" ; mid$(map$, x+(y-1)*20+1)
        towers=towers+1
        towerX(towers)=x
        towerY(towers)=y
        towerSpeed(towers)=9
        towerRange(towers)=4
        towerDamage(towers)=2400
        towerLVL(towers) = 12
        towerTime(towers)=100
        if forge = 1 then towerDamage(towers)= 3120
        if drapeau = 1 then towerSpeed(towers)= 10
        if viseur = 1 then towerRange(towers)= 5
        #td.main "addsprite towerX";x;"Y";y;" towerL; spritexy towerX";x;"Y";y;" ";(x-1)*40;" ";(y-1)*40
        bulletX(towers) = x : bulletY(towers) = y
        #td.main "addsprite bulletX";x;"Y";y;" bullet; spritexy bulletX";x;"Y";y;" ";(x-1)*20+5;" ";(y-1)*20+1 : #td.main "spritevisible bulletX";x;"Y";y;" off"
    end sub
    sub placeTower13 x, y
        map$=mid$(map$,1,x+(y-1)*20-1) ; "î" ; mid$(map$, x+(y-1)*20+1)
        towers=towers+1
        towerX(towers)=x
        towerY(towers)=y
        towerSpeed(towers)=9
        towerRange(towers)=4
        towerDamage(towers)=3900
        towerLVL(towers) = 13
        towerTime(towers)=100
        if forge = 1 then towerDamage(towers)= 5070
        if drapeau = 1 then towerSpeed(towers)= 10
        if viseur = 1 then towerRange(towers)= 5
        #td.main "addsprite towerX";x;"Y";y;" towerM; spritexy towerX";x;"Y";y;" ";(x-1)*40;" ";(y-1)*40
        bulletX(towers) = x : bulletY(towers) = y
        #td.main "addsprite bulletX";x;"Y";y;" bullet; spritexy bulletX";x;"Y";y;" ";(x-1)*20+5;" ";(y-1)*20+1 : #td.main "spritevisible bulletX";x;"Y";y;" off"
    end sub
    sub placeTower14 x, y
        map$=mid$(map$,1,x+(y-1)*20-1) ; "í" ; mid$(map$, x+(y-1)*20+1)
        towers=towers+1
        towerX(towers)=x
        towerY(towers)=y
        towerSpeed(towers)=10
        towerRange(towers)=4
        towerDamage(towers)=6300
        towerLVL(towers) = 14
        towerTime(towers)=100
        if forge = 1 then towerDamage(towers)= 8190
        if drapeau = 1 then towerSpeed(towers)= 11
        if viseur = 1 then towerRange(towers)= 5
        #td.main "addsprite towerX";x;"Y";y;" towerN; spritexy towerX";x;"Y";y;" ";(x-1)*40;" ";(y-1)*40
        bulletX(towers) = x : bulletY(towers) = y
        #td.main "addsprite bulletX";x;"Y";y;" bullet; spritexy bulletX";x;"Y";y;" ";(x-1)*20+5;" ";(y-1)*20+1 : #td.main "spritevisible bulletX";x;"Y";y;" off"
    end sub
    sub placeTower15 x, y
        map$=mid$(map$,1,x+(y-1)*20-1) ; "ì" ; mid$(map$, x+(y-1)*20+1)
        towers=towers+1
        towerX(towers)=x
        towerY(towers)=y
        towerSpeed(towers)=10
        towerRange(towers)=5
        towerDamage(towers)=8000
        towerLVL(towers) = 15
        towerTime(towers)=100
        if forge = 1 then towerDamage(towers)= 10400
        if drapeau = 1 then towerSpeed(towers)= 11
        if viseur = 1 then towerRange(towers)= 6
        #td.main "addsprite towerX";x;"Y";y;" towerO; spritexy towerX";x;"Y";y;" ";(x-1)*40;" ";(y-1)*40
        bulletX(towers) = x : bulletY(towers) = y
        #td.main "addsprite bulletX";x;"Y";y;" bullet; spritexy bulletX";x;"Y";y;" ";(x-1)*20+5;" ";(y-1)*20+1 : #td.main "spritevisible bulletX";x;"Y";y;" off"
    end sub
    sub placeTower16 x, y
        map$=mid$(map$,1,x+(y-1)*20-1) ; "ñ" ; mid$(map$, x+(y-1)*20+1)
        towers=towers+1
        towerX(towers)=x
        towerY(towers)=y
        towerSpeed(towers)=10
        towerRange(towers)=5
        towerDamage(towers)=11000
        towerLVL(towers) = 16
        towerTime(towers)=100
        if forge = 1 then towerDamage(towers)= 14300
        if drapeau = 1 then towerSpeed(towers)= 11
        if viseur = 1 then towerRange(towers)= 6
        #td.main "addsprite towerX";x;"Y";y;" towerP; spritexy towerX";x;"Y";y;" ";(x-1)*40;" ";(y-1)*40
        bulletX(towers) = x : bulletY(towers) = y
        #td.main "addsprite bulletX";x;"Y";y;" bullet; spritexy bulletX";x;"Y";y;" ";(x-1)*20+5;" ";(y-1)*20+1 : #td.main "spritevisible bulletX";x;"Y";y;" off"
    end sub
    sub placeTower17 x, y
        map$=mid$(map$,1,x+(y-1)*20-1) ; "ò" ; mid$(map$, x+(y-1)*20+1)
        towers=towers+1
        towerX(towers)=x
        towerY(towers)=y
        towerSpeed(towers)=11
        towerRange(towers)=5
        towerDamage(towers)=15000
        towerLVL(towers) = 17
        towerTime(towers)=100
        if forge = 1 then towerDamage(towers)= 18500
        if drapeau = 1 then towerSpeed(towers)= 12
        if viseur = 1 then towerRange(towers)= 6
        #td.main "addsprite towerX";x;"Y";y;" towerQ; spritexy towerX";x;"Y";y;" ";(x-1)*40;" ";(y-1)*40
        bulletX(towers) = x : bulletY(towers) = y
        #td.main "addsprite bulletX";x;"Y";y;" bullet; spritexy bulletX";x;"Y";y;" ";(x-1)*20+5;" ";(y-1)*20+1 : #td.main "spritevisible bulletX";x;"Y";y;" off"
    end sub
    sub placeTower18 x, y
        map$=mid$(map$,1,x+(y-1)*20-1) ; "¶" ; mid$(map$, x+(y-1)*20+1)
        towers=towers+1
        towerX(towers)=x
        towerY(towers)=y
        towerSpeed(towers)=11
        towerRange(towers)=6
        towerDamage(towers)=20000
        towerLVL(towers) = 18
        towerTime(towers)=100
        if forge = 1 then towerDamage(towers)= 26000
        if drapeau = 1 then towerSpeed(towers)= 12
        if viseur = 1 then towerRange(towers)= 7
        #td.main "addsprite towerX";x;"Y";y;" towerR; spritexy towerX";x;"Y";y;" ";(x-1)*40;" ";(y-1)*40
        bulletX(towers) = x : bulletY(towers) = y
        #td.main "addsprite bulletX";x;"Y";y;" bullet; spritexy bulletX";x;"Y";y;" ";(x-1)*20+5;" ";(y-1)*20+1 : #td.main "spritevisible bulletX";x;"Y";y;" off"
    end sub
    sub placeTower19 x, y
        map$=mid$(map$,1,x+(y-1)*20-1) ; "ß" ; mid$(map$, x+(y-1)*20+1)
        towers=towers+1
        towerX(towers)=x
        towerY(towers)=y
        towerSpeed(towers)=12
        towerRange(towers)=6
        towerDamage(towers)=25000
        towerLVL(towers) = 19
        towerTime(towers)=100
        if forge = 1 then towerDamage(towers)= 32500
        if drapeau = 1 then towerSpeed(towers)= 13
        if viseur = 1 then towerRange(towers)= 7
        #td.main "addsprite towerX";x;"Y";y;" towerS; spritexy towerX";x;"Y";y;" ";(x-1)*40;" ";(y-1)*40
        bulletX(towers) = x : bulletY(towers) = y
        #td.main "addsprite bulletX";x;"Y";y;" bullet; spritexy bulletX";x;"Y";y;" ";(x-1)*20+5;" ";(y-1)*20+1 : #td.main "spritevisible bulletX";x;"Y";y;" off"
    end sub
    sub placeTower20 x, y
        map$=mid$(map$,1,x+(y-1)*20-1) ; "©" ; mid$(map$, x+(y-1)*20+1)
        towers=towers+1
        towerX(towers)=x
        towerY(towers)=y
        towerSpeed(towers)=13
        towerRange(towers)=7
        towerDamage(towers)=40000
        towerLVL(towers) = 20
        towerTime(towers)=100
        if forge = 1 then towerDamage(towers)= 52000
        if drapeau = 1 then towerSpeed(towers)= 14
        if viseur = 1 then towerRange(towers)= 8
        #td.main "addsprite towerX";x;"Y";y;" towerT; spritexy towerX";x;"Y";y;" ";(x-1)*40;" ";(y-1)*40
        bulletX(towers) = x : bulletY(towers) = y
        #td.main "addsprite bulletX";x;"Y";y;" bullet; spritexy bulletX";x;"Y";y;" ";(x-1)*20+5;" ";(y-1)*20+1 : #td.main "spritevisible bulletX";x;"Y";y;" off"
    end sub


    [quit]
    GameActivation = 0
    pass$ = "0"
    open "secu.txt" for output as #secu
    print #secu, pass$
    close #secu
    gosub [print]
    if help = 1 then close #help
    if GameOver = 0 then close #td
    end

    [bruitage]
   ' actionBUTTON = 1
    if bruitage = 0 then
        bruitage = 1
        print #td.b9, "hide"
        print #td.b4, "show"
        if pause = 0 then goto [boucle]
        if pause = 1 then wait
    end if
    [bruitage2]
    if bruitage = 1 then
        bruitage = 0
        print #td.b9, "show"
        print #td.b4, "hide"
        if pause = 0 then goto [boucle]
        if pause = 1 then wait
    end if
    wait

    Sub Sleep ms
        CallDLL #kernel32, "Sleep",_
        ms as long,_
        ret as void
    End Sub

    function fileExist(dir$,file$)
        dim info$(10, 10)
        files dir$,file$, info$(
        if val(info$(0, 0)) > 0 then
            fileExist = 1
        else
            fileExist = 0
        end if
    end function

    sub AddToolTip cHndl, hWnd, Text$ 
        TOOLINFO.uId.struct = cHndl
        TOOLINFO.lpszText.struct = Text$
        CallDLL #user32, "SendMessageA",hWnd As long,1028 As long, _
        0 As long,TOOLINFO as ptr,ret As long
    end sub

    Function CreateTooltip(hMain)
        Struct TOOLINFO, _
        cbSize As long, _
        uFlags As long, _
        hwnd As long, _
        uId As long, _
        rectLeft As long, _
        rectTop As long, _
        rectRight As long, _
        rectBottom As long, _
        hinst As long, _
        lpszText As ptr
        CallDLL #comctl32,"InitCommonControlsEx", _
        ret As void
        TOOLINFO.cbSize.struct = Len(TOOLINFO.struct)
        TOOLINFO.uFlags.struct = flags Or 17 'TTF_IDISHWND Or TTF_SUBCLASS
        TOOLINFO.hwnd.struct = hMain
        CallDLL #user32,"CreateWindowExA",_
        0 As long, _
        "tooltips_class32" As ptr, _
        0 As long, style As long, _
        _CW_USEDEFAULT As long, _
        _CW_USEDEFAULT As long, _
        _CW_USEDEFAULT As long, _
        _CW_USEDEFAULT As long, _
        hMain As long, _
        0 As long, _
        0 as long, _
        0 As long, _
        CreateTooltip As Long
    end function

    sub RemooveOldTower x, y
    if UPGRADE = 0 then towers = 0 : map$=mid$(map$,1,x+(y-1)*20-1) ; " " ; mid$(map$, x+(y-1)*20+1)
    if UPGRADE = 1 then towerOLD = towers
    for x = 1 to 20
        for y = 1 to 14
            char$ = mid$(map$, x+(y-1)*20, 1)
            select case char$
                case "ÿ"
                    call placeTower1 x, y
                case "þ"
                    call placeTower2 x, y
                case "ý"
                    call placeTower3 x, y
                case "ü"
                    call placeTower4 x, y
                case "û"
                   call placeTower5 x, y
                case "ú"
                  call placeTower6 x, y
                case "ù"
                  call placeTower7 x, y
                case "ø"
                  call placeTower8 x, y
                case "÷"
                   call placeTower9 x, y
                case "ö"
                   call placeTower10 x, y
                case "õ"
                   call placeTower11 x, y
                case "ô"
                  call placeTower12 x, y
                case "î"
                  call placeTower13 x, y
                case "í"
                  call placeTower14 x, y
                case "ì"
                  call placeTower15 x, y
                case "ñ"
                  call placeTower16 x, y
                case "ò"
                  call placeTower17 x, y
                case "¶"
                  call placeTower18 x, y
                case "ß"
                  call placeTower19 x, y
                case "©"
                  call placeTower20 x, y
            end select
        next y
    next x
    if UPGRADE = 1 then towers = towers - towerOLD
    end sub

    function mcisend$(s$)
        buffer$=space$(256)+chr$(0)
        calldll #winmm,"mciSendStringA",s$ as ptr,buffer$ as ptr,_
                256 as long,0 as long,r as long
        if r>0 then
            mcisend$="error r="+str$(r)+" "+buffer$
        else
            mcisend$=buffer$
        end if
    end function
