importkandinskyaskdimportionimportnumpyasnpfromtimeimportsleep# Configuration de l'écran de la calculatrice NumWorks
WIDTH=320HEIGHT=240# Taille du niveau
LEVEL_WIDTH=64LEVEL_HEIGHT=64# Couleurs
WHITE=kd.color(255,255,255)BLUE=kd.color(0,0,255)GREEN=kd.color(0,255,0)# Niveau de Mario (matrice de 64x64)
level=[[WHITE]*LEVEL_WIDTHfor_inrange(LEVEL_HEIGHT)]# Dessiner le sol
forxinrange(LEVEL_WIDTH):level[LEVEL_HEIGHT-1][x]=GREEN# Position initiale de Mario
x_mario=10y_mario=LEVEL_HEIGHT-2# Tableau de touches
keys=np.zeros(256,dtype=bool)# Fonction pour effacer l'écran
defeffacer_ecran():kd.fill_rect(0,0,WIDTH,HEIGHT,WHITE)# Boucle de jeu
whileTrue:effacer_ecran()# Déplacement de Mario
ifkeys[ion.keypad.LEFT]andx_mario>0:x_mario-=1ifkeys[ion.keypad.RIGHT]andx_mario<LEVEL_WIDTH-1:x_mario+=1# Dessin du niveau
foryinrange(LEVEL_HEIGHT):forxinrange(LEVEL_WIDTH):kd.fill_rect(x*5,y*5,5,5,level[y][x])# Dessin de Mario
kd.fill_rect(x_mario*5,y_mario*5,5,5,BLUE)# Rafraîchir l'écran
kd.display()# Pause pour contrôler la vitesse de rafraîchissement
sleep(0.05)# 50 millisecondes
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.