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

nomainwin
build2$ = "2014-2026" : versionGame$ = "6.0" : start = 1 : help = 0 : version = 1 : factor = 1 : FPSmonitor = 0
iconDUmenu$ = "" : iconDUmenu2$ = "" : players$ = "" : NAMEplayers2$ = "" : labels1$ = "" : labels2$ = "" : labels3$ = "" : labels4$ = ""
sprites1$ = "perso1d perso2d perso3d perso4d perso1s perso2s perso3s perso4s perso1q perso2q perso3q perso4q perso1z perso2z perso3z perso4z E1 E2 E3 cata1 cata2 cata3 cata4 bullet persoDEAD ED1 atk"
sprites2$ = "nuage1 nuage2 nuage3 nuage4 OPTIONS ABOUT SAVE main UP HEAL HEAL2 sav load HELP quit fps music panteon"
for s = 1 to 27
    loadbmp word$(sprites1$,s), "data\perso\"+word$(sprites1$,s)+".bmp"
next
for s = 1 to 18
    loadbmp word$(sprites2$,s), "data\main\"+word$(sprites2$,s)+".bmp"
next
f$ = chr$(34) + "data\music\main.mp3" + chr$(34)
r$ = mcisend$("open " + f$ + " type mpegvideo alias main")
dim MoveE(100), PvE(100), Ex(100), Ey(100), securPoint(100)
dim scores(20), nameScores$(20)

[INI]
timer 0
xp = 0 : xpTotal = 50 : lvl = 1 : Score = 0 : main = 0 : Gold = 1000 : waveNumber = 1
HEROpv = 200 : HEROatk = 15 : HEROdef = 2 : HEROpvTOTAL = 200 : regen = 1
regenCompteur = 0 : regenCompteurLimite = 20 : regenCompteur2 = 0 : regenCompteur2Limite = 10
castlePVtotal = 5000 : castlePV = castlePVtotal : castleArmor = 6 : castleREGEN = 5
lvlHPhero = 1 : lvlARMORhero = 1 : lvlATKhero = 1 : lvlREGENhero = 1
perso1dx = 200 : perso1dy = 500 : persoDEADy = -200 : persoDEADx = -200
Movecata1 = 0 : HPcata1 = 0 : securPointcata1 = 0
cata1x = -200 : cata1y = -200 : bulletx = -200 : bullety = -200
for i = 1 to 100
    MoveE(i) = 0 : PvE(i) = 0 : Ex(i) = -200 : Ey(i) = -200 : securPoint(i) = 0
next
if start = 1 then goto [ini2]
if menuGame = 1 then close #menuGame
menuGame = 0

[ini2]
timer 0
start = 2 : main = 0 : WindowWidth = 1300 : WindowHeight = 750 : UpperLeftX = int((DisplayWidth-WindowWidth)/2) : UpperLeftY = int((DisplayHeight-WindowHeight)/2)
graphicbox #debut.map, 0, 0, 1300, 750
open "" for window_nf as #debut
#debut, "trapclose [quit]"
#debut.map, "down;fill white"
#debut.map, "when leftButtonDown [SimpleClick1]"
#debut.map, "font Times New Roman 50 bold; color black;backcolor white; place 350 160;\";"          EMPIRE\CASTLE DEFENSE"
#debut.map, "font Times New Roman 25; color black;backcolor white"
if version = 1 then #debut.map, "place 495 382;\";"NOUVELLE PARTIE"
if version = 2 then #debut.map, "place 500 382;\";"START NEW GAME"
#debut.map, "font Times New Roman 12; color black;backcolor white; place 570 650;\";"Production 2014-2026"
#debut.map, "place 525 680;\";"Liberty Basic 4.51 Professional license"
#debut.map, "place 617 553;\";"Scores"
#debut.map, "place 605 270;\";"Version ";versionGame$
#debut.map, "font Times New Roman 7; color black"
#debut.map, "drawbmp OPTIONS 540 470; drawbmp SAVE 620 470; drawbmp ABOUT 700 470; drawbmp panteon 605 565"
print #debut.map, "color black;size 1"
print #debut.map, "line 450 335 835 335"
print #debut.map, "line 450 405 835 405"
print #debut.map, "line 450 335 450 405"
print #debut.map, "line 835 335 835 405"
#debut.map, "flush"
if Setting = 2 then goto [setting]
wait

[SimpleClick1]
mX = MouseX : mY = MouseY
if mX>440 and mX<840 and mY>320 and mY<420 then close #debut : goto [Game]
if mX>540 and mX<580 and mY>470 and mY<505 then goto [setting]
if mX>620 and mX<660 and mY>470 and mY<505 then goto [load]
if mX>700 and mX<740 and mY>470 and mY<505 then goto [about]
if mX>605 and mX<675 and mY>565 and mY<600 then goto [score]
wait

[score]
WindowWidth = 450 : WindowHeight = 420 : UpperLeftX = int((DisplayWidth-WindowWidth)/2) : UpperLeftY = int((DisplayHeight-WindowHeight)/2)
if pant = 1 then close #pant
pant = 1
open "data\score.sys" for input as #save
for i = 1 to 20
    input #save, scores(i)
next
for i = 1 to 20
    input #save, nameScores$(i)
next
close #save
graphicbox #pant.pant, 0, 0, 450, 420
open "" for window_nf as #pant
#pant, "trapclose [about3]"
#pant.pant, "font Times New Roman 12 bold; color black;backcolor white"
if version = 1 then #pant.pant, "place 20 20;\";"Panthéon des meilleurs Scores"
if version = 2 then #pant.pant, "place 20 20;\";"Pantheon : Best Scores"
#pant.pant, "font Times New Roman 9; color blue;backcolor white"
yPos = 50 : NAMEplayers2$ = "First Second Third"
if version = 1 then NAMEplayers2$ = "Première Seconde Troisième"
for i = 1 to 3
    players$ = word$(NAMEplayers2$, i)
    if version = 1 then players$ = players$ + " place"
    if version = 2 then players$ = players$ + " place"
    #pant.pant, "place 20 ";yPos;";\";" " + players$ + "  :  ";scores(i);" - ";nameScores$(i) : yPos = yPos + 20
next
#pant.pant, "font Times New Roman 9; color red;backcolor white"
yPos = 125
for i = 4 to 20
    #pant.pant, "place 20 ";yPos;";\";"# ";i;"  :  ";scores(i);" - ";nameScores$(i) : yPos = yPos + 15
next
wait

[about]
WindowWidth = 450 : WindowHeight = 120 : UpperLeftX = int((DisplayWidth-WindowWidth)/2) : UpperLeftY = int((DisplayHeight-WindowHeight)/2)
if about = 1 then close #about
about = 1
txt$ = "Empire : Castle defense ® " + build2$ + " par  ALEXANDRE LOMUTO                    Musique : Airship Thunderchild par Otto Halmen"
if version = 2 then txt$ = "Empire : Castle defense ® " + build2$ + " by  ALEXANDRE LOMUTO                    Music : Airship Thunderchild by Otto Halmen"
statictext #about.txt, txt$, 75, 32, 330, 30
button #about, "Fermer", [about2], LR, 265, 10, 120, 25
open "" for window_popup as #about
#about, "trapclose [about2]"
wait

[about2] close #about : about = 0 : wait
[about3] close #pant : pant = 0 : wait

