cele
This commit is contained in:
parent
3972d0de03
commit
1eb21960ec
71
statek.py
71
statek.py
|
|
@ -1,7 +1,7 @@
|
||||||
import math
|
import math
|
||||||
from tkinter import *
|
from tkinter import *
|
||||||
|
from tkinter import ttk
|
||||||
from random import randrange
|
from random import randrange
|
||||||
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):
|
||||||
|
|
@ -134,13 +134,24 @@ def stzal_gluwny(event):
|
||||||
|
|
||||||
def cele_ruch():
|
def cele_ruch():
|
||||||
global cele
|
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):
|
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)
|
canvas.move(c["id"], -1, 0)
|
||||||
c["x1"] -= 1
|
c["x1"] -= 1
|
||||||
c["x2"] -= 1
|
c["x2"] -= 1
|
||||||
|
else:
|
||||||
print(idx, c["x1"], c["y1"], c["x2"], c["y2"])
|
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():
|
def aktualizuj_karabiny():
|
||||||
|
|
@ -172,25 +183,35 @@ def aktualizuj_karabiny():
|
||||||
if c["x1"] <= px <= c["x2"] and c["y1"] <= py <= c["y2"]:
|
if c["x1"] <= px <= c["x2"] and c["y1"] <= py <= c["y2"]:
|
||||||
pociski_do_usuniecia.append(i)
|
pociski_do_usuniecia.append(i)
|
||||||
if idx not in cele_do_usuniecia:
|
if idx not in cele_do_usuniecia:
|
||||||
|
c["hp"] -= 1
|
||||||
|
if c["hp"] <= 0:
|
||||||
cele_do_usuniecia.append(idx)
|
cele_do_usuniecia.append(idx)
|
||||||
break
|
break
|
||||||
|
|
||||||
cele_do_usuniecia.sort(reverse=True)
|
cele_do_usuniecia.sort(reverse=True)
|
||||||
for idx in cele_do_usuniecia:
|
for idx in cele_do_usuniecia:
|
||||||
c = cele[idx]
|
c = cele[idx]
|
||||||
|
c["ip"].destroy()
|
||||||
srodek_x = (c["x1"] + c["x2"]) / 2
|
srodek_x = (c["x1"] + c["x2"]) / 2
|
||||||
srodek_y = (c["y1"] + c["y2"]) / 2
|
srodek_y = (c["y1"] + c["y2"]) / 2
|
||||||
|
|
||||||
promien_wybuchu = 24
|
promien_wybuchu = 24
|
||||||
wybuch_id = canvas.create_oval(srodek_x - promien_wybuchu, srodek_y - promien_wybuchu,
|
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)
|
||||||
srodek_x + promien_wybuchu, srodek_y + promien_wybuchu,
|
promien_wybuchu = 18
|
||||||
fill="yellow", outline="red", width=2)
|
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)
|
||||||
root.after(500, lambda wid=wybuch_id: canvas.delete(wid))
|
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_sladu = 16
|
promien_wybuchu = 17
|
||||||
slad_id = canvas.create_oval(srodek_x - promien_sladu, srodek_y - promien_sladu,
|
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)
|
||||||
srodek_x + promien_sladu, srodek_y + promien_sladu,
|
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="")
|
fill="black", outline="")
|
||||||
canvas.tag_lower(slad_id)
|
canvas.tag_lower(slad_id)
|
||||||
|
|
||||||
|
|
@ -543,16 +564,16 @@ magazynek = 40
|
||||||
czekajmagazynek = 0
|
czekajmagazynek = 0
|
||||||
pelny = True
|
pelny = True
|
||||||
|
|
||||||
style = tk.Style()
|
style = ttk.Style()
|
||||||
style.theme_use('clam')
|
style.theme_use('default')
|
||||||
style.configure("szary.Horizontal.TProgressbar", troughcolor="grey15", background="grey61", thickness=20, borderwidth=0)
|
style.configure("szary.Horizontal.TProgressbar", troughcolor="grey15", background="grey61", thickness=15, borderwidth=1)
|
||||||
style.configure("zielony.Horizontal.TProgressbar", troughcolor="darkgreen", background="green3", thickness=50, borderwidth=0, lightcolor="green3", darkcolor="green3", bordercolor="green4")
|
style.configure("zielony.Horizontal.TProgressbar", troughcolor="darkgreen", background="green3", thickness=15, borderwidth=1, lightcolor="green3", darkcolor="green3", bordercolor="green4")
|
||||||
amo = tk.Progressbar(root, orient="horizontal", length=300, mode="determinate", style="szary.Horizontal.TProgressbar", maximum=40)
|
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.place(x=400, rely=1.0, y=-50)
|
||||||
amo['value'] = magazynek
|
amo['value'] = magazynek
|
||||||
|
|
||||||
ladowanie = 300
|
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.place(x=400, rely=1.0, y=-80)
|
||||||
pzeladowanie['value'] = ladowanie
|
pzeladowanie['value'] = ladowanie
|
||||||
|
|
||||||
|
|
@ -560,7 +581,7 @@ tempomat = False
|
||||||
temo = canvas.create_oval(0, 0, 0, 0, fill="firebrick1", outline="")
|
temo = canvas.create_oval(0, 0, 0, 0, fill="firebrick1", outline="")
|
||||||
|
|
||||||
hp = 100
|
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.place(relx=0.5, y=0, x=-150)
|
||||||
hpbar['value'] = hp
|
hpbar['value'] = hp
|
||||||
hpile = Label(root, text=hp, background="green4", foreground="green3", font=("Arial", 9, "bold"))
|
hpile = Label(root, text=hp, background="green4", foreground="green3", font=("Arial", 9, "bold"))
|
||||||
|
|
@ -594,15 +615,17 @@ cele = []
|
||||||
cele_zniszczone = 0
|
cele_zniszczone = 0
|
||||||
cel_wymagany = 5
|
cel_wymagany = 5
|
||||||
|
|
||||||
tekst_celu = Label(root, text=f"Cele do zniszczenia: {cele_zniszczone}/{cel_wymagany}",
|
tekst_celu = Label(root, text=f"Cele do zniszczenia: {cele_zniszczone}/{cel_wymagany}", background="darkolivegreen", foreground="white", font=("Arial", 14, "bold"))
|
||||||
background="darkolivegreen", foreground="white", font=("Arial", 14, "bold"))
|
|
||||||
tekst_celu.place(x=20, y=20)
|
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):
|
for i in range(cel_wymagany):
|
||||||
cx = randrange(200, 900)
|
cx = randrange(200, 900)
|
||||||
cy = randrange(200, 600)
|
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")
|
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 = []
|
kamycki = []
|
||||||
for i in range(60):
|
for i in range(60):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue