def __init__(self, master):
     Window.__init__(self, master=master, bg_music=master.bg_music)
     self.bind_key(pygame.K_ESCAPE, lambda event: self.stop())
     self.bind_joystick(0, "START", lambda event: self.stop())
     self.bind_joystick(0, "B", lambda event: self.stop())
     self.master = master
     self.bg = RectangleShape(*self.size, (0, 0, 0, 170))
     params_for_all_buttons = {
         "font": (RESOURCES.FONT["algerian"], 100),
         "bg": GREEN,
         "hover_bg": GREEN_LIGHT,
         "active_bg": GREEN_DARK,
         "hover_sound": RESOURCES.SFX["select"],
         "on_click_sound": RESOURCES.SFX["validate"],
         "outline": 3,
         "highlight_color": YELLOW
     }
     self.menu_buttons = ButtonListVertical(offset=30)
     self.menu_buttons.add(
         Button(self,
                "Return",
                **params_for_all_buttons,
                callback=self.stop),
         Button(self,
                "Options",
                **params_for_all_buttons,
                callback=self.show_options),
         Button(self,
                "Garage",
                **params_for_all_buttons,
                callback=self.return_to_garage),
         Button(self,
                "Menu",
                **params_for_all_buttons,
                callback=self.return_to_menu))
 def __init__(self, master=None):
     Window.__init__(self, bg_color=None)
     if master is not None:
         self.bg = master.bg
     self.frame = RectangleShape(0.5 * self.w, 0.5 * self.h, BLUE, outline=3)
     self.title = Text("Settings", font=(FONT["death_star"], 50), color=YELLOW)
     params_for_all_scales = {
         "width": 0.7 * self.frame.w,
         "height": 50,
         "color": BLUE_DARK,
         "scale_color": BLUE_LIGHT,
         "from_": 0,
         "to": 100,
         "outline": 3
     }
     params_for_all_buttons = {
         "font": (FONT["death_star"], 45),
         "color": YELLOW,
         "hover_sound": AUDIO["clank"],
         "on_click_sound": AUDIO["laser"],
     }
     self.scale_sound_volume = Scale(
         self, **params_for_all_scales, default=Window.sound_volume() * 100,
         command=self.update_sound_volume
     )
     self.scale_music_volume = Scale(
         self, **params_for_all_scales, default=Window.music_volume() * 100,
         command=self.update_music_volume
     )
     self.button_return = TextButton(self, "Return", **params_for_all_buttons, command=self.stop)
     self.bind_key(pygame.K_ESCAPE, lambda key: self.stop())
예제 #3
0
 def __init__(self, master, victory: bool):
     Window.__init__(
         self,
         master=master,
         bg_music=None if victory is None else RESOURCES.MUSIC["end"])
     self.master = master
     self.bg = RectangleShape(self.width, self.height, (0, 0, 0, 170))
     self.frame = RectangleShape(0.5 * self.width,
                                 0.5 * self.height,
                                 GREEN_DARK,
                                 outline=2)
     self.victory = victory
     if victory is not None:
         message = "{winner} won".format(
             winner="You" if victory else "Enemy")
     else:
         message = "The enemy has left\nthe game"
     self.text_finish = Text(message, font=(None, 70))
     params_for_all_buttons = {
         "font": (None, 40),
         "bg": GREEN,
         "hover_bg": GREEN_LIGHT,
         "active_bg": GREEN_DARK,
         "highlight_color": YELLOW
     }
     self.button_restart = Button(self,
                                  "Restart",
                                  callback=self.restart,
                                  **params_for_all_buttons)
     self.button_return_to_menu = Button(self,
                                         "Return to menu",
                                         callback=self.stop,
                                         **params_for_all_buttons)
     self.ask_restart = False
     self.bind_key(pygame.K_ESCAPE, lambda event: self.stop())
예제 #4
0
 def __init__(self, master: Window, champion_list: List[Tuple[str]]):
     Window.__init__(self, bg_music=AUDIO["battle"], bg_color=BLUE_DARK)
     self.bind_key(pygame.K_ESCAPE, lambda key: self.stop())
     loading_page = Loading(font=(FONT["death_star"], 270))
     loading_page.show(master)
     self.champions = list()
     self.not_created = list()
     for file, name in champion_list:
         champion = Champion(file, name)
         if not champion.create():
             self.not_created.append(name)
         else:
             self.champions.append(champion)
             self.add(champion)
     if len(self.not_created) == 0:
         self.memory_size = (0, 0)
         self.init_gameplay()
     else:
         msg = "\n".join(f" - {name} cannot be created"
                         for name in self.not_created)
         msg += "\n" + "\n" + "Press Escape to return\nto the menu"
         self.error_message = Text(msg, (FONT["death_star"], 70),
                                   YELLOW,
                                   justify="center",
                                   center=self.center)
     loading_page.hide(self)