[setting]
if Setting = 1 then close #setting
Setting = 1 : WindowWidth = 270 : WindowHeight = 125 : UpperLeftX = int((DisplayWidth-WindowWidth)/2) : UpperLeftY = int((DisplayHeight-WindowHeight)/2)
checkbox #setting.cb1, "Fr", [LangueFR], [LangueFR], 130, 10, 40, 20
checkbox #setting.cb2, "Eng", [LangueENG], [LangueENG], 190, 10, 40, 20
checkbox #setting.cb3, "On", [musicOn], [musicOff], 130, 30, 40, 20
checkbox #setting.cb4, "Off", [musicOff], [musicOn], 190, 30, 40, 20
checkbox #setting.cb5, "On", [RageModeOn], [RageModeOff], 130, 50, 40, 20
checkbox #setting.cb6, "Off", [RageModeOff], [RageModeOn], 190, 50, 40, 20
checkbox #setting.cb7, "On", [FPSOn], [FPSOff], 130, 70, 40, 20
checkbox #setting.cb8, "Off", [FPSOff], [FPSOn], 190, 70, 40, 20
labels1$ = "Langue Language" : labels2$ = "Musique Music" : labels3$ = "Mode_rage Rage_Mode" : labels4$ = "Affichage_FPS FPS_Monitor"
statictext #setting, word$(labels1$, version), 10, 10, 60, 20
statictext #setting, word$(labels2$, version), 10, 30, 60, 20
statictext #setting, word$(labels3$, 1 + version), 10, 50, 100, 20
statictext #setting, word$(labels4$, 1 + (version-1)*2), 10, 70, 100, 20
Open "" for window_nf As #setting
if version = 1 then print #setting.cb1, "set" : print #setting.cb2, "reset"
if version = 2 then print #setting.cb2, "set" : print #setting.cb1, "reset"
if music = 1 then print #setting.cb3, "set" : print #setting.cb4, "reset"
if music = 0 then print #setting.cb4, "set" : print #setting.cb3, "reset"
if factor = 10 then print #setting.cb5, "set" : print #setting.cb6, "reset"
if factor = 1 then print #setting.cb6, "set" : print #setting.cb5, "reset"
if FPSmonitor = 1 then print #setting.cb7, "set" : print #setting.cb8, "reset"
if FPSmonitor = 0 then print #setting.cb8, "set" : print #setting.cb7, "reset"
#setting, "trapclose [quitSetting]"
#setting, "font Times New Roman 10 bold; color black"
wait

[FPSOn] FPSmonitor = 1 : print #setting.cb7, "set" : print #setting.cb8, "reset" : wait
[FPSOff] FPSmonitor = 0 : print #setting.cb8, "set" : print #setting.cb7, "reset" : wait
[musicOn] music = 1 : print #setting.cb3, "set" : print #setting.cb4, "reset" : goto [iniMUSIC2]
[musicOff] music = 0 : print #setting.cb4, "set" : print #setting.cb3, "reset" : goto [iniMUSIC]
[RageModeOn] factor = 10 : print #setting.cb5, "set" : print #setting.cb6, "reset" : wait
[RageModeOff] factor = 1 : print #setting.cb6, "set" : print #setting.cb5, "reset" : wait

[LangueFR]
version = 1 : Setting = 0 : close #setting
if main = 0 then close #debut : goto [ini2]
if main = 1 then close #main : goto [Game]

[LangueENG]
version = 2 : Setting = 0 : close #setting
if main = 0 then close #debut : goto [ini2]
if main = 1 then close #main : goto [Game]

[GameINI]
timer 0
if help = 1 then close #ini
help = 1 : WindowWidth = 450 : WindowHeight = 350 : UpperLeftX = int((DisplayWidth-WindowWidth)/2) : UpperLeftY = int((DisplayHeight-WindowHeight)/2)
if version = 1 then
   statictext #ini.titre, "Contrôle et Aide :", 20, 20, 200, 15
   statictext #ini.titre2, "But du jeu :", 20, 130, 200, 15
   txt1$ = "Utilisez la souris de votre ordinateur pour vous déplacer. Clickez sur la zone que vous souhaité viser et votre personnage se déplacera la-bas. Une fois en contact avec les ennemis vos attaques se déclenche directement. Vous recevrez aussi leurs attaques."
   txt2$ = "Allez toujours plus loin ! Combattez jusqu'à que votre personnage n'est plus de force ou que vos remparts tombent. Plus vous allez loin et plus votre scoore augmentera. Défendez vos foritifications en tuant tous vos ennemis. De nombreuses améliorations vous aiderons dans votre destinée!"
else
   statictext #ini.titre, "Control and Help", 90, 20, 200, 15
   statictext #ini.titre2, "Goal :", 20, 130, 200, 15
   txt1$ = "You just have to use your mouse and click on ennemies for attack and kill it."
   txt2$ = "Kill all the enemies before your castle has 0 points of life. How? Your hero can hit points of damage by attacking the enemy (darken over several times! Each colision is a clash that hit an attack). Use it to kill your enemies. Good luck!"
end if
statictext #ini.txt, txt1$, 20, 40, 400, 60
statictext #ini.txt, txt2$, 20, 150, 400, 80
open "" for window_nf as #ini
#ini, "trapclose [quitHELP]"
#ini, "font Times New Roman 10 bold; color black"
print #ini.titre, "!font Times New Roman 10 bold"
print #ini.titre2, "!font Times New Roman 10 bold"
wait

[Game]
timer 0
WindowWidth = 1300 : WindowHeight = 808 : main = 1 : UpperLeftX = int((DisplayWidth-WindowWidth)/2) : UpperLeftY = int((DisplayHeight-WindowHeight)/2)
graphicbox #main.menu, 0, 0, 1300, 30
graphicbox #main.map, 0, 30, 1300, 750
open "" for window_nf as #main
#main, "trapclose [quit]"
#main.map, "down;setfocus; when leftButtonDown [SimpleClickStart]"
#main.menu, "fill white;when leftButtonDown [SimpleClickStart2]"
#main.map, "drawbmp main 0 0; background main"
gosub [loadSprites]
iconDUmenu2$ = "UP HEAL UP HEAL2 music sav load HELP quit fps" : xPos = 5
for i = 1 to 10
    iconDUmenu$ = word$(iconDUmenu2$, i) : #main.menu, "drawbmp ";iconDUmenu$;" ";xPos;" ";3
    if i = 1 then xPos = 30
    if i = 2 then xPos = 230
    if i = 3 then xPos = 255
    if i = 4 then xPos = 1010
    if i >= 5 then xPos = xPos + 30
next
#main.map, "addsprite persoDEAD persoDEAD; addsprite perso1d perso2d perso3d perso4d; addsprite perso1q perso2q perso3q perso4q; addsprite perso1s perso2s perso3s perso4s; addsprite perso1z perso2z perso3z perso4z"
#main.map, "addsprite E1 E2 E3; addsprite cata1 cata1; addsprite cata2 cata2; addsprite cata3 cata3; addsprite cata4 cata4; addsprite bullet bullet"
#main.map, "addsprite ED1 ED1; addsprite nuage1 nuage1; addsprite nuage2 nuage2; addsprite nuage3 nuage3; addsprite nuage4 nuage4; addsprite atk atk"
for i = 1 to 99
    #main.map, "addsprite E1";i;" E2 E3 E1; addsprite ED1";i;" ED1"
