This commit is contained in:
tymek 2026-05-17 22:24:36 +02:00
parent 7cf170766e
commit b55b76f413
2 changed files with 92 additions and 3 deletions

6
.idea/vcs.xml Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View file

@ -4,6 +4,7 @@ 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)]
@ -133,12 +134,13 @@ def stzal_gluwny(event):
def aktualizuj_karabiny(): def aktualizuj_karabiny():
global cele_zniszczone
szerokosc_okna = canvas.winfo_width() szerokosc_okna = canvas.winfo_width()
wysokosc_okna = canvas.winfo_height() wysokosc_okna = canvas.winfo_height()
pociski_do_usuniecia = [] pociski_do_usuniecia = []
kamyki_do_usuniecia = [] kamyki_do_usuniecia = []
cele_do_usuniecia = []
for i in range(len(karabiny) - 1, -1, -1): for i in range(len(karabiny) - 1, -1, -1):
p = karabiny[i] p = karabiny[i]
canvas.move(p["id"], p["dx"], p["dy"]) canvas.move(p["id"], p["dx"], p["dy"])
@ -156,6 +158,39 @@ def aktualizuj_karabiny():
if idx not in kamyki_do_usuniecia and j["pr"] < 12: if idx not in kamyki_do_usuniecia and j["pr"] < 12:
kamyki_do_usuniecia.append(idx) kamyki_do_usuniecia.append(idx)
break break
for idx, c in enumerate(cele):
if c["x1"] <= px <= c["x2"] and c["y1"] <= py <= c["y2"]:
pociski_do_usuniecia.append(i)
if idx not in cele_do_usuniecia:
cele_do_usuniecia.append(idx)
break
cele_do_usuniecia.sort(reverse=True)
for idx in cele_do_usuniecia:
c = cele[idx]
srodek_x = (c["x1"] + c["x2"]) / 2
srodek_y = (c["y1"] + c["y2"]) / 2
promien_wybuchu = 24
wybuch_id = canvas.create_oval(srodek_x - promien_wybuchu, srodek_y - promien_wybuchu,
srodek_x + promien_wybuchu, srodek_y + promien_wybuchu,
fill="yellow", outline="red", width=2)
root.after(500, lambda wid=wybuch_id: canvas.delete(wid))
promien_sladu = 16
slad_id = canvas.create_oval(srodek_x - promien_sladu, srodek_y - promien_sladu,
srodek_x + promien_sladu, srodek_y + promien_sladu,
fill="black", outline="")
canvas.tag_lower(slad_id)
canvas.delete(c["id"])
cele.pop(idx)
cele_zniszczone += 1
tekst_celu["text"] = f"Cele do zniszczenia: {cele_zniszczone}/{cel_wymagany}"
if cele_zniszczone == cel_wymagany:
tekst_celu["text"] = "MISJA UKOŃCZONA! ZNISZCZYŁEŚ CELE!"
tekst_celu["foreground"] = "gold"
kamyki_do_usuniecia.sort(reverse=True) kamyki_do_usuniecia.sort(reverse=True)
for idx in kamyki_do_usuniecia: for idx in kamyki_do_usuniecia:
@ -199,11 +234,13 @@ def aktualizuj_karabiny():
def aktualizuj_pociski(): def aktualizuj_pociski():
global cele_zniszczone
szerokosc_okna = canvas.winfo_width() szerokosc_okna = canvas.winfo_width()
wysokosc_okna = canvas.winfo_height() wysokosc_okna = canvas.winfo_height()
pociski_do_usuniecia = [] pociski_do_usuniecia = []
kamyki_do_usuniecia = [] kamyki_do_usuniecia = []
cele_do_usuniecia = []
for i in range(len(pociski) - 1, -1, -1): for i in range(len(pociski) - 1, -1, -1):
p = pociski[i] p = pociski[i]
@ -222,6 +259,39 @@ def aktualizuj_pociski():
if idx not in kamyki_do_usuniecia: if idx not in kamyki_do_usuniecia:
kamyki_do_usuniecia.append(idx) kamyki_do_usuniecia.append(idx)
break break
for idx, c in enumerate(cele):
if c["x1"] <= px <= c["x2"] and c["y1"] <= py <= c["y2"]:
pociski_do_usuniecia.append(i)
if idx not in cele_do_usuniecia:
cele_do_usuniecia.append(idx)
break
cele_do_usuniecia.sort(reverse=True)
for idx in cele_do_usuniecia:
c = cele[idx]
srodek_x = (c["x1"] + c["x2"]) / 2
srodek_y = (c["y1"] + c["y2"]) / 2
promien_wybuchu = 24
wybuch_id = canvas.create_oval(srodek_x - promien_wybuchu, srodek_y - promien_wybuchu,
srodek_x + promien_wybuchu, srodek_y + promien_wybuchu,
fill="yellow", outline="red", width=2)
root.after(500, lambda wid=wybuch_id: canvas.delete(wid))
promien_sladu = 16
slad_id = canvas.create_oval(srodek_x - promien_sladu, srodek_y - promien_sladu,
srodek_x + promien_sladu, srodek_y + promien_sladu,
fill="black", outline="")
canvas.tag_lower(slad_id)
canvas.delete(c["id"])
cele.pop(idx)
cele_zniszczone += 1
tekst_celu["text"] = f"Cele do zniszczenia: {cele_zniszczone}/{cel_wymagany}"
if cele_zniszczone == cel_wymagany:
tekst_celu["text"] = "MISJA UKOŃCZONA! ZNISZCZYŁEŚ CELE!"
tekst_celu["foreground"] = "gold"
kamyki_do_usuniecia.sort(reverse=True) kamyki_do_usuniecia.sort(reverse=True)
for idx in kamyki_do_usuniecia: for idx in kamyki_do_usuniecia:
@ -232,7 +302,6 @@ def aktualizuj_pociski():
promien_wybuchu = 24 promien_wybuchu = 24
wybuch_id = canvas.create_oval(srodek_x - promien_wybuchu, srodek_y - promien_wybuchu, srodek_x + promien_wybuchu, srodek_y + promien_wybuchu, fill="yellow", outline="red", width=2) wybuch_id = canvas.create_oval(srodek_x - promien_wybuchu, srodek_y - promien_wybuchu, srodek_x + promien_wybuchu, srodek_y + promien_wybuchu, fill="yellow", outline="red", width=2)
root.after(500, lambda wid=wybuch_id: canvas.delete(wid)) root.after(500, lambda wid=wybuch_id: canvas.delete(wid))
promien_sladu = 16 promien_sladu = 16
slad_id = canvas.create_oval(srodek_x - promien_sladu, srodek_y - promien_sladu, srodek_x + promien_sladu, srodek_y + promien_sladu, fill="black", outline="") slad_id = canvas.create_oval(srodek_x - promien_sladu, srodek_y - promien_sladu, srodek_x + promien_sladu, srodek_y + promien_sladu, fill="black", outline="")
canvas.tag_lower(slad_id) canvas.tag_lower(slad_id)
@ -279,7 +348,6 @@ def sprawdz_kolizje_czolgu():
hp -= x * 10 hp -= x * 10
else: else:
hp += x * 10 hp += x * 10
print(x)
hpbar['value'] = hp hpbar['value'] = hp
hpile["text"] = str(int(hp)) hpile["text"] = str(int(hp))
x = 0 x = 0
@ -498,6 +566,21 @@ 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_zniszczone = 0
cel_wymagany = 5
tekst_celu = Label(root, text=f"Cele do zniszczenia: {cele_zniszczone}/{cel_wymagany}",
background="darkolivegreen", foreground="white", font=("Arial", 14, "bold"))
tekst_celu.place(x=20, y=20)
for i in range(cel_wymagany):
cx = randrange(200, 900)
cy = randrange(200, 600)
wrog_id = canvas.create_polygon(cx, cy, cx + 30, cy, cx + 30, cy + 20, cx, cy + 20, fill="red3", outline="black")
cele.append({"id": wrog_id, "x1": cx, "y1": cy, "x2": cx + 30, "y2": cy + 20})
kamycki = [] kamycki = []
for i in range(60): for i in range(60):
kax = randrange(0, 1900) kax = randrange(0, 1900)