# Cubito's Adventures v.1 NW 30/10/2020
# https://nsi.xyz/Cubito's Adventures, un jeu en python pour la NumWorks
# par Clement Raphaël et Palix Gabin
fromkandinskyimport*fromionimport*fromrandomimport*fromtimeimport*try:get_keys()os=(192,53,53)#Se met à la couleur de l'OS alternatif Omega
except:os=(255,183,52)#Se met à la couleur de l'OS de base Epsilon
ja=(255,255,0)ble=(0,255,255)bl=(255,255,255)no=(0,0,0)deftext_center(text,x=160,y=110,col1=(255,255,255),col2=(255,255,255)):#Centre un texte
draw_string(text,x-len(text)*10//2,y,col1,col2)defmenu():globalniveaufill_rect(0,0,320,222,no)fill_rect(0,204,320,18,os)text_center("nsi.xyz/cubito par Gab & Raph",160,204,bl,os)text_center("Bienvenue dans :",160,7,ja,no)foriinrange(5,320,10):set_pixel(i,30,ja)sleep(0.05)text_center("Cubito's Adventures!",160,38,ja,(3,34,76))text_center("Pour bouger, utilise les fleches",160,61,ja,no)text_center("Mais, attention aux trous!",160,81,ja,no)text_center("Pour gagner, essaie d'avoir le",160,121,ja,no)text_center("plus de points!",160,141,ja,no)sleep(4)text_center("A toi de jouer!",160,166,ja,no)text_center('Appuie sur "OK" ou "clear"',160,186,ja,no)whilenotkeydown(5):ifkeydown(4)orkeydown(17):jeu()elifkeydown(36):whilenotkeydown(5):ifkeydown(43):fill_rect(0,0,320,222,no)niveau=42jeu()definitiation():#Génère les pièces
fill_rect(0,0,320,222,no)forjinrange(5,222,10):foriinrange(5,320,10):set_pixel(i,j,bl)initialisation()position=[0,0]#x,y
mvt=[0,0]#x,y
globalscorescore=0niveau=1definitialisation(etat=0):globalscore,niveau,scaleifetat==0:fill_rect(0,204,320,18,os)draw_string("Score :",0,204,bl,os)draw_string("Niveau :",160,204,bl,os)else:draw_string(str(score),80,204,bl,os)draw_string(str(niveau),250,204,bl,os)defpersonnage(aff=0):ifaff==0:fill_rect(position[0],position[1],10,10,no)else:fill_rect(position[0],position[1],10,10,ja)defcollision():'''on vérifie les collisions, si collisions, on retourne false, sinon true on teste mvt[0] et mvt[1]'''returnTruedefpoints():globalscore,position,mvt,longueur_scaleifget_pixel(position[0]+4,position[1]-39)==(248,252,248):personnage(0)position[1]-=longueur_scale+10position[0]=position[0]mvt[1]=position[1]personnage(1)elifget_pixel(mvt[0]+5,mvt[1]+5)!=(248,252,248):score-=1else:score+=1defvide():globalposition,mvt,score,niveau,chute_42whileget_pixel(position[0]+5,position[1]+15)!=(248,252,248)andposition[1]!=190:personnage(0)position[0]=position[0]position[1]+=10mvt[1]=position[1]score-=1personnage(1)sleep(1)ifniveau==42:chute_42=Truedeffin_niv():globalniveau,position,mvt,score,abscisse_arrivee,ordonnee_arriveeniveau_suivant=Falseifniveau==1andposition[0]==310andposition[1]==190:text_center("Tu as reussi le niveau 1!",160,42,ja,no)text_center("Avec un score de "+str(score),160,62,ja,no)niveau_suivant=Trueelifniveau==2andposition[0]==150andposition[1]==70:text_center("Tu as reussi le niveau 2!",160,42,ja,no)text_center("Avec un score de "+str(score),160,62,ja,no)niveau_suivant=Trueelifniveau==3andposition[0]==50andposition[1]==100:text_center("Tu as reussi le niveau 3!",160,42,ja,no)text_center("Avec un score de "+str(score),160,62,ja,no)niveau_suivant=Trueelifniveau==4andposition[0]==240andposition[1]==130:text_center("Tu as reussi le niveau 4!",160,42,ja,no)text_center("Avec un score de "+str(score),160,62,ja,no)niveau_suivant=Trueelifniveau==5andposition[0]==130andposition[1]==190:text_center("Tu as reussi le niveau 5!",160,42,ja,no)text_center("Avec un score de "+str(score),160,62,ja,no)niveau_suivant=Trueelifniveau==42andposition[0]==abscisse_arriveeandposition[1]==ordonnee_arrivee:text_center("Tu as reussi le niveau 42!",160,42,ja,no)text_center("Avec un score SUPREME de "+str(score),160,62,ja,no)niveau_suivant=Trueifniveau_suivant:sleep(4.2)ifniveau==42:fin()else:niveau+=1position=[0,0]mvt=[0,0]score=0jeu()defscale():globalabscisse_scale,longueur_scale,ordonnee_scale,ordonnee_scale42longueur_scale=40ifniveau==1:ordonnee_scale=60fill_rect(abscisse_scale,60,10,longueur_scale,bl)elifniveau==2:ordonnee_scale=80fill_rect(abscisse_scale,80,10,longueur_scale,bl)elifniveau==3:ordonnee_scale=50fill_rect(abscisse_scale,50,10,longueur_scale,bl)elifniveau==4:ordonnee_scale=140fill_rect(abscisse_scale,140,10,longueur_scale,bl)elifniveau==5:ordonnee_scale=130fill_rect(abscisse_scale,130,10,longueur_scale,bl)elifniveau==42:ordonnee_scale=ordonnee_scale42fill_rect(abscisse_scale,ordonnee_scale42,10,longueur_scale,bl)defmove():globalpostion,mvtbordure=[0,0,190,310]whilenotkeydown(5):vide()scale()is_key_pressed=Falseifkeydown(0):#gauche
mvt[0]=max(position[0]-10,bordure[0])is_key_pressed=Trueelifkeydown(1):#haut
mvt[1]=max(position[1]-10,bordure[1])is_key_pressed=Trueelifkeydown(2):#bas
mvt[1]=min(position[1]+10,bordure[2])is_key_pressed=Trueelifkeydown(3):#droite
mvt[0]=min(position[0]+10,bordure[3])is_key_pressed=Trueifis_key_pressedandcollision():points()sleep(0.25)fin_niv()initialisation(1)personnage(0)position[0]=mvt[0]position[1]=mvt[1]personnage(1)defpartie():globalniveau,position,score,abscisse_scale,ordonnee_scale42,abscisse_arrivee,ordonnee_arriveeinitiation()v=[]foriinrange(0,320,10):v.append(i)#pas sur la même ligne de l'arrivée
abscisse_scale=choice(v)ordonnee_scale42=choice(v[0:19])ifniveau==1:fill_rect(310,190,10,10,ble)elifniveau==2:fill_rect(150,70,10,10,ble)elifniveau==3:fill_rect(50,100,10,10,ble)elifniveau==4:fill_rect(240,130,10,10,ble)elifniveau==5:fill_rect(130,190,10,10,ble)elifniveau==42:x,y=[],[]foriinrange(0,310,10):x.append(i)forjinrange(20,190,10):y.append(j)abscisse_arrivee=choice(x)ordonnee_arrivee=choice(y)fill_rect(abscisse_arrivee,ordonnee_arrivee,10,10,ble)move()deffin():fill_rect(0,0,320,222,no)text_center("Tu as fini le dernier niveau!!",160,42,bl,no)fill_rect(0,204,320,18,os)draw_string("Score :",0,204,bl,os)draw_string("Niveau :",160,204,bl,os)sleep(4.2)defjeu():globalniveauwhileniveau!=6:fill_rect(0,0,320,222,no)sleep(2)partie()fill_rect(0,0,320,222,no)text_center("Tu as gagné!!!",160,42,ja,no)fill_rect(0,204,320,18,os)draw_string("Score :",0,204,bl,os)draw_string("Niveau :",160,204,bl,os)sleep(4.2)menu()
During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:
Ensure the proper functioning of the site (essential cookies); and
Track your browsing to send you personalized communications if you have created a professional account on the site and can be contacted (audience measurement cookies).
With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.