dinorun.py

Created by alban-scientifique

Created on June 19, 2023

1.61 KB


from kandinsky import *
from ion import *

# Dimensions de l'écran
largeur = 320
hauteur = 222

# Position du joueur
joueur_x = 40
joueur_y = hauteur // 2

# Position de l'obstacle
obstacle_x = largeur - 10
obstacle_y = hauteur // 2

# Variables pour le déplacement
vitesse = 1
score = 0

# Fonction pour effacer l'écran
def effacer_ecran():
    fill_rect(0, 0, largeur, hauteur, color(255, 255, 255))

# Fonction pour afficher le joueur
def afficher_joueur():
    fill_rect(joueur_x, joueur_y, 10, 10)

# Fonction pour afficher l'obstacle
def afficher_obstacle():
    fill_rect(obstacle_x, obstacle_y, 10, 10)

# Fonction pour afficher le score
def afficher_score():
    draw_string("Score: " + str(score), 10, 10)

# Fonction principale du jeu
def jouer_dino_race():
    global score

    while True:
        effacer_ecran()
        afficher_joueur()
        afficher_obstacle()
        afficher_score()

        # Déplacement du joueur
        if keydown(KEY_UP) and joueur_y > 0:
            joueur_y -= vitesse
        if keydown(KEY_DOWN) and joueur_y < hauteur - 10:
            joueur_y += vitesse

        # Déplacement de l'obstacle
        obstacle_x -= vitesse

        # Vérifier la collision
        if joueur_x + 10 > obstacle_x and joueur_x < obstacle_x + 10 and joueur_y + 10 > obstacle_y and joueur_y < obstacle_y + 10:
            break

        # Mettre à jour le score
        score += 1

        wait(10)

# Règles du jeu
effacer_ecran()
draw_string("Dino Race", 90, 50)
draw_string("Appuie sur EXE pour commencer", 40, 100)

while not keydown(KEY_EXE):
    pass

# Lancement du jeu
jouer_dino_race()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

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.