def create_menu(): GUI.get_element('game_menu').func = GameGUI.pause_menu_clear GUI.add_element( Image((Config.get_width() // 2, Config.get_height() // 2), load_image("images/game_menu_gui/menu.png"), 'background')) GameGUI.pause_menu_elements.add('background') GUI.add_element( MedievalButton( (Config.get_width() // 2, Config.get_height() // 2 - 50), 'Resume', 35, 'resume', GameGUI.pause_menu_clear)) GameGUI.pause_menu_elements.add('resume') GUI.add_element( MedievalButton( (Config.get_width() // 2, Config.get_height() // 2 + 20), 'Exit in menu', 33, 'exit', GameGUI.exit_in_menu)) GameGUI.pause_menu_elements.add('exit') GUI.add_element( MedievalButton( (Config.get_width() // 2, Config.get_height() // 2 + 90), 'Exit in desktop', 29, 'exit_in_desktop', MainMenuGUI.exit)) GameGUI.pause_menu_elements.add('exit_in_desktop')
def add_buttons(): GUI.add_element( MedievalButton( (Config.get_width() // 2, Config.get_height() // 2 + 180), 'Connect', 29, 'connect_with_server', lambda: Myultyplayer.connect_with_server( GUI.get_element('user_login').text, GUI.get_element('server`s_ip').text))) GUI.add_element( MedievalButton( (Config.get_width() // 2, Config.get_height() // 2 + 280), 'Close', 29, 'close_myultyplayer', Myultyplayer.exit))
def set_camera_pos(self): cam = SceneManager.current_scene.current_camera x, y = self.game_object.transform.coord if abs(x) < 1024 - Config.get_width() // 2: cam.transform.move_to(x, cam.transform.y) else: cam.transform.move_to(copysign(1024 - Config.get_width() // 2, x), cam.transform.y) if abs(y) < 1024 - Config.get_height() // 2: cam.transform.move_to(cam.transform.x, y) else: cam.transform.move_to(cam.transform.x, copysign(1024 - Config.get_height() // 2, y))
def update(self): for element in self.elements: element['element'].move(*element['step']) if element['element'].get_pos()[0] > Config.get_width() or element['element'].get_pos()[1] > Config.get_width() \ or element['element'].get_pos()[0] + element['element'].size[0] < 0 \ or element['element'].get_pos()[1] + element['element'].size[1] < 0: element['element'].set_const_pos()
def init(): MainMenuGUI.remove_buttons() GUI.add_element( TextBox((Config.get_width() // 2, Config.get_height() // 2, Config.get_height() // 2 + 100, 40), '', default_text='Login', name='user_login')) GUI.add_element( TextBox((Config.get_width() // 2, Config.get_height() // 2 + 80, Config.get_height() // 2 + 100, 40), '', default_text='Server`s IP address', name='server`s_ip')) Myultyplayer.add_buttons()
def add_move_buttons(): x = 230 y = 280 GUI.add_element( Label( (Config.get_width() // 2 - x, Config.get_height() // 2 - y + 75), 32, 'Change control keys', pygame.Color('white'), 'fonts/Dot.ttf', 'lbl_change_keys')) GUI.add_element( MedievalButton( (Config.get_width() // 2 - x, Config.get_height() // 2 - y + 75 * 2), 'Move up: {}'.format( pygame.key.name(SaveManager.get_entry('preferences', 'up'))), 29, 'btn_mvup', SettingsGUI.change_button, 'up')) GUI.add_element( MedievalButton( (Config.get_width() // 2 - x, Config.get_height() // 2 - y + 75 * 3), 'Move down: {}'.format( pygame.key.name( SaveManager.get_entry('preferences', 'down'))), 29, 'btn_mvdown', SettingsGUI.change_button, 'down')) GUI.add_element( MedievalButton( (Config.get_width() // 2 - x, Config.get_height() // 2 - y + 75 * 4), 'Move left: {}'.format( pygame.key.name( SaveManager.get_entry('preferences', 'left'))), 29, 'btn_mvleft', SettingsGUI.change_button, 'left')) GUI.add_element( MedievalButton( (Config.get_width() // 2 - x, Config.get_height() // 2 - y + 75 * 5), 'Move right: {}'.format( pygame.key.name( SaveManager.get_entry('preferences', 'right'))), 29, 'btn_mvright', SettingsGUI.change_button, 'right'))
def init(): GUI.add_element( Image((Config.get_width() // 2, Config.get_height() // 2 + 40), load_image('images/bg.png'), 'bg_img')) SettingsGUI.add_move_buttons() SettingsGUI.add_resolutions_buttons() GUI.add_element( MedievalCheckbox( 'toggle_fullscreen', (Config.get_width() // 2 + 230, Config.get_height() // 2 + 230), 'Toggle Fullscreen', 29, SaveManager.get_entry('preferences', 'fullscreen'), SettingsGUI.toggle_fullscreen)) GUI.add_element( MedievalButton( (Config.get_width() // 2, Config.get_height() // 2 + 280), 'Close', 29, 'close_settings', SettingsGUI.exit))
def init(): clouds_controller = CloudsController('Con', [1, 0]) CloudsController.generate_clouds(15, clouds_controller) GUI.add_element( Image((Config.get_width() // 2, Config.get_height() // 2), pygame.transform.scale( load_image('images/main_menu/sky.png'), (Config.get_width(), Config.get_height())), 'sky')) GUI.add_element(clouds_controller) GUI.add_element( Image((Config.get_width() // 2, 75), load_image('images/main_menu/title_bg.png'), 'title')) GUI.add_element( Label((Config.get_width() // 2, 159), 53, 'Untitled game', Color('white'), 'fonts/Dot.ttf', 'title_text')) MainMenuGUI.add_buttons()
def add_buttons(): GUI.add_element( MedievalButton((Config.get_width() // 2, Config.get_height() // 2), 'Start game', 35, 'start_game', MainMenuGUI.start_game)) GUI.add_element( MedievalButton( (Config.get_width() // 2, Config.get_height() // 2 + 75), 'Multiplayer', 35, 'myultyplayer', Myultyplayer.init)) GUI.add_element( MedievalButton( (Config.get_width() // 2, Config.get_height() // 2 + 150), 'Settings', 35, 'settings', MainMenuGUI.load_settings)) GUI.add_element( MedievalButton( (Config.get_width() // 2, Config.get_height() // 2 + 225), 'Exit', 35, 'exit', MainMenuGUI.exit))
def update(self, *args): container = self.game_object.get_component(ChatContainer) for msg in self.client.received.readlines(): container.add(': '.join(self.parse(msg))) for event in InputManager.get_events(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN: if not self.on_screen: GUI.add_element( TextBox((Config.get_width() // 8 + 10, Config.get_height() - 40, Config.get_width() // 4, 40), '', callback=self.client.send, name='message_textbox')) self.on_screen = True elif event.key == pygame.K_ESCAPE: if self.on_screen: GUI.del_element('message_textbox') self.on_screen = False
def update(self, *args): self.gui_obj.pos = Config.get_width() // 2, Config.get_height() - 100 if self._collider is not None and self._player_collider is not None: if self._collider.detect_collision(self._player_collider): if not self._button_shown: GUI.add_element(self.gui_obj) self._button_shown = True else: if self._button_shown: GUI.del_element(self.gui_obj.name) self._button_shown = False
def add_element(self, element): if randint(0, 1): self.elements.append({ 'element': element, 'step': (-self.change_pos[0], self.change_pos[1]) }) element.const_rect.x = Config.get_width() else: self.elements.append({ 'element': element, 'step': (self.change_pos[0], self.change_pos[1]) })
def draw(self, game_objects): for game_object in game_objects: if game_object.has_component(ImageComponent): transform = game_object.transform cam_transform = self.transform surface = game_object.get_component(ImageComponent).image obj_x, obj_y = transform.coord x, y = cam_transform.coord rect = surface.get_rect( centerx=Config.get_width() // 2 + obj_x - x, centery=Config.get_height() // 2 + y - obj_y ) self.surface.blit(surface, rect)
def add_resolutions_buttons(): x = 230 y = 280 GUI.add_element( Label((Config.get_width() // 2 + x, Config.get_height() // 2 - y + 75), 32, 'Set display resolution', pygame.Color('white'), 'fonts/Dot.ttf', 'lbl_set_resolution')) GUI.add_element( MedievalButton((Config.get_width() // 2 + x, Config.get_height() // 2 - y + 75 * 2), '1920x1080', 29, 'btn_res1080p', SettingsGUI.set_resolution, 1920, 1080)) GUI.add_element( MedievalButton((Config.get_width() // 2 + x, Config.get_height() // 2 - y + 75 * 3), '1440x900', 29, 'btn_res_wxga+', SettingsGUI.set_resolution, 1440, 900)) GUI.add_element( MedievalButton((Config.get_width() // 2 + x, Config.get_height() // 2 - y + 75 * 4), '1366x768', 29, 'btn_res_wxga', SettingsGUI.set_resolution, 1366, 768)) GUI.add_element( MedievalButton((Config.get_width() // 2 + x, Config.get_height() // 2 - y + 75 * 5), '1280x720', 29, 'btn_res_720p', SettingsGUI.set_resolution, 1280, 720)) GUI.add_element( MedievalButton((Config.get_width() // 2 + x, Config.get_height() // 2 - y + 75 * 6), '1024x768', 29, 'btn_res_xga', SettingsGUI.set_resolution, 1024, 768))
def __init__(self, game_object): super().__init__(game_object) self.gui_obj = MedievalButton( (Config.get_width() // 2, Config.get_height() - 100), 'Enter the village', 25, 'enter_village', self.load_scene)
def __init__(self, game_object): super().__init__(game_object) self.gui_obj = MedievalButton( (Config.get_width() // 2, Config.get_height() - 100), 'Enter in house', 29, 'house', self.load_scene)
def init(): GUI.add_element( MedievalButton((Config.get_width() // 2, Config.get_height() - 35), 'Menu', 35, 'game_menu', GameGUI.create_menu))