dino_game.py

Created by elnix90

Created on March 15, 2023

2.45 KB

Ce programme permet de jouer au très célèbre dino game créé par google


from random import randint
from kandinsky import fill_rect,draw_string,get_pixel
from ion import keydown,KEY_OK,KEY_UP
from time import sleep
meilleur_score=0
def dino(y_dino,e=True):
  if e:
    fill_rect(40,y_dino,10,-20,"black")
    fill_rect(50,y_dino-10,10,-10,"black")
    fill_rect(54,y_dino-14,2,-2,"white")
  else:
    fill_rect(40,y_dino,10,-20,"white")
    fill_rect(50,y_dino-10,10,-10,"white")
  if get_pixel(40,y_dino)==(248,0,0):
    return True
  elif get_pixel(50,y_dino)==(248,0,0):
    return True
  elif get_pixel(60,y_dino-11)==(248,0,0):
    return True
  elif get_pixel(60,y_dino-21)==(248,0,0):
    return True
def cactus(x,type,taille,couleur):
  if type==0:
    fill_rect(x,100,10,taille,couleur)
  elif type==1:
    fill_rect(x-1,100,10,taille,couleur)
    fill_rect(x+10,100,10,taille-5,couleur)
  elif type==2:
    fill_rect(x-2,100,10,taille-3,couleur)
    fill_rect(x+9,100,10,taille,couleur)
    fill_rect(x+20,100,10,taille-7,couleur)
while 1:
  fill_rect(0,0,320,222,"black")
  fill_rect(0,0,320,100,"white")
  dino(100)
  score=0
  draw_string("Score:",40,120,"orange","black")
  draw_string(str(score),200,120,"blue","black")
  draw_string("Meilleur score:",40,140,"orange","black")
  draw_string(str(meilleur_score),200,140,"blue","black")
  vitesse=0.04
  while 1:
    distance=320
    t=100
    taille=randint(-26,-19)
    type=randint(0,2)
    while distance>-10:
      if keydown(KEY_UP):
        s=1
        for i in range(10):
          dino(t,False)
          if s<6:
            t-=10
            s+=1
          else:
            t+=10
          dino(t)
          sleep(vitesse-0.002)
          cactus(distance,type,taille,"white")
          distance-=10
          cactus(distance,type,taille,"red")
          if dino(t):
            break
        if dino(t):
          break
      if dino(t):
        break
      sleep(vitesse)
      cactus(distance,type,taille,"white")
      distance-=10
      cactus(distance,type,taille,"red")
    vitesse-=0.001
    score+=1
    if score>meilleur_score:
      meilleur_score=score
    draw_string("Score:",40,120,"orange","black")
    draw_string(str(score),200,120,"blue","black")
    draw_string("Meilleur score:",40,140,"orange","black")
    draw_string(str(meilleur_score),200,140,"blue","black")
    if dino(t):
      draw_string("BRUH!",135,80,"blue","white")
      draw_string("REJOUER:",100,200,"white","black")
      draw_string("OK",190,200,"green","black")
      break
  while not keydown(KEY_OK):True

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.