def build_gui(self): logging.debug(f"Scene<{self.scene_name}> Is Building GUI") if self.gui is not None: logging.debug(f"Scene<{self.scene_name}> UIManager is present, clearing current values for rebuild") self.gui = None self.ui_elements.clear() self.gui = UIManager(self.display.get_size(), GUI_THEME_FILE) else: logging.debug(f"Scene<{self.scene_name}> UIManager not present, creating new manager") self.gui = UIManager(self.display.get_size(), GUI_THEME_FILE)
def __init__(self): # Start up Pygame. pygame.init() # Title the window our game runs in. pygame.display.set_caption(config.game_name) self.options = Options() # Define the dimensions of our game's window. self.window_surface = pygame.display.set_mode(self.options.resolution) self.window_surface.blit(pygame.image.load("media/images/background.png"), (0, 0)) self.start_up = True self.enter_mines = False self.enter_busstop = False self.enter_uptown = False self.background_surface = None self.ui_manager = UIManager(self.options.resolution, PackageResource(package='media.themes', resource='theme.json')) self.text_block = None self.text_entry = None self.message_window = None self.recreate_ui() self.clock = pygame.time.Clock() self.time_delta_stack = deque([]) self.running = True
def __init__(self): self.manager = UIManager((800, 600), 'themes/home.json') self.title = UILabel(relative_rect=pygame.Rect(400 - 100, 20, 200, 50), text='Instruction', manager=self.manager, object_id='#title') self.text = UITextBox( relative_rect=pygame.Rect(100, 100, 800 - 200, 600 - 100), html_text= "<body><b>Touche</b><br>Espace -> Tirer<br>Entrer -> Magasin<br>Echap -> Menu de sauvegarde<br>Flèche droite et gauche -> Se déplacer<br><br><b>Système de Niveau</b><br>Niveau 1 -> 0 à 5000 points<br>Niveau 2 -> 5000 à 10000 points<br>Niveau 3 -> 10000 à 15000 points<br>Niveau 4 -> plus de 15000 points<br><br><b>Système du jeu</b><br>Le Joueur commence avec 3 vies, lorsque un monstre touche le joueur celui-ci perd une vie et le monstre meurt.<br>Un monstre rapporte 100 points et 1 credit lorsque le joueur le tue et retire 50 points lorsque le monstre touche le sol<br>Le Joueur a un pourcentage de chance d'obtenir un bonus lorsqu'il tue un monstre<br><br><b>Les Bonus</b><br>Double attaque -> Double les dégats du missile du joueur<br>3 missiles -> Tire 3 missiles au lieu de 1<br>Double score -> Double le score du joueur<br>Temps d'apparition -> Le temps d'apparition est augmenté de 2s</body>", manager=self.manager) self.buttonReturn = UIButton(relative_rect=pygame.Rect( 20, 20, 200, 50), text='Retour', manager=self.manager) self.buttonLogout = UIButton(relative_rect=pygame.Rect( 800 - 220, 20, 200, 50), text='Déconnexion', manager=self.manager, object_id='#button-logout')
def __init__(self): self.manager = UIManager((800, 600), 'themes/theme.json') self.title = UILabel(relative_rect=pygame.Rect(350, 50, 100, 50), text='Connexion', manager=self.manager) self.labelPseudo = UILabel(relative_rect=pygame.Rect( 400 - 210, 142, 100, 50), text='Pseudo', manager=self.manager) self.pseudo = UITextEntryLine(relative_rect=pygame.Rect( 400 - 100, 150, 200, 50), manager=self.manager) self.labelPassword = UILabel(relative_rect=pygame.Rect( 400 - 210, 222, 100, 50), text='Mot de passe', manager=self.manager) self.password = UITextEntryLine(relative_rect=pygame.Rect( 400 - 100, 230, 200, 50), manager=self.manager) self.buttonLogin = UIButton(relative_rect=pygame.Rect( 400 - 100, 320, 200, 50), text='Se connecter', manager=self.manager) self.buttonSignup = UIButton(relative_rect=pygame.Rect( 400 - 100, 400, 200, 50), text='Pas de compte ?', manager=self.manager)
def test_show_hide_rendering(self, _init_pygame, default_ui_manager, _display_surface_return_none): resolution = (400, 400) empty_surface = pygame.Surface(resolution) empty_surface.fill(pygame.Color(0, 0, 0)) surface = empty_surface.copy() manager = UIManager(resolution) window = UIWindow(pygame.Rect(100, 100, 400, 400), window_display_title="Test Window", manager=manager, visible=0) manager.update(0.01) manager.draw_ui(surface) assert compare_surfaces(empty_surface, surface) surface.fill(pygame.Color(0, 0, 0)) window.show() manager.update(0.01) manager.draw_ui(surface) assert not compare_surfaces(empty_surface, surface) surface.fill(pygame.Color(0, 0, 0)) window.hide() manager.update(0.01) manager.draw_ui(surface) assert compare_surfaces(empty_surface, surface)
def __init__(self, screen_resolution, entity_master, game_clock): self.gui_manager = UIManager(screen_resolution, main_theme) self.entity_master = entity_master self.game_clock = game_clock self.main_menu_active = False self.main_menu_button = elements.UIButton(relative_rect=Rect( (screen_resolution[0] - 112, screen_resolution[1] - 112), (110, 110)), text='', object_id="button_main_menu", manager=self.gui_manager, tool_tip_text="Menu") self.pause_button = elements.UIButton(relative_rect=Rect( (screen_resolution[0] - 200, screen_resolution[1] - 80), (70, 70)), text="pause", object_id="sim_button", manager=self.gui_manager, tool_tip_text="Pause Sim") self.exit_button = elements.UIButton(relative_rect=Rect( (10, screen_resolution[1] - 80), (70, 70)), text="exit", object_id="sim_button", manager=self.gui_manager, tool_tip_text="Exit Sim") self.drag_begin = None self.info_screen = self.build_info_display(screen_resolution) self.info_screen.kill()
def __init__(self): pygame.init() pygame.display.set_caption("MineSweaper") self.iconImage = pygame.image.load('data/images/mine.png') pygame.display.set_icon(self.iconImage) self.options = Options() if self.options.fullscreen: self.window_surface = pygame.display.set_mode( self.options.resolution, pygame.FULLSCREEN) else: self.window_surface = pygame.display.set_mode( self.options.resolution) self.background_surface = None self.ui_manager = UIManager(self.options.resolution, 'data/theme/mineSweaper_theme.json') self.clock = pygame.time.Clock() self.running = True ''' Create game Window ''' self.mainMenu = None self.recreate_ui()
def test_using_theme_prototype(self, _init_pygame, _display_surface_return_none): manager = UIManager((800, 600), os.path.join("tests", "data", "themes", "ui_window_prototype.json")) window = UIWindow(pygame.Rect(0, 0, 200, 200), window_display_title="Test Window", manager=manager) button_rect = pygame.Rect(0, 0, 150, 30) button_rect.topright = (-10, 10) button = UIButton( relative_rect=button_rect, text="Test Button", tool_tip_text= "This is a test of the button's tool tip functionality.", manager=manager, container=window, anchors={ 'left': 'right', 'right': 'right', 'top': 'top', 'bottom': 'top' }) assert window.image is not None assert window.shadow_width == 1 assert window.border_width == 2 assert window.shape_corner_radius == 10 assert button.shadow_width == 1 assert button.border_width == 2 assert button.shape_corner_radius == 4
def __init__(self): self.manager = UIManager((800, 600), 'themes/signup.json') self.title = UILabel(relative_rect=pygame.Rect(400 - 100, 50, 200, 50), text='Inscription', manager=self.manager) self.labelPseudo = UILabel(relative_rect=pygame.Rect(400 - 210, 142, 100, 50), text='Pseudo', manager=self.manager) self.pseudo = UITextEntryLine(relative_rect=pygame.Rect(400 - 100, 150, 200, 50), manager=self.manager) self.labelPassword = UILabel(relative_rect=pygame.Rect(400 - 210, 222, 100, 50), text='Mot de passe', manager=self.manager) self.password = UITextEntryLine(relative_rect=pygame.Rect(400 - 100, 230, 200, 50), manager=self.manager) self.buttonSignup = UIButton(relative_rect=pygame.Rect(400 - 100, 320, 200, 50), text="S'inscrire", manager=self.manager) self.buttonLogin = UIButton(relative_rect=pygame.Rect(400 - 100, 400, 200, 50), text="Déja un compte ?", manager=self.manager)
def __init__(self): self.manager = UIManager((800, 600), 'themes/loading.json') self.title = UILabel(relative_rect=pygame.Rect(400 - 100, 20, 200, 50), text='Charger une partie', manager=self.manager, object_id='#title') self.scrollingContainer = UIScrollingContainer( relative_rect=pygame.Rect(100, 100, 700, 400), manager=self.manager) self.verticalScrollBar = UIVerticalScrollBar( relative_rect=pygame.Rect(680, 0, 20, 400), manager=self.manager, visible_percentage=0.8, container=self.scrollingContainer) self.background = UIPanel(relative_rect=pygame.Rect(0, 0, 500, 80), starting_layer_height=0, manager=self.manager, container=self.scrollingContainer) self.name = UILabel(relative_rect=pygame.Rect(10, 10, 200, 20), text='Charger une partie', manager=self.manager, object_id='#text-button', container=self.background) self.date = UILabel(relative_rect=pygame.Rect(300, 10, 200, 20), text='date de la partie', manager=self.manager, object_id='#text-button', container=self.background) self.currentScore = UILabel(relative_rect=pygame.Rect(10, 40, 200, 20), text='45544', manager=self.manager, object_id='#text-button', container=self.background) self.maxScore = UILabel(relative_rect=pygame.Rect(300, 40, 200, 20), text='1255454', manager=self.manager, object_id='#text-button', container=self.background) self.buttonCreating = UIButton(relative_rect=pygame.Rect( 0, 0, 500, 80), text='', manager=self.manager, container=self.scrollingContainer) self.buttonLogout = UIButton(relative_rect=pygame.Rect( 800 - 220, 20, 200, 50), text='Déconnexion', manager=self.manager, object_id='#button-logout')
def __init__(self): pygame.init() pygame.display.set_caption("Options UI") self.options = Options() if self.options.fullscreen: self.window_surface = pygame.display.set_mode( self.options.resolution, pygame.FULLSCREEN) else: self.window_surface = pygame.display.set_mode( self.options.resolution) self.background_surface = None self.ui_manager = UIManager( self.options.resolution, PackageResource(package='data.themes', resource='theme_2.json')) self.ui_manager.preload_fonts([{ 'name': 'fira_code', 'point_size': 10, 'style': 'bold' }, { 'name': 'fira_code', 'point_size': 10, 'style': 'regular' }, { 'name': 'fira_code', 'point_size': 10, 'style': 'italic' }, { 'name': 'fira_code', 'point_size': 14, 'style': 'italic' }, { 'name': 'fira_code', 'point_size': 14, 'style': 'bold' }]) self.test_button = None self.test_button_2 = None self.test_button_3 = None self.test_slider = None self.test_text_entry = None self.test_drop_down = None self.panel = None self.fps_counter = None self.frame_timer = None self.message_window = None self.recreate_ui() self.clock = pygame.time.Clock() self.button_response_timer = pygame.time.Clock() self.running = True self.debug_mode = False
def test_rebuild_from_changed_theme_data_bad_values( self, _init_pygame, _display_surface_return_none): manager = UIManager((800, 600), os.path.join("tests", "data", "themes", "ui_window_bad_values.json")) window = UIWindow(pygame.Rect(0, 0, 200, 200), window_display_title="Test Window", manager=manager) assert window.image is not None
def __init__(self): pygame.init() pygame.display.set_caption('Urizen 0.2.5') self.opt = GUIOptions() self.gen_state = GeneratorsState() if self.opt.fullscreen: self.window_surface = pygame.display.set_mode( self.opt.resolution, pygame.FULLSCREEN) else: self.window_surface = pygame.display.set_mode( self.opt.resolution, pygame.RESIZABLE) self.background_surface = None self.ui_manager = UIManager( self.opt.resolution, PackageResource('urizen.data.themes', 'gui_theme.json')) self.ui_manager.preload_fonts([{ 'name': 'fira_code', 'point_size': 10, 'style': 'bold' }, { 'name': 'fira_code', 'point_size': 10, 'style': 'regular' }, { 'name': 'fira_code', 'point_size': 10, 'style': 'italic' }, { 'name': 'fira_code', 'point_size': 14, 'style': 'italic' }, { 'name': 'fira_code', 'point_size': 14, 'style': 'bold' }]) self.panel = None self.message_window = None self.active_panel = None self.recreate_ui() self.clock = pygame.time.Clock() self.time_delta_stack = deque([]) self.button_response_timer = pygame.time.Clock() self.running = True
def __init__(self): self.manager = UIManager((800, 600), 'themes/createParty.json') self.labelParty = UILabel(relative_rect=pygame.Rect(10, 92, 150, 50), text='Nom de la partie', manager=self.manager) self.party = UITextEntryLine(relative_rect=pygame.Rect( 330, 100, 150, 50), manager=self.manager) self.buttonCreate = UIButton(relative_rect=pygame.Rect( 330, 200, 150, 50), text='Creer une partie', manager=self.manager)
def __init__(self, parse, name=""): init() display.init() self.DIMS = (display.Info().current_w, display.Info().current_h) self.BG = Surface(self.DIMS) self.SCREEN = display.set_mode(self.DIMS, -2147483648) self.MANAGER = UIManager(self.DIMS) set_visible(True) update() Exit((0, 0), self.MANAGER) clear = Clear((0, 30), self.MANAGER) Spawn((0, 60), self.MANAGER, clear, self.DIMS, parse, name) Killer((0, 90), self.MANAGER, clear) Paint((0, 120), self.MANAGER) self.clock = Clock() while True: self.process_events()
def main_menu_loop(screen, game_clock, settings): frame_resolution = settings.frame_resolution game_frame_rate = settings.frame_rate gui_manager = UIManager(frame_resolution, main_theme) menu_graphics = retrieve('main_menu_graphics') start_button = elements.UIButton( relative_rect=Rect((frame_resolution[0] / 2 + 150, frame_resolution[1] / 2 + 50), (400, 80)), text="Start Simulation", object_id="start_sim_button", manager=gui_manager) settings_button = elements.UIButton( relative_rect=Rect((frame_resolution[0] / 2 + 150, frame_resolution[1] / 2 + 130), (400, 80)), text="Settings", object_id="settings_button", manager=gui_manager) screen.fill((179, 147, 0)) # This is the initial draw, we don't need to re render the menu graphics later screen.blit(menu_graphics, (0, 0)) # This ensures a decent fps # Main Game Loop while True: time_delta = game_clock.tick(game_frame_rate) / 1000.0 gui_manager.update(time_delta) gui_manager.draw_ui(screen) display.update() for e in event.get(): if e.type == QUIT: quit() exit() if e.type == USEREVENT: if e.user_type == 'ui_button_pressed': if e.ui_element == start_button: return 1 if e.ui_element == settings_button: return 2 gui_manager.process_events(e)
def __init__(self): self.manager = UIManager((800, 600), 'themes/home.json') self.title = UILabel(relative_rect=pygame.Rect(400 - 100, 20, 200, 50), text='Accueil', manager=self.manager, object_id='#title') self.buttonCreating = UIButton(relative_rect=pygame.Rect( 400 - 100, 100, 200, 50), text='Creer partie', manager=self.manager) self.buttonLoading = UIButton(relative_rect=pygame.Rect( 400 - 100, 180, 200, 50), text='Charger une partie', manager=self.manager) self.buttonInstruction = UIButton(relative_rect=pygame.Rect( 400 - 100, 260, 200, 50), text='Instruction', manager=self.manager) # self.buttonShop = UIButton(relative_rect=pygame.Rect(400 - 100, 340, 200, 50), # text='Magasin', # manager=self.manager) # self.buttonRanking = UIButton(relative_rect=pygame.Rect(400 - 100, 420, 200, 50), # text='Classement', # manager=self.manager) self.buttonLogout = UIButton(relative_rect=pygame.Rect( 800 - 220, 20, 200, 50), text='Déconnexion', manager=self.manager, object_id='#button-logout')
def main(): pygame.init() os.environ['SDL_VIDEO_CENTERED'] = '1' pygame.key.set_repeat() x_screen_size = 1024 y_screen_size = 600 pygame.display.set_caption('Turret Warfare') screen = pygame.display.set_mode((x_screen_size, y_screen_size)) screen_data = ScreenData([x_screen_size, 128], [x_screen_size, 184], [x_screen_size, y_screen_size]) ui_manager = UIManager(screen.get_size(), "data/ui_theme.json") ui_manager.preload_fonts([{'name': 'fira_code', 'point_size': 10, 'style': 'bold'}, {'name': 'fira_code', 'point_size': 10, 'style': 'regular'}, {'name': 'fira_code', 'point_size': 14, 'style': 'bold'}]) app_state_manager = AppStateManager() MainMenu(ui_manager, app_state_manager) SelectLevelMenu(ui_manager, app_state_manager) GameState(ui_manager, screen, screen_data, app_state_manager) EditorState(ui_manager, screen, screen_data, app_state_manager) QuitState(app_state_manager) app_state_manager.set_initial_state('main_menu') clock = pygame.time.Clock() running = True while running: frame_time = clock.tick(60) time_delta = min(frame_time/1000.0, 0.1) running = app_state_manager.run(screen, time_delta) pygame.display.flip() # flip all our drawn stuff onto the screen pygame.quit() # exited game loop so quit pygame
def settings_loop(screen, game_clock, settings): def update_settings(): data = { 'map_size': int(map_size_dropdown.selected_option), 'resolution': ast.literal_eval(resolution_dropdown.selected_option), 'initial_hives': int(bee_hive_dropdown.selected_option), 'initial_bees': int(bees_dropdown.selected_option), 'flower_strat': flower_spawn_strat_dropdown.selected_option, 'hive_strat': hive_spawn_strat_dropdown.selected_option, 'music': music_dropdown.selected_option == 'True', 'flower_num': int(flower_num_dropdown.selected_option) } new_settings = Settings(data) new_screen = display.set_mode(new_settings.frame_resolution, DOUBLEBUF) return 0, new_screen, new_settings frame_resolution = settings.frame_resolution game_frame_rate = settings.frame_rate gui_manager = UIManager(frame_resolution, main_theme) element_size = (150, 50) element_size_l = (250, 50) tooltip_size = (150, 25) tooltip_size_l = (250, 25) back_button = elements.UIButton(relative_rect=Rect((30, 30), (50, 50)), text='', object_id="back_button", manager=gui_manager) save_settings_button = elements.UIButton(relative_rect=Rect((30, 100), (125, 50)), text="Save Settings", object_id="save_settings_button", manager=gui_manager) resolution_dropdown = elements.UIDropDownMenu( options_list=[ '1920, 1080', '1536, 864', '1360, 768', '1280, 1024', '640, 360', ], starting_option=str( settings.frame_resolution)[1:len(str(settings.frame_resolution)) - 1], relative_rect=Rect((200, 100), element_size), manager=gui_manager) resolution_tooltip = elements.UILabel(relative_rect=Rect((200, 75), tooltip_size), text="Window Resolution", manager=gui_manager) map_size_dropdown = elements.UIDropDownMenu( options_list=['2000', '1000', '500'], starting_option=str(settings.map_size), relative_rect=Rect((200, 250), element_size), manager=gui_manager) map_size_tooltip = elements.UILabel(relative_rect=Rect((200, 225), tooltip_size), text="Map Size", manager=gui_manager) music_dropdown = elements.UIDropDownMenu( options_list=["True", "False"], starting_option=str(settings.play_music), relative_rect=Rect((200, 400), element_size), manager=gui_manager) music_tooltip = elements.UILabel(relative_rect=Rect((200, 375), tooltip_size), text="Play Music", manager=gui_manager) bee_hive_dropdown = elements.UIDropDownMenu( options_list=['2', '5', '10', '12', '20'], starting_option=str(settings.initial_hives), relative_rect=Rect((375, 100), element_size), manager=gui_manager) bee_hive_tooltip = elements.UILabel(relative_rect=Rect((375, 75), tooltip_size), text="Number of Hives", manager=gui_manager) bees_dropdown = elements.UIDropDownMenu( options_list=['6', '8', '10', '12', '16', '20'], starting_option=str(settings.initial_bees_per_hive), relative_rect=Rect((375, 250), element_size), manager=gui_manager) bees_tooltip = elements.UILabel(relative_rect=Rect((375, 225), tooltip_size), text="Initial Bees", manager=gui_manager) flower_spawn_strat_dropdown = elements.UIDropDownMenu( options_list=['normal distribution'], starting_option=settings.flower_spawn_strategy, relative_rect=Rect((550, 100), element_size_l), manager=gui_manager) flower_spawn_strat_tooltip = elements.UILabel(relative_rect=Rect( (550, 75), tooltip_size_l), text="Flower Spawn Strategy", manager=gui_manager) hive_spawn_strat_dropdown = elements.UIDropDownMenu( options_list=['default'], starting_option=settings.hive_spawn_strategy, relative_rect=Rect((550, 250), element_size_l), manager=gui_manager) hive_spawn_strat_tooltip = elements.UILabel(relative_rect=Rect( (550, 225), tooltip_size_l), text="Hive Spawn Strategy", manager=gui_manager) flower_num_dropdown = elements.UIDropDownMenu( options_list=['200', '300', '400', '500', '600', '700'], starting_option=str(settings.flower_num), relative_rect=Rect((550, 400), element_size_l), manager=gui_manager) music_tooltip = elements.UILabel(relative_rect=Rect((550, 375), tooltip_size_l), text="Number of Flowers", manager=gui_manager) while True: screen.fill((219, 173, 92)) time_delta = game_clock.tick(game_frame_rate) / 1000.0 gui_manager.update(time_delta) gui_manager.draw_ui(screen) display.update() for e in event.get(): if e.type == QUIT: quit() exit() if e.type == USEREVENT: if e.user_type == 'ui_button_pressed': if e.ui_element == back_button: return 0, screen, settings # Returns back to main menu elif e.ui_element == save_settings_button: return update_settings() gui_manager.process_events(e)
from pygame_gui import UIManager from pygame import Color WINDOW_WIDTH = 800 WINDOW_HEIGHT = 800 SQUARE_WIDTH = 100 SQUARE_HEIGHT = 100 MANAGER = UIManager((WINDOW_WIDTH, WINDOW_HEIGHT)) WHITE = Color(255, 255, 255) BLACK = Color(0, 0, 0) GREY = Color(128, 128, 128) RED = Color(255, 0, 0)
def __init__(self, session): self.manager = UIManager((800, 600), 'themes/game.json') image = pygame.image.load('assets/background.png') self.background = UIImage(relative_rect=pygame.Rect(0, 0, 800, 600), manager=self.manager, image_surface=image) self.session = session self.allPlayers = pygame.sprite.Group() self.player = Perso(self, self.session) self.allPlayers.add(self.player) self.pressed = {} self.allEnemy = pygame.sprite.Group() self.addScore = 100 self.score = 0 self.level = Niveau(self, self.score) self.panelTop = UIPanel(relative_rect=pygame.Rect(0, 0, 800, 20), starting_layer_height=2, manager=self.manager, object_id="#panel-top") self.labelHealthTitle = UILabel(relative_rect=pygame.Rect( 0, 0, 50, 20), text="Vie :", manager=self.manager, object_id="#label-score", container=self.panelTop) self.labelHealth = UILabel(relative_rect=pygame.Rect(30, 0, 50, 20), text=str(self.player.health), manager=self.manager, object_id="#label-score", container=self.panelTop) self.labelAsset = UILabel(relative_rect=pygame.Rect( 800 - 100, 0, 50, 20), text=str(self.level.assetIsActive[2]), manager=self.manager, object_id="#label-score", container=self.panelTop) self.labelScore = UILabel(relative_rect=pygame.Rect( 0, 600 - 50, 200, 50), text=str(self.score), manager=self.manager, object_id="#label-score") self.playerImage = UIImage(relative_rect=pygame.Rect( (self.player.rect.x, self.player.rect.y), (50, 50)), manager=self.manager, image_surface=self.player.image) self.panel = UIPanel(relative_rect=pygame.Rect((0, 0), (0, 0)), starting_layer_height=3, manager=self.manager, object_id="#panel-game-over") self.labelGameOver = UILabel(relative_rect=pygame.Rect( 400 - 100, 300 - 50, 200, 50), text="Game Over", manager=self.manager, object_id="#label-game-over", container=self.panel) self.buttonMenu = UIButton(relative_rect=pygame.Rect( 400 - 100, 300 + 50, 200, 50), text='Quitter', manager=self.manager, container=self.panel) self.buttonParty = UIButton(relative_rect=pygame.Rect( (400 - 100, 300 + 50 + 80), (200, 50)), text='Recommencer', manager=self.manager, container=self.panel) self.panelPause = UIPanel(relative_rect=pygame.Rect((0, 0), (0, 0)), starting_layer_height=3, manager=self.manager, object_id="#panel-game-over") self.labelPause = UILabel(relative_rect=pygame.Rect( 400 - 100, 300 - 50, 200, 50), text="Pause", manager=self.manager, object_id="#label-game-over", container=self.panelPause) self.buttonSave = UIButton(relative_rect=pygame.Rect( 400 - 100, 300 + 50, 200, 50), text='Sauvegarder et quitter', manager=self.manager, container=self.panelPause) self.buttonQuit = UIButton(relative_rect=pygame.Rect( (400 - 100, 300 + 50 + 80), (200, 50)), text='Quitter', manager=self.manager, container=self.panelPause) self.panelAsset = UIPanel(relative_rect=pygame.Rect((0, 0), (0, 0)), starting_layer_height=3, manager=self.manager, object_id="#panel-game-over") self.labelEquipment = UILabel(relative_rect=pygame.Rect( 400 - 100, 50, 200, 50), text="Pause", manager=self.manager, object_id="#label-game-over", container=self.panelAsset) self.button1 = UIButton(relative_rect=pygame.Rect( 400 - 100, 50 + 50, 200, 50), text="Double l'attaque 10C", manager=self.manager, container=self.panelAsset) self.button2 = UIButton(relative_rect=pygame.Rect( (400 - 100, 120 + 50), (200, 50)), text='3 Missiles 100C', manager=self.manager, container=self.panelAsset) self.button3 = UIButton(relative_rect=pygame.Rect( (400 - 100, 190 + 50), (200, 50)), text='Double Score 20C', manager=self.manager, container=self.panelAsset) self.button4 = UIButton(relative_rect=pygame.Rect( (400 - 100, 260 + 50), (200, 50)), text="Temps d'apparition 50C", manager=self.manager, container=self.panelAsset) self.labelCredit = UILabel(relative_rect=pygame.Rect( 400 - 100, 330 + 50, 200, 50), text=str(self.player.credit), manager=self.manager, object_id="#label-game-over", container=self.panelAsset) self.pause = True
def gameloop( playerOrder: bool, p1Char: str, nick1: str, p2Char: str, nick2: str, udp: UDP_P2P, ) -> str: # region DocString """ Function that starts the loop for pygame ### Arguments `playerOrder {bool}`: `summary`: true if this host is the first player, false otherwise `p1Char {str}`: `summary`: the character chosen by this host `nick1 {str}`: `summary`: the username of this host `p2Char {str}`: `summary`: the character chosen by the remote player `nick2 {str}`: `summary`: the username of the remote player `udp {UDP_P2P}`: `summary`: the udp object ### Returns `str`: the exit status. It can be 'Lost' if this host lose, 'Quit' if this host closed the window,\n 'Win' if the remote host lose, 'Quitted' if the remote host closed the window """ # endregion global gamestate clock = Clock() COORDSYNC = USEREVENT + 1 set_timer(COORDSYNC, 1000) # region Screen setup screen = set_mode((Game.SIZE[0] + 400, Game.SIZE[1])) set_caption(Game.TITLE) set_icon(load(Game.ICON_PATH)) bg = load(Game.BG_PATH).convert_alpha() bg = scale(bg, Game.SIZE) manager = UIManager((Game.SIZE[0] + 400, Game.SIZE[1])) chat = Chat((400, Game.SIZE[1]), manager, udp, nick1) # endregion all_sprites = Group() # region Players setup if p1Char == "Ichigo": pl = Ichigo(playerOrder, nick1, all_sprites) elif p1Char == "Vegeth": pl = Vegeth(playerOrder, nick1, all_sprites) if p2Char == "Ichigo": pl2 = Ichigo(not playerOrder, nick2, all_sprites) elif p2Char == "Vegeth": pl2 = Vegeth(not playerOrder, nick2, all_sprites) # endregion rcvT = udp.receptionThread( lambda data, addr, time: rcv(pl2, data, addr, time, chat), rcvErr) rcvT.start() while True: dt = clock.tick(Game.FPS) / 1000 # region Handle window close pressed_keys = get_pressed() for event in get(): if event.type == QUIT: snd(nick1, "Quit", udp) gamestate = "Quit" if event.type == COORDSYNC: sndCoords(nick1, (pl.rect.x, pl.rect.y), udp) manager.process_events(event) # endregion manager.update(dt) # region Handle key press and update sprites all_sprites.update(pressed_keys) sndKeys( nick1, ( pressed_keys[K_LEFT], pressed_keys[K_RIGHT], pressed_keys[K_UP], pressed_keys[K_z], ), udp, ) if pl.update(pressed_keys): snd(nick1, "Lost", udp) gamestate = "Lost" # endregion # region Sprite drawing screen.fill(Color.WHITE) screen.blit(bg, (0, 0)) all_sprites.draw(screen) pl.draw(screen) pl2.draw(screen) pl.health.draw(screen) pl2.health.draw(screen) # endregion manager.draw_ui(screen) flip() if gamestate: udp.stopThread() quit() return gamestate