Mar-25-2019, 07:27 AM
Hi guys,
I am working on a "shooting game" where there are 2 players moving up and down and shooting. But i can not make moving single shots.
They are called "strela". "Strela" creates when i press "d" key and it is supposed to move to the right (or left).
I tried to move ammo (strela) with this command:
def pohyb_strela():
if janko==1:
platno.move(strela,+10,0)
pohyb_strela()
Where janko==1 is always true so it is cycled.
But it says that "strela" is not defined.
Please help. Thank you
I am working on a "shooting game" where there are 2 players moving up and down and shooting. But i can not make moving single shots.
They are called "strela". "Strela" creates when i press "d" key and it is supposed to move to the right (or left).
I tried to move ammo (strela) with this command:
def pohyb_strela():
if janko==1:
platno.move(strela,+10,0)
pohyb_strela()
Where janko==1 is always true so it is cycled.
But it says that "strela" is not defined.
Please help. Thank you
import tkinter velkost=20 pole=[] pole2=[] janko=1 def kolizia(): if platno.coords(bublina_1)[2]>= platno.coords(bublina_2)[0] and platno.coords(bublina_1)[3]>= platno.coords(bublina_2)[1]: print("kolizia") def b1_hore(udalost): platno.move(bublina_1,0,-10) def posun_bublinu(udalost): klaves=udalost.keysym if platno.coords(bublina_1)[1]<=0: if klaves=="s": platno.move(bublina_1,0,+10) if klaves=="d": strelba() elif platno.coords(bublina_1)[3]>=600: if klaves=="w": platno.move(bublina_1,0,-10) if klaves=="d": strelba() else: if klaves=="s": platno.move(bublina_1,0,+10) if klaves=="w": platno.move(bublina_1,0,-10) if klaves=="d": strelba() if platno.coords(bublina_2)[1]<=0: if klaves=="Down": platno.move(bublina_2,0,+10) if klaves=="Left": strelba2() elif platno.coords(bublina_2)[3]>=600: if klaves=="Up": platno.move(bublina_2,0,-10) if klaves=="Left": strelba2() else: if klaves=="Down": platno.move(bublina_2,0,+10) if klaves=="Left": strelba2() if klaves=="Up": platno.move(bublina_2,0,-10) def strelba(): sx=platno.coords(bublina_1)[0] sy=platno.coords(bublina_1)[1] strela=platno.create_rectangle(sx,sy,sx+15,sy+15,fill="yellow") pole.append(strela) pohyb_strela() def strelba2(): sx2=platno.coords(bublina_2)[0] sy2=platno.coords(bublina_2)[1] strela2=platno.create_rectangle(sx2,sy2,sx2+15,sy2+15,fill="green") pole2.append(strela2) def pohyb_strela(): if janko==1: platno.move(strela,+10,0) pohyb_strela() okno=tkinter.Tk() okno.title("Strielacka") platno=tkinter.Canvas(okno, height=600, width=600, bg="lightgray") platno.pack() bublina_1=platno.create_rectangle(60-velkost/2,150-velkost/2,60+velkost/2, 150+velkost/2,fill="red") bublina_2=platno.create_rectangle(240-velkost/2,150-velkost/2,240+velkost/2, 150+velkost/2,fill="blue") platno.bind_all("<Key>", posun_bublinu) okno.mainloop()