예제 #5
0
 def __init__(self, master):
     Window.__init__(self, master=master, bg_music=master.bg_music)
     self.bg = RectangleShape(*self.size, (0, 0, 0, 170))
     self.frame = RectangleShape(0.50 * self.width,
                                 0.50 * self.height,
                                 GREEN,
                                 outline=3)
     self.text = Text("Are you sure you want\nto buy this car ?",
                      (RESOURCES.FONT["algerian"], 60),
                      justify=Text.T_CENTER)
     self.button_yes = Button(self,
                              "Yes",
                              self.text.font,
                              bg=GREEN,
                              hover_bg=GREEN_LIGHT,
                              active_bg=GREEN_DARK,
                              hover_sound=RESOURCES.SFX["select"],
                              on_click_sound=RESOURCES.SFX["validate"],
                              highlight_color=YELLOW,
                              callback=self.buy)
     self.button_red_cross = ImageButton(
         self,
         img=RESOURCES.IMG["red_cross"],
         active_img=RESOURCES.IMG["red_cross_hover"],
         hover_sound=RESOURCES.SFX["select"],
         on_click_sound=RESOURCES.SFX["back"],
         callback=self.stop,
         highlight_color=YELLOW)
     self.buyed = False
     self.bind_key(pygame.K_ESCAPE,
                   lambda event: self.stop(sound=RESOURCES.SFX["back"]))
     self.bind_joystick(
         0, "B", lambda event: self.stop(sound=RESOURCES.SFX["back"]))
    def __init__(self, master: Window, action: str):
        Window.__init__(self, master=master, bg_music=master.bg_music)

        self.action = action

        self.bg = RectangleShape(self.width, self.height, (0, 0, 0, 170))
        self.frame = RectangleShape(0.4 * self.width,
                                    0.4 * self.height,
                                    BLACK,
                                    outline=3,
                                    outline_color=WHITE)
        self.escape = Text(
            "Echap (clavier) ou bouton START (manette): Annuler",
            font=("calibri", 30),
            color=WHITE)
        self.instruction = Text("Appuyez sur une touche",
                                font=("calibri", 50),
                                color=WHITE)

        for event in (pygame.KEYDOWN, pygame.JOYBUTTONDOWN,
                      pygame.JOYAXISMOTION, pygame.JOYHATMOTION):
            self.bind_event(event, self.choose)
        self.bind_key(pygame.K_ESCAPE,
                      lambda event: self.stop(sound=RESOURCES.SFX["back"]))
        self.bind_joystick(
            0, "START", lambda event: self.stop(sound=RESOURCES.SFX["back"]))
 def __color_animation(self, window: Window, color: pygame.Color, alpha_range: range) -> None:
     self.bg.size = window.size
     for alpha in alpha_range:
         self.bg.color = set_color_alpha(color, alpha)
         window.draw_screen()
         self.bg.draw(window.surface)
         window.refresh(pump=True)
         pygame.time.wait(10)
예제 #8
0
 def __init__(self, master):
     Window.__init__(self, master=master, bg_music=master.bg_music)
     self.master = master
     self.bg = RectangleShape(self.width, self.height, (0, 0, 0, 170))
     self.frame = RectangleShape(0.5 * self.width,
                                 0.5 * self.height,
                                 GREEN_DARK,
                                 outline=2)
     self.text = Text("Waiting for enemy", font=(None, 70))
예제 #9
0
 def __init__(self, master: Window, assembly_file: str, *args, **kwargs):
     TextButton.__init__(
         self,
         master,
         *args,
         **kwargs,
         command=lambda self=self: master.launch_assembly_editor(self.file))
     self.file = assembly_file
     master.bind_event(pygame.MOUSEBUTTONUP, self.delete)
예제 #10
0
 def show_new_looping_window(self, window: Window) -> None:
     self.game_img.image = window.save_screen()
     self.game_img.midleft = window.midright
     offset = 50
     while self.game_img.left > 0:
         self.game_img.left = max(self.game_img.left - offset, 0)
         self.menu_img.draw(window.surface)
         self.game_img.draw(window.surface)
         window.refresh(pump=True)
         pygame.time.wait(10)
