Aggiorna la gestione dei tasti e aggiungi nuovi file di configurazione per le schermate di pausa e menu di avvio
This commit is contained in:
+6
-4
@@ -14,7 +14,7 @@ class GameWindow:
|
||||
self.cell_size = cell_size
|
||||
self.width = width * cell_size
|
||||
self.height = height * cell_size
|
||||
actual_screen_size = os.environ.get("RESOLUTIONz", "640x480").split("x")
|
||||
actual_screen_size = os.environ.get("RESOLUTION", "640x480").split("x")
|
||||
actual_screen_size = tuple(map(int, actual_screen_size))
|
||||
self.target_size = actual_screen_size if self.width > actual_screen_size[0] or self.height > actual_screen_size[1] else (self.width, self.height)
|
||||
self.w_start_offset = (self.target_size[0] - self.width) // 2
|
||||
@@ -119,6 +119,8 @@ class GameWindow:
|
||||
self.draw_rectangle(50, 50,
|
||||
self.target_size[0] - 100, self.target_size[1] - 100, "win", filling=(255, 255, 255))
|
||||
self.draw_text(text, self.fonts[self.target_size[1]//20], "center", sdl2.ext.Color(0, 0, 0))
|
||||
if subtitle := kwargs.get("subtitle"):
|
||||
self.draw_text(subtitle, self.fonts[self.target_size[1]//30], (self.target_size[0] // 2 - 50, self.target_size[1] // 2 + 50), sdl2.ext.Color(0, 0, 0))
|
||||
if image := kwargs.get("image"):
|
||||
image_size = self.get_image_size(image)
|
||||
self.draw_image(self.target_size[0] // 2 - image_size[0] // 2 - self.w_offset,
|
||||
@@ -130,6 +132,7 @@ class GameWindow:
|
||||
sprite.position = (self.target_size[0] // 2 - 50, self.target_size[1] // 2 + 30)
|
||||
self.renderer.copy(sprite, dstrect=sprite.position)
|
||||
for i, score in enumerate(scores[:5]):
|
||||
score = " - ".join(score)
|
||||
#self.draw_text(score, self.fonts[self.target_size[1]//40], (self.target_size[0] // 2 - 50, self.target_size[1] // 2 + 50 + 30 * (i + 1)), sdl2.ext.Color(0, 0, 0))
|
||||
sprite_score = self.factory.from_text(score, color=sdl2.ext.Color(0, 0, 0), fontmanager=self.fonts[self.target_size[1]//40])
|
||||
sprite_score.position = (self.target_size[0] // 2 - 50-sprite_score.size[0] // 4,
|
||||
@@ -230,7 +233,6 @@ class GameWindow:
|
||||
self.h_offset = y
|
||||
|
||||
def play_sound(self, sound_file, tag="base"):
|
||||
print(sound_file)
|
||||
sound_file = os.path.join("sound", sound_file)
|
||||
rw = sdl2.SDL_RWFromFile(byteify(sound_file, "utf-8"), b"rb")
|
||||
if not rw:
|
||||
@@ -257,9 +259,9 @@ class GameWindow:
|
||||
sdl2.SDL_ClearQueuedAudio(dev[1])
|
||||
|
||||
def start_dialog(self, **kwargs):
|
||||
self.dialog("Welcome to the Mice!", **kwargs)
|
||||
self.dialog("Welcome to the Mice!", subtitle="A game by Matteo because was bored", **kwargs)
|
||||
center = self.get_view_center()
|
||||
self.draw_button(center[0], center[1] + 10 * self.scale, "Start", 120, 50, (0, 0))
|
||||
#self.draw_button(center[0], center[1] + 10 * self.scale, "Start", 120, 50, (0, 0))
|
||||
|
||||
def draw_button(self, x, y, text, width, height, coords):
|
||||
if self.button_cursor[0] == coords[0] and self.button_cursor[1] == coords[1]:
|
||||
|
||||
Reference in New Issue
Block a user