next
#main.map, "spritexy perso1d ";perso1dx;" ";perso1dy
#main.map, "spritexy persoDEAD ";persoDEADx;" ";persoDEADy
perso1zx = perso1dx : perso1zy = perso1dy : perso1qx = perso1dx : perso1qy = perso1dy : perso1sx = perso1dx : perso1sy = perso1dy
#main.map, "spritexy perso1z ";perso1zx;" ";perso1zy
#main.map, "spritexy perso1q ";perso1qx;" ";perso1qy
#main.map, "spritexy perso1s ";perso1sx;" ";perso1sy
nuage1x = -20 : nuage1y = 170 : nuage2x = -120 : nuage2y = 60 : nuage3x = 120 : nuage3y = 155 : nuage4x = 450 : nuage4y = 130
#main.map, "spritexy nuage1 ";nuage1x;" ";nuage1y;"; spritexy nuage2 ";nuage2x;" ";nuage2y;"; spritexy nuage3 ";nuage3x;" ";nuage3y;"; spritexy nuage4 ";nuage4x;" ";nuage4y
#main.map, "spritexy cata1 ";cata1x;" ";cata1y
#main.map, "spritexy cata2 -200 -200; spritexy cata3 -200 -200; spritexy cata4 -200 -200"
#main.map, "spritexy bullet ";bulletx;" ";bullety
#main.map, "spritexy ED1 -200 -200; spritexy E1 -200 -200; spritexy atk -200 -200"
for i = 1 to 99
    #main.map, "spritexy E1";i;" ";Ex(i);" ";Ey(i);"; spritexy ED1";i;" -200 -200"
next
#main.map, "SpriteVisible perso1z off; SpriteVisible perso1q off; SpriteVisible perso1s off; SpriteVisible persoDEAD off; SpriteVisible bullet off; SpriteVisible cata1 off; SpriteVisible cata2 off; SpriteVisible cata3 off; SpriteVisible cata4 off; SpriteVisible atk off"
#main.map, "font Times New Roman 10; color black"
#main.menu, "font Times New Roman 10; color black"
#main.map, "drawsprites"
#main.menu, "color black;size 1"
#main.menu, "line 950 0 950 50"
#main.menu, "line 650 0 650 50"
#main.menu, "line 480 0 480 50"
#main.menu, "line 220 0 220 50"
#main.menu, "flush"
#main.map, "flush"
#main.menu, "font Times New Roman 8 bold; color black;backcolor white"
startSECURITY = 1
wait

[SimpleClickStart]
timer 0
mX = MouseX : mY = MouseY
if mY < 30 then wait
if upgradeHERO = 1 then close #upgradeHERO : upgradeHERO = 0
if upgradeCASTLE = 1 then close #upgradeCASTLE : upgradeCASTLE = 0
if mX > perso1dx then goto [marcheDROITE2]
if mX < perso1qx then goto [marcheGAUCHE2]
if mY < perso1zy then goto [marcheHAUT2]
if mY > perso1sy then goto [marcheBAS2]
timer 10, [Eq]
wait

[SimpleClickStart2]
mX = MouseX : mY = MouseY
if mX > 1010 and mX < 1035 and mY > 2 and mY < 25 then
    if MusicSELECT = 0 then goto [iniMUSIC2]
    goto [iniMUSIC]
end if
if mX > 5 and mX < 28 and mY > 3 and mY < 25 then goto [upgradeCASTLE]
if mX > 30 and mX < 53 and mY > 3 and mY < 25 then goto [repairCastle]
if mX > 230 and mX < 255 and mY > 3 and mY < 25 then goto [upgradeHERO]
if mX > 256 and mX < 281 and mY > 3 and mY < 25 then goto [repairHero]
if mX > 1130 and mX < 1153 and mY > 3 and mY < 25 then goto [quitToMenu]
if mX > 1040 and mX < 1063 and mY > 3 and mY < 25 then goto [save]
if mX > 1070 and mX < 1093 and mY > 3 and mY < 25 then goto [loadS]
if mX > 1100 and mX < 1123 and mY > 3 and mY < 25 then goto [GameINI]
if mX > 1160 and mX < 1183 and mY > 3 and mY < 25 then FPSmonitor = 1 - FPSmonitor : wait
wait

[repairCastle]
timer 0
cost = int(waveNumber*200)
msg1$ = "Vous n'avez pas asser d'or pour réparer vos fortifications."
msg2$ = "Vos fortifications n'ont pas besoin d'être réparées !"
msg3$ = "Réparations effectuées"
if version = 2 then msg1$ = "You dont have enought gold for repair castle." : msg2$ = "Your castle is full life, you dont need to repair !" : msg3$ = "Castle repair"
if castlePV = castlePVtotal then notice " " + chr$(13) + msg2$ + " (" + str$(cost) + ")" : wait
if Gold < cost then notice " " + chr$(13) + msg1$ + " (" + str$(cost) + ")" : wait
Gold = Gold - cost : castlePV = castlePVtotal : notice " " + chr$(13) + msg3$
timer 10, [Eq]
wait

[repairHero]
timer 0
cost = int(waveNumber*100)
msg1$ = "Vous n'avez pas asser d'or pour vous soigner."
msg2$ = "Votre héro est en bonne santé !"
msg3$ = "Soins effectués"
if version = 2 then msg1$ = "You dont have enought gold." : msg2$ = "Your character is full life, you dont need heal!" : msg3$ = "Full heal"
if HEROpv = HEROpvTOTAL then notice " " + chr$(13) + msg2$ + " (" + str$(cost) + ")" : wait
if Gold < cost then notice " " + chr$(13) + msg1$ + " (" + str$(cost) + ")" : wait
Gold = Gold - cost : HEROpv = HEROpvTOTAL : notice " " + chr$(13) + msg3$
timer 10, [Eq]
wait

[quitToMenu]
timer 0
msg$ = "Voulez vous quitter la partie et revenir au menu principal ?"
if version = 2 then msg$ = "Would you like to return to main menu ?"
confirm msg$; confirm$
if confirm$ = "no" then timer 10, [Eq] : wait
close #main : goto [INI]

[addTOscoore]
close #main
WindowWidth = 250 : WindowHeight = 160 : UpperLeftX = int((DisplayWidth-WindowWidth)/2) : UpperLeftY = int((DisplayHeight-WindowHeight)/2) : BackgroundColor$ = "white" : ForegroundColor$ = "black"
graphicbox #score.map, 0, 0, WindowWidth, WindowHeight
textbox #score.login, 20, 50, 200, 20
button #score.default, "VALIDER", [addTOscoore2], UL, 80, 85, 80, 25
open "" for dialog_nf as #score
print #score, "trapclose [addTOscoore2]"
print #score.map, "down;fill white;font Times Times New Roman 9"
print #score.map, "place 50 35 ;\"; "Indiquez votre nom : "
wait

[addTOscoore2]
print #score.login, "!contents? namePLAYER$"
close #score
open "data\score.sys" for input as #save
for i = 1 to 20
    input #save, scores(i)
next
for i = 1 to 20
    input #save, nameScores$(i)
next
close #save
for i = 1 to 20
    if Score >= scores(i) then
        for j = 20 to i+1 step -1
            scores(j) = scores(j-1) : nameScores$(j) = nameScores$(j-1)
        next
        scores(i) = Score : nameScores$(i) = namePLAYER$
        exit for
    end if
next
open "data\score.sys" for output as #save
for i = 1 to 20
    print #save, scores(i)
next
for i = 1 to 20
    print #save, nameScores$(i)
next
close #save
goto [INI]

[save]
timer 0
open "data\save.ini" for output as #save
print #save, version
print #save, xp
print #save, xpTotal
print #save, lvl
print #save, factor
print #save, Score
print #save, Gold
print #save, waveNumber
print #save, HEROpv
print #save, HEROpvTOTAL
print #save, HEROatk
print #save, HEROdef
print #save, regen
print #save, castlePVtotal
print #save, castlePV
print #save, castleArmor
print #save, castleREGEN
print #save, lvlARMORhero
print #save, lvlREGENhero
print #save, lvlATKhero
print #save, lvlHPhero
print #save, UnitsE
close #save
msg$ = "Partie sauvegardée !"
if version = 2 then msg$ = "Game saved !"
notice " " + chr$(13) + msg$ : wait