예제 #11
0
 def show_previous_window_end_loop(self, window: Window) -> None:
     self.menu_img.image = window.save_screen()
     self.menu_img.center = window.center
     offset = 50
     while self.game_img.left < window.right:
         self.game_img.move_ip(offset, 0)
         self.menu_img.draw(window.surface)
         self.game_img.draw(window.surface)
         window.refresh(pump=True)
         pygame.time.wait(10)
예제 #12
0
 def __init__(self, master):
     Window.__init__(self, master=master)
     self.master = master
     self.bg = RectangleShape(self.width, self.height, (0, 0, 0, 170))
     self.frame = RectangleShape(0.5 * self.width, 0.5 * self.height, GREEN_DARK, outline=2)
     self.victory = None
     self.text_finish = Text(font=(None, 70))
     self.button_restart = Button(self, "Restart", font=(None, 40), callback=self.restart)
     self.button_return_to_menu = Button(self, "Return to menu", font=(None, 40), callback=self.stop)
     self.ask_restart = False
     self.bind_key(pygame.K_ESCAPE, lambda event: self.stop())
예제 #13
0
 def __init__(self, master: Window, width: int, height: int, **kwargs):
     self.default_color = TRANSPARENT
     self.filled_color = BLUE_LIGHT
     RectangleShape.__init__(self,
                             width,
                             height,
                             self.default_color,
                             outline=1,
                             **kwargs)
     master.add(self)
     self.__value = 0
     self.highlight = 0
예제 #14
0
 def __init__(self, player_id: int):
     Window.__init__(self,
                     bg_color=(0, 200, 255),
                     bg_music=RESOURCES.MUSIC["setup"])
     self.gameplay = Gameplay(player_id)
     self.count_down = CountDown(self,
                                 60,
                                 "Time left: {seconds}",
                                 font=(None, 70),
                                 color=WHITE)
     self.start_count_down = lambda: self.count_down.start(
         at_end=self.timeout) if self.client_socket.connected() else None
     params_for_all_buttons = {
         "bg": GREEN,
         "hover_bg": GREEN_LIGHT,
         "active_bg": GREEN_DARK,
         "highlight_color": YELLOW
     }
     self.button_back = ImageButton(self,
                                    RESOURCES.IMG["arrow_blue"],
                                    **params_for_all_buttons,
                                    rotate=180,
                                    size=50,
                                    callback=self.stop)
     self.navy_grid = DrawableListVertical(offset=0, bg_color=(0, 157, 255))
     for i in range(NB_LINES_BOXES):
         box_line = DrawableListHorizontal(offset=0)
         for j in range(NB_COLUMNS_BOXES):
             box_line.add(BoxSetup(self, size=BOX_SIZE, pos=(i, j)))
         self.navy_grid.add(box_line)
     self.ships_list = DrawableListVertical(offset=70, justify="left")
     for ship_name, ship_infos in SHIPS.items():
         ship_line = DrawableListHorizontal(offset=ship_infos["offset"])
         for _ in range(ship_infos["nb"]):
             ship_line.add(ShipSetup(self, ship_name, ship_infos["size"]))
         self.ships_list.add(ship_line)
     option_size = 50
     self.button_restart = Button.withImageOnly(
         self,
         Image(RESOURCES.IMG["reload_blue"], size=option_size),
         callback=self.reinit_all_ships,
         **params_for_all_buttons)
     self.button_random = Button.withImageOnly(self,
                                               Image(
                                                   RESOURCES.IMG["random"],
                                                   size=option_size),
                                               callback=self.shuffle,
                                               **params_for_all_buttons)
     self.button_play = Button(self,
                               "Play",
                               font=(None, 40),
                               callback=self.play,
                               **params_for_all_buttons)
예제 #15
0
 def __init__(self):
     Window.__init__(self, bg_color=(0, 200, 255))
     self.player_id = 0
     self.button_back = ImageButton(self, RESOURCES.IMG["arrow_blue"], rotate=180, size=50, callback=self.stop, highlight_color=YELLOW)
     self.player_grid = PlayerNavy(self, self.client_socket)
     self.opposite_grid = OppositeNavy(self, self.client_socket)
     self.ai = AI()
     self.turn_checker = TurnArrow()
     self.restart = False
     self.bind_key(pygame.K_ESCAPE, lambda event: self.stop())
     self.text_finish = Text("Finish !!!", font=(None, 120), color=WHITE)
     self.window_finish = FinishWindow(self)
     self.game_finished = False
