This commit is contained in:
tymek 2026-05-27 21:56:15 +02:00
parent 3972d0de03
commit 1eb21960ec

View file

@ -1,7 +1,7 @@
import math
from tkinter import *
from tkinter import ttk
from random import randrange
import tkinter.ttk as tk
def obroc_prostokat_o_2_stopnie_zg(canvas, element_id):
@ -134,13 +134,24 @@ def stzal_gluwny(event):
def cele_ruch():
global cele
x1, y1, x2, y2, x3, y3, x4, y4 = canvas.coords(dul)
celx=int((x1+x2+x3+x4)/4)
cely=int((y1+y2+y3+y4)/4)
for idx, c in enumerate(cele):
if c["x1"] > 0:
if c["x1"] < celx:
c["l"] = False
if c["x2"] > celx:
c["l"] = True
if c["l"]:
canvas.move(c["id"], -1, 0)
c["x1"] -= 1
c["x2"] -= 1
print(idx, c["x1"], c["y1"], c["x2"], c["y2"])
else:
canvas.move(c["id"], 1, 0)
c["x1"] += 1
c["x2"] += 1
c["ip"].place(x=c["x1"]+2.5,y=c["y1"]-10)
c["ip"]['value']=c["hp"]
def aktualizuj_karabiny():
@ -172,26 +183,36 @@ def aktualizuj_karabiny():
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)
c["hp"] -= 1
if c["hp"] <= 0:
cele_do_usuniecia.append(idx)
break
cele_do_usuniecia.sort(reverse=True)
for idx in cele_do_usuniecia:
c = cele[idx]
c["ip"].destroy()
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="")
wybuch_id1 = 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)
promien_wybuchu = 18
wybuch_id2 = 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)
promien_wybuchu = 13
wybuch_id3 = 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)
promien_wybuchu = 17
wybuch_id4 = canvas.create_oval(srodek_x - promien_wybuchu, srodek_y - promien_wybuchu, srodek_x + promien_wybuchu, srodek_y + promien_wybuchu, fill="grey60", outline="", width=2)
canvas.tag_lower(wybuch_id2, wybuch_id1)
canvas.tag_lower(wybuch_id3, wybuch_id2)
canvas.tag_lower(wybuch_id4, wybuch_id3)
root.after(500, lambda wid1=wybuch_id1: canvas.delete(wid1))
root.after(1000, lambda wid2=wybuch_id2: canvas.delete(wid2))
root.after(1500, lambda wid3=wybuch_id3: canvas.delete(wid3))
root.after(3000, lambda wid4=wybuch_id4: canvas.delete(wid4))
slad_id = canvas.create_rectangle(srodek_x - 15, srodek_y - 10,
srodek_x + 15, srodek_y + 10,
fill="black", outline="")
canvas.tag_lower(slad_id)
canvas.delete(c["id"])
@ -467,7 +488,7 @@ def gluwna():
sl = True
else:
sl = False
k2=k1="#000000"
k2 = k1 = "#000000"
if sl:
t1 = canvas.create_oval(sxl - rk_slad, syl - rk_slad, sxl + rk_slad, syl + rk_slad, fill=k1, outline="")
@ -543,16 +564,16 @@ magazynek = 40
czekajmagazynek = 0
pelny = True
style = tk.Style()
style.theme_use('clam')
style.configure("szary.Horizontal.TProgressbar", troughcolor="grey15", background="grey61", thickness=20, borderwidth=0)
style.configure("zielony.Horizontal.TProgressbar", troughcolor="darkgreen", background="green3", thickness=50, borderwidth=0, lightcolor="green3", darkcolor="green3", bordercolor="green4")
amo = tk.Progressbar(root, orient="horizontal", length=300, mode="determinate", style="szary.Horizontal.TProgressbar", maximum=40)
style = ttk.Style()
style.theme_use('default')
style.configure("szary.Horizontal.TProgressbar", troughcolor="grey15", background="grey61", thickness=15, borderwidth=1)
style.configure("zielony.Horizontal.TProgressbar", troughcolor="darkgreen", background="green3", thickness=15, borderwidth=1, lightcolor="green3", darkcolor="green3", bordercolor="green4")
amo = ttk.Progressbar(root, orient="horizontal", length=300, mode="determinate", style="szary.Horizontal.TProgressbar", maximum=40)
amo.place(x=400, rely=1.0, y=-50)
amo['value'] = magazynek
ladowanie = 300
pzeladowanie = tk.Progressbar(root, orient="horizontal", length=300, mode="determinate", style="szary.Horizontal.TProgressbar", maximum=300)
pzeladowanie = ttk.Progressbar(root, orient="horizontal", length=300, mode="determinate", style="szary.Horizontal.TProgressbar", maximum=300)
pzeladowanie.place(x=400, rely=1.0, y=-80)
pzeladowanie['value'] = ladowanie
@ -560,7 +581,7 @@ tempomat = False
temo = canvas.create_oval(0, 0, 0, 0, fill="firebrick1", outline="")
hp = 100
hpbar = tk.Progressbar(root, orient="horizontal", length=300, mode="determinate", style="zielony.Horizontal.TProgressbar", maximum=100)
hpbar = ttk.Progressbar(root, orient="horizontal", length=300, mode="determinate", style="zielony.Horizontal.TProgressbar", maximum=100)
hpbar.place(relx=0.5, y=0, x=-150)
hpbar['value'] = hp
hpile = Label(root, text=hp, background="green4", foreground="green3", font=("Arial", 9, "bold"))
@ -594,15 +615,17 @@ 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 = 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)
style.configure("wrog.Horizontal.TProgressbar", troughcolor="darkgreen", background="green3", borderwidth=0, thickness=6)
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})
hp_wrog_id = ttk.Progressbar(root, orient="horizontal", length=25, mode="determinate", style="wrog.Horizontal.TProgressbar", maximum=10)
hp_wrog_id.place(x=cx, y=cy-10)
hp_wrog_id['value'] = 10
cele.append({"id": wrog_id, "x1": cx, "y1": cy, "x2": cx + 30, "y2": cy + 20,"hp":10, "l": True,"ip":hp_wrog_id})
kamycki = []
for i in range(60):