diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/statek.py b/statek.py index 1a5577f..3fca13e 100644 --- a/statek.py +++ b/statek.py @@ -4,6 +4,7 @@ from random import randrange import tkinter.ttk as tk + def obroc_prostokat_o_2_stopnie_zg(canvas, element_id): wspolrzedne = canvas.coords(element_id) xs = [wspolrzedne[i] for i in range(0, len(wspolrzedne), 2)] @@ -133,12 +134,13 @@ def stzal_gluwny(event): def aktualizuj_karabiny(): + global cele_zniszczone szerokosc_okna = canvas.winfo_width() wysokosc_okna = canvas.winfo_height() pociski_do_usuniecia = [] kamyki_do_usuniecia = [] - + cele_do_usuniecia = [] for i in range(len(karabiny) - 1, -1, -1): p = karabiny[i] 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: kamyki_do_usuniecia.append(idx) 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) for idx in kamyki_do_usuniecia: @@ -199,11 +234,13 @@ def aktualizuj_karabiny(): def aktualizuj_pociski(): + global cele_zniszczone szerokosc_okna = canvas.winfo_width() wysokosc_okna = canvas.winfo_height() pociski_do_usuniecia = [] kamyki_do_usuniecia = [] + cele_do_usuniecia = [] for i in range(len(pociski) - 1, -1, -1): p = pociski[i] @@ -222,6 +259,39 @@ def aktualizuj_pociski(): if idx not in kamyki_do_usuniecia: kamyki_do_usuniecia.append(idx) 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) for idx in kamyki_do_usuniecia: @@ -232,7 +302,6 @@ def aktualizuj_pociski(): 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) @@ -279,7 +348,6 @@ def sprawdz_kolizje_czolgu(): hp -= x * 10 else: hp += x * 10 - print(x) hpbar['value'] = hp hpile["text"] = str(int(hp)) 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") 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 = [] for i in range(60): kax = randrange(0, 1900)