import kandinsky as kd import ion import numpy as np from time import sleep # Configuration de l'écran de la calculatrice NumWorks WIDTH = 320 HEIGHT = 240 # Taille du niveau LEVEL_WIDTH = 64 LEVEL_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_WIDTH for _ in range(LEVEL_HEIGHT)] # Dessiner le sol for x in range(LEVEL_WIDTH): level[LEVEL_HEIGHT - 1][x] = GREEN # Position initiale de Mario x_mario = 10 y_mario = LEVEL_HEIGHT - 2 # Tableau de touches keys = np.zeros(256, dtype=bool) # Fonction pour effacer l'écran def effacer_ecran(): kd.fill_rect(0, 0, WIDTH, HEIGHT, WHITE) # Boucle de jeu while True: effacer_ecran() # Déplacement de Mario if keys[ion.keypad.LEFT] and x_mario > 0: x_mario -= 1 if keys[ion.keypad.RIGHT] and x_mario < LEVEL_WIDTH - 1: x_mario += 1 # Dessin du niveau for y in range(LEVEL_HEIGHT): for x in range(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