[loadS]
timer 0
msg$ = "Voulez vous charger la partie enregistrée ?"
if version = 2 then msg$ = "Would you like to load saved game ?"
confirm msg$; confirm$
if confirm$ = "no" then wait
if fileExist("", "data\save.ini") = 0 then
    msg$ = "Vous n'avez aucune sauvegarde d'enregistrée !"
    if version = 2 then msg$ = "You have no backup saved!"
    notice " " + chr$(13) + msg$
    wait
end if
close #main
goto [loading]

[load]
timer 0
msg$ = "Voulez vous charger la partie enregistrée ?"
if version = 2 then msg$ = "Would you like to load saved game ?"
confirm msg$; confirm$
if confirm$ = "no" then wait
if fileExist("", "data\save.ini") = 0 then
    msg$ = "Vous n'avez aucune sauvegarde d'enregistrée !"
    if version = 2 then msg$ = "You have no backup saved!"
    notice " " + chr$(13) + msg$
    wait
end if
close #debut

[loading]
open "data\save.ini" for input as #save
input #save, version
input #save, xp
input #save, xpTotal
input #save, lvl
input #save, factor
input #save, Score
input #save, Gold
input #save, waveNumber
input #save, HEROpv
input #save, HEROpvTOTAL
input #save, HEROatk
input #save, HEROdef
input #save, regen
input #save, castlePVtotal
input #save, castlePV
input #save, castleArmor
input #save, castleREGEN
input #save, lvlARMORhero
input #save, lvlREGENhero
input #save, lvlATKhero
input #save, lvlHPhero
input #save, UnitsE
close #save
goto [Game]

[lvlUPhero]
lvl = lvl + 1
xpTotal = xpTotal + int(xpTotal/2 + int(25*waveNumber))
HEROpvTOTAL = HEROpvTOTAL + int(rnd(1)*(15*waveNumber)+1)
HEROpv = HEROpvTOTAL
HEROatk = HEROatk + int(rnd(1)*(5*waveNumber)+1)
HEROdef = HEROdef + int(rnd(1)*waveNumber)
regen = regen + waveNumber
return

[securPoints]
UnitsE = UnitsE - 1
Gold = Gold + int((rnd(1)*30+1)*waveNumber)
Score = Score + int(10*waveNumber)
xp = xp + int((rnd(1)*30+1)*waveNumber)
if xp > xpTotal then gosub [lvlUPhero]
return

[colisions]
dommage = int((rnd(1)*int(HEROatk+1))-defE)
dommageE = int((rnd(1)*int(atkE+1))-HEROdef/2)
if dommageE < 0 then dommageE = 0
if dommage < 0 then dommage = 0
for i = 1 to 100
    if MoveE(i) > 0 then
        if int(Ex(i) - perso1dx) < 15 and int(Ex(i) - perso1dx) > -15 then
            if int(Ey(i) - perso1dy) < 10 and int(Ey(i) - perso1dy) > -10 then
                PvE(i) = int(PvE(i) - dommage)
                HEROpv = int(HEROpv - dommageE)
                actiVtimingCounter = 1
                #main.map, "spritexy atk ";perso1dx;" ";perso1dy;"; SpriteVisible atk on"
                if PvE(i) <= 0 then
                    #main.map, "SpriteVisible E1";i;" off" : MoveE(i) = 0
                    if securPoint(i) = 0 then gosub [securPoints] : securPoint(i) = 1
                end if
                #main.map, "spritetofront atk"
            end if
        end if
    end if
next
if Movecata1 > 0 then
    if perso1dx < cata1x+80 and perso1dx > cata1x then
        if perso1dy < cata1y+40 and perso1dy > cata1y-20 then
            HPcata1 = int(HPcata1 - HEROatk)
            if HPcata1 <= 0 then
                #main.map, "SpriteVisible cata3 off" : Movecata1 = 0
                if securPointcata1 = 0 then gosub [securPoints] : securPointcata1 = 1
            end if
        end if
    end if
end if
return

[txtREFRESH]
if version = 1 then
    #main.menu, "place 60 18;\";"Fortifications : ";str$(castlePV);"    "
    #main.menu, "place 290 11;\";"Niveau : ";str$(lvl);"   -   ";str$(xp);" / ";str$(xpTotal)
    #main.menu, "place 290 24;\";"Santé : ";str$(HEROpv);" / ";str$(HEROpvTOTAL);"    "
    #main.menu, "place 500 11;\";"Vague : ";str$(waveNumber);"    "
    #main.menu, "place 500 24;\";"Ennemis restants : ";str$(UnitsE);"    "
    #main.menu, "place 670 24;\";"Votre OR : ";str$(Gold);"    "
else
    #main.menu, "place 60 18;\";"Fortifications : ";str$(castlePV);"    "
    #main.menu, "place 290 12;\";"Level : ";str$(lvl);"   -   ";str$(xp);" / ";str$(xpTotal)
    #main.menu, "place 290 24;\";"Heal : ";str$(HEROpv);" / ";str$(HEROpvTOTAL);"    "
    #main.menu, "place 500 12;\";"Wave : ";str$(waveNumber);"    "
    #main.menu, "place 500 24;\";"Ennemies alive : ";str$(UnitsE);"    "
    #main.menu, "place 670 24;\";"Gold : ";str$(Gold);"    "
end if
#main.menu, "place 670 11;\";"Score : ";str$(Score);"    "
if FPSmonitor = 1 then
    oldTime = time : time = time$("ms") : frameTime = (time - oldTime) / 1000.0
    if frameTime > 0 then
        fps = int(1/frameTime) : if fps < 1 then fps = 1
        #main.menu, "place 1200 18;\";"FPS : ";fps;"     "
    end if
end if
return

[collisionMARCHE]
if mY < 30 then goto [marcheEXIT]
if perso1qy < 350 or perso1dy < 350 or perso1zy < 350 then
    perso1qy = 350 : perso1dy = 350 : perso1zy = 350 : mY = 350
    goto [marcheEXIT]
end if
if perso1dx > 1280 then perso1dx = 1280 : mX = 1280 : goto [marcheEXIT]
if perso1qy > 725 or perso1dy > 725 or perso1sy > 725 then
    perso1qy = 725 : perso1dy = 725 : perso1sy = 725 : mY = 725
    goto [marcheEXIT]
end if
if perso1qy < 447 and perso1qx < 220 then perso1qx = 220 : mX = perso1qx
if perso1qy > 1 and perso1qx < 185 then perso1qx = 185 : mX = perso1qx
if perso1qy > 575 and perso1qx < 210 then perso1qx = 210 : mX = perso1qx
return

[Eq]
if startSECURITY = 1 then mX = 200 : mY = 500
startSECURITY = 0

[marcheDROITE2]
gosub [collisionMARCHE]
if mX > perso1dx then
    PERSOmoove = 1 : perso1dx = perso1dx + 3 : if perso1dx > mX then perso1dx = mX
    #main.map, "SpriteVisible perso1s off; SpriteVisible perso1q off; SpriteVisible perso1z off; SpriteVisible perso1d on"
    perso1qx = perso1dx : perso1sx = perso1dx : perso1zx = perso1dx : perso1qy = perso1dy : perso1sy = perso1dy : perso1zy = perso1dy : activPOS1 = 1
    #main.map, "spritexy perso1d ";perso1dx;" ";perso1dy;"; cyclesprite perso1d 1; spritetofront perso1d"
    if mY < perso1dy then perso1dy = perso1dy - 2
    if mY > perso1dy then perso1dy = perso1dy + 2
    goto [marcheEXIT]