예제 #16
0
    def __init__(self, master):
        Window.__init__(self,
                        bg_color=master.bg_color,
                        bg_music=master.bg_music)
        params_for_button = {
            "highlight_color": YELLOW,
            "hover_sound": RESOURCES.SFX["select"],
            "on_click_sound": RESOURCES.SFX["back"]
        }
        self.master = master
        self.button_back = ImageButton(self,
                                       img=RESOURCES.IMG["blue_arrow"],
                                       **params_for_button,
                                       callback=self.stop)

        self.objects.add(master.text_highscore, master.text_money)

        self.text_title = Text("ENVIRONMENT", (RESOURCES.FONT["algerian"], 90),
                               GREEN_DARK,
                               shadow=True,
                               shadow_x=2,
                               shadow_y=2)
        self.environment = ButtonListHorizontal(offset=15)
        self.texts = DrawableList()
        for name, color in ENVIRONMENT.items():
            b = Button(self,
                       img=Image(RESOURCES.IMG[name],
                                 max_width=180,
                                 max_height=180),
                       compound="center",
                       outline=3,
                       callback=lambda env=name: self.play(env),
                       bg=color,
                       hover_bg=change_saturation(color, -20),
                       active_bg=change_brightness(color, -20),
                       hover_sound=RESOURCES.SFX["select"],
                       on_click_sound=RESOURCES.SFX["validate"],
                       highlight_color=YELLOW)
            b.set_size(200)
            self.texts.add(
                Text(name.upper(), (RESOURCES.FONT["algerian"], 50),
                     GREEN_DARK,
                     shadow=True,
                     shadow_x=2,
                     shadow_y=2))
            self.environment.add(b)

        self.bind_key(pygame.K_ESCAPE,
                      lambda event: self.stop(sound=RESOURCES.SFX["back"]))
        self.bind_joystick(
            0, "B", lambda event: self.stop(sound=RESOURCES.SFX["back"]))
예제 #17
0
 def __init__(self, master: Window):
     Window.__init__(self, bg_color=BLUE_DARK, bg_music=AUDIO["crusaders"])
     loading_page = Loading(font=(FONT["death_star"], 270))
     loading_page.show(master)
     self.bg_title = RectangleShape(self.width, self.height, self.bg_color)
     self.title = Text("Battle",
                       font=(FONT["death_star"], 150),
                       color=YELLOW)
     self.subtitle = Text("Choose your champions for the fight",
                          font=(FONT["death_star"], 70),
                          color=YELLOW)
     self.params_for_all_buttons = {
         "font": (FONT["death_star"], 80),
         "color": YELLOW,
         "hover_fg": (255, 255, 128),
         "hover_sound": AUDIO["clank"],
         "on_click_sound": AUDIO["laser"],
         "outline": 2,
         "outline_color": YELLOW,
         "offset": 6,
     }
     self.button_menu = TextButton(self,
                                   "Menu",
                                   **self.params_for_all_buttons,
                                   command=self.stop)
     self.champions = list()
     champion_files = sorted(
         os.path.join(CHAMPIONS_FOLDER, file)
         for file in os.listdir(CHAMPIONS_FOLDER) if file.endswith(".s"))
     for file in champion_files:
         name = get_champion_name(file)
         champion = ChampionViewer(self, file, name,
                                   **self.params_for_all_buttons)
         self.champions.append(champion)
         self.add(champion)
     self.selected = list()
     self.start_champion = 0
     self.move_champion_up = False
     self.move_champion_down = False
     self.infos = Infos(self,
                        1,
                        1,
                        self.bg_color,
                        outline=3,
                        outline_color=YELLOW)
     self.bind_key(pygame.K_ESCAPE, lambda key: self.stop())
     self.bind_event(pygame.MOUSEBUTTONDOWN, self.move_champion_list)
     loading_page.hide(self)
