Flappy bird

camille - Modifié le 23 mai 2020 à 19:56
Whismeril
Messages postés
17339
Date d'inscription
mardi 11 mars 2003
Statut
Modérateur
Dernière intervention
24 mai 2022
- 23 mai 2020 à 20:26
Bonjour , je dois coder un jeux flapppy bird mais je bloque beaucoup pour les fonctions pause , play et le message game over lorsque l'oiseau touche un tuyeau , j'ai également du mal avec les trois points de vie qui devront s'effacer et les cœurs, merci d'avance ! (tout doit se faire en tkinter)

voici mon debut de travail :

#importation des modules

from tkinter import *
from math import *


#définition des fonction


def haut (event):
    zone_dessin.move(flappy_c, 0, -8)
    zone_dessin.move(flap, 0, -8)
    zone_dessin.move(flappy_y, 0, -8)
    zone_dessin.move(flappy_yn, 0, -8)
    zone_dessin.move(aile, 0, -8)
    zone_dessin.move(bec, 0, -8)

def bas (event):
    zone_dessin.move(flappy_c, 0, 8)
    zone_dessin.move(flap, 0, 8)
    zone_dessin.move(flappy_y, 0, 8)
    zone_dessin.move(flappy_yn, 0, 8)
    zone_dessin.move(aile, 0, 8)
    zone_dessin.move(bec, 0, 8)


def deplacer1(zone_dessin, tuyau1, x) :
    x -= 5
    zone_dessin.move(tuyau1, -5, 0)
    if x > 0 :
        zone_dessin.after(100, deplacer1, zone_dessin, tuyau1, x)

def deplacer2(zone_dessin, t1, x) :
    x -= 5
    zone_dessin.move(t1, -5, 0)
    if x > 0 :
        zone_dessin.after(100, deplacer2, zone_dessin, t1, x)


def deplacer3(zone_dessin, tuyau2, x) :
    x -= 5
    zone_dessin.move(tuyau2, -5, 0)
    if x > 0 :
        zone_dessin.after(100, deplacer3, zone_dessin, tuyau2, x)

def deplacer4(zone_dessin, t2, x) :
    x -= 5
    zone_dessin.move(t2, -5, 0)
    if x > 0 :
        zone_dessin.after(100, deplacer4, zone_dessin, t2, x)

def deplacer5(zone_dessin, tuyau3, x) :
    x -= 5
    zone_dessin.move(tuyau3, -5, 0)
    if x > 0 :
        zone_dessin.after(100, deplacer5, zone_dessin, tuyau3, x)

def deplacer6(zone_dessin, t3, x) :
    x -= 5
    zone_dessin.move(t3, -5, 0)
    if x > 0 :
        zone_dessin.after(100, deplacer6, zone_dessin, t3, x)

def deplacer7(zone_dessin, tuyau4, x) :
    x -= 5
    zone_dessin.move(tuyau4, -5, 0)
    if x > 0 :
        zone_dessin.after(100, deplacer7, zone_dessin, tuyau4, x)

def deplacer8(zone_dessin, t4, x) :
    x -= 5
    zone_dessin.move(t4, -5, 0)
    if x > 0 :
        zone_dessin.after(100, deplacer8, zone_dessin, t4, x)


#création de l’objet principal (fenêtre vide)

fenetre = Tk()
fenetre.title("Flappy Bird")


#création des widgets esclaves

zone_dessin = Canvas(fenetre,height = 500,width = 800,bg = "PaleTurquoise2")


#création des objets dans les widgets esclaves

