This commit is contained in:
tymek 2026-05-27 16:19:20 +02:00
parent b55b76f413
commit 3972d0de03

View file

@ -4,7 +4,6 @@ from random import randrange
import tkinter.ttk as tk import tkinter.ttk as tk
def obroc_prostokat_o_2_stopnie_zg(canvas, element_id): def obroc_prostokat_o_2_stopnie_zg(canvas, element_id):
wspolrzedne = canvas.coords(element_id) wspolrzedne = canvas.coords(element_id)
xs = [wspolrzedne[i] for i in range(0, len(wspolrzedne), 2)] xs = [wspolrzedne[i] for i in range(0, len(wspolrzedne), 2)]
@ -93,7 +92,7 @@ def strzal_z_karabinu():
kat_myszy = math.atan2(mysz_y - cy, mysz_x - cx) kat_myszy = math.atan2(mysz_y - cy, mysz_x - cx)
dlugosc_lufy = 15 dlugosc_lufy = 8
start_x = cx + dlugosc_lufy * math.cos(kat_myszy) start_x = cx + dlugosc_lufy * math.cos(kat_myszy)
start_y = cy + dlugosc_lufy * math.sin(kat_myszy) start_y = cy + dlugosc_lufy * math.sin(kat_myszy)
@ -119,7 +118,7 @@ def stzal_gluwny(event):
kat_myszy = math.atan2(mysz_y - cy, mysz_x - cx) kat_myszy = math.atan2(mysz_y - cy, mysz_x - cx)
dlugosc_lufy = 15 dlugosc_lufy = 8
start_x = cx + dlugosc_lufy * math.cos(kat_myszy) start_x = cx + dlugosc_lufy * math.cos(kat_myszy)
start_y = cy + dlugosc_lufy * math.sin(kat_myszy) start_y = cy + dlugosc_lufy * math.sin(kat_myszy)
@ -133,6 +132,17 @@ def stzal_gluwny(event):
pociski.append({"id": id_pocisku, "dx": dx, "dy": dy}) pociski.append({"id": id_pocisku, "dx": dx, "dy": dy})
def cele_ruch():
global cele
for idx, c in enumerate(cele):
if c["x1"] > 0:
canvas.move(c["id"], -1, 0)
c["x1"] -= 1
c["x2"] -= 1
print(idx, c["x1"], c["y1"], c["x2"], c["y2"])
def aktualizuj_karabiny(): def aktualizuj_karabiny():
global cele_zniszczone global cele_zniszczone
szerokosc_okna = canvas.winfo_width() szerokosc_okna = canvas.winfo_width()
@ -191,6 +201,7 @@ def aktualizuj_karabiny():
if cele_zniszczone == cel_wymagany: if cele_zniszczone == cel_wymagany:
tekst_celu["text"] = "MISJA UKOŃCZONA! ZNISZCZYŁEŚ CELE!" tekst_celu["text"] = "MISJA UKOŃCZONA! ZNISZCZYŁEŚ CELE!"
tekst_celu["foreground"] = "gold" tekst_celu["foreground"] = "gold"
root.after(5000, lambda: tekst_celu.pack_forget())
kamyki_do_usuniecia.sort(reverse=True) kamyki_do_usuniecia.sort(reverse=True)
for idx in kamyki_do_usuniecia: for idx in kamyki_do_usuniecia:
@ -439,21 +450,34 @@ def gluwna():
aktualizuj_pozycje_figur() aktualizuj_pozycje_figur()
rk_slad = 1.5 rk_slad = 1.5
klawisze_ruchu = ["w", "s", "a", "d"]
sxl = (wspol[0] * 3 + wspol[6]) / 4 sxl = (wspol[0] * 3 + wspol[6]) / 4
syl = (wspol[1] * 3 + wspol[7]) / 4 syl = (wspol[1] * 3 + wspol[7]) / 4
sxp = (wspol[0] + wspol[6] * 3) / 4 sxp = (wspol[0] + wspol[6] * 3) / 4
syp = (wspol[1] + wspol[7] * 3) / 4 syp = (wspol[1] + wspol[7] * 3) / 4
k1 = "#00" + str(randrange(4000, 6000, 100)) if any(wcisniete_klawisze[k] for k in klawisze_ruchu):
k2 = "#00" + str(randrange(4000, 6000, 100)) k1 = "#00" + str(randrange(5000, 6000, 100))
k2 = "#00" + str(randrange(5000, 6000, 100))
sl = True
elif x != 0:
k1 = "#00" + str(randrange(6000, 7000, 100))
k2 = "#00" + str(randrange(6000, 7000, 100))
sl = True
else:
sl = False
k2=k1="#000000"
t1 = canvas.create_oval(sxl - rk_slad, syl - rk_slad, sxl + rk_slad, syl + rk_slad, fill=k1, outline="") if sl:
t2 = canvas.create_oval(sxp - rk_slad, syp - rk_slad, sxp + rk_slad, syp + rk_slad, fill=k2, outline="") t1 = canvas.create_oval(sxl - rk_slad, syl - rk_slad, sxl + rk_slad, syl + rk_slad, fill=k1, outline="")
canvas.tag_lower(t1) t2 = canvas.create_oval(sxp - rk_slad, syp - rk_slad, sxp + rk_slad, syp + rk_slad, fill=k2, outline="")
canvas.tag_lower(t2) canvas.tag_lower(t1)
canvas.tag_lower(t1) canvas.tag_lower(t2)
canvas.tag_lower(t2) canvas.tag_lower(t1)
canvas.tag_lower(t2)
cele_ruch()
root.after(16, gluwna) root.after(16, gluwna)
@ -566,7 +590,6 @@ for tekst in teksty_napisow:
id_tekstu = canvas.create_text(0, 0, text=tekst, font=("Arial", 10, "bold"), fill="black") id_tekstu = canvas.create_text(0, 0, text=tekst, font=("Arial", 10, "bold"), fill="black")
napisy_ids.append(id_tekstu) napisy_ids.append(id_tekstu)
cele = [] cele = []
cele_zniszczone = 0 cele_zniszczone = 0
cel_wymagany = 5 cel_wymagany = 5