예제 #18
0
    def __init__(self, master: Window):
        Window.__init__(self, bg_color=BACKGROUND_COLOR)
        self.bind_key(pygame.K_ESCAPE, lambda event: self.stop())

        self.master = master
        self.logo = Image(RESOURCES.IMG["logo"])
        arrow = pygame.transform.flip(RESOURCES.IMG["arrow"], True, False)
        self.button_back = ImageButton(self,
                                       img=arrow,
                                       width=100,
                                       callback=self.stop,
                                       active_offset=(0, 5),
                                       highlight_color=YELLOW)
        self.grid = FourInARowGrid(self, self.width / 2, self.height * 0.75)
        self.__player_turn = 0
        self.player_who_start_first = 0
        self.player = 0
        self.__turn = str()
        self.__turn_dict = dict()
        self.__score_player = self.__score_enemy = 0
        self.__highlight_line_window_callback = None
        self.enemy = str()

        self.ai = FourInARowAI()

        self.text_score = Text()
        self.text_player_turn = Text()
        self.left_options = ButtonListVertical(offset=50)
        self.left_options.add(
            Button(self, "Restart", theme="option", callback=self.restart),
            Button(self, "Quit game", theme="option", callback=self.quit_game))
        self.text_winner = Text()
        self.text_drawn_match = Text("Drawn match.")

        self.token_players = Grid(self)
        for row in range(2):
            self.token_players.place(CircleShape(20,
                                                 PLAYER_TOKEN_COLOR[row + 1],
                                                 outline=2,
                                                 outline_color=WHITE),
                                     row,
                                     column=1,
                                     padx=5,
                                     pady=5,
                                     justify="left")

        self.enemy_quit_dialog = EnemyQuitGame(self)
예제 #19
0
 def __init__(self, master: Window):
     Window.__init__(self,
                     bg_color=BLUE_DARK,
                     bg_music=AUDIO["dark_techno_city"])
     loading_page = Loading(font=(FONT["death_star"], 270))
     loading_page.show(master)
     self.title = Text("Editor",
                       font=(FONT["death_star"], 150),
                       color=YELLOW)
     self.subtitle = Text("Choose the champion to edit",
                          font=(FONT["death_star"], 70),
                          color=YELLOW)
     self.params_for_all_buttons = {
         "font": (FONT["death_star"], 80),
         "color": YELLOW,
         "hover_fg": (255, 255, 128),
         "hover_sound": AUDIO["clank"],
         "on_click_sound": AUDIO["laser"],
         "outline": 2,
         "outline_color": YELLOW,
         "offset": 6,
     }
     self.button_menu = TextButton(self,
                                   "Menu",
                                   **self.params_for_all_buttons,
                                   command=self.stop)
     self.champions = list()
     champion_files = sorted(
         os.path.join(CHAMPIONS_FOLDER, file)
         for file in os.listdir(CHAMPIONS_FOLDER) if file.endswith(".s"))
     for file in champion_files:
         name = get_champion_name(file)
         champion = ChampionEditor(self, file, name,
                                   **self.params_for_all_buttons)
         self.champions.append(champion)
         self.add(champion)
     self.new_file = TextButton(self,
                                "New",
                                **self.params_for_all_buttons,
                                command=self.launch_assembly_editor)
     self.editors = list()
     self.bind_key(pygame.K_ESCAPE, lambda key: self.stop())
     loading_page.hide(self)
예제 #20
0
 def __init__(self, master: Window):
     Window.__init__(self)
     self.bg = master.bg
     self.title = Text("Game", font=(FONT["death_star"], 220), color=YELLOW)
     params_for_all_buttons = {
         "bg": BLUE,
         "hover_bg": BLUE_LIGHT,
         "active_bg": BLUE_DARK,
         "active_fg": YELLOW,
         "hover_sound": AUDIO["clank"],
         "on_click_sound": AUDIO["laser"],
         "outline": 5,
     }
     params_for_section_button = {
         "font": (FONT["death_star"], 200)
     }
     self.button_battle = Button(self, "Battle", **params_for_all_buttons, **params_for_section_button, command=self.launch_battle)
     self.button_edit = Button(self, "Editor", **params_for_all_buttons, **params_for_section_button, command=self.launch_editor)
     self.button_menu = Button(self, "Menu", **params_for_all_buttons, font=(FONT["death_star"], 80), command=self.stop)
