lufy do celów + jazda x,y
This commit is contained in:
parent
ae83a87bc6
commit
df82b85a75
73
statek.py
73
statek.py
|
|
@ -137,21 +137,37 @@ def cele_ruch():
|
||||||
x1, y1, x2, y2, x3, y3, x4, y4 = canvas.coords(dul)
|
x1, y1, x2, y2, x3, y3, x4, y4 = canvas.coords(dul)
|
||||||
celx = int((x1 + x2 + x3 + x4) / 4)
|
celx = int((x1 + x2 + x3 + x4) / 4)
|
||||||
cely = int((y1 + y2 + y3 + y4) / 4)
|
cely = int((y1 + y2 + y3 + y4) / 4)
|
||||||
|
|
||||||
for idx, c in enumerate(cele):
|
for idx, c in enumerate(cele):
|
||||||
if c["x1"] < celx:
|
krok_x=0
|
||||||
c["l"] = False
|
krok_y=0
|
||||||
if c["x2"] > celx:
|
dx = celx - c["dul"]["x1"]
|
||||||
c["l"] = True
|
dy = cely - c["dul"]["y1"]
|
||||||
if c["l"]:
|
odleglosc_kwadrat = dx ** 2 + dy ** 2
|
||||||
canvas.move(c["id"], -1, 0)
|
if odleglosc_kwadrat > 40000:
|
||||||
c["x1"] -= 1
|
odleglosc = math.sqrt(odleglosc_kwadrat)
|
||||||
c["x2"] -= 1
|
predkosc = 1.0
|
||||||
else:
|
krok_x = (dx / odleglosc) * predkosc
|
||||||
canvas.move(c["id"], 1, 0)
|
krok_y = (dy / odleglosc) * predkosc
|
||||||
c["x1"] += 1
|
canvas.move(c["dul"]["id"], krok_x, krok_y)
|
||||||
c["x2"] += 1
|
c["dul"]["x1"] += krok_x
|
||||||
c["ip"].place(x=c["x1"] + 2.5, y=c["y1"] - 10)
|
c["dul"]["x2"] += krok_x
|
||||||
|
c["dul"]["y1"] += krok_y
|
||||||
|
c["dul"]["y2"] += krok_y
|
||||||
|
c["ip"].place(x=c["dul"]["x1"] + 2.5, y=c["dul"]["y1"] - 10)
|
||||||
c["ip"]['value'] = c["hp"]
|
c["ip"]['value'] = c["hp"]
|
||||||
|
cx = (c["dul"]["x1"] + c["dul"]["x2"]) / 2
|
||||||
|
cy = (c["dul"]["y1"] + c["dul"]["y2"]) / 2
|
||||||
|
|
||||||
|
dlugosc_lufy = c["lufa"]["wiel"]
|
||||||
|
dx = celx - cx
|
||||||
|
dy = cely - cy
|
||||||
|
kat_czolgu = math.atan2(dy, dx)
|
||||||
|
lx = cx + dlugosc_lufy * math.cos(kat_czolgu)
|
||||||
|
ly = cy + dlugosc_lufy * math.sin(kat_czolgu)
|
||||||
|
canvas.coords(c["lufa"]["id"], cx, cy, lx, ly)
|
||||||
|
|
||||||
|
canvas.move(c["wieza"]["id"],krok_x,krok_y)
|
||||||
|
|
||||||
|
|
||||||
def aktualizuj_karabiny():
|
def aktualizuj_karabiny():
|
||||||
|
|
@ -180,7 +196,7 @@ def aktualizuj_karabiny():
|
||||||
kamyki_do_usuniecia.append(idx)
|
kamyki_do_usuniecia.append(idx)
|
||||||
break
|
break
|
||||||
for idx, c in enumerate(cele):
|
for idx, c in enumerate(cele):
|
||||||
if c["x1"] <= px <= c["x2"] and c["y1"] <= py <= c["y2"]:
|
if c["dul"]["x1"] <= px <= c["dul"]["x2"] and c["dul"]["y1"] <= py <= c["dul"]["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
|
c["hp"] -= 1
|
||||||
|
|
@ -192,8 +208,8 @@ def aktualizuj_karabiny():
|
||||||
for idx in cele_do_usuniecia:
|
for idx in cele_do_usuniecia:
|
||||||
c = cele[idx]
|
c = cele[idx]
|
||||||
c["ip"].destroy()
|
c["ip"].destroy()
|
||||||
srodek_x = (c["x1"] + c["x2"]) / 2
|
srodek_x = (c["dul"]["x1"] + c["dul"]["x2"]) / 2
|
||||||
srodek_y = (c["y1"] + c["y2"]) / 2
|
srodek_y = (c["dul"]["y1"] + c["dul"]["y2"]) / 2
|
||||||
|
|
||||||
promien_wybuchu = 24
|
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)
|
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)
|
||||||
|
|
@ -215,7 +231,7 @@ def aktualizuj_karabiny():
|
||||||
fill="black", outline="")
|
fill="black", outline="")
|
||||||
canvas.tag_lower(slad_id)
|
canvas.tag_lower(slad_id)
|
||||||
|
|
||||||
canvas.delete(c["id"])
|
canvas.delete(c["dul"]["id"])
|
||||||
cele.pop(idx)
|
cele.pop(idx)
|
||||||
cele_zniszczone += 1
|
cele_zniszczone += 1
|
||||||
tekst_celu["text"] = f"Cele do zniszczenia: {cele_zniszczone}/{cel_wymagany}"
|
tekst_celu["text"] = f"Cele do zniszczenia: {cele_zniszczone}/{cel_wymagany}"
|
||||||
|
|
@ -282,7 +298,9 @@ def misja():
|
||||||
hp_wrog_id = ttk.Progressbar(root, orient="horizontal", length=25, mode="determinate", style="wrog.Horizontal.TProgressbar", maximum=60)
|
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.place(x=cx, y=cy - 10)
|
||||||
hp_wrog_id['value'] = 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})
|
long = randrange(5, 20)
|
||||||
|
lufa_id = canvas.create_line(cx + 15, cy + 10, cx + long + 15, cy + 10, width=long / 5)
|
||||||
|
cele.append({"dul":{"id": wrog_id, "x1": cx, "y1": cy, "x2": cx + 30, "y2": cy + 20}, "hp": 60, "ip": hp_wrog_id, "lufa": {"id": lufa_id, "x": 0, "y": 0, "wiel": long}})
|
||||||
|
|
||||||
|
|
||||||
def aktualizuj_pociski():
|
def aktualizuj_pociski():
|
||||||
|
|
@ -312,7 +330,7 @@ def aktualizuj_pociski():
|
||||||
kamyki_do_usuniecia.append(idx)
|
kamyki_do_usuniecia.append(idx)
|
||||||
break
|
break
|
||||||
for idx, c in enumerate(cele):
|
for idx, c in enumerate(cele):
|
||||||
if c["x1"] <= px <= c["x2"] and c["y1"] <= py <= c["y2"]:
|
if c["dul"]["x1"] <= px <= c["dul"]["x2"] and c["dul"]["y1"] <= py <= c["dul"]["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:
|
||||||
cele_do_usuniecia.append(idx)
|
cele_do_usuniecia.append(idx)
|
||||||
|
|
@ -322,8 +340,8 @@ def aktualizuj_pociski():
|
||||||
for idx in cele_do_usuniecia:
|
for idx in cele_do_usuniecia:
|
||||||
c = cele[idx]
|
c = cele[idx]
|
||||||
|
|
||||||
srodek_x = (c["x1"] + c["x2"]) / 2
|
srodek_x = (c["dul"]["x1"] + c["dul"]["x2"]) / 2
|
||||||
srodek_y = (c["y1"] + c["y2"]) / 2
|
srodek_y = (c["dul"]["y1"] + c["dul"]["y2"]) / 2
|
||||||
|
|
||||||
promien_wybuchu = 24
|
promien_wybuchu = 24
|
||||||
wybuch_id = canvas.create_oval(srodek_x - promien_wybuchu, srodek_y - promien_wybuchu,
|
wybuch_id = canvas.create_oval(srodek_x - promien_wybuchu, srodek_y - promien_wybuchu,
|
||||||
|
|
@ -337,7 +355,7 @@ def aktualizuj_pociski():
|
||||||
fill="black", outline="")
|
fill="black", outline="")
|
||||||
canvas.tag_lower(slad_id)
|
canvas.tag_lower(slad_id)
|
||||||
|
|
||||||
canvas.delete(c["id"])
|
canvas.delete(c["dul"]["id"])
|
||||||
c["ip"].place_forget()
|
c["ip"].place_forget()
|
||||||
cele.pop(idx)
|
cele.pop(idx)
|
||||||
cele_zniszczone += 1
|
cele_zniszczone += 1
|
||||||
|
|
@ -413,7 +431,8 @@ def sprawdz_kolizje_czolgu():
|
||||||
|
|
||||||
def end():
|
def end():
|
||||||
grafika_misji = PhotoImage(file="GAME-OVER.png")
|
grafika_misji = PhotoImage(file="GAME-OVER.png")
|
||||||
c = Label(root, image=grafika_misji,bg="black")#darkolivegreen")
|
c = Label(root, image=grafika_misji, bg="darkolivegreen")
|
||||||
|
c.image = grafika_misji
|
||||||
c.place(relx=0.5, rely=0.5, x=-330)
|
c.place(relx=0.5, rely=0.5, x=-330)
|
||||||
root.after(1000, exit)
|
root.after(1000, exit)
|
||||||
|
|
||||||
|
|
@ -656,7 +675,13 @@ for i in range(cel_wymagany):
|
||||||
hp_wrog_id = ttk.Progressbar(root, orient="horizontal", length=25, mode="determinate", style="wrog.Horizontal.TProgressbar", maximum=60)
|
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.place(x=cx, y=cy - 10)
|
||||||
hp_wrog_id['value'] = 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})
|
long = randrange(5, 20)
|
||||||
|
lufa_id = canvas.create_line(cx + 15, cy + 10, cx + long + 15, cy + 10, width=long / 5)
|
||||||
|
promien_kola = long / 2
|
||||||
|
wieza_id = canvas.create_oval(cx - promien_kola+15, cy - promien_kola+10, cx + promien_kola+15, cy + promien_kola+10, fill="red3", outline="black")
|
||||||
|
canvas.tag_lower(wieza_id,lufa_id)
|
||||||
|
cele.append({"dul": {"id": wrog_id, "x1": cx, "y1": cy, "x2": cx + 30, "y2": cy + 20}, "hp": 60, "ip": hp_wrog_id, "lufa": {"id": lufa_id, "x": 0, "y": 0, "wiel": long},
|
||||||
|
"wieza": {"id": wieza_id, "pro": promien_kola}})
|
||||||
|
|
||||||
kamycki = []
|
kamycki = []
|
||||||
for i in range(60):
|
for i in range(60):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue