def main_loop(self): while not self.done: for e in pygame.event.get(): if e.type is pygame.QUIT: pygame.quit() datingsim.quit() quit() elif e.type is pygame.MOUSEMOTION: for tile in self.tiles: if tile.rect.collidepoint(e.pos): if (tile != self.curr_tile): tile.on_hover() self.curr_tile = tile elif tile == self.curr_tile: # didn't collide with curr_tile tile.on_unhover() self.curr_tile = None elif e.type is pygame.MOUSEBUTTONDOWN: if self.curr_tile != None: self.curr_tile.on_click() for button in self.buttons: if button.rect.collidepoint(e.pos): button.on_click() if self.bg_img: self.main_surface.blit(self.bg_img, [0,0]) else: self.main_surface.fill((0, 0, 0)) self.all_sprites.update() self.all_sprites.draw(self.main_surface) pygame.display.flip() pygame.time.wait(1000//20) self.ath()
def game_loop(): datingsim.checkinit() global in_game_loop, stop_request, stack, basescene in_game_loop = True stop_request = False while not stop_request: print(stack) if len(stack) == 0: # TODO: how to open worldmap multiple times # TODO: update worldmap to add Scenes to stack rather than directly calling main_loop if base_scene: base_scene.done = False base_scene.main_loop() base_scene.ath() else: next_scene = stack[-1] print("Next scene will be: " + str(next_scene)) next_scene.done = False next_scene.main_loop() next_scene.ath() in_game_loop = False datingsim.quit() pygame.quit() quit()
def test(): pygame.init() datingsim.init() def do_jog(): p = datingsim.player cost = 30 if p.hp < cost: text = "Not enough hp." else: p.hp -= cost spe_ch = random.randint(1, 5) dex_ch = random.randint(1, 3) p.spe += spe_ch p.dex += dex_ch text = ("Speed increased by {}.\n" "Dexterity increased by {}.\n").format(spe_ch, dex_ch) CoolDialogue(text).main_loop() button_data = [("wowz", lambda: print("hai")), ("lolz", lambda: print("lol")), ("Jog", do_jog)] bg_img = datingsim.assets["NZ_map"] loc = Location(button_data, bg_img) loc.enter() datingsim.quit() pygame.quit()
def test2(): pygame.init() datingsim.init() # loc = random.choice(list(datingsim.locs.values())) loc = datingsim.locs["castle"] loc.enter() datingsim.quit() pygame.quit()
def test_run(): pygame.init() datingsim.init() gurl_imgs = {} gurl_imgs['askance'] = datingsim.assets.get_img_safe('GURL_kanaya_askance') gurl_imgs['happy'] = gurl_imgs['default'] = datingsim.assets.get_img_safe('GURL_kanaya_smile') ask_data = None quiz_data = None gurl = Isadora() gurl.exp = 3998 d = MeetScene(gurl) d.main_loop() d.ath() datingsim.quit() pygame.quit()
def main_loop(self): while not self.done: self.main_loop_before() for e in pygame.event.get(): if e.type is pygame.QUIT: datingsim.quit() pygame.quit() quit() elif e.type is pygame.MOUSEBUTTONDOWN: for button in self.buttons: if button.rect.collidepoint(e.pos): button.on_click() if self.bg_surf: self.main_surface.blit(self.bg_surf, (0, 0)) else: self.main_surface.fill((0, 0, 0)) self.all_sprites.update() self.all_sprites.draw(self.main_surface) pygame.display.flip() self.main_loop_after() pygame.time.wait(1000//20) self.ath()
def test(): pygame.init() datingsim.init() pygame.display.set_caption("Shop test") W, H = datingsim.RESOLUTION popup_w, popup_h = popup_size = (400, 600) popup_x, popup_y = popup_pos = ( (W - popup_w) / 2, (H - popup_h) / 2 ) popup_bg_color = (255, 255, 255) popup_bg_surf = pygame.Surface(popup_size) popup_bg_surf.fill(popup_bg_color) items = [datingsim.player.inventory.get(key) for key in ('potion', 'arrows', 'tractor')] shop = ShopDialogue(popup_pos, items, popup_bg_surf=popup_bg_surf) shop.main_loop() datingsim.quit() pygame.quit()
def test3(): pygame.init() datingsim.init() done = False def end_program(): nonlocal done done = True print("\nGood day to you, you handsome bastard, you.") while not done: try: loc_key = input("Where do you want to visit?") datingsim.locs[loc_key].enter() except KeyboardInterrupt: end_program() except EOFError: end_program() except KeyError: print("location not defined.") datingsim.quit() pygame.quit()
def test_run_test_buttons(): pygame.init() datingsim.init() gurl_imgs = {} gurl_imgs['askance'] = datingsim.assets.get_img_safe('GURL_kanaya_askance') gurl_imgs['happy'] = datingsim.assets.get_img_safe('GURL_kanaya_smile') gurl = Gurl("Kanaya", gurl_imgs, None) gurl.exp = 3998 d = MeetScene(gurl, use_default_buttons=False) d.add_button("test button", lambda: print("test 1")) def finish(): d.done = True d.add_button("end", finish) d.add_button("update conv", lambda: d.update_conversation("changed")) def increase_exp(): d.gurl.exp += 1 d.add_button("increase exp", increase_exp) d.add_button("happy", lambda: d.change_mood("happy")) d.add_button("askance", lambda: d.change_mood("askance")) d.main_loop() d.ath() datingsim.quit() pygame.quit()