Ejemplo n.º 1
0
 def __init__(self, master, **kwargs):
     Dialog.__init__(self, master=master, bg_color=GREEN_DARK, **kwargs)
     self.start_game = master.start_game
     self.text_title = Text("Waiting for Player 2", font=("calibri", 50))
     self.text_ip_address = Text(font=("calibri", 40))
     self.text_port_of_connection = Text(font=("calibri", 40))
     self.button_cancel = Button(self, "Return to menu", theme="option", callback=self.stop)
     self.lets_play_countdown = CountDown(self, 3, "Player 2 connected.\nGame start in {seconds} seconds", font=("calibri", 35), color=YELLOW, justify="center")
Ejemplo n.º 2
0
 def __init__(self, master, **kwargs):
     Dialog.__init__(self, master=master, bg_color=GREEN_DARK, **kwargs)
     self.start_game = master.start_game
     self.text_title = Text("Connect to Player 1", font=("calibri", 50))
     self.form = Form(self)
     self.form.add_entry("IP", Text("IP address", font=("calibri", 40), color=YELLOW), Entry(self, width=15, font=("calibri", 30), bg=GREEN, highlight_color=YELLOW, outline=2))
     self.form.add_entry("Port", Text("Port", font=("calibri", 40), color=YELLOW), Entry(self, width=15, font=("calibri", 30), bg=GREEN, highlight_color=YELLOW, outline=2))
     self.text_connection = Text(font=("calibri", 25), color=YELLOW)
     self.text_connection.hide()
     self.button_connect = Button(self, "Connection", theme="option", callback=self.connection)
     self.button_cancel = Button(self, "Return to menu", theme="option", callback=self.stop)
     self.lets_play_countdown = CountDown(self, 3, "Connected.\nGame start in {seconds} seconds", font=("calibri", 35), color=YELLOW, justify="center")
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
 def __init__(self, master, **kwargs):
     Dialog.__init__(self, master=master, bg_color=GREEN_DARK, **kwargs)
     params_for_all_buttons = {
         "font": ("calibri", 30),
         "bg": GREEN,
         "hover_bg": GREEN_LIGHT,
         "active_bg": GREEN_DARK,
         "outline": 3,
         "highlight_color": YELLOW
     }
     self.start_game = master.start_game
     self.text_title = Text("Waiting for Player 2", ("calibri", 50))
     self.text_ip_address = Text(font=("calibri", 40))
     self.text_port_of_connection = Text(font=("calibri", 40))
     self.button_cancel = Button(self, "Return to menu", callback=self.stop, **params_for_all_buttons)
     self.lets_play_countdown = CountDown(self, 3, "Player 2 connected.\nGame start in {seconds} seconds", font=("calibri", 35), color=YELLOW, justify="center")
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
 def __init__(self, master, **kwargs):
     Dialog.__init__(self, master=master, bg_color=GREEN_DARK, **kwargs)
     params_for_all_buttons = {
         "font": ("calibri", 30),
         "bg": GREEN,
         "hover_bg": GREEN_LIGHT,
         "active_bg": GREEN_DARK,
         "highlight_color": YELLOW,
         "outline": 3
     }
     self.start_game = NavySetup(2)
     self.text_title = Text("Connect to Player 1", ("calibri", 50))
     self.ip = Entry(self, width=15, font=("calibri", 40), bg=GREEN, highlight_color=YELLOW, outline=2)
     self.text_ip_address = Text("IP address", ("calibri", 40), YELLOW)
     self.port = Entry(self, width=15, font=("calibri", 40), bg=GREEN, highlight_color=YELLOW, outline=2)
     self.text_port_of_connection = Text("Port", ("calibri", 40), YELLOW)
     self.text_connection = Text(font=("calibri", 25), color=YELLOW)
     self.text_connection.hide()
     self.button_connect = Button(self, "Connection", callback=self.connection, **params_for_all_buttons)
     self.button_cancel = Button(self, "Return to menu", callback=self.stop, **params_for_all_buttons)
     self.lets_play_countdown = CountDown(self, 3, "Connected.\nGame start in {seconds} seconds", font=("calibri", 35), color=YELLOW, justify="center")
    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()