예제 #21
0
 def __init__(self):
     Window.__init__(self, bg_color=(0, 200, 255))
     self.gameplay = Gameplay()
     self.enemy_quit_window = EnemyQuitGame(self)
     self.transition = GameSetupTransition()
     self.count_down = CountDown(self,
                                 60,
                                 "Time left: {seconds}",
                                 font=(None, 70),
                                 color=WHITE)
     self.start_count_down = lambda: self.count_down.start(
         at_end=self.timeout) if self.client_socket.connected() else None
     self.button_back = ImageButton(self,
                                    RESOURCES.IMG["arrow_blue"],
                                    rotate=180,
                                    size=50,
                                    callback=self.stop)
     self.navy_grid = Grid(self, bg_color=(0, 157, 255))
     self.__boxes_dict = {(i, j): BoxSetup(self, size=BOX_SIZE, pos=(i, j))
                          for i in range(NB_LINES_BOXES)
                          for j in range(NB_COLUMNS_BOXES)}
     self.__boxes_list = list(self.__boxes_dict.values())
     self.navy_grid.place_multiple(self.__boxes_dict)
     self.ships_list = DrawableListVertical(offset=70, justify="left")
     for ship_name, ship_infos in SHIPS.items():
         ship_line = DrawableListHorizontal(offset=ship_infos["offset"])
         for _ in range(ship_infos["nb"]):
             ship_line.add(ShipSetup(self, ship_name, ship_infos["size"]))
         self.ships_list.add(ship_line)
     option_size = 50
     self.button_restart = Button(self,
                                  img=Image(RESOURCES.IMG["reload_blue"],
                                            size=option_size),
                                  callback=self.reinit_all_ships)
     self.button_random = Button(self,
                                 img=Image(RESOURCES.IMG["random"],
                                           size=option_size),
                                 callback=self.shuffle)
     self.button_play = Button(self,
                               "Play",
                               font=(None, 40),
                               callback=self.play)
예제 #22
0
 def __init__(self, master):
     Window.__init__(self, master=master, bg_music=master.bg_music)
     self.bg = RectangleShape(self.width, self.height, (0, 0, 0, 170))
     self.frame = RectangleShape(0.5 * self.width,
                                 0.5 * self.height,
                                 GREEN_DARK,
                                 outline=2)
     self.text_finish = Text("The enemy has left\nthe game",
                             font=(None, 70))
     params_for_all_buttons = {
         "font": (None, 40),
         "bg": GREEN,
         "hover_bg": GREEN_LIGHT,
         "active_bg": GREEN_DARK,
         "highlight_color": YELLOW
     }
     self.button_return_to_menu = Button(self,
                                         "Return to menu",
                                         callback=self.stop,
                                         **params_for_all_buttons)
     self.bind_key(pygame.K_ESCAPE, lambda event: self.stop())
예제 #23
0
    def __init__(self):
        Window.__init__(self, size=(1280, 720), flags=pygame.DOUBLEBUF, bg_music=RESOURCES.MUSIC["menu"])
        self.set_icon(RESOURCES.IMG["icon"])
        self.set_title(f"Navy - v{__version__}")
        self.set_fps(60)
        self.disable_key_joy_focus_for_all_window()

        self.bg = Image(RESOURCES.IMG["menu_bg"], self.size)
        self.logo = Image(RESOURCES.IMG["logo"])

        params_for_all_buttons = {
            "font": (None, 100),
            "bg": GREEN,
            "hover_bg": GREEN_LIGHT,
            "active_bg": GREEN_DARK,
            "outline": 3,
            "highlight_color": YELLOW,
        }

        params_for_dialogs = {
            "outline": 5,
            "hide_all_without": [self.bg, self.logo]
        }

        self.start_game = NavySetup(1)
        self.multiplayer_server = PlayerServer(self, **params_for_dialogs)
        self.multiplayer_client = PlayerClient(self, **params_for_dialogs)
        self.dialog_credits = Credits(self, **params_for_dialogs)
        self.dialog_options = Options(self, **params_for_dialogs)

        self.menu_buttons = ButtonListVertical(offset=30)
        self.menu_buttons.add(
            Button(self, "Play against AI", **params_for_all_buttons, callback=self.start_game.mainloop),
            Button(self, "Play as P1", **params_for_all_buttons, callback=self.multiplayer_server.mainloop),
            Button(self, "Play as P2", **params_for_all_buttons, callback=self.multiplayer_client.mainloop),
            Button(self, "Quit", **params_for_all_buttons, callback=self.stop)
        )

        self.button_credits = Button(self, "Credits", callback=self.dialog_credits.mainloop, **params_for_all_buttons)
        self.button_settings = Button.withImageOnly(self, Image(RESOURCES.IMG["settings"], size=self.button_credits.height - 20), callback=self.dialog_options.mainloop, **params_for_all_buttons)
