From 8994105d4efbfc0675583d58e62a78ad85f8d622 Mon Sep 17 00:00:00 2001 From: miteruzo Date: Sun, 30 Nov 2025 03:17:15 +0900 Subject: [PATCH] #34 --- main.py | 72 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 23 deletions(-) diff --git a/main.py b/main.py index c19ba4c..fbab4ae 100644 --- a/main.py +++ b/main.py @@ -51,17 +51,25 @@ def main ( x = CWindow.WIDTH * 3 / 4, y = CWindow.HEIGHT - 120, balloon = balloon) + snack_time = SnackTime (game) CurrentTime (game, SYSTEM_FONT) + try: broadcast = Broadcast (os.environ['BROADCAST_CODE']) except Exception: pass + + waiting_balloon = (False, '', '') + while True: for event in pygame.event.get (): if event.type == pygame.QUIT: pygame.quit () sys.exit () - if not balloon.enabled: + if (not balloon.enabled) and (not snack_time.enabled): + if waiting_balloon[0]: + deerjika.talk (waiting_balloon[1], waiting_balloon[2]) + waiting_balloon = (False, '', '') try: DB.begin_transaction () answer_flags = (AnsweredFlag.where ('platform', Platform.YOUTUBE.value) @@ -70,11 +78,18 @@ def main ( if answer_flags: answer_flag = random.choice (answer_flags) answer = Answer.find (answer_flag.answer_id) - if answer.query_rel.query_type == QueryType.YOUTUBE_COMMENT.value: - query = Query.find (answer.query_id) - deerjika.talk (query.content, answer.content) - answer_flag.answered = True - answer_flag.save () + match QueryType (answer.query_rel.query_type): + case QueryType.YOUTUBE_COMMENT: + query = Query.find (answer.query_id) + deerjika.talk (query.content, answer.content) + answer_flag.answered = True + answer_flag.save () + case QueryType.SNACK_TIME: + snack_time.play () + query = Query.find (answer.query_id) + waiting_balloon = (True, query.content, answer.content) + answer_flag.answered = True + answer_flag.save () DB.commit () add_query (broadcast) except Exception as ex: @@ -171,7 +186,7 @@ class Game: self.fps = FPS self.frame = 0 self.objects = [] - self.bgm = Sound ('assets/bgm.mp3') + self.bgm = Sound ('./assets/bgm.mp3') self.bgm.set_volume (.15) self.bgm.play (loops = -1) self._create_sky () @@ -292,10 +307,10 @@ class BgBase (GameObject): layer: float, ): super ().__init__ (game, layer = layer) - self.bg = self._load_image ('assets/bg.jpg') - self.bg_evening = self._load_image ('assets/bg-evening.jpg') - self.bg_grass = self._load_image ('assets/bg-grass.png') - self.bg_night = self._load_image ('assets/bg-night.jpg') + self.bg = self._load_image ('./assets/bg.jpg') + self.bg_evening = self._load_image ('./assets/bg-evening.jpg') + self.bg_grass = self._load_image ('./assets/bg-grass.png') + self.bg_night = self._load_image ('./assets/bg-night.jpg') self.sun = sun @staticmethod @@ -356,7 +371,7 @@ class BgGrass (GameObject): ): super ().__init__ (game) self.game = game - self.surface = pygame.image.load ('assets/bg-grass.png') + self.surface = pygame.image.load ('./assets/bg-grass.png') self.surface = pygame.transform.scale (self.surface, (CWindow.WIDTH, CWindow.HEIGHT)) def redraw ( @@ -420,14 +435,14 @@ class Deerjika (Creature): case Direction.LEFT: self.width = 1280 self.height = 720 - surface = pygame.image.load ('assets/deerjika_relax_left.png') + surface = pygame.image.load ('./assets/deerjika_relax_left.png') self.surfaces = [] for x in range (0, surface.get_width (), self.width): self.surfaces.append ( surface.subsurface (x, 0, self.width, self.height)) case Direction.RIGHT: ... - self.sound = Sound ('assets/noon.wav') + self.sound = Sound ('./assets/noon.wav') def redraw ( self, @@ -505,10 +520,10 @@ class CurrentTime (GameObject): def redraw ( self, ) -> None: - for i in range (4): - self.game.screen.blit ( - self.font.render (f"{ self.game.now } { self.game.fps } fps", True, (0, 0, 0)), - (i % 2, i // 2 * 2)) + for i in range (2): + cl = (i * 255, i * 255, i * 255) + self.game.screen.blit (self.font.render (str (self.game.now), True, cl), (-i, -i)) + self.game.screen.blit (self.font.render ('%2.3f fps' % self.game.fps, True, cl), (-i, 24 - i)) super ().redraw () @@ -543,7 +558,7 @@ class Balloon (GameObject): super ().__init__ (game, enabled = False) self.x_flip = x_flip self.y_flip = y_flip - self.surface = pygame.transform.scale (pygame.image.load ('assets/balloon.png'), + self.surface = pygame.transform.scale (pygame.image.load ('./assets/balloon.png'), (CWindow.WIDTH, CWindow.HEIGHT / 2)) self.surface = pygame.transform.flip (self.surface, self.x_flip, self.y_flip) @@ -610,7 +625,7 @@ class KitaSun (GameObject): game: Game, ): super ().__init__ (game) - self.surface = pygame.transform.scale (pygame.image.load ('assets/sun.png'), (200, 200)) + self.surface = pygame.transform.scale (pygame.image.load ('./assets/sun.png'), (200, 200)) self.sun = Sun () def redraw ( @@ -674,7 +689,7 @@ class Jojoko (GameObject): game: Game, ): super ().__init__ (game) - self.base = pygame.transform.scale (pygame.image.load ('assets/moon.png'), (200, 200)) + self.base = pygame.transform.scale (pygame.image.load ('./assets/moon.png'), (200, 200)) self.moon = Moon () self.surface = self._get_surface () @@ -899,14 +914,15 @@ class Video (GameObject): def redraw ( self, ) -> None: - self.game.screen.blit (self.surfaces[self.frame], (self.x, self.y)) + surface = pygame.transform.scale (self.surfaces[self.frame], (self.width, self.height)) + self.game.screen.blit (surface, (self.x, self.y)) super ().redraw () def update ( self, ) -> None: if self.frame >= len (self.surfaces) - 1: - self.pause () + self.stop () if self.pausing: self.frame -= 1 super ().update () @@ -916,6 +932,16 @@ class NicoVideo (Video): ... +class SnackTime (Video): + def __init__ ( + self, + game: Game, + ): + super ().__init__ (game, './assets/snack_time.mp4') + (self.width, self.height) = (CWindow.HEIGHT * 16 // 9, CWindow.HEIGHT) + (self.x, self.y) = ((CWindow.WIDTH - self.width) / 2, 0) + + def fetch_bytes_from_url ( url: str, ) -> bytes | None: