flappy_bird.py

Created by naul

Created on December 12, 2022

1.72 KB

Flappy Bird avec une option Bot. Appuyez sur OK pour sauter.


from math import *
from matplotlib.pyplot import *
from random import *
from kandinsky import *
from ion import *
from time import *
bird=0
jump=0
g=0
pipe=-20
pepe=0
score=-1
bestscore=0
autopilot=0
gen=0
while True:
  draw_string("Score:"+str(score),0,0)
  draw_string("Best Score:"+str(bestscore),0,15)
  fill_rect(30,bird,10,10,color('white'))
  if jump<1:
    bird+=g
    g+=1
  else:
    bird-=jump
    jump-=1
  if autopilot==1:
    if pipe>10:
      if bird>pepe+45:
        jump=9
        g=0
    else:
      if bird>100:
        jump=9
        g=0
  else:
    if keydown(KEY_OK) and jump<1 and bird>45:
     jump=9
     g=0
  fill_rect(pipe,0,20,pepe,color(255,255,255))
  fill_rect(pipe,pepe+60,20,222-(pepe+30),color(255,255,255))
  if pipe<-20:
    pepe=randint(0,150)
    pipe=342
    score+=1
  pipe-=4+round(score/10)
  fill_rect(pipe,0,20,pepe,color(0,255,0))
  fill_rect(pipe,pepe+60,20,222-(pepe+30),color(0,255,0))
  if bird<-5 or bird>212 or get_pixel(35,bird)==color(0,255,0) or get_pixel(45,bird)==color(0,255,0):
    if score>bestscore:
      bestscore=score
    if autopilot==1:
      gen+=1
    fill_rect(0,0,322,222,color(255,255,255))
    bird=0
    jump=0
    g=0
    pipe=-20
    pepe=0
    score=-1
    fill_rect(30,bird,10,10,color('brown'))
    if autopilot==0:
      for i in range(4):
        draw_string(str(round(4-i)),50,50)
        sleep(1/2)
        fill_rect(50,50,20,20,color(255,255,255))
  if keydown(KEY_BACKSPACE):
    return print("Best Score:"+bestscore)
  if autopilot==0:
    fill_rect(30,bird,10,10,color('brown'))
  if autopilot==1:
    draw_string("Gen:"+str(gen),0,200)
  if autopilot==0:
    sleep(1/32)
  autopilot=0
#BestScore=78
#IAScore=193
#Press OK to jump
#Have fun !
#Made by Lear.Co

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.