end if

[marcheGAUCHE2]
gosub [collisionMARCHE]
if mX < perso1qx then
    PERSOmoove = 1 : perso1qx = perso1qx - 3 : if perso1qx < mX then perso1qx = mX
    #main.map, "SpriteVisible perso1s off; SpriteVisible perso1d off; SpriteVisible perso1z off; SpriteVisible perso1q on"
    perso1dx = perso1qx : perso1sx = perso1qx : perso1zx = perso1qx : perso1dy = perso1qy : perso1sy = perso1qy : perso1zy = perso1qy : activPOS2 = 1
    #main.map, "spritexy perso1q ";perso1qx;" ";perso1qy;"; cyclesprite perso1q 1; spritetofront perso1q"
    if mY < perso1qy then perso1qy = perso1qy - 2
    if mY > perso1qy then perso1qy = perso1qy + 2
    goto [marcheEXIT]
end if

[marcheHAUT2]
gosub [collisionMARCHE]
if mY < perso1zy then
    PERSOmoove = 1 : perso1zy = perso1zy - 3 : if perso1zy < mY then perso1zy = mY
    #main.map, "SpriteVisible perso1s off; SpriteVisible perso1d off; SpriteVisible perso1q off; SpriteVisible perso1z on"
    perso1qy = perso1zy : perso1sy = perso1zy : perso1dy = perso1zy : perso1qx = perso1zx : perso1sx = perso1zx : perso1dx = perso1zx : activPOS3 = 1
    #main.map, "spritexy perso1z ";perso1zx;" ";perso1zy;"; cyclesprite perso1z 1; spritetofront perso1z"
    goto [marcheEXIT]
end if

[marcheBAS2]
gosub [collisionMARCHE]
if mY > perso1sy then
    PERSOmoove = 1 : perso1sy = perso1sy + 3 : if perso1sy > mY then perso1sy = mY
    #main.map, "SpriteVisible perso1z off; SpriteVisible perso1d off; SpriteVisible perso1q off; SpriteVisible perso1s on"
    perso1zy = perso1sy : perso1dy = perso1sy : perso1qy = perso1sy : perso1zx = perso1sx : perso1dx = perso1sx : perso1qx = perso1sx : activPOS4 = 1
    #main.map, "spritexy perso1s ";perso1sx;" ";perso1sy;"; cyclesprite perso1s 1; spritetofront perso1s"
end if

[marcheEXIT]
#main.map, "drawsprites"
if timingCounter = 5 then #main.map, "SpriteVisible atk off" : timingCounter = 0 : actiVtimingCounter = 0
if actiVtimingCounter = 1 then timingCounter = timingCounter + 1
gosub [colisions]
timer 0

for i = 1 to 100
    if MoveE(i) > 0 then
        Ex(i) = Ex(i) - MoveE(i)
        #main.map, "spritexy E1";i;" ";Ex(i);" ";Ey(i);"; SpriteVisible E1";i;" on; cyclesprite E1";i;" 1; SpriteVisible ED1";i;" off; spritetofront E1";i
        if Ex(i) < 185 then Ex(i) = 185 : castlePV = castlePV - int(rnd(1)*((atkE+1)-castleArmor)+1)
        if Ex(i) < 220 and Ey(i) < 447 then Ex(i) = 220 : castlePV = castlePV - int(rnd(1)*((atkE+1)-castleArmor)+1)
        if Ex(i) < 210 and Ey(i) > 580 then Ex(i) = 210 : castlePV = castlePV - int(rnd(1)*((atkE+1)-castleArmor)+1)
    else
        if PvE(i) <= 0 then
            #main.map, "spritexy ED1";i;" ";Ex(i);" ";Ey(i)+10;"; SpriteVisible ED1";i;" on; SpriteVisible E1";i;" off"
        end if
    end if
next

cata1x = cata1x - Movecata1 : compteur = compteur + 1
if compteur > 400 and ENDactionBULLET = 1 and HPcata1 > 0 and Movecata1 > 0 then Movecata1 = 0.2 : compteur = 0 : ACTIONcata1 = 1 : ENDactionBULLET = 0
if cata1x <= 880 and Movecata1 > 0 then cata1x = 880 : ENDactionBULLET = 1
if Movecata1 > 0 then
    if ACTIONcata1 = 1 and cata1x = 880 then
        #main.map, "spritexy cata3 ";cata3x;" ";cata1y-5;"; SpriteVisible cata3 on; SpriteVisible cata1 off"
        ACTIONbullet = 1 : VALmaxBULLET = int(rnd(cata1y-12.0)*1.0+cata1y-12.0)
        bulletx = cata1x + 10.0 : bullety = cata1y - 2
        #main.map, "SpriteVisible bullet on; spritetofront bullet"
    else
        #main.map, "spritexy cata1 ";cata1x;" ";cata1y;"; SpriteVisible cata1 on; SpriteVisible cata3 off"
    end if
end if
if Movecata1 = 0 then #main.map, "SpriteVisible cata1 off; SpriteVisible cata2 off; SpriteVisible cata3 off"

if ACTIONbullet = 1 then
    ATKcata1 = int((500*waveNumber)*factor)
    if ANGLEbullet <= 60 then bulletx = bulletx - 3.5 : bullety = bullety - 0.5 : ANGLEbullet = ANGLEbullet + 1
    if ANGLEbullet > 60 and ANGLEbullet <= 100 then bulletx = bulletx - 3.5 : bullety = bullety - 0.2 : ANGLEbullet = ANGLEbullet + 1
    if ANGLEbullet > 100 and ANGLEbullet <= 130 then bulletx = bulletx - 3.5 : bullety = bullety + 0.1 : ANGLEbullet = ANGLEbullet + 1
    if ANGLEbullet > 130 and ANGLEbullet <= 160 then bulletx = bulletx - 3.5 : bullety = bullety + 0.4 : ANGLEbullet = ANGLEbullet + 1
    if ANGLEbullet > 160 and ANGLEbullet <= 190 then bulletx = bulletx - 3.5 : bullety = bullety + 0.7 : ANGLEbullet = ANGLEbullet + 1
    if ANGLEbullet > 190 then bulletx = bulletx - 3.5 : bullety = bullety + 1.0 : ANGLEbullet = ANGLEbullet + 1
    if bulletx < 170 then
        ANGLEbullet = 0 : ACTIONbullet = 0 : bullety = cata1y + 1.5 : bulletx = cata3x + 2.0 : ENDactionBULLET = 1 : damageCATAcastle = int(ATKcata1-castleArmor)
        if damageCATAcastle < 0 then damageCATAcastle = 0
        castlePV = castlePV - damageCATAcastle
        #main.map, "SpriteVisible bullet off"
    end if
end if
#main.map, "spritexy bullet ";bulletx;" ";bullety
ACTIONcata1 = 0

regenCompteur = regenCompteur + 1
if regenCompteur >= regenCompteurLimite then
    regenCompteur = 0 : HEROpv = int(HEROpv + regen) : if HEROpv > HEROpvTOTAL then HEROpv = HEROpvTOTAL
end if
regenCompteur2 = regenCompteur2 + 1
if regenCompteur2 >= regenCompteur2Limite then
    regenCompteur2 = 0 : castlePV = castlePV + castleREGEN : if castlePV > castlePVtotal then castlePV = castlePVtotal
