tanks/statek.py
2026-05-28 22:10:35 +02:00

678 lines
24 KiB
Python

import math
from tkinter import *
from tkinter import ttk
from random import randrange
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)]
ys = [wspolrzedne[i] for i in range(1, len(wspolrzedne), 2)]
cx = sum(xs) / len(xs)
cy = sum(ys) / len(ys)
radiany = math.radians(2)
cos_k = math.cos(radiany)
sin_k = math.sin(radiany)
nowe_wspolrzedne = []
for x_val, y_val in zip(xs, ys):
nx = cx + (x_val - cx) * cos_k - (y_val - cy) * sin_k
ny = cy + (x_val - cx) * sin_k + (y_val - cy) * cos_k
nowe_wspolrzedne.extend([nx, ny])
canvas.coords(element_id, nowe_wspolrzedne)
def obroc_prostokat_o_2_stopnie_prz(canvas, element_id):
wspolrzedne = canvas.coords(element_id)
xs = [wspolrzedne[i] for i in range(0, len(wspolrzedne), 2)]
ys = [wspolrzedne[i] for i in range(1, len(wspolrzedne), 2)]
cx = sum(xs) / len(xs)
cy = sum(ys) / len(ys)
radiany = math.radians(-2)
cos_k = math.cos(radiany)
sin_k = math.sin(radiany)
nowe_wspolrzedne = []
for x_val, y_val in zip(xs, ys):
nx = cx + (x_val - cx) * cos_k - (y_val - cy) * sin_k
ny = cy + (x_val - cx) * sin_k + (y_val - cy) * cos_k
nowe_wspolrzedne.extend([nx, ny])
canvas.coords(element_id, nowe_wspolrzedne)
def rusz_w_strone_boku(canvas, element_id, dystans):
wspolrzedne = canvas.coords(element_id)
if len(wspolrzedne) < 8:
return
x1, y1 = wspolrzedne[4], wspolrzedne[5]
x2, y2 = wspolrzedne[2], wspolrzedne[3]
kat_krutkiego_boku = math.atan2(y2 - y1, x2 - x1)
kat_ruchu = kat_krutkiego_boku + (math.pi / 2)
dx = dystans * math.cos(kat_ruchu)
dy = dystans * math.sin(kat_ruchu)
canvas.move(element_id, dx, dy)
def klawisz_wcisniety(event):
key = event.keysym.lower()
if key in wcisniete_klawisze:
if key == "q":
global tempomat
tempomat = not tempomat
else:
wcisniete_klawisze[key] = True
def klawisz_puszczony(event):
key = event.keysym.lower()
if key in wcisniete_klawisze and key != "q":
wcisniete_klawisze[key] = False
def strzal_z_karabinu():
global firerate, magazynek, pelny
amo['value'] = magazynek
if firerate <= 0 < magazynek and pelny:
firerate = 0.1
magazynek -= 1
wspol = canvas.coords(dul)
xs = [wspol[i] for i in range(0, len(wspol), 2)]
ys = [wspol[i] for i in range(1, len(wspol), 2)]
cx = sum(xs) / len(xs)
cy = sum(ys) / len(ys)
kat_myszy = math.atan2(mysz_y - cy, mysz_x - cx)
dlugosc_lufy = 8
start_x = cx + dlugosc_lufy * math.cos(kat_myszy)
start_y = cy + dlugosc_lufy * math.sin(kat_myszy)
predkosc_karabinu = 12
dx = predkosc_karabinu * math.cos(kat_myszy)
dy = predkosc_karabinu * math.sin(kat_myszy)
r_karabinu = 1
id_karabinu = canvas.create_oval(start_x - r_karabinu, start_y - r_karabinu, start_x + r_karabinu, start_y + r_karabinu, fill="black", outline="")
karabiny.append({"id": id_karabinu, "dx": dx, "dy": dy})
def stzal_gluwny(event):
global ladowanie, pociski
if ladowanie == 300:
ladowanie = 0
wspol = canvas.coords(dul)
xs = [wspol[i] for i in range(0, len(wspol), 2)]
ys = [wspol[i] for i in range(1, len(wspol), 2)]
cx = sum(xs) / len(xs)
cy = sum(ys) / len(ys)
kat_myszy = math.atan2(mysz_y - cy, mysz_x - cx)
dlugosc_lufy = 8
start_x = cx + dlugosc_lufy * math.cos(kat_myszy)
start_y = cy + dlugosc_lufy * math.sin(kat_myszy)
predkosc_pocisku = 15
dx = predkosc_pocisku * math.cos(kat_myszy)
dy = predkosc_pocisku * math.sin(kat_myszy)
r_pocisku = 3
id_pocisku = canvas.create_oval(start_x - r_pocisku, start_y - r_pocisku, start_x + r_pocisku, start_y + r_pocisku, fill="red", outline="black")
pociski.append({"id": id_pocisku, "dx": dx, "dy": dy})
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"] < 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
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():
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"])
coords = canvas.coords(p["id"])
if coords:
px, py = coords[0], coords[1]
if px < 0 or px > szerokosc_okna or py < 0 or py > wysokosc_okna:
pociski_do_usuniecia.append(i)
continue
for idx, j in enumerate(kamycki):
if j["x"] <= px <= j["x"] + j["pr"] and j["y"] <= py <= j["y"] + j["pr"]:
pociski_do_usuniecia.append(i)
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:
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_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"])
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"
root.after(5000, lambda: tekst_celu.place_forget())
kamyki_do_usuniecia.sort(reverse=True)
for idx in kamyki_do_usuniecia:
kam = kamycki[idx]
srodek_x = kam["x"] + (kam["pr"] / 2)
srodek_y = kam["y"] + (kam["pr"] / 2)
promien_wybuchu = 10
wybuch_id = canvas.create_oval(srodek_x - promien_wybuchu, srodek_y - promien_wybuchu, srodek_x + promien_wybuchu, srodek_y + promien_wybuchu, fill="yellow", outline="orange")
root.after(200, lambda wid=wybuch_id: canvas.delete(wid))
promien_sladu = 6
slad_id = canvas.create_oval(srodek_x - promien_sladu, srodek_y - promien_sladu, srodek_x + promien_sladu, srodek_y + promien_sladu, fill="grey13", outline="")
canvas.tag_lower(slad_id)
canvas.delete(kam["id"])
kamycki.pop(idx)
pociski_do_usuniecia = list(set(pociski_do_usuniecia))
pociski_do_usuniecia.sort(reverse=True)
for idx in pociski_do_usuniecia:
c = karabiny[idx]
coords_pocisku = canvas.coords(c["id"])
if coords_pocisku:
pocisk_x = coords_pocisku[0]
pocisk_y = coords_pocisku[1]
if 0 <= pocisk_x <= szerokosc_okna and 0 <= pocisk_y <= wysokosc_okna:
promien_wybuchu = 2
wybuch_id = canvas.create_oval(pocisk_x - promien_wybuchu, pocisk_y - promien_wybuchu, pocisk_x + promien_wybuchu, pocisk_y + promien_wybuchu, fill="yellow", outline="orange")
root.after(400, lambda wid=wybuch_id: canvas.delete(wid))
promien_sladu = 1
slad_id = canvas.create_oval(pocisk_x - promien_sladu, pocisk_y - promien_sladu, pocisk_x + promien_sladu, pocisk_y + promien_sladu, fill="gold", outline="")
canvas.tag_lower(slad_id)
canvas.delete(c["id"])
karabiny.pop(idx)
def misja():
print("X")
global ktura_misja, cele, cele_zniszczone, cel_wymagany
ktura_misja += 1
tekst_celu.place(x=20, y=20)
tekst_celu["text"] = f"misja {ktura_misja}"
cele = []
cele_zniszczone = 0
cel_wymagany = ktura_misja * 5
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")
hp_wrog_id = ttk.Progressbar(root, orient="horizontal", length=25, mode="determinate", style="wrog.Horizontal.TProgressbar", maximum=60)
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": 60, "l": True, "ip": hp_wrog_id})
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]
canvas.move(p["id"], p["dx"], p["dy"])
coords = canvas.coords(p["id"])
if coords:
px, py = coords[0], coords[1]
if px < 0 or px > szerokosc_okna or py < 0 or py > wysokosc_okna:
pociski_do_usuniecia.append(i)
continue
for idx, j in enumerate(kamycki):
if j["x"] <= px <= j["x"] + j["pr"] and j["y"] <= py <= j["y"] + j["pr"]:
pociski_do_usuniecia.append(i)
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"])
c["ip"].place_forget()
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"
root.after(5000, lambda: tekst_celu.place_forget())
root.after(7000, misja)
kamyki_do_usuniecia.sort(reverse=True)
for idx in kamyki_do_usuniecia:
kam = kamycki[idx]
srodek_x = kam["x"] + (kam["pr"] / 2)
srodek_y = kam["y"] + (kam["pr"] / 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(kam["id"])
kamycki.pop(idx)
pociski_do_usuniecia.sort(reverse=True)
for idx in pociski_do_usuniecia:
canvas.delete(pociski[idx]["id"])
pociski.pop(idx)
def sprawdz_kolizje_czolgu():
global x, tempomat, hp
if x == 0:
return
wspol = canvas.coords(dul)
if len(wspol) < 8:
return
xs = [wspol[i] for i in range(0, len(wspol), 2)]
ys = [wspol[i] for i in range(1, len(wspol), 2)]
cx = sum(xs) / len(xs)
cy = sum(ys) / len(ys)
promien_czolgu = 18
for k in kamycki:
kx_srodek = k["x"] + (k["pr"] / 2)
ky_srodek = k["y"] + (k["pr"] / 2)
odleglosc = math.sqrt((cx - kx_srodek) ** 2 + (cy - ky_srodek) ** 2)
min_odleglosc = promien_czolgu + (k["pr"] / 2)
if odleglosc < min_odleglosc:
nakladanie = min_odleglosc - odleglosc
kat = math.atan2(cy - ky_srodek, cx - kx_srodek)
dx = nakladanie * math.cos(kat)
dy = nakladanie * math.sin(kat)
canvas.move(dul, dx, dy)
if x >= 0:
hp -= x * 10
else:
hp += x * 10
hpbar['value'] = hp
hpile["text"] = str(int(hp))
x = 0
tempomat = False
break
def gluwna():
global x, tempomat, firerate, czekajmagazynek, pelny, magazynek, ladowanie, pzeladowanie
if wcisniete_klawisze["a"]:
obroc_prostokat_o_2_stopnie_prz(canvas, dul)
if wcisniete_klawisze["d"]:
obroc_prostokat_o_2_stopnie_zg(canvas, dul)
if wcisniete_klawisze["w"]:
x += 0.02
tempomat = False
if wcisniete_klawisze["s"]:
x -= 0.01
tempomat = False
if wcisniete_klawisze["space"]:
strzal_z_karabinu()
if x != 0:
rusz_w_strone_boku(canvas, dul, x)
if x > 0 and not tempomat:
x -= 0.003
if x < 0 and not tempomat:
x += 0.003
if x > 2:
x = 2
if x < -1:
x = -1
if x != 0:
rusz_w_strone_boku(canvas, dul, x)
sprawdz_kolizje_czolgu()
wspol = canvas.coords(dul)
xs = [wspol[i] for i in range(0, len(wspol), 2)]
ys = [wspol[i] for i in range(1, len(wspol), 2)]
cx = sum(xs) / len(xs)
cy = sum(ys) / len(ys)
r = 5
canvas.coords(wieza, cx - r, cy - r, cx + r, cy + r)
kxl = (wspol[2] * 3 + wspol[4]) / 4
kyl = (wspol[3] * 3 + wspol[5]) / 4
kxp = (wspol[2] + wspol[4] * 3) / 4
kyp = (wspol[3] + wspol[5] * 3) / 4
rk = 2
canvas.coords(swietlo_lewe, kxl - rk, kyl - rk, kxl + rk, kyl + rk)
canvas.coords(swietlo_prawe, kxp - rk, kyp - rk, kxp + rk, kyp + rk)
dlugosc_lufy = 15
kat_myszy = math.atan2(mysz_y - cy, mysz_x - cx)
lx = cx + dlugosc_lufy * math.cos(kat_myszy)
ly = cy + dlugosc_lufy * math.sin(kat_myszy)
canvas.coords(lufa, cx, cy, lx, ly)
canvas.tag_raise(wieza, dul)
canvas.tag_lower(swietlo_lewe, dul)
canvas.tag_lower(swietlo_prawe, dul)
canvas.tag_raise(temo, prtlo)
aktualizuj_karabiny()
aktualizuj_pociski()
if firerate > 0:
firerate -= 1
if magazynek == 0 and pelny:
czekajmagazynek = 320
pelny = False
if czekajmagazynek > 0:
czekajmagazynek = czekajmagazynek - 1
amo['value'] = 160 - (czekajmagazynek / 2)
if czekajmagazynek == 0:
magazynek = 160
pelny = True
amo['value'] = magazynek
pzeladowanie['value'] = ladowanie
if ladowanie < 300:
ladowanie += 1
aktualizuj_pozycje_figur()
rk_slad = 1.5
klawisze_ruchu = ["w", "s", "a", "d"]
sxl = (wspol[0] * 3 + wspol[6]) / 4
syl = (wspol[1] * 3 + wspol[7]) / 4
sxp = (wspol[0] + wspol[6] * 3) / 4
syp = (wspol[1] + wspol[7] * 3) / 4
if any(wcisniete_klawisze[k] for k in klawisze_ruchu):
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"
if sl:
t1 = canvas.create_oval(sxl - rk_slad, syl - rk_slad, sxl + rk_slad, syl + rk_slad, fill=k1, outline="")
t2 = canvas.create_oval(sxp - rk_slad, syp - rk_slad, sxp + rk_slad, syp + rk_slad, fill=k2, outline="")
canvas.tag_lower(t1)
canvas.tag_lower(t2)
canvas.tag_lower(t1)
canvas.tag_lower(t2)
cele_ruch()
root.after(16, gluwna)
def ruch_myszy(event):
global mysz_x, mysz_y
mysz_x = event.x
mysz_y = event.y
def aktualizuj_pozycje_figur():
wysokosc_okna = canvas.winfo_height()
promien_tarczy = 150
cx_tarczy = 160
cy_tarczy = wysokosc_okna - 100
canvas.coords(prtlo, cx_tarczy - promien_tarczy, cy_tarczy - promien_tarczy, cx_tarczy + promien_tarczy, cy_tarczy + promien_tarczy)
canvas.coords(temo, cx_tarczy + 20, cy_tarczy - 20, cx_tarczy + 35, cy_tarczy - 35)
if tempomat:
canvas.itemconfig(temo, fill="green2")
else:
canvas.itemconfig(temo, fill="firebrick1")
maks_predkosc = 2.0
min_predkosc = -1.0
procent = (x - min_predkosc) / (maks_predkosc - min_predkosc)
stopnie = procent * 270
aktualny_kat = 225 - stopnie
radiany = math.radians(aktualny_kat)
dlugosc_wskazowki = promien_tarczy - 10
wx = cx_tarczy + dlugosc_wskazowki * math.cos(radiany)
wy = cy_tarczy - dlugosc_wskazowki * math.sin(radiany)
canvas.coords(prwska, cx_tarczy, cy_tarczy, wx, wy)
promien_tekstu = promien_tarczy - 20
for i, predkosc_punktu in enumerate(wartosci_predkosci):
proc = (predkosc_punktu - min_predkosc) / (maks_predkosc - min_predkosc)
stopn = proc * 270
kat_napisu = 225 - stopn
rad = math.radians(kat_napisu)
tx = cx_tarczy + promien_tekstu * math.cos(rad)
ty = cy_tarczy - promien_tekstu * math.sin(rad)
canvas.coords(napisy_ids[i], tx, ty)
root = Tk()
root.geometry("1000x700")
canvas = Canvas(root, bg="darkolivegreen", highlightthickness=0)
canvas.pack(fill="both", expand=True)
x1, y1 = 100, 100
x2, y2 = 130, 120
dul = canvas.create_polygon(x1, y1, x2, y1, x2, y2, x1, y2, fill="green", outline="black")
x = 0
mysz_x, mysz_y = 0, 0
wcisniete_klawisze = {"w": False, "s": False, "a": False, "d": False, "q": False, "space": False}
karabiny = []
pociski = []
firerate = 0
magazynek = 160
czekajmagazynek = 0
pelny = True
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=160)
amo.place(x=400, rely=1.0, y=-50)
amo['value'] = magazynek
ladowanie = 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
tempomat = False
temo = canvas.create_oval(0, 0, 0, 0, fill="firebrick1", outline="")
hp = 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"))
hpile.place(relx=0.5, y=0, x=+150)
cx_poczatkowy = (x1 + x2) / 2
cy_poczatkowy = (y1 + y2) / 2
promien_kola = 5
wieza = canvas.create_oval(cx_poczatkowy - promien_kola, cy_poczatkowy - promien_kola, cx_poczatkowy + promien_kola, cy_poczatkowy + promien_kola, fill="darkgreen", outline="black")
kx_poczatkowe = x2
ky_poczatkowe = (y1 + y2) / 2
r_kropki = 2
swietlo_lewe = canvas.create_oval(kx_poczatkowe - r_kropki, ky_poczatkowe - r_kropki, kx_poczatkowe + r_kropki, ky_poczatkowe + r_kropki, fill="orange2", outline="black")
swietlo_prawe = canvas.create_oval(kx_poczatkowe - r_kropki, ky_poczatkowe - r_kropki, kx_poczatkowe + r_kropki, ky_poczatkowe + r_kropki, fill="orange2", outline="black")
lufa = canvas.create_line(0, 0, 0, 0, fill="black", width=3)
prtlo = canvas.create_oval(0, 0, 0, 0, fill="grey60", outline="black", width=2)
prwska = canvas.create_line(0, 0, 10, 10, width=5, fill="black")
wartosci_predkosci = [-1.0, -0.75, -0.5, -0.25, 0.0, 0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0]
teksty_napisow = ["-1", "-0.75", "-0.5", "-0.25", "0", "0.25", "0.5", "0.75", "1", "1.25", "1.5", "1.75", "2"]
napisy_ids = []
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
ktura_misja = 1
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")
hp_wrog_id = ttk.Progressbar(root, orient="horizontal", length=25, mode="determinate", style="wrog.Horizontal.TProgressbar", maximum=60)
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": 60, "l": True, "ip": hp_wrog_id})
kamycki = []
for i in range(60):
kax = randrange(0, 1900)
kay = randrange(0, 1000)
ka = "grey" + str(randrange(30, 40))
wt = randrange(7, 20)
t = canvas.create_oval(kax, kay, kax + wt, kay + wt, fill=ka, outline="")
canvas.tag_lower(t)
kamycki.append({"id": t, "x": kax, "y": kay, "pr": wt})
for i in range(1600):
trxx = randrange(0, 1900)
tryy = randrange(0, 1000)
tr = "#00" + str(randrange(40, 60))
tr += "00"
wt = randrange(3, 7)
t = canvas.create_oval(trxx, tryy, trxx + wt, tryy + wt, fill=tr, outline="")
canvas.tag_lower(t)
root.bind("<KeyPress>", klawisz_wcisniety)
root.bind("<KeyRelease>", klawisz_puszczony)
root.bind("<Motion>", ruch_myszy)
root.bind("<Button-1>", stzal_gluwny)
gluwna()
root.mainloop()