Aggiornamenti al codice: modifiche ai file Python, aggiunta di file audio e miglioramenti alla GUI.
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
+13
-2
@@ -39,12 +39,23 @@ class Knight:
|
||||
screen_y += (screen_y_dest - screen_y) * self.partial_move
|
||||
else:
|
||||
screen_x, screen_y = self.engine.iso_transform(*self.destination)
|
||||
self.visited = self.visited[-4:]
|
||||
neighbors_list = self.engine.find_neighbors(self.destination) # Get the neighbors of the destination cell
|
||||
neighbors_list = [cell for cell in neighbors_list if cell not in self.visited]
|
||||
|
||||
# Remove any neighbors that are not walkable
|
||||
self.best_next = self.engine.get_closest_neighbor(neighbors_list,self.target)
|
||||
#if best next is not walkable, find the closest walkable cell to best next
|
||||
neighbors_list = [cell for cell in neighbors_list if self.engine.battlefield[cell[1]][cell[0]].walkable]
|
||||
if self.engine.battlefield[self.best_next[1]][self.best_next[0]].walkable == False:
|
||||
self.best_next = self.engine.get_closest_neighbor(neighbors_list,self.best_next)
|
||||
if not self.best_next:
|
||||
self.target = self.destination
|
||||
self.best_next = self.destination
|
||||
self.position = self.destination
|
||||
self.destination = self.engine.get_closest_neighbor(neighbors_list,self.target)
|
||||
self.destination = self.best_next
|
||||
self.partial_move = 0
|
||||
self.visited.append(self.destination)
|
||||
print(self.partial_move)
|
||||
|
||||
|
||||
@@ -57,6 +68,6 @@ class Knight:
|
||||
self.state = "Walk"
|
||||
|
||||
def run_to(self, target):
|
||||
self.speed = .15
|
||||
self.speed = .13
|
||||
self.target = target
|
||||
self.state = "Run"
|
||||
@@ -7,10 +7,16 @@ import json
|
||||
from Units.knight import Knight
|
||||
from Effects.order_click import OrderClick
|
||||
from tkinter import Menu
|
||||
import yt_dlp
|
||||
import os
|
||||
|
||||
from pydub import AudioSegment
|
||||
|
||||
import subprocess
|
||||
import threading
|
||||
import asyncio
|
||||
import sys
|
||||
|
||||
|
||||
class IsometricGame:
|
||||
def __init__(self, width, height, data):
|
||||
self.width = width
|
||||
@@ -30,6 +36,8 @@ class IsometricGame:
|
||||
self.input_lock = False
|
||||
|
||||
self.window = tk.Tk()
|
||||
self.window.protocol("WM_DELETE_WINDOW", self.on_close)
|
||||
|
||||
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.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('<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.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):
|
||||
if self.input_lock:
|
||||
return
|
||||
@@ -73,7 +92,7 @@ class IsometricGame:
|
||||
elif delta_x == -1 and delta_y == 0:
|
||||
return 3 # Ovest
|
||||
elif delta_x == -1 and delta_y == -1:
|
||||
return 4 # Nord-Ovest
|
||||
return 4 # Nord-Ovest
|
||||
elif delta_x == 0 and delta_y == -1:
|
||||
return 5 # Nord
|
||||
elif delta_x == 1 and delta_y == -1:
|
||||
@@ -235,7 +254,9 @@ class IsometricGame:
|
||||
def on_canvas_click(self, event):
|
||||
# calculate the clicked cell's coordinates
|
||||
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_units()
|
||||
|
||||
@@ -290,6 +311,23 @@ class Cell:
|
||||
|
||||
|
||||
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:
|
||||
data = json.load(file)
|
||||
# data is a boolean matrix, find dmensions
|
||||
|
||||
Reference in New Issue
Block a user