end if

if UnitsE = 0 then
    timer 0
    #main.map, "drawsprites"
    IncomWave = 1000 * waveNumber : Gold = Gold + IncomWave
    msg$ = "Victoire ! + " + str$(IncomWave) + " d'or"
    if version = 2 then msg$ = "Victory ! + " + str$(IncomWave) + " gold"
    if HPcata1 > 1 and Movecata1 > 0 then #main.map, "backcolor 86 53 35;" ; " place ";cata1x+20;" ";cata1y-3;";\";"";str$(HPcata1);" / ";str$(HPcataTOTAL1)
    notice " " + chr$(13) + " " + chr$(13) + msg$
    goto [INInextWave]
end if

if castlePV <= 0 or HEROpv <= 0 then
    timer 0
    castlePV = 0 : perso1zx = perso1dx : perso1zy = perso1dy : perso1qx = perso1zx : perso1qy = perso1zy : perso1sx = perso1qx : perso1sy = perso1qy : persoDEADx = perso1sx : persoDEADy = perso1sy
    #main.map, "SpriteVisible perso1q off; SpriteVisible perso1d off; SpriteVisible perso1s off; SpriteVisible perso1z off; SpriteVisible bullet off; spritexy persoDEAD ";persoDEADx;" ";persoDEADy;"; SpriteVisible persoDEAD on"
    #main.map, "when characterInput [w]"
    #main.map, "drawsprites"
    msg$ = "Défaite !"
    if version = 2 then msg$ = "Defeat !"
    notice " " + chr$(13) + " " + chr$(13) + msg$
    castlePV = 0
    goto [addTOscoore]
end if

#main.map, "cyclesprite perso1s 0; cyclesprite perso1z 0; cyclesprite perso1d 0; cyclesprite perso1q 0"

nuage1x = nuage1x + 0.2 : nuage2x = nuage2x + 0.1 : nuage3x = nuage3x + 0.15 : nuage4x = nuage4x + 0.3
if nuage1x > 1350 then nuage1x = -60
if nuage2x > 1400 then nuage2x = -100
if nuage3x > 1350 then nuage3x = -60
if nuage4x > 1400 then nuage4x = -100
#main.map, "spritexy nuage1 ";nuage1x;" ";nuage1y;"; spritexy nuage2 ";nuage2x;" ";nuage2y;"; spritexy nuage3 ";nuage3x;" ";nuage3y;"; spritexy nuage4 ";nuage4x;" ";nuage4y
if PERSOmoove = 0 then #main.map, "drawsprites"
PERSOmoove = 0
gosub [txtREFRESH]
if MusicSELECT = 1 then TIMINGmusic = TIMINGmusic + 1
if TIMINGmusic = 5000 and MusicSELECT = 1 then TIMINGmusic = 0 : gosub [stopMusic2] : gosub [startMusic]

if activPOS1 = 1 and (castlePV > 0 or HEROpv > 0) then
    if mX > perso1dx then timer 40, [marcheDROITE2] : wait
    activPOS1 = 0
end if
if activPOS2 = 1 and (castlePV > 0 or HEROpv > 0) then
    if mX < perso1qx then timer 40, [marcheGAUCHE2] : wait
    activPOS2 = 0
end if
if activPOS3 = 1 and (castlePV > 0 or HEROpv > 0) then
    if mY < perso1zy then timer 40, [marcheHAUT2] : wait
    activPOS3 = 0
end if
if activPOS4 = 1 and (castlePV > 0 or HEROpv > 0) then
    if mY > perso1sy then timer 4, [marcheBAS2] : wait
    activPOS4 = 0
end if
timer 40, [marcheEXIT] : wait

[loadSprites]
timer 0
HPcata1 = int((500*waveNumber)*factor) : HPcataTOTAL1 = HPcata1 : securPointcata1 = 0 : ATKcata1 = int((1000*waveNumber)*factor) : DEFcata1 = int((5+waveNumber)*factor) : Ncata = 1
baseHP = int((6 + int(2*waveNumber))*factor) : atkE = int((8 + waveNumber*5)*factor) : defE = int((1 + waveNumber)*factor)
for i = 1 to 100
    PvE(i) = baseHP : Ex(i) = int(rnd(1)*500) + 1300 : Ey(i) = int(rnd(1)*350) + 345 : securPoint(i) = 0
next
gosub [waveMooveControle]
cata1x = 1300 : cata1y = int(rnd(1)*100) + 370 : cata2x = cata1x : cata2y = cata1y : cata3x = cata1x : cata3y = cata1y
timer 10, [Eq]
return

[waveMooveControle]
if waveNumber = 1 then UnitsE = 10
if waveNumber = 2 then UnitsE = 20 : Movecata1 = 0
if waveNumber = 3 then UnitsE = 31 : Movecata1 = 0.35
if waveNumber = 4 then UnitsE = 41 : Movecata1 = 0.35
if waveNumber = 5 then UnitsE = 61 : Movecata1 = 0.35
if waveNumber = 6 then UnitsE = 81 : Movecata1 = 0.35
if waveNumber >= 7 then UnitsE = 101 : Movecata1 = 0.35
for i = 1 to UnitsE
    MoveE(i) = rnd(0.1)*2 + 0.5
next
for i = UnitsE+1 to 100
    MoveE(i) = 0
next
UnitsEtotal = UnitsE
if Movecata1 > 0 then UnitsE = UnitsE + 1
return

[INInextWave]
timer 0
waveNumber = waveNumber + 1
HPcata1 = int((500*waveNumber)*factor) : HPcataTOTAL1 = HPcata1 : ATKcata1 = int((1000*waveNumber)*factor) : DEFcata1 = int((5+waveNumber)*factor) : cata1x = 1300 : cata1y = int(rnd(1)*100) + 370 : cata2x = cata1x : cata2y = cata1y : cata3x = cata1x : cata3y = cata1y
baseHP = int((5 + int(2*waveNumber))*factor) : atkE = int((8 + waveNumber*5)*factor) : defE = int((1 + waveNumber)*factor)
for i = 1 to 100
    PvE(i) = baseHP : Ex(i) = int(rnd(1)*500) + 1300 : Ey(i) = int(rnd(1)*350) + 345 : securPoint(i) = 0
next
securPointcata1 = 0 : ACTIONbullet = 0
gosub [waveMooveControle]
close #main
goto [Game]

[upgradeCASTLE]
timer 0
if upgradeCASTLE = 1 then close #upgradeCASTLE
upgradeCASTLE = 1 : WindowWidth = 450 : WindowHeight = 330 : UpperLeftX = int((DisplayWidth-WindowWidth)/2) : UpperLeftY = int((DisplayHeight-WindowHeight)/2)
CoutUPcastleREGEN = int(castleREGEN*10)
CoutUPcastleHP = int((castlePVtotal/10)*2)
CoutUPcastleARMOR = int(castleArmor*20*castleArmor)
groupbox #upgradeCASTLE.1, "", 10, 10, 420, 80
groupbox #upgradeCASTLE.2, "", 10, 85, 420, 80
groupbox #upgradeCASTLE.3, "", 10, 160, 420, 80
if version = 1 then
    txt1$ = "Augmenter la solidité ("+str$(castlePVtotal)+") de vos fortifications avec de nouveaux matériaux afin de tenir plus longtemps face aux dégâts de vos ennemis."
    txt2$ = "Améliore la défense ("+str$(castleArmor)+") de vos fortification en augmentant la taille et l'épaisseur des murs afin de réduire les dégâts reçus."
    txt3$ = "Accélère les réparations ("+str$(castleREGEN)+") des fortifications en ajoutant des ouvrier prêt a travaillés afin de réparer les dommages causés par l'ennemi."
