def main_loop(self): """The player enters this location in the dating sim""" all_sprites = pygame.sprite.Group() buttons = pygame.sprite.Group() # generate Location-specific buttons LocButton.reset() LocButton.containers = [all_sprites, buttons] for name, on_click in self.button_data: LocButton(on_click, name) # generate generic menu buttons LocButton2.reset() LocButton2.containers = [all_sprites, buttons] dumby_fn = lambda: None def inventory_fn(): text = datingsim.player.inventory.dump() d = CoolDialogue(text, snapshot=datingsim.snapshot()) d.main_loop() def statistics_fn(): text = datingsim.player.stats_dump() CoolDialogue(text, snapshot=datingsim.snapshot()).main_loop() LocButton2(dumby_fn, "Location Name") LocButton2(inventory_fn, "Inventory") LocButton2(statistics_fn, "Statistics") BackToMap.containers = [all_sprites, buttons] BackToMap() QuickSleepButton.containers = [all_sprites, buttons] QuickSleepButton() # cash and HP display text cash_text_loc = (200, HEIGHT - 30) CashHPText.containers = [all_sprites] CashHPText(cash_text_loc) # okay, and now we loop self.done = False while not self.done: for event in pygame.event.get(): if event.type is pygame.QUIT: import kitchen kitchen.finish() return elif event.type is pygame.MOUSEBUTTONDOWN: for button in buttons: if button.rect.collidepoint(event.pos): # TODO: consider whether this is worth implementing # if location switches, button is expected to change # global variable location and return True # done = button.on_click() or False click_result = button.on_click() if click_result == Location.STATUS_END_SCENE: self.done = True import kitchen kitchen.remove_scene(self) elif click_result == Location.STATUS_NEXT_SCENE: self.done = True all_sprites.update() datingsim.screen.fill(self.WASH_COLOR) if self.bg_img: datingsim.screen.blit(self.bg_img, [0, 0]) all_sprites.draw(datingsim.screen) # blit_title() # update_text() # screen.blit(text_surf, text_loc) pygame.display.flip() pygame.time.wait(1000 // 20)
def on_exit_click(): import kitchen kitchen.remove_scene(self) print("exit click") self.done = True