
    ' Creat By Atomose Studio 2025 with LibertyBasic 4.51 pro

    nomainwin
    global dy, dx, direction, rotation, gaucheLibre, droiteLibre, murDevant, oldPerso1x, oldPerso1y, oldDirection
    global nbMonstres, enCombat, monstreActuel, timerMonstre, delaiMouvementMonstre
    global hero.nom$, hero.niveau, hero.pv, hero.pvMax, hero.attaque, hero.defense, hero.xp, hero.xpProchain, hero.kills
    global oldHero.pv, oldHero.xp, oldHero.niveau, oldEnCombat, oldMonstreActuel, oldMonstrePv
    global bossX, bossY, bossActif, bossPv, bossPvMax, bossVaincu
    global timerDegatsProximite, delaiDegatsProximite, derniersDegatsProximite
    global timerRegeneration, delaiRegeneration, regenParSeconde

    dim p(50,50)
    dim monstre(51, 8), oldMonstre(51, 2)  ' 51 lignes (0 à 50), 8 colonnes (0 à 7)

    WindowWidth = 1100 : WindowHeight = 630 : UpperLeftX=int((DisplayWidth-WindowWidth)/2) : UpperLeftY=int((DisplayHeight-WindowHeight)/2)
    x = 50 : y = 50 : perso1x = 1 : perso1y = 1 : oldPerso1x = perso1x : oldPerso1y = perso1y : oldDirection = direction
    direction = 1 : rotation = 0

    hero.nom$ = "Héros"
    hero.niveau = 1
    hero.pvMax = 100
    hero.pv = hero.pvMax
    hero.attaque = 10
    hero.defense = 5
    hero.xp = 0
    hero.xpProchain = 50
    hero.kills = 0
    enCombat = 0
    monstreActuel = 0
    timerMonstre = 0
    delaiMouvementMonstre = 5

    bossActif = 1
    bossVaincu = 0
    bossX = 23
    bossY = 23
    bossPv = 300
    bossPvMax = 300

    timerDegatsProximite = 0
    delaiDegatsProximite = 10
    derniersDegatsProximite = 0

    regenParSeconde = 1
    timerRegeneration = 0
    delaiRegeneration = 10

    ' Variables pour détecter les changements
    oldHero.pv = hero.pv
    oldHero.xp = hero.xp
    oldHero.niveau = hero.niveau
    oldEnCombat = 0
    oldMonstreActuel = 0
    oldMonstrePv = 0

    for i = 1 to 50
        oldMonstre(i, 0) = -1
        oldMonstre(i, 1) = -1
    next i

    sprites$ = "mur1 mur2 mur3 mur4 mur5 mur6 mur7 mur8 mur11 mur12 mur13 mur14 perso1 garde1 boss1"
    for s = 1 to 15
        loadbmp word$(sprites$,s), "data\"+word$(sprites$,s)+".bmp"
    next

    graphicbox #main.map, 2, 0, 900, 599
    graphicbox #main.minimap, 903, 0,188, 190
    graphicbox #main.info, 903, 193,188, 406
    open "Ancestral Dungeon by Atomose" for window_nf as #main
    #main, "trapclose [quit]"
    #main.map, "setfocus; down; fill black; when leftButtonDown [clicGauche]"
    #main.map, "addsprite mur13 mur13; addsprite mur1 mur1; addsprite mur2 mur2; addsprite mur3 mur3; addsprite mur4 mur4; addsprite mur5 mur5; addsprite mur6 mur6; addsprite mur7 mur7; addsprite mur8 mur8; addsprite mur9 mur8; addsprite mur10 mur8; addsprite mur11 mur11; addsprite mur12 mur12; addsprite mur14 mur14; addsprite perso1 perso1; addsprite garde1 garde1 ; addsprite boss1 boss1"
    #main.map, "spriteXY mur13 0 0;spriteXY mur1 0 0; spriteXY mur2 0 0; spriteXY mur3 0 0; spriteXY mur4 0 0; spriteXY mur5 0 0; spriteXY mur6 0 0; spriteXY mur7 0 0; spriteXY mur8 0 0; spriteXY mur9 0 0; spriteXY mur10 0 0; spriteXY mur11 0 0; spriteXY mur12 0 0; spriteXY mur14 0 0; spriteXY perso1 300 400; spriteXY garde1 0 0; spriteXY boss1 0 0"
    #main.map, "spritevisible mur13 off;spritevisible mur1 off; spritevisible mur2 off; spritevisible mur3 off; spritevisible mur4 off; spritevisible mur5 off; spritevisible mur6 off; spritevisible mur7 off; spritevisible mur8 off; spritevisible mur9 off; spritevisible mur10 off; spritevisible mur11 off; spritevisible mur12 off; spritevisible mur14 off; spritevisible perso1 on; spritevisible garde1 off; spritevisible boss1 off "
    #main.map, "spritetofront perso1; spritescale perso1 200"

    gosub [map]
    gosub [placerMonstres]
    gosub [verifierMonstre]
    gosub [afficherInfo]
    gosub [drawMinimap]

    #main.map, "drawsprites"

    '------------------------      BOUCLE PRINCIPALE DU JEU      ------------------------------------------------------------------------------------------------------

    [endLEVEL]
    timer 0
    scan
    #main.map, "discard"
    dy = 0 : dx = 0 : rotation = 0
    call readJStick 1

    ' Déplacement des monstres
    timerMonstre = timerMonstre + 1
    if timerMonstre >= delaiMouvementMonstre then timerMonstre = 0 : gosub [deplacerMonstres]
    timerDegatsProximite = timerDegatsProximite + 1
    if timerDegatsProximite >= delaiDegatsProximite then timerDegatsProximite = 0 : gosub [verifierDegatsProximite]
    timerRegeneration = timerRegeneration + 1
    if timerRegeneration >= delaiRegeneration and noHEAL = 0 then timerRegeneration = 0 : gosub [regenererVie]
    noHEAL = 0

    ' Gestion des touches de combat
    if enCombat = 1 then
        if GetAsyncKeyState(asc("F")) then gosub [fuir]
        goto [skipMovement]
    end if
    if rotation <> 0 then
        direction = direction + rotation
        if direction < 0 then direction = 3
        if direction > 3 then direction = 0
        goto [skipMovement]
    end if

    ' Gestion du mouvement avant/arrière selon la direction actuelle
    if dy <> 0 or dx <> 0 then
        newX = perso1x : newY = perso1y
        select case direction
            case 0  ' Nord (haut)
                if dy = -1 then newY = perso1y - 1  ' Avancer
                if dy = 1 then newY = perso1y + 1   ' Reculer
            case 1  ' Est (droite)
                if dy = -1 then newX = perso1x + 1  ' Avancer
                if dy = 1 then newX = perso1x - 1   ' Reculer
            case 2  ' Sud (bas)
                if dy = -1 then newY = perso1y + 1  ' Avancer
                if dy = 1 then newY = perso1y - 1   ' Reculer
            case 3  ' Ouest (gauche)
                if dy = -1 then newX = perso1x - 1  ' Avancer
                if dy = 1 then newX = perso1x + 1   ' Reculer
        end select
        if newX >= 0 and newX < x and newY >= 0 and newY < y and p(INT(newX),INT(newY)) = 0 then perso1x = newX : perso1y = newY : gosub [verifierMonstre]
    end if

    ' Vérifier aussi après une rotation (tourner vers un monstre)
    if rotation <> 0 then gosub [verifierMonstre]
    [skipMovement]
    ' Vérifier les monstres à chaque frame (si pas déjà en combat)
    if enCombat = 0 then gosub [verifierMonstre]

    ' === OPTIMISATION MINIMAP : CODE UNIQUE ===
    joueurBouge = 0
    if perso1x <> oldPerso1x or perso1y <> oldPerso1y or direction <> oldDirection then joueurBouge = 1 : oldPerso1x = perso1x : oldPerso1y = perso1y : oldDirection = direction

    monstreBouge = 0
    if joueurBouge = 0 then
        mapSize = 5
        for i = 1 to nbMonstres
            if monstre(i, 2) = 1 then
                mx = monstre(i, 0) : my = monstre(i, 1)
                if mx >= perso1x - mapSize and mx <= perso1x + mapSize then
                    if my >= perso1y - mapSize and my <= perso1y + mapSize then
                        if oldMonstre(i, 0) <> mx or oldMonstre(i, 1) <> my then
                            monstreBouge = 1
                            exit for
                        end if
                    end if
                end if
            end if
        next i
    end if

    if joueurBouge = 1 or monstreBouge = 1 then
        gosub [drawMinimap]
        for i = 1 to nbMonstres
            if monstre(i, 2) = 1 then
                mx = monstre(i, 0) : my = monstre(i, 1)
                if mx >= perso1x - mapSize and mx <= perso1x + mapSize then
                    if my >= perso1y - mapSize and my <= perso1y + mapSize then
                        oldMonstre(i, 0) = mx : oldMonstre(i, 1) = my
                    else
                        oldMonstre(i, 0) = -1 : oldMonstre(i, 1) = -1
                    end if
                else
                    oldMonstre(i, 0) = -1 : oldMonstre(i, 1) = -1
                end if
            else
                oldMonstre(i, 0) = -1 : oldMonstre(i, 1) = -1
            end if
        next i
    end if

    ' Masquer tous les murs
    #main.map "spritevisible garde1 off; spritevisible boss1 off; spritevisible mur1 off; spritevisible mur2 off; spritevisible mur3 off; spritevisible mur4 off; spritevisible mur5 off; spritevisible mur6 off; spritevisible mur7 off; spritevisible mur8 off; spritevisible mur9 off; spritevisible mur10 off; spritevisible mur11 off; spritevisible mur12 off; spritevisible mur13 off; spritevisible mur14 off"

    ' Calcul des positions relatives selon la direction
    [deplacement]
    select case direction
        case 0  ' Nord
            frontX = perso1x : frontY = perso1y - 1
            front2X = perso1x : front2Y = perso1y - 2
            front3X = perso1x : front3Y = perso1y - 3
            leftX = perso1x - 1 : leftY = perso1y
            rightX = perso1x + 1 : rightY = perso1y
            leftFrontX = perso1x - 1 : leftFrontY = perso1y - 1
            rightFrontX = perso1x + 1 : rightFrontY = perso1y - 1
            leftFront2X = perso1x - 1 : leftFront2Y = perso1y - 2
            rightFront2X = perso1x + 1 : rightFront2Y = perso1y - 2
        case 1  ' Est
            frontX = perso1x + 1 : frontY = perso1y
            front2X = perso1x + 2 : front2Y = perso1y
            front3X = perso1x + 3 : front3Y = perso1y
            leftX = perso1x : leftY = perso1y - 1
            rightX = perso1x : rightY = perso1y + 1
            leftFrontX = perso1x + 1 : leftFrontY = perso1y - 1
            rightFrontX = perso1x + 1 : rightFrontY = perso1y + 1
            leftFront2X = perso1x + 2 : leftFront2Y = perso1y - 1
            rightFront2X = perso1x + 2 : rightFront2Y = perso1y + 1
        case 2  ' Sud
            frontX = perso1x : frontY = perso1y + 1
            front2X = perso1x : front2Y = perso1y + 2
            front3X = perso1x : front3Y = perso1y + 3
            leftX = perso1x + 1 : leftY = perso1y
            rightX = perso1x - 1 : rightY = perso1y
            leftFrontX = perso1x + 1 : leftFrontY = perso1y + 1
            rightFrontX = perso1x - 1 : rightFrontY = perso1y + 1
            leftFront2X = perso1x + 1 : leftFront2Y = perso1y + 2
            rightFront2X = perso1x - 1 : rightFront2Y = perso1y + 2
        case 3  ' Ouest
            frontX = perso1x - 1 : frontY = perso1y
            front2X = perso1x - 2 : front2Y = perso1y
            front3X = perso1x - 3 : front3Y = perso1y
            leftX = perso1x : leftY = perso1y + 1
            rightX = perso1x : rightY = perso1y - 1
            leftFrontX = perso1x - 1 : leftFrontY = perso1y + 1
            rightFrontX = perso1x - 1 : rightFrontY = perso1y - 1
            leftFront2X = perso1x - 2 : leftFront2Y = perso1y + 1
            rightFront2X = perso1x - 2 : rightFront2Y = perso1y - 1
    end select

    ' Vérifier si un monstre est devant
    gosub [afficherMonstreDevant]

    ' Mur 13 : mur au loin visible quand il y a exactement 1 case libre devant
    if frontX >= 0 and frontX < x and frontY >= 0 and frontY < y then
        if p(INT(frontX),INT(frontY)) = 0 then
            if front2X >= 0 and front2X < x and front2Y >= 0 and front2Y < y then
                if p(INT(front2X),INT(front2Y)) = 1 then #main.map "spriteXY mur13 300 0; spritevisible mur13 on"
            else
                #main.map "spriteXY mur13 300 0; spritevisible mur13 on"
            end if
        end if
    end if

    ' Mur 14 : vue de face avec 3 cases libres ou plus devant
    if frontX >= 0 and frontX < x and frontY >= 0 and frontY < y then
        if p(INT(frontX),INT(frontY)) = 0 then
            if front2X >= 0 and front2X < x and front2Y >= 0 and front2Y < y then
                if p(INT(front2X),INT(front2Y)) = 0 then
                    if front3X >= 0 and front3X < x and front3Y >= 0 and front3Y < y then
                        if p(INT(front3X),INT(front3Y)) = 0 then #main.map "spriteXY mur14 300 0; spritevisible mur14 on"
                    else
                        #main.map "spriteXY mur14 300 0; spritevisible mur14 on"
                    end if
                end if
            end if
        end if
        else
        #main.map "spriteXY mur14 300 0; spritevisible mur14 on"
    end if

    ' Mur 2 : vue de face avec exactement 2 cases libres devant puis mur bloquant
    if frontX >= 0 and frontX < x and frontY >= 0 and frontY < y then
        if p(INT(frontX),INT(frontY)) = 0 then
            if front2X >= 0 and front2X < x and front2Y >= 0 and front2Y < y then
                if p(INT(front2X),INT(front2Y)) = 0 then
                    ' Les 2 premières cases sont libres, vérifions la 3ème
                    if front3X >= 0 and front3X < x and front3Y >= 0 and front3Y < y then
                        if p(INT(front3X),INT(front3Y)) = 1 then #main.map "spriteXY mur2 300 0; spritevisible mur2 on"
                    else
                        #main.map "spriteXY mur2 300 0; spritevisible mur2 on"
                    end if
                end if
            end if
        end if
    end if

    ' Mur 1 : vue proche gauche
    if frontX >= 0 and frontX < x and frontY >= 0 and frontY < y then
        if p(INT(frontX),INT(frontY)) = 0 then
            if leftFrontX >= 0 and leftFrontX < x and leftFrontY >= 0 and leftFrontY < y then
                if p(INT(leftFrontX),INT(leftFrontY)) = 1 then #main.map "spriteXY mur1 0 0; spritevisible mur1 on"
            else
                #main.map "spriteXY mur1 0 0; spritevisible mur1 on"
            end if
        end if
    end if
    if leftX >= 0 and leftX < x and leftY >= 0 and leftY < y then
        if p(INT(leftX),INT(leftY)) = 1 then
            if frontX >= 0 and frontX < x and frontY >= 0 and frontY < y then
                if p(INT(frontX),INT(frontY)) = 0 then #main.map "spriteXY mur1 0 0; spritevisible mur1 on"
            end if
        end if
    else
        if frontX >= 0 and frontX < x and frontY >= 0 and frontY < y then
            if p(INT(frontX),INT(frontY)) = 0 then #main.map "spriteXY mur1 0 0; spritevisible mur1 on"
        end if
    end if

    ' Mur 3 : vue proche droite
    if frontX >= 0 and frontX < x and frontY >= 0 and frontY < y then
        if p(INT(frontX),INT(frontY)) = 0 then
            if rightFrontX >= 0 and rightFrontX < x and rightFrontY >= 0 and rightFrontY < y then
                if p(INT(rightFrontX),INT(rightFrontY)) = 1 then #main.map "spriteXY mur3 600 0; spritevisible mur3 on"
            else
                #main.map "spriteXY mur3 600 0; spritevisible mur3 on"
            end if
        end if
    end if
    if rightX >= 0 and rightX < x and rightY >= 0 and rightY < y then
        if p(INT(rightX),INT(rightY)) = 1 then
            if frontX >= 0 and frontX < x and frontY >= 0 and frontY < y then
                if p(INT(frontX),INT(frontY)) = 0 then #main.map "spriteXY mur3 600 0; spritevisible mur3 on"
            end if
        end if
    else
        if frontX >= 0 and frontX < x and frontY >=  0 and frontY < y then
            if p(INT(frontX),INT(frontY)) = 0 then #main.map "spriteXY mur3 600 0; spritevisible mur3 on"
        end if
    end if

    ' Mur 4 : virage droite éloigné
    if rightFrontX >= 0 and rightFrontX < x and rightFrontY >= 0 and rightFrontY < y then
        if p(INT(rightFrontX),INT(rightFrontY)) = 0 then #main.map "spriteXY mur4 600 0; spritevisible mur4 on"
    end if

    ' Mur 5 : virage gauche éloigné
    if leftFrontX >= 0 and leftFrontX < x and leftFrontY >= 0 and leftFrontY < y then
        if p(INT(leftFrontX),INT(leftFrontY)) = 0 then #main.map "spriteXY mur5 0 0; spritevisible mur5 on"
    end if

    ' Mur 6 : virage proche gauche
    if leftX >= 0 and leftX < x and leftY >= 0 and leftY < y then
        if p(INT(leftX),INT(leftY)) = 0 then #main.map "spriteXY mur6 0 0; spritevisible mur6 on"
    end if

    ' Mur 7 : virage proche droite
    if rightX >= 0 and rightX < x and rightY >= 0 and rightY < y then
        if p(INT(rightX),INT(rightY)) = 0 then #main.map "spriteXY mur7 600 0; spritevisible mur7 on"
    end if

    ' Mur 8 : mur de face (ne peut plus avancer) - PRIORITAIRE
    murDevant = 0
    if frontX >= 0 and frontX < x and frontY >= 0 and frontY < y then
        if p(INT(frontX),INT(frontY)) = 1 then murDevant = 1 : #main.map "spriteXY mur8 300 0; spritevisible mur8 on; spritevisible mur2 off; spritevisible mur6 off; spritevisible mur7 off"
    else
        murDevant = 1 : #main.map "spriteXY mur8 300 0; spritevisible mur8 on; spritevisible mur2 off; spritevisible mur6 off; spritevisible mur7 off"
    end if

    ' Si mur devant, vérifier les passages latéraux pour murs 9, 10, 11, 12
    if murDevant = 1 then
        gaucheLibre = 0 : droiteLibre = 0
        ' Vérifier si passage à gauche
        if leftX >= 0 and leftX < x and leftY >= 0 and leftY < y and p(INT(leftX),INT(leftY)) = 0 then gaucheLibre = 1
        ' Vérifier si passage à droite (ou si hors limites = bloqué)
        if rightX >= 0 and rightX < x and rightY >= 0 and rightY < y and p(INT(rightX),INT(rightY)) = 0 then droiteLibre = 1
        ' CUL-DE-SAC
        if gaucheLibre = 0 and droiteLibre = 0 then #main.map "spriteXY mur11 0 0; spritevisible mur11 on; spriteXY mur12 600 0; spritevisible mur12 on"
        '  mur de face avec passage gauche possible
        if gaucheLibre = 1 and droiteLibre = 0 then #main.map "spriteXY mur9 0 0; spritevisible mur9 on; spriteXY mur12 600 0; spritevisible mur12 on"
        '  mur de face avec passage droite possible
        if droiteLibre = 1 and gaucheLibre = 0 then #main.map "spriteXY mur10 600 0; spritevisible mur10 on; spriteXY mur11 0 0; spritevisible mur11 on"
        '  Passages des deux côtés
        if gaucheLibre = 1 and droiteLibre = 1 then #main.map "spriteXY mur9 0 0; spritevisible mur9 on; spriteXY mur10 600 0; spritevisible mur10 on"
    end if

    #main.map, "drawsprites"
    timer 100, [endLEVEL] : wait

    [quit]
    close #main : end


    '------------------------      FONCTIONS POUR DEPLACEMENT DU JEU AVEC CLAVIER SANS DELAI DES TOUCHES      ------------------------------------------------------------------------------------------------------

    function GetAsyncKeyState(key)
        calldll #user32, "GetAsyncKeyState",key as long,GetAsyncKeyState as long
        if GetAsyncKeyState<>0 then GetAsyncKeyState=1
    end function

    sub readJStick n
        if GetAsyncKeyState(asc("Z")) or GetAsyncKeyState(_VK_UP) then dy = -1
        if GetAsyncKeyState(asc("S")) or GetAsyncKeyState(_VK_DOWN) then dy = 1
        if GetAsyncKeyState(asc("Q")) or GetAsyncKeyState(_VK_LEFT) then rotation = -1
        if GetAsyncKeyState(asc("D")) or GetAsyncKeyState(_VK_RIGHT) then rotation = 1
    end sub

    [clicGauche]
    if enCombat = 1 then gosub [attaquer]
    wait


    [map]
    x = 25 : y = 25
    redim p(x,y)
    data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
    data 1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1
    data 1,0,1,1,1,0,1,0,1,1,1,1,1,0,1,0,1,1,1,1,1,1,1,0,1
    data 1,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,1
    data 1,0,1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,0,1,0,1
    data 1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,1
    data 1,1,1,1,1,0,1,1,1,0,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1
    data 1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1
    data 1,0,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,0,1,0,1,0,1
    data 1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,0,1,0,1
    data 1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1,1,0,1
    data 1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1
    data 1,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
    data 1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1
    data 1,0,1,1,1,1,1,0,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,0,1
    data 1,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1
    data 1,0,1,0,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1,0,1
    data 1,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1
    data 1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1,1
    data 1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1
    data 1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,0,1
    data 1,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1
    data 1,0,1,0,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,0,1,0,1,0,1
    data 1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1
    data 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
    restore [map]
    for b=0 to y-1
        for a=0 to x-1
            read valeur : p(a,b)= valeur
        next a
    next b
    return

    '------------------------      MINIMAP      ------------------------------------------------------------------------------------------------------

    [drawMinimap]
    mapSize = 5 : cellSize = 16
    totalCells = mapSize * 2 + 1  ' 11 cases
    totalWidth = totalCells * cellSize  ' 176 pixels
    totalHeight = totalCells * cellSize  ' 176 pixels
    offsetX = (188 - totalWidth) / 2 : offsetY = (190 - totalHeight) / 2
    #main.minimap, "down; fill black"
    for dy = 0 to mapSize * 2
        for dx = 0 to mapSize * 2
            mapX = perso1x - mapSize + dx : mapY = perso1y - mapSize + dy
            if mapX >= 0 and mapX < x and mapY >= 0 and mapY < y then
                screenX = offsetX + dx * cellSize : screenY = offsetY + dy * cellSize
                if p(INT(mapX), INT(mapY)) = 1 then
                    #main.minimap, "backcolor darkgray; color darkgray; place "; screenX; " "; screenY
                    #main.minimap, "boxfilled "; screenX + cellSize - 2; " "; screenY + cellSize - 2
                else
                    #main.minimap, "color lightgray; backcolor black; place "; screenX; " "; screenY
                    #main.minimap, "box "; screenX + cellSize - 2; " "; screenY + cellSize - 2
                end if
            end if
        next dx
    next dy

     ' Afficher les monstres actifs sur la minimap
    for i = 1 to nbMonstres
        if monstre(i, 2) = 1 then
            mx = monstre(i, 0) : my = monstre(i, 1)
            if mx >= perso1x - mapSize and mx <= perso1x + mapSize then
                if my >= perso1y - mapSize and my <= perso1y + mapSize then
                    dx = mx - (perso1x - mapSize) : dy = my - (perso1y - mapSize)
                    screenX = offsetX + dx * cellSize : screenY = offsetY + dy * cellSize
                    if monstre(i, 8) = 1 then #main.minimap, "color red; backcolor red"    'boss
                    if monstre(i, 8) = 0 then #main.minimap, "color blue; backcolor blue"  'gardes
                    #main.minimap, "place "; screenX + 7; " "; screenY + 7
                    #main.minimap, "circlefilled 3"
                end if
            end if
        end if
    next i

    centerX = 188 / 2 : centerY = 190 / 2 : playerSize = 5
    #main.minimap, "color yellow; backcolor yellow; place "; centerX - playerSize+4; " "; centerY - playerSize+4
    #main.minimap, "circlefilled "; playerSize
    #main.minimap, "color red; size 2"
    select case direction
        case 0  ' Nord (haut)
            #main.minimap, "line "; centerX; " "; centerY; " "; centerX; " "; centerY - playerSize - 3
        case 1  ' Est (droite)
            #main.minimap, "line "; centerX; " "; centerY; " "; centerX + playerSize + 3; " "; centerY
        case 2  ' Sud (bas)
            #main.minimap, "line "; centerX; " "; centerY; " "; centerX; " "; centerY + playerSize + 3
        case 3  ' Ouest (gauche)
            #main.minimap, "line "; centerX; " "; centerY; " "; centerX - playerSize - 3; " "; centerY
    end select
    #main.minimap, "size 1; flush"
    return


    '------------------------      PLACEMENT MONSTRES      ------------------------------------------------------------------------------------------------------

    [placerMonstres]
    nbMonstres = 1
    monstre(1, 0) = bossX  ' x
    monstre(1, 1) = bossY  ' y
    monstre(1, 2) = 1      ' actif
    monstre(1, 3) = bossPv ' pv
    monstre(1, 4) = bossPvMax  ' pvMax
    monstre(1, 5) = 15     ' attaque
    monstre(1, 6) = 8      ' defense
    monstre(1, 7) = 500    ' xpDonne
    monstre(1, 8) = 1      ' 1 = BOSS, 0 = monstre normal

    ' Placer les monstres normaux
    tentatives = 0
    while nbMonstres < 20 and tentatives < 200
        tentatives = tentatives + 1 : mx = int(rnd(0) * (x - 2)) + 1 : my = int(rnd(0) * (y - 2)) + 1
        ' Vérifier que c'est une case libre ET pas la position du joueur ET pas trop près du boss
        distanceBoss = abs(mx - bossX) + abs(my - bossY)
        if p(mx, my) = 0 and (mx <> perso1x or my <> perso1y) and distanceBoss > 3 then
            dejaPresent = 0
            for j = 1 to nbMonstres
                if monstre(j, 0) = mx and monstre(j, 1) = my then
                    dejaPresent = 1
                    exit for
                end if
            next j
            if dejaPresent = 0 then
                nbMonstres = nbMonstres + 1
                monstre(nbMonstres, 0) = mx
                monstre(nbMonstres, 1) = my
                monstre(nbMonstres, 2) = 1
                monstre(nbMonstres, 3) = 20 + int(rnd(0) * 10)
                monstre(nbMonstres, 4) = monstre(nbMonstres, 3)
                monstre(nbMonstres, 5) = 3 + int(rnd(0) * 3)
                monstre(nbMonstres, 6) = 2 + int(rnd(0) * 2)
                monstre(nbMonstres, 7) = 15 + int(rnd(0) * 10)
                monstre(nbMonstres, 8) = 0  ' monstre normal
            end if
        end if
    wend
    return

    [respawnMonstre]
    if bossVaincu = 1 then return
    tentatives = 0 : monstrePlace = 0
    while monstrePlace = 0 and tentatives < 100
        tentatives = tentatives + 1 : mx = int(rnd(0) * (x - 2)) + 1 : my = int(rnd(0) * (y - 2)) + 1

        ' Vérifier que c'est une case libre, loin du joueur
        distanceJoueur = abs(mx - perso1x) + abs(my - perso1y)

        if p(mx, my) = 0 and distanceJoueur > 5 then
            dejaPresent = 0
            for j = 1 to nbMonstres
                if monstre(j, 2) = 1 then  ' si actif
                    if monstre(j, 0) = mx and monstre(j, 1) = my then
                        dejaPresent = 1
                        exit for
                    end if
                end if
            next j
            if dejaPresent = 0 then
                slotLibre = 0
                for i = 1 to nbMonstres
                    if monstre(i, 2) = 0 then  ' slot inactif
                        slotLibre = i
                        exit for
                    end if
                next i
                if slotLibre = 0 then nbMonstres = nbMonstres + 1 : slotLibre = nbMonstres
                facteurDifficulte = 1 + (hero.niveau * 0.2)
                monstre(slotLibre, 0) = mx
                monstre(slotLibre, 1) = my
                monstre(slotLibre, 2) = 1  ' actif
                monstre(slotLibre, 3) = int((30 + int(rnd(0) * 15)) * facteurDifficulte)  ' pv
                monstre(slotLibre, 4) = monstre(slotLibre, 3)  ' pvMax
                monstre(slotLibre, 5) = int((5 + int(rnd(0) * 5)) * facteurDifficulte)  ' attaque
                monstre(slotLibre, 6) = int((2 + int(rnd(0) * 2)) * facteurDifficulte)  ' defense
                monstre(slotLibre, 7) = int((15 + int(rnd(0) * 10)) * facteurDifficulte)  ' xpDonne
                monstrePlace = 1
            end if
        end if
    wend
    return


    '------------------------      AFFICHAGE INFO      ------------------------------------------------------------------------------------------------------

    [afficherInfo]
    #main.info, "cls; down; backcolor darkgray; fill darkgray"

    ' === CADRE SANTÉ ===
    #main.info, "backcolor white; color white"
    #main.info, "place 10 10; boxfilled 178 70"
    #main.info, "backcolor lightgray; color lightgray"
    #main.info, "place 12 12; boxfilled 176 68"

    ' Label Santé avec régénération
    #main.info, "backcolor lightgray; color black; place 20 30; font Arial 10 bold"
    regenInfo$ = "Sante : " + str$(hero.pv) + "/" + str$(hero.pvMax)
    if regenParSeconde > 0 then regenInfo$ = regenInfo$ + " (+" + str$(regenParSeconde) + "/s)"
    #main.info, "\"; regenInfo$; "  "

    ' Barre de santé
    #main.info, "backcolor black; color black"
    #main.info, "place 20 38; boxfilled 168 50"
    #main.info, "backcolor darkred; color darkred"
    #main.info, "place 21 39; boxfilled 167 49"

    ' Remplissage santé
    pvPourcent = hero.pv / hero.pvMax : largeurPV = int(144 * pvPourcent)
    #main.info, "backcolor red; color red"
    #main.info, "place 22 40; boxfilled "; 22 + largeurPV; " 48"

    ' === CADRE NIVEAU ===
    #main.info, "backcolor white; color white"
    #main.info, "place 10 78; boxfilled 178 140"
    #main.info, "backcolor lightgray; color lightgray"
    #main.info, "place 12 80; boxfilled 176 138"

    ' Label Niveau
    #main.info, "backcolor lightgray; color black; place 20 98; font Arial 10 bold"
    #main.info, "\Niveau : ";hero.niveau

    ' Texte EXPERIENCE
    #main.info, "place 20 116; font Arial 9 bold; color black"
    xp$ = "EXPERIENCE  " + str$(hero.xp) + "/" + str$(hero.xpProchain)
    #main.info, "\"; xp$

    ' Barre XP
    #main.info, "backcolor black; color black"
    #main.info, "place 20 122; boxfilled 168 134"
    #main.info, "backcolor darkblue; color darkblue"
    #main.info, "place 21 123; boxfilled 167 133"

    xpPourcent = hero.xp / hero.xpProchain
    largeurXP = int(144 * xpPourcent)
    #main.info, "backcolor blue; color blue"
    #main.info, "place 22 124; boxfilled "; 22 + largeurXP; " 132"

    ' === STATS ATTAQUE / ARMURE ===
    ' Cadre Attaque
    #main.info, "backcolor white; color white"
    #main.info, "place 10 146; boxfilled 88 210"
    #main.info, "backcolor lightgray; color lightgray"
    #main.info, "place 12 148; boxfilled 86 208"

    #main.info, "backcolor lightgray; color black; place 28 165; font Arial 9 bold"
    #main.info, "\Attaque"
    #main.info, "place 38 192; font Arial 16 bold"
    #main.info, "\"; str$(hero.attaque)

    ' Cadre Armure (Défense)
    #main.info, "backcolor white; color white"
    #main.info, "place 100 146; boxfilled 178 210"
    #main.info, "backcolor lightgray; color lightgray"
    #main.info, "place 102 148; boxfilled 176 208"

    #main.info, "backcolor lightgray; color black; place 118 165; font Arial 9 bold"
    #main.info, "\Armure"
    #main.info, "place 132 192; font Arial 16 bold"
    #main.info, "\"; str$(hero.defense)

    ' === SECTION COMBAT ===
    if enCombat = 1 and monstreActuel > 0 then

        ' Cadre combat principal
        #main.info, "backcolor white; color white"
        #main.info, "place 10 220; boxfilled 178 394"
        #main.info, "backcolor darkred; color darkred"
        #main.info, "place 12 222; boxfilled 176 392"

        ' Bannière ! COMBAT !
        #main.info, "backcolor red; color red"
        #main.info, "place 20 230; boxfilled 168 250"
        #main.info, "backcolor red; color yellow; place 50 246; font Arial 12 bold"
        #main.info, "\! COMBAT !"

        ' Nom monstre
        if monstre(monstreActuel, 8) = 1 then #main.info, "backcolor darkred; color white; place 50 273; font Arial 11 bold" : #main.info, "\*** BOSS ***"
        if monstre(monstreActuel, 8) = 0 then #main.info, "backcolor darkred; color white; place 35 273; font Arial 11 bold" : #main.info, "\Garde du Donjon"

        ' POINTS DE VIE
        #main.info, "place 34 295; font Arial 9 bold"
        mpv$ = "Santé : " + str$(monstre(monstreActuel, 3)) + "/" + str$(monstre(monstreActuel, 4))
        #main.info, "\"; mpv$

        ' Stats ATT / DEF
        #main.info, "place 34 310; font Arial 8 bold; color yellow"
        #main.info, "\Attaque "; str$(monstre(monstreActuel, 5))
        #main.info, "place 34 325; color cyan"
        #main.info, "\Armure "; str$(monstre(monstreActuel, 6))

        ' Ligne séparation
        #main.info, "color white; size 2; line 20 345 168 345"

        ' Instructions
        #main.info, "size 1; backcolor darkred; color white; place 30 365; font Arial 9"
        #main.info, "\Attaquer : Clic gauche"
        #main.info, "place 30 380"
        #main.info, "\Fuir : Touche F"
    end if

    #main.info, "flush"
    return

    '------------------------      VERIFICATION ET AFFICHAGE MONSTRES      ------------------------------------------------------------------------------------------------------

    [verifierMonstre]
    monstreActuel = 0
    select case direction
        case 0  ' Nord (haut)
            frontX = perso1x
            frontY = perso1y - 1
        case 1  ' Est (droite)
            frontX = perso1x + 1
            frontY = perso1y
        case 2  ' Sud (bas)
            frontX = perso1x
            frontY = perso1y + 1
        case 3  ' Ouest (gauche)
            frontX = perso1x - 1
            frontY = perso1y
    end select
    for i = 1 to nbMonstres
        if monstre(i, 2) = 1 then  ' si actif
            mx = monstre(i, 0) : my = monstre(i, 1)
            if mx = frontX and my = frontY then
                monstreActuel = i : enCombat = 1
                gosub [afficherInfo]
                exit for
            end if
        end if
    next i
    return

   [afficherMonstreDevant]
    ' Masquer les deux sprites au début
    #main.map "spritevisible garde1 off; spritevisible boss1 off"

    ' Si en combat, afficher le monstre actuel en grand au centre
    if enCombat = 1 and monstreActuel > 0 then
        if monstre(monstreActuel, 2) = 1 then
            if monstre(monstreActuel, 8) = 1 then #main.map "spriteXY boss1 210 200; spritevisible boss1 on; spritescale boss1 250"
            if monstre(monstreActuel, 8) = 0 then #main.map "spriteXY garde1 350 200; spritevisible garde1 on; spritescale garde1 250"
        end if
        return
    end if

    ' Calculer les positions devant selon la direction (jusqu'à 3 cases)
    select case direction
        case 0  ' Nord (haut)
            front1X = perso1x : front1Y = perso1y - 1
            front2X = perso1x : front2Y = perso1y - 2
            front3X = perso1x : front3Y = perso1y - 3
        case 1  ' Est (droite)
            front1X = perso1x + 1 : front1Y = perso1y
            front2X = perso1x + 2 : front2Y = perso1y
            front3X = perso1x + 3 : front3Y = perso1y
        case 2  ' Sud (bas)
            front1X = perso1x : front1Y = perso1y + 1
            front2X = perso1x : front2Y = perso1y + 2
            front3X = perso1x : front3Y = perso1y + 3
        case 3  ' Ouest (gauche)
            front1X = perso1x - 1 : front1Y = perso1y
            front2X = perso1x - 2 : front2Y = perso1y
            front3X = perso1x - 3 : front3Y = perso1y
    end select


    ' Chercher un monstre dans la ligne de vue (priorité aux plus proches)
    monstreTrouve = 0 : monstreEstBoss = 0

    ' Vérifier case à 2 distances (moyenne distance)
    if monstreTrouve = 0 then
        if front2X >= 0 and front2X < x and front2Y >= 0 and front2Y < y then
            ' Vérifier qu'il n'y a pas de mur entre nous et la case 2
            murBloque = 0
            if front1X >= 0 and front1X < x and front1Y >= 0 and front1Y < y then
                if p(INT(front1X),INT(front1Y)) = 1 then murBloque = 1
            else
                murBloque = 1
            end if

            if murBloque = 0 then
                for i = 1 to nbMonstres
                    if monstre(i, 2) = 1 then
                        if monstre(i, 0) = front2X and monstre(i, 1) = front2Y then
                            monstreEstBoss = monstre(i, 8)
                            if monstreEstBoss = 1 then
                                #main.map "spriteXY boss1 370 200; spritevisible boss1 on; spritescale boss1 90"
                            else
                                #main.map "spriteXY garde1 416 200; spritevisible garde1 on; spritescale garde1 90"
                            end if
                            monstreTrouve = 1
                            exit for
                        end if
                    end if
                next i
            end if
        end if
    end if

    ' Vérifier case à 3 distances (loin, petite taille)
    if monstreTrouve = 0 then
        if front3X >= 0 and front3X < x and front3Y >= 0 and front3Y < y then
            ' Vérifier qu'il n'y a pas de mur entre nous et la case 3
            murBloque = 0
            if front1X >= 0 and front1X < x and front1Y >= 0 and front1Y < y then
                if p(INT(front1X),INT(front1Y)) = 1 then murBloque = 1
            end if
            if front2X >= 0 and front2X < x and front2Y >= 0 and front2Y < y then
                if p(INT(front2X),INT(front2Y)) = 1 then murBloque = 1
            end if

            if murBloque = 0 then
                for i = 1 to nbMonstres
                    if monstre(i, 2) = 1 then
                        if monstre(i, 0) = front3X and monstre(i, 1) = front3Y then
                            monstreEstBoss = monstre(i, 8)
                            if monstreEstBoss = 1 then
                                #main.map "spriteXY boss1 400 200; spritevisible boss1 on; spritescale boss1 50"
                            else
                                #main.map "spriteXY garde1 430 200; spritevisible garde1 on; spritescale garde1 50"
                            end if
                            monstreTrouve = 1
                            exit for
                        end if
                    end if
                next i
            end if
        end if
    end if

    return

    [deplacerMonstres]
    for i = 1 to nbMonstres
    if monstre(i, 2) = 1 then   ' si actif
        if enCombat = 1 and i = monstreActuel then goto [skipMonsterMove]
        mx = monstre(i, 0) : my = monstre(i, 1) : distX = perso1x - mx : distY = perso1y - my : distance = abs(distX) + abs(distY)

        if distance <= 5 then
            newMX = mx : newMY = my
            if abs(distX) > abs(distY) then
                if distX > 0 then newMX = mx + 1 else newMX = mx - 1
            else
                if distY > 0 then newMY = my + 1 else newMY = my - 1
            end if
        else
            choixDir = int(rnd(0) * 4) : newMX = mx : newMY = my
            select case choixDir
                case 0: newMY = my - 1  ' Nord
                case 1: newMX = mx + 1  ' Est
                case 2: newMY = my + 1  ' Sud
                case 3: newMX = mx - 1  ' Ouest
            end select
        end if

        ' Vérifier que la nouvelle position est valide
        mouvementValide = 0
        if newMX >= 0 and newMX < x and newMY >= 0 and newMY < y then
            if p(INT(newMX), INT(newMY)) = 0 then
                caseLibre = 1
                for j = 1 to nbMonstres
                    if j <> i and monstre(j, 2) = 1 then
                        if monstre(j, 0) = newMX and monstre(j, 1) = newMY then
                            caseLibre = 0
                            exit for
                        end if
                    end if
                next j
                if newMX = perso1x and newMY = perso1y then caseLibre = 0
                if caseLibre = 1 then mouvementValide = 1 : monstre(i, 0) = newMX : monstre(i, 1) = newMY
            end if
        end if

        if mouvementValide = 0 and distance <= 8 then
            newMX = mx  : newMY = my
            if abs(distX) > abs(distY) and distY > 0 then newMY = my + 1 else if distY < 0 then newMY = my - 1
            if abs(distX) > abs(distY) and distX > 0 then newMX = mx + 1 else if distX < 0 then newMX = mx - 1
            if newMX >= 0 and newMX < x and newMY >= 0 and newMY < y then
                if p(INT(newMX), INT(newMY)) = 0 then
                    caseLibre = 1
                    for j = 1 to nbMonstres
                        if j <> i and monstre(j, 2) = 1 then
                            if monstre(j, 0) = newMX and monstre(j, 1) = newMY then
                                caseLibre = 0
                                exit for
                            end if
                        end if
                    next j
                    if newMX = perso1x and newMY = perso1y then caseLibre = 0
                    if caseLibre = 1 then monstre(i, 0) = newMX : monstre(i, 1) = newMY
                end if
            end if
        end if

        [skipMonsterMove]
    end if
    next i
    return

    '------------------------      DEGATS DE PROXIMITE      ------------------------------------------------------------------------------------------------------

    [verifierDegatsProximite]
    nbMonstresAdjacents = 0 : checkX = perso1x : checkY = perso1y - 1
    if checkX >= 0 and checkX < x and checkY >= 0 and checkY < y then
        for i = 1 to nbMonstres
            if monstre(i, 2) = 1 then  ' si actif
                if monstre(i, 0) = checkX and monstre(i, 1) = checkY then nbMonstresAdjacents = nbMonstresAdjacents + 1
            end if
        next i
    end if
    checkX = perso1x : checkY = perso1y + 1
    if checkX >= 0 and checkX < x and checkY >= 0 and checkY < y then
        for i = 1 to nbMonstres
            if monstre(i, 2) = 1 then
                if monstre(i, 0) = checkX and monstre(i, 1) = checkY then nbMonstresAdjacents = nbMonstresAdjacents + 1
            end if
        next i
    end if
    checkX = perso1x + 1 : checkY = perso1y
    if checkX >= 0 and checkX < x and checkY >= 0 and checkY < y then
        for i = 1 to nbMonstres
            if monstre(i, 2) = 1 then
                if monstre(i, 0) = checkX and monstre(i, 1) = checkY then nbMonstresAdjacents = nbMonstresAdjacents + 1
            end if
        next i
    end if
    checkX = perso1x - 1 : checkY = perso1y
    if checkX >= 0 and checkX < x and checkY >= 0 and checkY < y then
        for i = 1 to nbMonstres
            if monstre(i, 2) = 1 then
                if monstre(i, 0) = checkX and monstre(i, 1) = checkY then nbMonstresAdjacents = nbMonstresAdjacents + 1
            end if
        next i
    end if
    if nbMonstresAdjacents > 0 then
        degatsProximite = 3 * nbMonstresAdjacents : hero.pv = hero.pv - degatsProximite : noHEAL = 1
        gosub [afficherInfo]
        if hero.pv <= 0 then gosub [gameOver] : return
    end if
    return

    '------------------------      REGENERATION PASSIVE      ------------------------------------------------------------------------------------------------------

    [regenererVie]
    if hero.pv < hero.pvMax then
        regenParSeconde = 1 + int((hero.niveau - 1) * 0.5)
        hero.pv = hero.pv + regenParSeconde
        if hero.pv > hero.pvMax then hero.pv = hero.pvMax
        if hero.pv <> oldHero.pv then oldHero.pv = hero.pv : gosub [afficherInfo]
    end if
    return

    '------------------------      COMBAT      ------------------------------------------------------------------------------------------------------

    [attaquer]
    if enCombat = 0 or monstreActuel = 0 then return
    degatsJoueur = hero.attaque - monstre(monstreActuel, 6)
    if degatsJoueur < 1 then degatsJoueur = 1
    degatsJoueur = degatsJoueur + int(rnd(0) * 3) - 1
    monstre(monstreActuel, 3) = monstre(monstreActuel, 3) - degatsJoueur
    if monstre(monstreActuel, 3) <= 0 then
        monstre(monstreActuel, 2) = 0 : hero.xp = hero.xp + monstre(monstreActuel, 7) : hero.kills = hero.kills + 1 : enCombat = 0 : monstreActuel = 0
        if hero.xp >= hero.xpProchain then gosub [monterNiveau]
        gosub [drawMinimap]
        gosub [respawnMonstre]
        if monstre(monstreActuel, 8) = 1 then bossVaincu = 1 : bossActif = 0
    else
        degatsMonstre = monstre(monstreActuel, 5) - hero.defense  ' attaque
        if degatsMonstre < 1 then degatsMonstre = 1
        degatsMonstre = degatsMonstre + int(rnd(0) * 2)
        hero.pv = hero.pv - degatsMonstre
        messageCombat$ = messageCombat$ + " Le monstre riposte: -" + str$(degatsMonstre) + " PV"
        if hero.pv <= 0 then gosub [gameOver] : return
    end if
    gosub [afficherInfo]
    return

    [fuir]
    if enCombat = 0 then return
    if rnd(0) < 0.5 then
        newFuiteX = perso1x : newFuiteY = perso1y
        select case direction
            case 0: newFuiteY = perso1y + 1  ' Reculer vers le sud
            case 1: newFuiteX = perso1x - 1  ' Reculer vers l'ouest
            case 2: newFuiteY = perso1y - 1  ' Reculer vers le nord
            case 3: newFuiteX = perso1x + 1  ' Reculer vers l'est
        end select
        fuiteValide = 0
        if newFuiteX >= 0 and newFuiteX < x and newFuiteY >= 0 and newFuiteY < y and p(INT(newFuiteX), INT(newFuiteY)) = 0 then fuiteValide = 1
        if fuiteValide = 1 then
            messageCombat$ = "Vous avez fui!"
            enCombat = 0
            monstreActuel = 0
            perso1x = newFuiteX
            perso1y = newFuiteY
        else
            degatsMonstre = monstre(monstreActuel, 5) - hero.defense
            if degatsMonstre < 1 then degatsMonstre = 1
            degatsMonstre = degatsMonstre + int(rnd(0) * 2)
            hero.pv = hero.pv - degatsMonstre
            messageCombat$ = "Fuite bloquee! Le monstre attaque: -" + str$(degatsMonstre) + " PV"
            if hero.pv <= 0 then gosub [gameOver] : return
        end if
    else
        degatsMonstre = monstre(monstreActuel, 5) - hero.defense
        if degatsMonstre < 1 then degatsMonstre = 1
        degatsMonstre = degatsMonstre + int(rnd(0) * 2)
        hero.pv = hero.pv - degatsMonstre
        messageCombat$ = "Fuite echouee! Le monstre attaque: -" + str$(degatsMonstre) + " PV"
        if hero.pv <= 0 then gosub [gameOver] : return
    end if
    gosub [afficherInfo]
    return

    [monterNiveau]
    hero.niveau = hero.niveau + 1
    hero.xp = hero.xp - hero.xpProchain
    hero.xpProchain = int(hero.xpProchain * 1.25)
    hero.pvMax = hero.pvMax + int(rnd(0)*10+3)
    hero.pv = hero.pvMax  ' Soin complet
    hero.attaque = hero.attaque + int(rnd(0)*4+1)
    hero.defense = hero.defense + int(rnd(0)*2)
    gosub [afficherInfo]
    return

    [gameOver]
    timer 0
    #main.map, "cls; backcolor red; color white; place 300 250; font Arial 20 bold"
    #main.map, "\GAME OVER"
    #main.map, "place 250 300; font Arial 14"
    go1$ = "Niveau atteint: " + str$(hero.niveau)
    #main.map, "\"; go1$
    #main.map, "place 250 330"
    go2$ = "Monstres vaincus: " + str$(hero.kills)
    #main.map, "\"; go2$
    msg$ = "Vous etes mort! Voulez-vous recommencer?" + chr$(13) + "Niveau: " + str$(hero.niveau) + " - Kills: " + str$(hero.kills)
    notice msg$
    close #main
    end