else
    txt1$ = "Increase the strength ("+str$(castlePVtotal)+") of your fortifications to take longer against the damage of your enemies."
    txt2$ = "Improves the armor ("+str$(castleArmor)+") of your fortification to reduce the damage received."
    txt3$ = "Accelerate the repairs ("+str$(castleREGEN)+") of the fortifications to restore strength."
end if
statictext #upgradeCASTLE.txtA, txt1$, 20, 25, 400, 30
statictext #upgradeCASTLE.txtC, "Pour "+str$(CoutUPcastleHP)+" d'or", 130, 62, 150, 15
button #upgradeCASTLE.santé, "AMELIORER", [UPcastleHP], UL, 20, 60, 100, 22
statictext #upgradeCASTLE.txtE, txt2$, 20, 100, 400, 30
statictext #upgradeCASTLE.txtG, "Pour "+str$(CoutUPcastleARMOR)+" d'or", 130, 137, 150, 15
button #upgradeCASTLE.armure, "AMELIORER", [UPcastleARMOR], UL, 20, 135, 100, 22
statictext #upgradeCASTLE.txtI, txt3$, 20, 175, 400, 30
statictext #upgradeCASTLE.txtK, "Pour "+str$(CoutUPcastleREGEN)+" d'or", 130, 213, 150, 15
button #upgradeCASTLE.regen, "AMELIORER", [UPcastleREGEN], UL, 20, 210, 100, 22
statictext #upgradeCASTLE.txtGOLD, "VOTRE OR : "+str$(Gold)+" ", 135, 255, 200, 30
if version = 2 then print #upgradeCASTLE.txtGOLD, "YOUR GOLD : "+str$(Gold)+" "
title$ = "Amélioration des fortifications"
if version = 2 then title$ = "Castle upgrade menu"
open title$ for window_nf as #upgradeCASTLE
#upgradeCASTLE, "trapclose [quitUPcastle]"
#upgradeCASTLE, "font Times New Roman 9"
#upgradeCASTLE.txtGOLD, "!font Times New Roman 14 bold"
wait

[quitUPcastle] close #upgradeCASTLE : upgradeCASTLE = 0 : timer 10, [Eq] : wait

[upgradeHERO]
timer 0
if upgradeHERO = 1 then close #upgradeHERO
upgradeHERO = 1 : WindowWidth = 450 : WindowHeight = 410 : UpperLeftX = int((DisplayWidth-WindowWidth)/2) : UpperLeftY = int((DisplayHeight-WindowHeight)/2)
CoutUPheroHP = int(lvlHPhero*100)
CoutUPheroARMOR = int(lvlARMORhero*50)
CoutUPheroDAMAGE = int(lvlATKhero*50)
CoutUPheroREGEN = int(lvlREGENhero*20)
groupbox #upgradeHERO.1, "", 10, 10, 420, 80
groupbox #upgradeHERO.2, "", 10, 85, 420, 80
groupbox #upgradeHERO.3, "", 10, 160, 420, 80
groupbox #upgradeHERO.4, "", 10, 235, 420, 80
if version = 1 then
    txt1$ = "Augmente les points de vie ("+str$(HEROpvTOTAL)+") définitivement de votre personnage pour que vous puissiez survivre aux attaques ennemis lors des combats."
    txt2$ = "Améliore la défense ("+str$(HEROdef)+") définitivement de votre personnage pour diminuer les dégâts reçus par les ennemis sur le champ de bataille."
    txt3$ = "Accélère la régénération ("+str$(regen)+") définitivement de votre personnage pour regagner vos points de vie sur le champ de bataille."
    txt4$ = "Augmente l'attaque ("+str$(HEROatk)+") définitivement de votre personnage pour infliger d'avantage de dégâts aux ennemis sur le champs de bataille."
else
    txt1$ = "Up your character's life points ("+str$(HEROpvTOTAL)+") definitly for help you in the battlefield."
    txt2$ = "Up your character's armor ("+str$(HEROdef)+") definitly to decrease the damage received by enemies on the battlefield."
    txt3$ = "Accelerate the regeneration ("+str$(regen)+") permanently of your character to regain your hit points on the battlefield."
    txt4$ = "Increases the attack ("+str$(HEROatk)+") permanently on your character to deal more damage to enemies on the battlefield."
end if
statictext #upgradeHERO.txtA, txt1$, 20, 25, 400, 35
statictext #upgradeHERO.txtD, "Pour : "+str$(CoutUPheroHP), 130, 62, 150, 15
button #upgradeHERO.santé, "AMELIORER", [UPheroHP], UL, 20, 60, 100, 22
statictext #upgradeHERO.txtE, txt2$, 20, 100, 400, 35
statictext #upgradeHERO.txtH, "Pour : "+str$(CoutUPheroARMOR), 130, 137, 150, 15
button #upgradeHERO.armure, "AMELIORER", [UPheroARMOR], UL, 20, 135, 100, 22
statictext #upgradeHERO.txtJ, txt3$, 20, 175, 400, 35
statictext #upgradeHERO.txtL, "Pour : "+str$(CoutUPheroREGEN), 130, 212, 150, 15
button #upgradeHERO.regen, "AMELIORER", [UPheroREGEN], UL, 20, 210, 100, 22
statictext #upgradeHERO.txtN, txt4$, 20, 250, 400, 35
statictext #upgradeHERO.txtP, "Pour : "+str$(CoutUPheroDAMAGE), 130, 287, 150, 15
button #upgradeHERO.attaque, "AMELIORER", [UPheroATK], UL, 20, 285, 100, 22
statictext #upgradeHERO.txtGOLD, "VOTRE OR : "+str$(Gold)+" ", 135, 330, 200, 30
if version = 2 then print #upgradeHERO.txtGOLD, "YOUR GOLD : "+str$(Gold)+" "
title$ = "Amélioration des caractéristiques du héro"
if version = 2 then title$ = "Character upgrade menu"
open title$ for window_nf as #upgradeHERO
#upgradeHERO, "trapclose [quitUPhero]"
#upgradeHERO, "font Times New Roman 9"
#upgradeHERO.txtGOLD, "!font Times New Roman 14 bold"
wait

[quitUPhero] close #upgradeHERO : upgradeHERO = 0 : timer 10, [Eq] : wait

[UPheroHP]
CoutUPheroHP = int(lvlHPhero*100)
if Gold < CoutUPheroHP then gosub [noMoney] : wait
Gold = Gold - CoutUPheroHP
HEROpv = HEROpv + int((HEROpvTOTAL/100)*20)
lvlHPhero = lvlHPhero + 1
HEROpvTOTAL = HEROpvTOTAL + int((HEROpvTOTAL/100)*20)
CoutUPheroHP = int(lvlHPhero*100)
gosub [refreshUpgradeHero]
wait

[UPheroARMOR]
CoutUPheroARMOR = int(lvlARMORhero*50)
if Gold < CoutUPheroARMOR then gosub [noMoney] : wait
Gold = Gold - CoutUPheroARMOR
HEROdef = HEROdef + 1
lvlARMORhero = lvlARMORhero + 1
CoutUPheroARMOR = int(lvlARMORhero*50)
gosub [refreshUpgradeHero]
wait

[UPheroATK]
CoutUPheroDAMAGE = int(lvlATKhero*50)
if Gold < CoutUPheroDAMAGE then gosub [noMoney] : wait
Gold = Gold - CoutUPheroDAMAGE
HEROatk = HEROatk + 1
lvlATKhero = lvlATKhero + 1
CoutUPheroDAMAGE = int(lvlATKhero*50)
gosub [refreshUpgradeHero]
wait