buisson1 = zone_dessin.create_arc(0,400,50,435, width = 2 ,outline = "spring green" , fill = "spring green",extent=180)
buisson2 = zone_dessin.create_arc(40,405,80,435, width = 2 ,outline = "spring green" , fill = "spring green", extent = 180)
buisson3 = zone_dessin.create_arc(70,400,100,450, width = 2 ,outline = "spring green" , fill = "spring green", start = 50)
buisson4 = zone_dessin.create_arc(90,390,150,450, width = 2 ,outline = "spring green" , fill = "spring green", extent = 180)
buisson5 = zone_dessin.create_arc(145,395,180,445, width = 2 ,outline = "spring green" , fill = "spring green", extent = 180)
buisson6 = zone_dessin.create_arc(176,400,210,435, width = 2 ,outline = "spring green" , fill = "spring green", extent = 180)
buisson7 = zone_dessin.create_arc(200,410,260,450, width = 2 ,outline = "spring green" , fill = "spring green", extent = 180)
buisson8 = zone_dessin.create_arc(230,400,290,450, width = 2 ,outline = "spring green" , fill = "spring green", extent = 180)
buisson9 = zone_dessin.create_arc(280,405,320,450, width = 2 ,outline = "spring green" , fill = "spring green", extent = 180)
buisson10 = zone_dessin.create_arc(310,395,350,450, width = 2 ,outline = "spring green" , fill = "spring green", extent = 180)
buisson11 = zone_dessin.create_arc(340,400,400,440, width = 2 ,outline = "spring green" , fill = "spring green", extent = 180)
buisson12 = zone_dessin.create_arc(390,400,440,435, width = 2 ,outline = "spring green" , fill = "spring green",extent=180)
buisson13 = zone_dessin.create_arc(430,405,470,435, width = 2 ,outline = "spring green" , fill = "spring green", extent = 180)
buisson14 = zone_dessin.create_arc(430,400,460,450, width = 2 ,outline = "spring green" , fill = "spring green", start = 50)
buisson15 = zone_dessin.create_arc(450,390,510,450, width = 2 ,outline = "spring green" , fill = "spring green", extent = 180)
buisson16 = zone_dessin.create_arc(505,395,545,445, width = 2 ,outline = "spring green" , fill = "spring green", extent = 180)
buisson17 = zone_dessin.create_arc(541,400,575,435, width = 2 ,outline = "spring green" , fill = "spring green", extent = 180)
buisson18 = zone_dessin.create_arc(565,410,620,450, width = 2 ,outline = "spring green" , fill = "spring green", extent = 180)
buisson19 = zone_dessin.create_arc(590,400,650,450, width = 2 ,outline = "spring green" , fill = "spring green", extent = 180)
buisson20 = zone_dessin.create_arc(640,405,680,450, width = 2 ,outline = "spring green" , fill = "spring green", extent = 180)
buisson21 = zone_dessin.create_arc(670,395,710,450, width = 2 ,outline = "spring green" , fill = "spring green", extent = 180)
buisson22 = zone_dessin.create_arc(700,400,760,440, width = 2 ,outline = "spring green" , fill = "spring green", extent = 180)
buisson23 = zone_dessin.create_arc(750,400,800,435, width = 2 ,outline = "spring green" , fill = "spring green",extent=180)
buisson24 = zone_dessin.create_arc(790,395,810,450, width = 2 ,outline = "spring green" , fill = "spring green", extent = 180)

buisson25 = zone_dessin.create_rectangle(0,420,805,436, width = 2 ,outline = "spring green" , fill = "spring green")


sol = zone_dessin.create_rectangle(0,450,805,500, width = 1 ,outline = "tan" , fill = "tan")
ligne = zone_dessin.create_line(0,448,805,448, width = 3 , fill = "peru")
herbe = zone_dessin.create_rectangle(0,437,805,447, width = 1 ,outline = "black" , fill = "pale green")

haut = zone_dessin.create_rectangle(0,0,805,50, width = 1 ,outline ="black", fill="tan")


pause = zone_dessin.create_rectangle(10,8,44,42, width = 1 ,outline ="black", fill="white")
pause1 = zone_dessin.create_rectangle(18,14,25,36, width = 1 ,outline ="black", fill="black")
pause2 = zone_dessin.create_rectangle(30,14,37,36, width = 1 ,outline ="black", fill="black")

recvies = zone_dessin.create_rectangle(55,8,200,42, width = 1 ,outline ="black", fill="beige")

text_1=zone_dessin.create_text(700,30,text="Flappy bird",fill="black",font=("Courier", 18))


nuage0 = zone_dessin.create_oval(80,110,110,140, width = 2 ,outline = "white" , fill = "white")
nuage1 = zone_dessin.create_oval(95,90,130,120, width = 2 ,outline = "white" , fill = "white")
nuage2 = zone_dessin.create_oval(125,90,170,150, width = 2 ,outline = "white" , fill = "white")
nuage3 = zone_dessin.create_oval(100,130,140,155, width = 2 ,outline = "white" , fill = "white")
nuage4 = zone_dessin.create_oval(135,110,175,154, width = 2 ,outline = "white" , fill = "white")
nuage5 = zone_dessin.create_oval(100,115,130,145, width = 2 ,outline = "white" , fill = "white")
nuage6 = zone_dessin.create_oval(150,98,190,130, width = 2 ,outline = "white" , fill = "white")
nuage7 = zone_dessin.create_oval(155,120,192,145, width = 2 ,outline = "white" , fill = "white")

