|
|
|
@ -7,10 +7,16 @@ import json |
|
|
|
from Units.knight import Knight |
|
|
|
from Units.knight import Knight |
|
|
|
from Effects.order_click import OrderClick |
|
|
|
from Effects.order_click import OrderClick |
|
|
|
from tkinter import Menu |
|
|
|
from tkinter import Menu |
|
|
|
|
|
|
|
import yt_dlp |
|
|
|
|
|
|
|
import os |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from pydub import AudioSegment |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import subprocess |
|
|
|
|
|
|
|
import threading |
|
|
|
|
|
|
|
import asyncio |
|
|
|
|
|
|
|
import sys |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class IsometricGame: |
|
|
|
class IsometricGame: |
|
|
|
def __init__(self, width, height, data): |
|
|
|
def __init__(self, width, height, data): |
|
|
|
self.width = width |
|
|
|
self.width = width |
|
|
|
@ -30,6 +36,8 @@ class IsometricGame: |
|
|
|
self.input_lock = False |
|
|
|
self.input_lock = False |
|
|
|
|
|
|
|
|
|
|
|
self.window = tk.Tk() |
|
|
|
self.window = tk.Tk() |
|
|
|
|
|
|
|
self.window.protocol("WM_DELETE_WINDOW", self.on_close) |
|
|
|
|
|
|
|
|
|
|
|
files = sorted(glob.glob("Tiles/**/*.png", recursive=True)) |
|
|
|
files = sorted(glob.glob("Tiles/**/*.png", recursive=True)) |
|
|
|
self.tiles = {os.path.splitext(os.path.basename(file))[0]: tk.PhotoImage(file=file) for file in files} |
|
|
|
self.tiles = {os.path.splitext(os.path.basename(file))[0]: tk.PhotoImage(file=file) for file in files} |
|
|
|
# self.battlefield = [[Cell(walkable = True, tile=self.tiles["landscapeTiles_067"] ) for x in range(self.width)] for y in range(self.height)] |
|
|
|
# self.battlefield = [[Cell(walkable = True, tile=self.tiles["landscapeTiles_067"] ) for x in range(self.width)] for y in range(self.height)] |
|
|
|
@ -48,10 +56,21 @@ class IsometricGame: |
|
|
|
self.canvas.bind('<Double-Button-3>', self.on_canvas_double_rclick) |
|
|
|
self.canvas.bind('<Double-Button-3>', self.on_canvas_double_rclick) |
|
|
|
self.canvas.bind('<Motion>', self.calculate_coordinates) |
|
|
|
self.canvas.bind('<Motion>', self.calculate_coordinates) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
menubar = tk.Menu(self.window, tearoff=0) |
|
|
|
|
|
|
|
menubar.add_command(label="Chiudi", command=self.on_close) |
|
|
|
|
|
|
|
self.window.config(menu=menubar) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.knight = Knight(self, (1,1)) |
|
|
|
self.knight = Knight(self, (1,1)) |
|
|
|
self.draw_battlefield() |
|
|
|
self.draw_battlefield() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def on_close(self): |
|
|
|
|
|
|
|
print("Chiusura") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.window.quit() # Chiude la finestra |
|
|
|
|
|
|
|
self.window.destroy() # Distrugge l'oggetto finestra |
|
|
|
|
|
|
|
sys.exit() # Termina l'esecuzione del programma |
|
|
|
|
|
|
|
|
|
|
|
def calculate_coordinates(self, event): |
|
|
|
def calculate_coordinates(self, event): |
|
|
|
if self.input_lock: |
|
|
|
if self.input_lock: |
|
|
|
return |
|
|
|
return |
|
|
|
@ -73,7 +92,7 @@ class IsometricGame: |
|
|
|
elif delta_x == -1 and delta_y == 0: |
|
|
|
elif delta_x == -1 and delta_y == 0: |
|
|
|
return 3 # Ovest |
|
|
|
return 3 # Ovest |
|
|
|
elif delta_x == -1 and delta_y == -1: |
|
|
|
elif delta_x == -1 and delta_y == -1: |
|
|
|
return 4 # Nord-Ovest |
|
|
|
return 4 # Nord-Ovest |
|
|
|
elif delta_x == 0 and delta_y == -1: |
|
|
|
elif delta_x == 0 and delta_y == -1: |
|
|
|
return 5 # Nord |
|
|
|
return 5 # Nord |
|
|
|
elif delta_x == 1 and delta_y == -1: |
|
|
|
elif delta_x == 1 and delta_y == -1: |
|
|
|
@ -235,7 +254,9 @@ class IsometricGame: |
|
|
|
def on_canvas_click(self, event): |
|
|
|
def on_canvas_click(self, event): |
|
|
|
# calculate the clicked cell's coordinates |
|
|
|
# calculate the clicked cell's coordinates |
|
|
|
cell_x, cell_y = self.inv_iso_transform(event.x, event.y) |
|
|
|
cell_x, cell_y = self.inv_iso_transform(event.x, event.y) |
|
|
|
self.battlefield[cell_y][cell_x].walkable ^= True |
|
|
|
cell=self.battlefield[cell_y][cell_x] |
|
|
|
|
|
|
|
cell.walkable ^= True |
|
|
|
|
|
|
|
cell.tile = self.tiles["landscapeTiles_067"] if cell.walkable else self.tiles["landscapeTiles_066"] |
|
|
|
self.draw_battlefield() |
|
|
|
self.draw_battlefield() |
|
|
|
self.draw_units() |
|
|
|
self.draw_units() |
|
|
|
|
|
|
|
|
|
|
|
@ -290,6 +311,23 @@ class Cell: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
if __name__ == "__main__": |
|
|
|
|
|
|
|
output_filename = "audio" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# use ytdb for download audio from youtube video with lower posible quality using output_filename as filename |
|
|
|
|
|
|
|
ydl_opts = { |
|
|
|
|
|
|
|
'format': '140', |
|
|
|
|
|
|
|
'outtmpl': output_filename, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not os.path.exists(output_filename): |
|
|
|
|
|
|
|
with yt_dlp.YoutubeDL(ydl_opts) as ydl: |
|
|
|
|
|
|
|
ydl.download(['https://www.youtube.com/watch?v=-IQZEk-oaYU']) |
|
|
|
|
|
|
|
# play the audio asynchrounously |
|
|
|
|
|
|
|
audio = AudioSegment.from_file(output_filename) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
playb = subprocess.Popen(["ffplay", "-nodisp", "-autoexit", output_filename], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
|
|
|
|
|
|
|
|
|
|
|
with open('maze.json', 'r') as file: |
|
|
|
with open('maze.json', 'r') as file: |
|
|
|
data = json.load(file) |
|
|
|
data = json.load(file) |
|
|
|
# data is a boolean matrix, find dmensions |
|
|
|
# data is a boolean matrix, find dmensions |
|
|
|
|