[UPheroREGEN]
CoutUPheroREGEN = int(lvlREGENhero*20)
if Gold < CoutUPheroREGEN then gosub [noMoney] : wait
Gold = Gold - CoutUPheroREGEN
regen = regen + 1
lvlREGENhero = lvlREGENhero + 1
CoutUPheroREGEN = int(lvlREGENhero*20)
gosub [refreshUpgradeHero]
wait

[UPcastleHP]
CoutUPcastleHP = int((castlePVtotal/10)*2)
if Gold < CoutUPcastleHP then gosub [noMoney] : wait
Gold = Gold - CoutUPcastleHP
castlePV = castlePV + int((castlePVtotal/100)*20)
castlePVtotal = castlePVtotal + int((castlePVtotal/100)*20)
CoutUPcastleHP = int((castlePVtotal/10)*2)
gosub [refreshUpgradeCastle]
wait

[UPcastleARMOR]
CoutUPcastleARMOR = int(castleArmor*20*castleArmor)
if Gold < CoutUPcastleARMOR then gosub [noMoney] : wait
Gold = Gold - CoutUPcastleARMOR
castleArmor = castleArmor + int(castleArmor/2)
CoutUPcastleARMOR = int(castleArmor*20*castleArmor)
gosub [refreshUpgradeCastle]
wait

[UPcastleREGEN]
CoutUPcastleREGEN = int(castleREGEN*10)
if Gold < CoutUPcastleREGEN then gosub [noMoney] : wait
Gold = Gold - CoutUPcastleREGEN
castleREGEN = castleREGEN + 1
CoutUPcastleREGEN = int(castleREGEN*10)
gosub [refreshUpgradeCastle]
wait

[noMoney]
if version = 1 then msg$ = "Vous n'avez pas assez pour cette amélioration"
if version = 2 then msg$ = "You havent any money for this upgrade"
notice " " + chr$(13) + msg$
return

[refreshUpgradeHero]
gosub [txtREFRESH]
if version = 1 then
    print #upgradeHERO.txtA, "Augmente les points de vie ("+str$(HEROpvTOTAL)+") définitivement de votre personnage pour que vous puissiez survivre aux attaques ennemis lors des combats."
    print #upgradeHERO.txtD, "Pour : "+str$(CoutUPheroHP)
    print #upgradeHERO.txtE, "Améliore la défense ("+str$(HEROdef)+") définitivement de votre personnage pour diminuer les dégâts reçus par les ennemis sur le champ de bataille."
    print #upgradeHERO.txtH, "Pour : "+str$(CoutUPheroARMOR)
    print #upgradeHERO.txtJ, "Accélère la régénération ("+str$(regen)+") définitivement de votre personnage pour regagner vos points de vie sur le champ de bataille."
    print #upgradeHERO.txtL, "Pour : "+str$(CoutUPheroREGEN)
    print #upgradeHERO.txtN, "Augmente l'attaque ("+str$(HEROatk)+") définitivement de votre personnage pour infliger d'avantage de dégâts aux ennemis sur le champs de bataille."
    print #upgradeHERO.txtP, "Pour : "+str$(CoutUPheroDAMAGE)
    print #upgradeHERO.txtGOLD, "VOTRE OR : "+str$(Gold)+"       "
else
    print #upgradeHERO.txtA, "Up your character's life points ("+str$(HEROpvTOTAL)+") definitly for help you in the battlefield."
    print #upgradeHERO.txtD, "For : "+str$(CoutUPheroHP)
    print #upgradeHERO.txtE, "Up your character's armor ("+str$(HEROdef)+") definitly to decrease the damage received by enemies on the battlefield."
    print #upgradeHERO.txtH, "For : "+str$(CoutUPheroARMOR)
    print #upgradeHERO.txtJ, "Accelerate the regeneration ("+str$(regen)+") permanently of your character to regain your hit points on the battlefield."
    print #upgradeHERO.txtL, "For : "+str$(CoutUPheroREGEN)
    print #upgradeHERO.txtN, "Increases the attack ("+str$(HEROatk)+") permanently on your character to deal more damage to enemies on the battlefield."
    print #upgradeHERO.txtP, "For : "+str$(CoutUPheroDAMAGE)
    print #upgradeHERO.txtGOLD, "YOUR GOLD : "+str$(Gold)+"       "
end if
return

[refreshUpgradeCastle]
gosub [txtREFRESH]
if version = 1 then
    print #upgradeCASTLE.txtA, "Augmenter la solidité ("+str$(castlePVtotal)+") de vos fortifications avec de nouveaux matériaux afin de tenir plus longtemps face aux dégâts de vos ennemis."
    print #upgradeCASTLE.txtC, "Pour "+str$(CoutUPcastleHP)+" d'or"
    print #upgradeCASTLE.txtE, "Améliore la défense ("+str$(castleArmor)+") de vos fortification en augmentant la taille et l'épaisseur des murs afin de réduire les dégâts reçus."
    print #upgradeCASTLE.txtG, "Pour "+str$(CoutUPcastleARMOR)+" d'or"
    print #upgradeCASTLE.txtI, "Accélère les réparations ("+str$(castleREGEN)+") des fortifications en ajoutant des ouvrier prêt a travaillés afin de réparer les dommages causés par l'ennemi."
    print #upgradeCASTLE.txtK, "Pour "+str$(CoutUPcastleREGEN)+" d'or"
    print #upgradeCASTLE.txtGOLD, "VOTRE OR : "+str$(Gold)+"       "
else
    print #upgradeCASTLE.txtA, "Increase the strength ("+str$(castlePVtotal)+") of your fortifications to take longer against the damage of your enemies."
    print #upgradeCASTLE.txtC, "For "+str$(CoutUPcastleHP)+" gold"
    print #upgradeCASTLE.txtE, "Improves the armor ("+str$(castleArmor)+") of your fortification to reduce the damage received."
    print #upgradeCASTLE.txtG, "For "+str$(CoutUPcastleARMOR)+" gold"
    print #upgradeCASTLE.txtI, "Accelerate the repairs ("+str$(castleREGEN)+") of the fortifications to restore strength."
    print #upgradeCASTLE.txtK, "For "+str$(CoutUPcastleREGEN)+" gold"
    print #upgradeCASTLE.txtGOLD, "YOUR GOLD : "+str$(Gold)+"       "
end if
return

[quitHELP] close #ini : help = 0 : timer 10, [Eq] : wait
[quitSetting] close #setting : Setting = 0 : wait

[quit]
timer 0
if menuGame = 1 then close #menuGame
if infoGame = 1 then close #info
if upgradeCASTLE = 1 then close #upgradeCASTLE
if upgradeHERO = 1 then close #upgradeHERO
if Setting = 1 then close #setting
if help = 1 then close #ini
if main = 1 then close #main
if main = 0 then close #debut
if about = 1 then close #about
if pant = 1 then close #pant
if MusicSELECT = 1 then r$ = mcisend$("pause main")
end

[iniMUSIC] MusicSELECT = 0 : gosub [stopMusic2] : wait
[iniMUSIC2] MusicSELECT = 1 : gosub [startMusic] : wait
[startMusic] r$  =mcisend$("set main time format ms") : r$ = mcisend$("status main length") : looplength=val(r$) : r$ = mcisend$("play main from 0 repeat") : wait
[stopMusic2] r$ = mcisend$("pause main") : wait

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

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