예제 #24
0
 def __init__(self, master: Window, **kwargs):
     Dialog.__init__(self, master=master, bg_color=GREEN_DARK, **kwargs)
     self.text_title = Text("Options", ("calibri", 50))
     params_for_all_scales = {
         "width": 0.45 * self.frame.w,
         "height": 30,
         "color": TRANSPARENT,
         "scale_color": GREEN,
         "from_": 0,
         "to": 100,
         "highlight_color": YELLOW,
         "outline": 3
     }
     params_for_all_buttons = {
         "font": ("calibri", 30),
         "bg": GREEN,
         "hover_bg": GREEN_LIGHT,
         "active_bg": GREEN_DARK,
         "highlight_color": params_for_all_scales["highlight_color"],
         "outline": params_for_all_scales["outline"]
     }
     self.scale_music = Scale(
         self, **params_for_all_scales,
         default=Window.music_volume() * 100,
         callback=lambda value, percent: Window.set_music_volume(percent)
     )
     self.scale_music.show_label("Music: ", Scale.S_LEFT, font=params_for_all_buttons["font"])
     self.scale_music.show_value(Scale.S_RIGHT, font=params_for_all_buttons["font"])
     self.scale_sound = Scale(
         self, **params_for_all_scales,
         default=Window.sound_volume() * 100,
         callback=lambda value, percent: Window.set_sound_volume(percent)
     )
     self.scale_sound.show_label("SFX: ", Scale.S_LEFT, font=params_for_all_buttons["font"])
     self.scale_sound.show_value(Scale.S_RIGHT, font=params_for_all_buttons["font"])
     self.button_cancel = Button(self, "Return to menu", callback=self.stop, **params_for_all_buttons)
예제 #25
0
 def update_music_volume(self):
     Window.set_music_volume(self.scale_music_volume.percent)
예제 #26
0
 def hide_actual_looping_window_start_loop(self, window: Window) -> None:
     self.menu_img.image = window.save_screen()
     self.menu_img.center = window.center
