Console
Clique sur « Exécuter » pour lancer le programme.
Aucune exécutionCtrl+Entrée : exécuter · Échap : arrêter
Code CoddyRun
@ Réglages
MAX_U est un nombre
MAX_U vaut 60
X_STATION est un nombre
X_STATION vaut 50
X_SOURCE est un nombre
X_SOURCE vaut 430
ligneY est un tableau
ligneY ajoute 120
ligneY ajoute 220
ligneY ajoute 320
@ État
ecran est une toile
dimension(ecran, 480, 500)
uAct est un tableau
uType est un tableau
uX est un tableau
uY est un tableau
uPV est un tableau
uTimer est un tableau
uPhase est un tableau
uLigne est un tableau
energie, pvStation, pvStationMax, mineraiCollecte est un nombre
spawnTimer, etatJeu, ticsCompteur, dureeJeu, nbDrones, vagueIndex est un nombre
ligneActive est un nombre
tra1, tra2, tra3, resetTraite est un nombre
dem1, dem2, dem3, resetDemande est un nombre
enJeu est un booléen
action, ptX, ptY est un nombre
idxI, idxJ, targetIdx, minDist, distVal est un nombre
ligEnnemi, posXVal, ligneYVal, pvMaxVal est un nombre
dem1 vaut 0
dem2 vaut 0
dem3 vaut 0
resetDemande vaut 0
tra1 vaut 0
tra2 vaut 0
tra3 vaut 0
resetTraite vaut 0
enJeu vaut vrai
vagueIndex vaut 0
ligneActive vaut 0
pour idxI de 0 à MAX_U - 1
uAct ajoute 0
uType ajoute 1
uX ajoute 0
uY ajoute 0
uPV ajoute 0
uTimer ajoute 0
uPhase ajoute 0
uLigne ajoute 0
fin pour
@ Caractéristiques
fonction coutType(t)
si t = 1 alors
retourne 20
sinon si t = 2 alors
retourne 45
fin si
retourne 80
fin fonction
fonction pvType(t)
si t = 1 alors
retourne 30
sinon si t = 2 alors
retourne 150
sinon si t = 3 alors
retourne 10
sinon si t = 4 alors
retourne 50
sinon si t = 5 alors
retourne 350
sinon si t = 6 alors
retourne 120
fin si
retourne 100
fin fonction
fonction degatType(t)
si t = 2 alors
retourne 20
sinon si t = 3 alors
retourne 120
sinon si t = 4 alors
retourne 12
sinon si t = 5 alors
retourne 35
sinon si t = 6 alors
retourne 22
fin si
retourne 0
fin fonction
fonction vitesseType(t)
si t = 1 alors
retourne 30
sinon si t = 2 alors
retourne 18
sinon si t = 3 alors
retourne 55
sinon si t = 4 alors
retourne 22
sinon si t = 5 alors
retourne 10
sinon si t = 6 alors
retourne 14
fin si
retourne 15
fin fonction
@ Mise en place
procédure creerUnite(t, lig)
targetIdx vaut - 1
pour idxI de 0 à MAX_U - 1
si uAct[idxI] = 0 et targetIdx < 0 alors
targetIdx vaut idxI
fin si
fin pour
si targetIdx >= 0 alors
uAct[targetIdx] vaut 1
uType[targetIdx] vaut t
uPV[targetIdx] vaut pvType(t)
uTimer[targetIdx] vaut 0
uPhase[targetIdx] vaut 0
uLigne[targetIdx] vaut lig
uY[targetIdx] vaut ligneY[lig]
si t >= 4 alors
uX[targetIdx] vaut 490
sinon
uX[targetIdx] vaut X_STATION + 15
fin si
fin si
fin procédure
procédure nouvellePartie()
energie vaut 120
pvStationMax vaut 1000
pvStation vaut pvStationMax
mineraiCollecte vaut 0
spawnTimer vaut 400
vagueIndex vaut 0
etatJeu vaut 0
dureeJeu vaut 0
ligneActive vaut 0
pour idxI de 0 à MAX_U - 1
uAct[idxI] vaut 0
fin pour
fin procédure
@ Dessin
procédure dessinerUnite(g, sx, sy, t, phaseVal, pvActuel, lig)
si t = 1 alors
// Drone Récolteur
contour(g, #06283D, 2)
cercle(g, sx, sy, 8, #0EA5E9)
cercle(g, sx + 4, sy - 2, 4, #38BDF8)
contour(g, #0)
ligne(g, sx - 6, sy - 6, sx + 6, sy - 6, #E0F2FE, 2)
ligne(g, sx - 6, sy + 6, sx + 6, sy + 6, #E0F2FE, 2)
si phaseVal = 1 alors
contour(g, #D97706, 1)
cercle(g, sx + 8, sy, 5, #FBBF24)
contour(g, #0)
fin si
sinon si t = 2 alors
// Sous-Marin Chasseur
contour(g, #0B192C, 2)
ellipse(g, sx, sy, 12, 7, #1E3E62)
rectangle(g, sx - 3, sy - 10, 5, 4, #000000)
contour(g, #0)
cercle(g, sx + 5, sy - 1, 3, #EF4444)
ligne(g, sx - 12, sy, sx - 17, sy - 4, #1E3E62, 2)
ligne(g, sx - 12, sy, sx - 17, sy + 4, #1E3E62, 2)
sinon si t = 3 alors
// Torpille Rapide
contour(g, #7C2D12, 1)
rectangle_arrondi(g, sx - 8, sy - 3, 16, 6, 2, #F97316)
contour(g, #0)
cercle(g, sx + 7, sy, 3, #EF4444)
ligne(g, sx - 10, sy, sx - 14, sy, #F59E0B, 3)
sinon si t = 4 alors
// Anguille Abyssale
contour(g, #31103F, 2)
ellipse(g, sx, sy, 14, 5, #8B5CF6)
cercle(g, sx - 8, sy - 1, 3, #FACC15)
contour(g, #0)
ligne(g, sx, sy, sx + 14, sy + 2, #7C3AED, 2)
sinon si t = 5 alors
// Kraken Abyssal
contour(g, #450A0A, 2)
cercle(g, sx, sy, 14, #991B1B)
contour(g, #0)
cercle(g, sx - 6, sy - 3, 3, #F87171)
cercle(g, sx - 6, sy + 3, 3, #F87171)
ligne(g, sx + 10, sy - 8, sx + 22, sy - 12, #7F1D1D, 2)
ligne(g, sx + 10, sy - 3, sx + 24, sy - 4, #7F1D1D, 2)
ligne(g, sx + 10, sy + 3, sx + 24, sy + 4, #7F1D1D, 2)
ligne(g, sx + 10, sy + 8, sx + 22, sy + 12, #7F1D1D, 2)
sinon si t = 6 alors
// Méduse Bioluminescente
contour(g, #064E3B, 2)
cercle(g, sx, sy - 2, 10, #10B981)
contour(g, #0)
ligne(g, sx - 6, sy, sx - 6, sy + 10, #34D399, 1)
ligne(g, sx - 2, sy, sx - 2, sy + 12, #6EE7B7, 1)
ligne(g, sx + 2, sy, sx + 2, sy + 12, #6EE7B7, 1)
ligne(g, sx + 6, sy, sx + 6, sy + 10, #34D399, 1)
fin si
pvMaxVal vaut pvType(t)
si pvActuel < pvMaxVal et pvActuel > 0 alors
rectangle(g, sx - 10, sy - 14, 20, 3, #1E293B)
rectangle(g, sx - 10, sy - 14, 20 * (pvActuel / pvMaxVal), 3, #22C55E)
fin si
fin procédure
procédure carteUnite(g, cx, t, nom)
contour(g, #0F172A, 2)
si energie >= coutType(t) alors
rectangle_arrondi(g, cx, 380, 142, 110, 10, #1E293B)
sinon
rectangle_arrondi(g, cx, 380, 142, 110, 10, #0F172A)
fin si
label(g, cx + 8, 396, nom, #F8FAFC, 11)
rectangle_arrondi(g, cx + 6, 402, 130, 48, 6, #0284C7)
contour(g, #0)
appelle dessinerUnite(g, cx + 71, 426, t, 0, pvType(t), 0)
contour(g, #0F172A, 2)
rectangle_arrondi(g, cx + 18, 455, 106, 28, 8, #0369A1)
contour(g, #0)
cercle(g, cx + 36, 469, 7, #38BDF8)
label(g, cx + 52, 474, convertir_texte(coutType(t)), #F8FAFC, 14)
fin procédure
procédure dessinerTout()
effacer(ecran)
// Fond abyssal
rectangle(ecran, 0, 0, 480, 500, #030712)
rectangle(ecran, 0, 90, 480, 270, #070F2B)
// Lignes abyssales (Fosses de passage)
pour idxI de 0 à 2
ligneYVal vaut ligneY[idxI]
si idxI = ligneActive alors
rectangle(ecran, 0, ligneYVal - 22, 480, 44, #1E3E62)
ligne(ecran, 0, ligneYVal, 480, ligneYVal, #38BDF8, 2)
sinon
ligne(ecran, 0, ligneYVal, 480, ligneYVal, #1E293B, 1)
fin si
fin pour
// Station Abyssale (Gauche)
contour(ecran, #0284C7, 2)
rectangle_arrondi(ecran, 5, 95, 55, 260, 12, #0F172A)
contour(ecran, #0)
cercle(ecran, X_STATION, 120, 16, #0284C7)
cercle(ecran, X_STATION, 220, 16, #0284C7)
cercle(ecran, X_STATION, 320, 16, #0284C7)
// Barre de vie de la Station
contour(ecran, #0F172A, 2)
rectangle_arrondi(ecran, 10, 360, 130, 12, 3, #22C55E)
contour(ecran, #0)
label(ecran, 14, 370, "STATION " + convertir_texte(arrondi((pvStation / pvStationMax) * 100)) + "%", #F8FAFC, 9)
// Source Hydrothermale (Droite)
contour(ecran, #B45309, 2)
rectangle_arrondi(ecran, X_SOURCE, 95, 45, 260, 10, #451A03)
contour(ecran, #0)
cercle(ecran, X_SOURCE + 20, 120, 12, #F59E0B)
cercle(ecran, X_SOURCE + 20, 220, 12, #F59E0B)
cercle(ecran, X_SOURCE + 20, 320, 12, #F59E0B)
// Unités
pour idxI de 0 à MAX_U - 1
si uAct[idxI] = 1 alors
appelle dessinerUnite(ecran, uX[idxI], uY[idxI], uType[idxI], uPhase[idxI], uPV[idxI], uLigne[idxI])
fin si
fin pour
// Bandeau Supérieur (HUD)
contour(ecran, #1E293B, 2)
rectangle_arrondi(ecran, 10, 8, 460, 42, 10, #0F172A)
contour(ecran, #0)
label(ecran, 22, 34, convertir_texte(arrondi(dureeJeu / 16)) + " s", #F8FAFC, 14)
rectangle_arrondi(ecran, 160, 12, 140, 34, 8, #1E293B)
cercle(ecran, 180, 29, 9, #38BDF8)
cercle(ecran, 180, 29, 5, #E0F2FE)
label(ecran, 198, 36, convertir_texte(arrondi(energie)), #F8FAFC, 17)
label(ecran, 315, 34, "Vague " + convertir_texte(vagueIndex) + " - " + convertir_texte(mineraiCollecte) + " min.", #38BDF8, 11)
// Sélecteurs de ligne dans le HUD
pour idxI de 0 à 2
posXVal vaut 10 + (idxI * 155)
si idxI = ligneActive alors
contour(ecran, #38BDF8, 2)
rectangle_arrondi(ecran, posXVal, 56, 150, 26, 6, #0284C7)
contour(ecran, #0)
label(ecran, posXVal + 12, 73, "LIGNE " + convertir_texte(idxI + 1) + " [ACTIF]", #F8FAFC, 10)
sinon
contour(ecran, #1E293B, 1)
rectangle_arrondi(ecran, posXVal, 56, 150, 26, 6, #0F172A)
contour(ecran, #0)
label(ecran, posXVal + 22, 73, "Ligne " + convertir_texte(idxI + 1), #94A3B8, 10)
fin si
fin pour
si nbDrones = 0 et energie < coutType(1) alors
label(ecran, 182, 53, "+1 secours...", #F59E0B, 10)
fin si
appelle carteUnite(ecran, 14, 1, "DRONE")
appelle carteUnite(ecran, 169, 2, "CHASSEUR")
appelle carteUnite(ecran, 324, 3, "TORPILLE")
si etatJeu <> 0 alors
contour(ecran, #7F1D1D, 3)
rectangle_arrondi(ecran, 50, 150, 380, 120, 16, #0F172A)
contour(ecran, #0)
label(ecran, 110, 200, "STATION DÉTRUITE !", #EF4444, 22)
label(ecran, 105, 235, "Survie : " + convertir_texte(arrondi(dureeJeu / 16)) + " s - " + convertir_texte(mineraiCollecte) + " minerais", #94A3B8, 14)
fin si
affiche ecran
fin procédure
@ Moteur (processus parallèle)
processus MoteurJeu()
tant que enJeu
ticsCompteur vaut ticsCompteur + 1
si resetTraite < resetDemande alors
resetTraite vaut resetTraite + 1
appelle nouvellePartie()
fin si
si tra1 < dem1 alors
tra1 vaut tra1 + 1
si etatJeu = 0 et energie >= coutType(1) alors
energie vaut energie - coutType(1)
appelle creerUnite(1, ligneActive)
fin si
fin si
si tra2 < dem2 alors
tra2 vaut tra2 + 1
si etatJeu = 0 et energie >= coutType(2) alors
energie vaut energie - coutType(2)
appelle creerUnite(2, ligneActive)
fin si
fin si
si tra3 < dem3 alors
tra3 vaut tra3 + 1
si etatJeu = 0 et energie >= coutType(3) alors
energie vaut energie - coutType(3)
appelle creerUnite(3, ligneActive)
fin si
fin si
si etatJeu = 0 alors
dureeJeu vaut dureeJeu + 1
nbDrones vaut 0
pour idxI de 0 à MAX_U - 1
si uAct[idxI] = 1 et uType[idxI] = 1 alors
nbDrones vaut nbDrones + 1
fin si
fin pour
si nbDrones = 0 et energie < coutType(1) alors
si ticsCompteur mod 18 = 0 alors
energie vaut energie + 1
fin si
fin si
// Apparition des vagues abyssales
spawnTimer vaut spawnTimer - 1
si spawnTimer <= 0 alors
vagueIndex vaut vagueIndex + 1
ligEnnemi vaut hasard(0, 2)
si vagueIndex mod 5 = 0 alors
appelle creerUnite(5, ligEnnemi)
appelle creerUnite(4, ligEnnemi)
sinon si vagueIndex mod 3 = 0 alors
appelle creerUnite(6, ligEnnemi)
ligEnnemi vaut hasard(0, 2)
appelle creerUnite(6, ligEnnemi)
sinon
appelle creerUnite(4, ligEnnemi)
si vagueIndex > 3 alors
ligEnnemi vaut hasard(0, 2)
appelle creerUnite(4, ligEnnemi)
fin si
fin si
spawnTimer vaut limiter(420 - (arrondi_inferieur(dureeJeu / 12) * 5), 70, 420)
fin si
// Mouvements et IA par unité
pour idxI de 0 à MAX_U - 1
si uAct[idxI] = 1 alors
// Recherche de la cible la plus proche sur la MÊME LIGNE
targetIdx vaut - 1
minDist vaut 9999
pour idxJ de 0 à MAX_U - 1
si uAct[idxJ] = 1 et uLigne[idxJ] = uLigne[idxI] alors
si (uType[idxI] >= 4 et uType[idxJ] <= 3) ou (uType[idxI] <= 3 et uType[idxJ] >= 4) alors
distVal vaut absolue(uX[idxJ] - uX[idxI])
si distVal < minDist alors
minDist vaut distVal
targetIdx vaut idxJ
fin si
fin si
fin si
fin pour
// Ciblage de la station pour les monstres marins
si uType[idxI] >= 4 alors
distVal vaut absolue(X_STATION - uX[idxI])
si distVal < minDist alors
minDist vaut distVal
targetIdx vaut - 2
fin si
fin si
// Comportements selon le type
si uType[idxI] = 1 alors
// Drone Récolteur (aller-retour station/source)
si uPhase[idxI] = 0 alors
uX[idxI] vaut uX[idxI] + (vitesseType(1) / 10)
si uX[idxI] >= X_SOURCE alors
uPhase[idxI] vaut 1
fin si
sinon
uX[idxI] vaut uX[idxI] - (vitesseType(1) / 10)
si uX[idxI] <= X_STATION alors
uPhase[idxI] vaut 0
energie vaut energie + 25
mineraiCollecte vaut mineraiCollecte + 1
fin si
fin si
sinon si uType[idxI] = 2 alors
// Sous-Marin Chasseur
si targetIdx >= 0 et minDist <= 35 alors
uTimer[idxI] vaut uTimer[idxI] + 1
si uTimer[idxI] >= 14 alors
uTimer[idxI] vaut 0
uPV[targetIdx] vaut uPV[targetIdx] - degatType(2)
si uPV[targetIdx] <= 0 alors
uAct[targetIdx] vaut 0
fin si
fin si
sinon
si uX[idxI] < 450 alors
uX[idxI] vaut uX[idxI] + (vitesseType(2) / 10)
fin si
fin si
sinon si uType[idxI] = 3 alors
// Torpille Rapide (projectile monocible)
si targetIdx >= 0 et minDist <= 20 alors
uPV[targetIdx] vaut uPV[targetIdx] - degatType(3)
si uPV[targetIdx] <= 0 alors
uAct[targetIdx] vaut 0
fin si
uAct[idxI] vaut 0
sinon
uX[idxI] vaut uX[idxI] + (vitesseType(3) / 10)
si uX[idxI] >= 480 alors
uAct[idxI] vaut 0
fin si
fin si
sinon
// Créatures Ennemies (Anguille, Kraken, Méduse)
si targetIdx <> - 1 et minDist <= 30 alors
uTimer[idxI] vaut uTimer[idxI] + 1
si uTimer[idxI] >= 16 alors
uTimer[idxI] vaut 0
si targetIdx = -2 alors
pvStation vaut pvStation - degatType(uType[idxI])
si pvStation <= 0 alors
pvStation vaut 0
etatJeu vaut 1
fin si
sinon
uPV[targetIdx] vaut uPV[targetIdx] - degatType(uType[idxI])
si uPV[targetIdx] <= 0 alors
uAct[targetIdx] vaut 0
fin si
fin si
fin si
sinon
uX[idxI] vaut uX[idxI] - (vitesseType(uType[idxI]) / 10)
fin si
fin si
fin si
fin pour
fin si
appelle dessinerTout()
pause 60
fin tant que
fin processus
@ Programme principal
appelle nouvellePartie()
appelle dessinerTout()
MoteurJeu()
tant que enJeu
interagir ecran, ["1", "2", "3", "a", "z", "e", "n", "p"] dans action, ptX, ptY
si non enJeu alors
arrête
fin si
si action = 0 alors
// Clics cartes d'unités (ptX, ptY, x, y, largeur, hauteur)
si clique(ptX, ptY, 14, 380, 142, 110) alors
dem1 vaut dem1 + 1
sinon si clique(ptX, ptY, 169, 380, 142, 110) alors
dem2 vaut dem2 + 1
sinon si clique(ptX, ptY, 324, 380, 142, 110) alors
dem3 vaut dem3 + 1
// Clics sélecteurs de ligne
sinon si clique(ptX, ptY, 10, 56, 150, 26) alors
ligneActive vaut 0
sinon si clique(ptX, ptY, 165, 56, 150, 26) alors
ligneActive vaut 1
sinon si clique(ptX, ptY, 320, 56, 150, 26) alors
ligneActive vaut 2
fin si
sinon si action = 1 alors
dem1 vaut dem1 + 1
sinon si action = 2 alors
dem2 vaut dem2 + 1
sinon si action = 3 alors
dem3 vaut dem3 + 1
sinon si action = 4 alors
ligneActive vaut 0
sinon si action = 5 alors
ligneActive vaut 1
sinon si action = 6 alors
ligneActive vaut 2
sinon si action = 7 alors
resetDemande vaut resetDemande + 1
sinon
enJeu vaut faux
arrête
fin si
fin tant que
affiche "Station engloutie - " + convertir_texte(arrondi(dureeJeu / 16)) + " s - " + convertir_texte(mineraiCollecte) + " minerais"