Example #1
0
 def set_resolution(width, height):
     Config.set_resolution(width, height)
     SaveManager.set_entry('preferences', 'resolution', [width, height])
     GUI.clear()
     MainMenuGUI.init()
     MainMenuGUI.remove_buttons()
     SettingsGUI.init()
Example #2
0
 def load_scene(self):
     from scene_loader import load_scene
     GUI.del_element('house')
     SaveManager.set_entry('village1', 'plr_coord',
                           self._player.transform.coord)
     load_scene('scenes/house1.json')
     if SaveManager.get_entry('village1', 'seen_tardis'):
         SceneManager.current_scene.remove_object(
             SceneManager.current_scene.find_object('tardis'))
Example #3
0
 def exit_in_menu():
     for scene in SceneManager.scenes.values():
         for obj in scene.objects:
             for component in obj.get_components(NetworkingController):
                 component.client.shutdown()
             for component in obj.get_components(ChatController):
                 component.client.shutdown()
     GUI.clear()
     load_scene('scenes/main_menu.json')
     MainMenuGUI.init()
Example #4
0
    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')
Example #5
0
 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
Example #6
0
    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()
Example #7
0
 def clear():
     GUI.del_element(
         'lbl_change_keys',
         'btn_mvup',
         'btn_mvdown',
         'btn_mvleft',
         'btn_mvright',
         'lbl_set_resolution',
         'btn_res1080p',
         'btn_res_wxga+',
         'btn_res_wxga',
         'btn_res_720p',
         'btn_res_xga',
         'bg_img',
         'toggle_fullscreen',
         'close_settings',
     )
Example #8
0
    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'))
Example #9
0
 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
Example #10
0
    def add(self, message):
        if len(self.container) >= 5:
            GUI.del_element(self.container[0][0])
            self.container.pop(0)

        for i in range(5):
            name = 'message' + str(i)
            try:
                if name not in list(zip(*self.container))[0]:
                    break
            except IndexError:
                break

        self.container.append(
            (name,
             GUI.add_element(
                 Label((200, Config.get_height() - 80), 32, message,
                       pygame.Color('black'), 'fonts/Dot.ttf', name))))

        for name, label in self.container:
            label.pos[1] -= 50
Example #11
0
    def change_button(name):
        if SettingsGUI._button_changer is not None:
            if SettingsGUI._button_changer[
                    2] in SceneManager.current_scene.objects:
                SceneManager.current_scene.remove_object(
                    SettingsGUI._button_changer[2])
                SettingsGUI._button_changer[
                    0].text = SettingsGUI._button_changer[1]

        button = GUI.get_element('btn_mv' + name)
        go = GameObject()
        go.add_component(ButtonChanger(name, button, go))
        SettingsGUI._button_changer = [button, button.text, go]
        button.text = 'Press any key...'
        SceneManager.current_scene.add_object(go)
Example #12
0
 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))
Example #13
0
    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()
Example #14
0
    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))
Example #15
0
    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))
Example #16
0
 def clear():
     GUI.del_element('user_login', 'server`s_ip', 'bg_img',
                     'close_myultyplayer', 'connect_with_server')
Example #17
0
import pygame
import sys

from engine.input_manager import InputManager
from engine.save_manager import SaveManager
from engine.gui import GUI

from user_components import NetworkingController, ChatController
from scene_loader import load_scene
from guis import MainMenuGUI

SaveManager.load_profile('preferences', 'user_prefs.json')
Config.set_resolution(*SaveManager.get_entry('preferences', 'resolution'))
Config.set_fullscreen(SaveManager.get_entry('preferences', 'fullscreen'))

GUI.set_cursor(SaveManager.get_entry('config', 'cursor'))

InputManager.set_axis('Horizontal', {
    SaveManager.get_entry('preferences', 'right'): 1,
    SaveManager.get_entry('preferences', 'left'): -1,
})

InputManager.set_axis('Vertical', {
    SaveManager.get_entry('preferences', 'up'): 1,
    SaveManager.get_entry('preferences', 'down'): -1,
})

load_scene('scenes/main_menu.json')
MainMenuGUI.init()

while True:
Example #18
0
 def init():
     GUI.add_element(
         MedievalButton((Config.get_width() // 2, Config.get_height() - 35),
                        'Menu', 35, 'game_menu', GameGUI.create_menu))
Example #19
0
 def remove_buttons():
     GUI.del_element('start_game')
     GUI.del_element('myultyplayer')
     GUI.del_element('settings')
     GUI.del_element('exit')
Example #20
0
 def load_scene(self):
     from scene_loader import load_scene
     GUI.del_element('house')
     SaveManager.set_entry('village1', 'plr_coord',
                           self._player.transform.coord)
     load_scene('scenes/house3.json')
Example #21
0
    def pause_menu_clear():
        for _ in GameGUI.pause_menu_elements:
            GUI.del_element(_)

        GameGUI.pause_menu_elements.clear()
        GUI.get_element('game_menu').func = GameGUI.create_menu
Example #22
0
 def start_game():
     load_scene('scenes/scene1.json')
     SaveManager.add_profile('village1', {'seen_tardis': False})
     GUI.clear()
     GameGUI.init()
Example #23
0
 def load_scene(self):
     from scene_loader import load_scene
     GUI.del_element('enter_village')
     load_scene('scenes/scene1.json')
     SceneManager.current_scene.find_object('player').transform.move_to(
         *SaveManager.get_entry('village1', 'plr_coord'))
Example #24
0
    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))