Ecran titre de jeu
ninouillelanouille
Messages postés
5
Statut
Membre
-
dsy73 Messages postés 9003 Date d'inscription Statut Contributeur Dernière intervention -
dsy73 Messages postés 9003 Date d'inscription Statut Contributeur Dernière intervention -
Bonjour,
je suis débutante en python et je dois créer un jeu qui consiste à faire gonfler un ballon jusqu'à une punaise. Le jeu fonctionne mais j'aimerais créer un écran titre pour le jeu, contenant un bouton démarrer qui lancerait toutes mes fonctions. Comment faire ?
Merci d'avance
je suis débutante en python et je dois créer un jeu qui consiste à faire gonfler un ballon jusqu'à une punaise. Le jeu fonctionne mais j'aimerais créer un écran titre pour le jeu, contenant un bouton démarrer qui lancerait toutes mes fonctions. Comment faire ?
Merci d'avance
1 réponse
-
Salut
difficile de te répondre car tu n'indiques pas comment tu as créé ton jeu. PyGame n'est pas la seule bibliothèque existante. Qu'utilises-tu ?
Sinon tu crées un nouvel écran, non ?-
Désolée, j'utilise Tkinter
Voilà mon code:
from Tkinter import*
import time
fen1=Tk()
fen1.title("Le plus grand des ballons")
size=20
now=time.time()
future=now+4
def jeu():
cadre=Canvas
cadre=Canvas(fen1,width=700, height=550, bg="black")
x=280
y=320
ballon=cadre.create_oval(x-size, y-size, x+size, y+size, fill="pink")
def commencer():
cadre.itemconfigure(ballon, fill="pink")
start.destroy()
def pomper():
global size
if size<90:
size=size+6
cadre.coords(ballon, x-size, y-size, x+size, y+size)
if size>90:
cadre.delete(ballon)
cadre.create_text (700/2, 550/2, text="PERDU! Ton ballon a éclaté", fill='cyan', font='Arial 45')
if size>80 and size<87 and time.time()<future and time.time()>future-1:
cadre.create_text (700/2, 550/2, text="BRAVO! C'est parfait", fill='cyan', font='Arial 45')
cadre.delete(ballon)
if size<79 and size>62 and time.time()<future and time.time()>future-1:
cadre.create_text (700/2, 550/2, text="BOF! C'est moyen", fill='cyan', font='Arial 45')
cadre.delete(ballon)
if size<61 and time.time()<future and time.time()>future-1:
cadre.create_text (700/2, 550/2, text="NUL! Entraine toi", fill='cyan', font='Arial 45')
cadre.delete(ballon)
def stop():
fen1.destroy()
#écran titre
ecrantitre=Canvas(fen1,width=700, height=550, bg="black")
start=Button(fen1, text="jouer!", command=jeu)
start.pack()
#autres widgets
pomper=Button(fen1, text="Souffle", command=pomper)
pomper.pack()
fen1.mainloop()
Quand j'essaie de faire fonctionner le programme, il me dit "pomper is not defined" pourtant la fonction est bien définie et je pense que cela est lié au fait qu'elle soit incluse elle même dans la fonction "jeu"
je ne sais pas du tout comment faire -
-
from Tkinter import*
import time
fen1=Tk()
fen1.title("Le plus grand des ballons")
size=20
now=time.time()
future=now+4
def jeu():
x=280
y=320
ballon=cadre.create_oval(x-size, y-size, x+size, y+size, fill="pink")
def commencer():
cadre.itemconfigure(ballon, fill="pink")
start.destroy()
def souffler():
global size
if size<90:
size=size+6
cadre.coords(ballon, x-size, y-size, x+size, y+size)
if size>90:
cadre.delete(ballon)
cadre.create_text (700/2, 550/2, text="PERDU! Ton ballon a éclaté", fill='cyan', font='Arial 45')
if size>80 and size<87 and time.time()<future and time.time()>future-1:
cadre.create_text (700/2, 550/2, text="BRAVO! C'est parfait", fill='cyan', font='Arial 45')
cadre.delete(ballon)
if size<79 and size>62 and time.time()<future and time.time()>future-1:
cadre.create_text (700/2, 550/2, text="BOF! C'est moyen", fill='cyan', font='Arial 45')
cadre.delete(ballon)
if size<61 and time.time()<future and time.time()>future-1:
cadre.create_text (700/2, 550/2, text="NUL! Entraine toi", fill='cyan', font='Arial 45')
cadre.delete(ballon)
def stop():
fen1.destroy()
#écran titre
ecrantitre=Canvas(fen1,width=700, height=550, bg="black")
start=Button(fen1, text="jouer!", command=jeu)
start.pack()
#autres widgets
cadre=Canvas
cadre=Canvas(fen1,width=700, height=550, bg="black")
pomper=Button(fen1, text="Souffle", command=souffler)
pomper.pack()
quitter=Button(fen1, text="quitter", command=stop)
quitter.pack()
fen1.mainloop() -
-
-