예제 #27
0
    def __init__(self):
        Window.__init__(self,
                        bg_color=GRAY,
                        bg_music=RESOURCES.MUSIC["garage"])
        params_for_all_buttons = {
            "bg": GREEN,
            "hover_bg": GREEN_LIGHT,
            "active_bg": GREEN_DARK,
            "highlight_color": YELLOW,
            "hover_sound": RESOURCES.SFX["select"],
        }
        params_for_button_except_back = {
            "on_click_sound": RESOURCES.SFX["validate"],
            "disabled_sound": RESOURCES.SFX["block"],
            "disabled_bg": GRAY_LIGHT,
        }
        params_for_button_except_back.update(params_for_all_buttons)
        params_for_car_viewer = {
            k: params_for_button_except_back[k]
            for k in ["hover_sound", "on_click_sound"]
        }
        self.button_back = ImageButton(self,
                                       RESOURCES.IMG["blue_arrow"],
                                       **params_for_all_buttons,
                                       on_click_sound=RESOURCES.SFX["back"],
                                       callback=self.stop)
        self.car_viewer = CarViewer(self, SAVE["car"], **params_for_car_viewer)

        size_progress_bar = (300, 30)
        self.speed_bar = ProgressBar(*size_progress_bar, TRANSPARENT, GREEN)
        self.maniability_bar = ProgressBar(*size_progress_bar, TRANSPARENT,
                                           GREEN)
        self.braking_bar = ProgressBar(*size_progress_bar, TRANSPARENT, GREEN)

        self.left_arrow = ImageButton(
            self,
            img=RESOURCES.IMG["left_arrow"],
            active_img=RESOURCES.IMG["left_arrow_hover"],
            **params_for_button_except_back,
            callback=self.car_viewer.decrease_id)
        self.right_arrow = ImageButton(
            self,
            img=RESOURCES.IMG["right_arrow"],
            active_img=RESOURCES.IMG["right_arrow_hover"],
            **params_for_button_except_back,
            callback=self.car_viewer.increase_id)
        for arrow in [self.left_arrow, self.right_arrow]:
            arrow.take_focus(False)
        self.button_price = Button(self,
                                   font=(RESOURCES.FONT["algerian"], 40),
                                   img=Image(RESOURCES.IMG["piece"], size=40),
                                   compound="right",
                                   callback=self.buy_car,
                                   **params_for_button_except_back)
        self.button_play = Button(self,
                                  "Play",
                                  font=(RESOURCES.FONT["algerian"], 70),
                                  callback=self.play,
                                  **params_for_button_except_back)
        self.text_money = Text(format_number(SAVE["money"]),
                               (RESOURCES.FONT["algerian"], 50),
                               YELLOW,
                               img=Image(RESOURCES.IMG["piece"], height=40),
                               compound="right")
        self.text_highscore = Text(
            "Highscore: {}".format(format_number(SAVE["highscore"])),
            (RESOURCES.FONT["algerian"], 50), YELLOW)
        self.padlock = Image(RESOURCES.IMG["padlock"])
        self.bind_key(pygame.K_ESCAPE,
                      lambda event: self.stop(sound=RESOURCES.SFX["back"]))
        self.bind_joystick(
            0, "B", lambda event: self.stop(sound=RESOURCES.SFX["back"]))
    def __init__(self, car_id: int, env: str):
        Window.__init__(self,
                        bg_color=ENVIRONMENT[env],
                        bg_music=RESOURCES.MUSIC["gameplay"])
        self.bind_key(pygame.K_ESCAPE, lambda event: self.pause())
        self.bind_joystick(0, "START", lambda event: self.pause())

        font = RESOURCES.FONT["cooperblack"]

        # Demaraction lines
        self.road = DrawableListVertical(bg_color=GRAY, offset=70)
        self.white_bands = list()
        white_bands_width = 50  #px
        white_lines_height = 10  #px
        for i in range(5):
            if i % 2 == 0:
                self.road.add(
                    RectangleShape(self.width, white_lines_height, WHITE))
            else:
                white_bands = DrawableListHorizontal(offset=20)
                while white_bands.width < self.width:
                    white_bands.add(
                        RectangleShape(white_bands_width, white_lines_height,
                                       WHITE))
                self.road.add(white_bands)
                self.white_bands.append(white_bands)

        # Environment
        self.env_top = DrawableListHorizontal(offset=400)
        self.env_bottom = DrawableListHorizontal(offset=400)
        while self.env_top.width < self.width:
            self.env_top.add(Image(RESOURCES.IMG[env], height=110))
        while self.env_bottom.width < self.width:
            self.env_bottom.add(Image(RESOURCES.IMG[env], height=110))

        #Infos
        params_for_infos = {
            "font": (font, 45),
            "color": YELLOW,
            "shadow": True,
            "shadow_x": 3,
            "shadow_y": 3
        }
        self.infos_score = Info("Score", round_n=0, **params_for_infos)
        self.infos_speed = Info("Speed",
                                extension="km/h",
                                **params_for_infos,
                                justify="right")
        self.infos_distance = Info("Distance",
                                   round_n=2,
                                   extension="km",
                                   **params_for_infos,
                                   justify="right")
        self.infos_time_100 = Info("High speed", **params_for_infos)
        self.infos_time_opposite = Info("Opposite side", **params_for_infos)
        self.clock_time_100 = Clock()
        self.clock_time_opposite = Clock()
        self.total_time_100 = self.total_time_opposite = 0

        self.car = PlayerCar(car_id)
        self.speed = 0
        self.traffic = TrafficCarList(nb_ways=4, max_nb_car=6)
        self.clock_traffic = Clock()
        self.img_crash = Image(RESOURCES.IMG["crash"], size=150)
        self.count_down = CountDown(self,
                                    3,
                                    font=(font, 90),
                                    color=YELLOW,
                                    shadow=True,
                                    shadow_x=5,
                                    shadow_y=5)
        self.last_car_way = 0

        # Background
        self.background = DrawableList(draw=False)
        self.background.add(self.env_top, self.env_bottom, *self.white_bands,
                            self.traffic)

        # Default values
        self.update_clock = Clock()
        self.update_time = 15  #ms
        self.pixel_per_sec = 6  # For 1km/h
        self.pixel_per_ms = self.pixel_per_sec * self.update_time / 1000
        self.paused = False
        self.go_to_garage = self.restart = False
        self.crashed_car = None

        self.disable_key_joy_focus()
        self.init_game()
예제 #29
0
 def update_sound_volume(self):
     Window.set_sound_volume(self.scale_sound_volume.percent)
예제 #30
0
 def hide_actual_looping_window_end_loop(self, window: Window) -> None:
     self.game_img.image = window.save_screen()
     self.game_img.center = window.center