Mar-30-2018, 03:45 PM
Hey everyone :D
So i need to make a little game for school and i have a problem but first i need to explain how this game will work :
So basically you'll have an ennemy (boxe type game btw) in front of you that will throw some punches at you and you have a window of (for now it's 1s) to respond by pressing a key my problem
right now is that the key isn't detected and i'm not too sure of what going wriong, could anyone help please ? (Sorry for the lack of comment, please ask if you have any question)
So i need to make a little game for school and i have a problem but first i need to explain how this game will work :
So basically you'll have an ennemy (boxe type game btw) in front of you that will throw some punches at you and you have a window of (for now it's 1s) to respond by pressing a key my problem
right now is that the key isn't detected and i'm not too sure of what going wriong, could anyone help please ? (Sorry for the lack of comment, please ask if you have any question)
from tkinter import* from random import* import time D,H,B,G=0,0,0,0 def AttackSelect(C): C=randint(1,4) C=1 if C==1: txt = canvas.create_text(700, 80, text="Jab", font="Arial 16 italic", fill="black") elif C==2: txt = canvas.create_text(700, 450, text="Direct", font="Arial 16 italic", fill="red") elif C==3: S=randint(1,2) if S==1: txt = canvas.create_text(70, 450, text="Right Hook", font="Arial 16 italic", fill="blue") else: txt = canvas.create_text(1330, 450, text="Left Hook", font="Arial 16 italic", fill="blue") elif C==4: txt = canvas.create_text(700, 800, text="Uppercut", font="Arial 16 italic", fill="Orange") fenetre.update() return C def Clear(): canvas.create_rectangle(670, 70, 730, 90, fill="white", outline="white") canvas.create_rectangle(640, 440, 760, 460, fill="white", outline="white") canvas.create_rectangle(15, 440, 150, 460, fill="white", outline="white") canvas.create_rectangle(1260, 440, 1400, 460, fill="white", outline="white") canvas.create_rectangle(560, 790, 840, 810, fill="white", outline="white") fenetre.update() def Gauche(event): global G print("gauche") G=1 def Droite(event): global D print("Droite") D=1 def Haut(event): print("haut") global H H=1 def Bas(event): return (True) def AttackDefense(V): global G,D,H,B if C==1: max = 1 start = time.time() while True: for i in range (500000): a=1 remaining = max + start - time.time() print(D,G,H) if D==1 or G==1 or H==1: V=2 G,D,H=0,0,0 return V elif remaining <= 0: V=0 return V def Timer(): max = 1 start = time.time() while True: for i in range (500000): a=1 remaining = max + start - time.time() if remaining <= 0: break def jeu(): global V,E,J,C while J>0 and E>0: C=AttackSelect(C) V=AttackDefense(V) Clear() print(V) if V==2: E=E-100 canvas.create_rectangle(E+10,30,1400,40,fill="grey") elif V==0: J=J-100 canvas.create_rectangle(J+10,820,1400,830,fill="grey") Timer() fenetre = Tk() canvas = Canvas(fenetre, width=1440, height=900, background='white') PVJ = canvas.create_rectangle(10,820,1400,830,fill="red") PVE = canvas.create_rectangle(10, 30, 1400, 40, fill="yellow") canvas.pack() fenetre.update() canvas.bind('<Left>',Gauche) canvas.bind('<Right>',Droite) canvas.bind('<Up>',Haut) canvas.bind('<Down>',Bas) D,H,B,G=0,0,0,0 C=0 V=0 J=1390 E=1390 jeu() fenetre.mainloop()