nuage00 = zone_dessin.create_oval(600,110,630,140, width = 2 ,outline = "white" , fill = "white")
nuage01 = zone_dessin.create_oval(620,95,655,130, width = 2 ,outline = "white" , fill = "white")
nuage02 = zone_dessin.create_oval(645,90,675,115, width = 2 ,outline = "white" , fill = "white")
nuage03 = zone_dessin.create_oval(665,97,695,125, width = 2 ,outline = "white" , fill = "white")
nuage04 = zone_dessin.create_oval(615,130,645,155, width = 2 ,outline = "white" , fill = "white")
nuage05 = zone_dessin.create_oval(635,135,670,160, width = 2 ,outline = "white" , fill = "white")
nuage06 = zone_dessin.create_oval(665,133,695,154, width = 2 ,outline = "white" , fill = "white")
nuage07 = zone_dessin.create_oval(685,110,715,140, width = 2 ,outline = "white" , fill = "white")
nuage08 = zone_dessin.create_oval(625,100,690,140, width = 2 ,outline = "white" , fill = "white")

nuage000 = zone_dessin.create_oval(245,85,280,110, width = 2 ,outline = "white" , fill = "white")
nuage001 = zone_dessin.create_oval(265,75,295,105, width = 2 ,outline = "white" , fill = "white")
nuage002 = zone_dessin.create_oval(260,95,290,121, width = 2 ,outline = "white" , fill = "white")
nuage003 = zone_dessin.create_oval(280,85,310,120, width = 2 ,outline = "white" , fill = "white")
nuage004 = zone_dessin.create_oval(285,80,318,110, width = 2 ,outline = "white" , fill = "white")

tuyau1 = zone_dessin.create_rectangle(400,437,445,300, width=1, outline="black", fill = "green")
tuyau2 = zone_dessin.create_rectangle(400,50,445,200, width=1, outline="black", fill = "green")
tuyau3 = zone_dessin.create_rectangle(600,437,645,380, width=1, outline="black", fill = "green")
tuyau4 = zone_dessin.create_rectangle(600,50,645,280, width=1, outline="black", fill = "green")

t1 = zone_dessin.create_rectangle(395,288,450,300, width=1, outline="black", fill = "green")
t2 = zone_dessin.create_rectangle(395,200,450,212, width=1, outline="black", fill = "green")
t3 = zone_dessin.create_rectangle(595,368,650,380, width=1, outline="black", fill = "green")
t4 = zone_dessin.create_rectangle(595,280,650,292, width=1, outline="black", fill = "green")


flap = zone_dessin.create_polygon(180,251,180,279,200,265,width = 1, outline = "black", fill="LightGoldenrod1")
flappy_c = zone_dessin.create_oval(190,250,230,280, width = 1 ,outline = "black" , fill = "yellow")
flappy_y = zone_dessin.create_oval(211,252,224,265, width = 1 ,outline = "black" ,fill = "white")
flappy_yn = zone_dessin.create_oval(216,256,224,265, width = 1 ,outline = "black", fill="black")
bec = zone_dessin.create_polygon(230,262,230,270,240,266, width = 1, outline = "black", fill="orange")
aile = zone_dessin.create_polygon(185,285,200,265,213,273,width = 1, outline = "black", fill="LightGoldenrod1")


#positionnement des widgets

zone_dessin.grid(row = 1)

#liaison et évènement

fenetre.bind("<Down>", bas)
fenetre.bind("<Up>", haut)


deplacer1(zone_dessin, tuyau1, 800)
deplacer2(zone_dessin, t1, 800)
deplacer3(zone_dessin, tuyau2, 800)
deplacer4(zone_dessin, t2, 800)
deplacer5(zone_dessin, tuyau3, 800)
deplacer6(zone_dessin, t3, 800)
deplacer7(zone_dessin, tuyau4, 800)
deplacer8(zone_dessin, t4, 800)


#ouvre le gestionnaire d’évènements

fenetre.mainloop()
A voir également:

3 réponses

@karamel
Messages postés
1807
Date d'inscription
vendredi 9 mai 2008
Statut
Modérateur
Dernière intervention
5 mai 2022
144
23 mai 2020 à 19:57
j'ai ajouter l'indentation
1
je n'ai pas compris
0
Whismeril
Messages postés
17339
Date d'inscription
mardi 11 mars 2003
Statut
Modérateur
Dernière intervention
24 mai 2022
596
23 mai 2020 à 18:22
Bonjour
En python, il y a truc primordial : l’indentation.

Pour qu’elle soit préservée sur il site, il faut utiliser les balises de codes comme décrit sur ce petit tuto https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code

Sans cela aucune chance que quelqu’un puisse te venir en aide.
Tu as encore un peu de temps pour modifier ton message
0
pouvez vous m'aider ?
0
Whismeril
Messages postés
17339
Date d'inscription
mardi 11 mars 2003
Statut
Modérateur
Dernière intervention
24 mai 2022
596 > camille
23 mai 2020 à 20:26
Non, mais karamel l’a fait, et il suffit de lire le tuto que je t’ai mis en lien pour comprendre
0
pouvez vous m'aider avec mon programme
0