コード例 #1
0
    def __init__(
        self,
        screen: pg.Surface,
        biomes: List[Biome],
        heat_per_tick: float,
        heat_per_task: float,
    ):
        self.screen = screen

        self.biomes = biomes
        self.heat_per_tick = heat_per_tick
        self.heat_per_task = heat_per_task

        # Thermometer to display heat
        self.thermo = load_img(THERMO)
        self.thermo_fill = load_img(THERMO_FILL)

        # Sun image
        self.image = load_img(SUN_IMAGE)
        new_height = int(HEIGHT // 2)
        scale_percent = new_height / self.image.get_height()
        new_width = int(self.image.get_width() * scale_percent)
        self.image = pg.transform.scale(self.image, (new_width, new_height))
        # Create cache of every image rotation, so we don't have to calculate each time
        self._image_cache = []
        for angle in range(361):
            self._image_cache.append(pg.transform.rotate(self.image, angle))
コード例 #2
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.maze = []
        # If the player has started the maze - moved mouse over start
        self.started = False

        self.cell_size = (
            self.window_rect.width // self.maze_width,
            self.window_rect.height // self.maze_height,
        )

        # Prepare images for the maze
        self.start_image = scale(
            load_img(self.biome.image_from(MAZE_START), False), self.cell_size
        )

        self.end_image = scale(
            load_img(self.biome.image_from(MAZE_END), False), self.cell_size
        )

        self.path_image = scale(
            load_img(self.biome.image_from(MAZE_PATH), False), self.cell_size
        )

        self.wall_image = scale(
            load_img(self.biome.image_from(MAZE_WALL), False), self.cell_size
        )
コード例 #3
0
ファイル: credits.py プロジェクト: skilldeliver/code-jam-5
    def __init__(self, screen: pg.Surface):
        self.screen = screen

        # images of the back button and its hover state
        back_btn_img = load_img(BTN["back-btn"])
        back_btn_img_h = load_img(BTN["back-btn-hover"])

        # layout of the credits and background image
        self.credits = load_img(PATH_CREDITS)
        self.background = load_img(PATH_CREDITS_BG)

        # rectangles for infinity looping the backgroud image
        self.bg_rect_1 = pg.Rect(0, 0, WIDTH, HEIGHT)
        self.bg_rect_2 = pg.Rect(-WIDTH, 0, WIDTH, HEIGHT)

        # create an instance of a back button
        self.back_btn = Button(
            screen=self.screen,
            x=ButtonProperties.back_btn_x,
            y=ButtonProperties.back_btn_y,
            width=ButtonProperties.back_btn_w,
            height=ButtonProperties.back_btn_h,
            image=back_btn_img,
            image_hover=back_btn_img_h,
        )
コード例 #4
0
    def __init__(self, screen: pg.Surface, difficulty: int = 1):
        """
        Initializer for GameView class.

        screen - parent screen to draw objects on
        difficulty - 0, 1, 2. Difficulty increases with number.
        """
        self.screen = screen

        # Delay before repeated pausing/unpausing of the game
        self.pause_start = 0

        # Pause window
        self.window_rect = pg.Rect(int(WIDTH * 0.375), int(HEIGHT * 0.2),
                                   int(WIDTH * 0.25), int(HEIGHT * 0.5))
        self.window_image = load_img(PAUSE_WINDOW)
        self.window_image = pg.transform.scale(self.window_image,
                                               self.window_rect.size)

        btn_height = 80
        btn_offset_x = 20
        btn_offset_y = 50

        exit_btn_image = load_img(BUTTONS["exit-btn"])
        exit_btn_hover = load_img(BUTTONS["exit-btn-hover"])
        self.exit_btn = Button(
            self.screen,
            self.window_rect.x + btn_offset_x,
            self.window_rect.y + self.window_rect.height - btn_height -
            btn_offset_y,
            self.window_rect.width - btn_offset_x * 2,
            btn_height,
            exit_btn_image,
            exit_btn_hover,
        )

        resume_btn_image = load_img(BUTTONS["resume-btn"])
        resume_btn_hover = load_img(BUTTONS["resume-btn-hover"])
        self.resume_btn = Button(
            self.screen,
            self.window_rect.x + btn_offset_x,
            self.exit_btn.rect.y - btn_height - btn_offset_y // 2,
            self.window_rect.width - btn_offset_x * 2,
            btn_height,
            resume_btn_image,
            resume_btn_hover,
        )

        if difficulty == 0:
            self.period = PeriodMedieval(self.screen)
        elif difficulty == 1:
            self.period = PeriodModern(self.screen)
        elif difficulty == 2:
            self.period = PeriodFuture(self.screen)
        else:
            raise TypeError(f"Unknown difficulty level passed: {difficulty}")
コード例 #5
0
ファイル: tile.py プロジェクト: skilldeliver/code-jam-5
    def __init__(self, image: str):
        self._image = load_img(image)

        # Current task associated with this tile
        # Tiles with tasks have different appearance
        self.task = None
        # If currently hovering over the tile
        self.is_hovering = False

        scale_percent = TILE_WIDTH / self._image.get_width()
        new_height = int(self._image.get_height() * scale_percent)

        # scale image based on game screen size
        self._image = pg.transform.scale(self._image, (TILE_WIDTH, new_height))
        # Cache every possible scale of image
        _image_width = self._image.get_width()
        _image_height = self._image.get_height()
        self._image_cache = {}
        scale_n = 1
        while scale_n <= self.scale_n_max:
            new_width = int(_image_width *
                            (1 + scale_n * self.breathing_speed))
            new_height = int(_image_height *
                             (1 + scale_n * self.breathing_speed))
            self._image_cache[scale_n] = pg.transform.scale(
                self._image, (new_width, new_height))
            scale_n += 1
コード例 #6
0
ファイル: slider.py プロジェクト: skilldeliver/code-jam-5
    def __init__(self, screen: Surface, number: float):
        """Sets rectangle object for the slider."""
        self.screen = screen
        self.number = number

        if self.number == 1:
            self.volume = user_data.sound_volume
        else:
            self.volume = user_data.music_volume

        self.body_img = load_img(SLIDER_BODY)
        self.indicator_img = load_img(SLIDER_INDICATOR)

        self.__calculate_body_properties()
        self.__calculate_indicator_properties()
        self.__create_rectangles()

        self.click = False
コード例 #7
0
    def __load_set_github_button(self) -> None:
        """
        Create the github icon button on the bottom right corner.

        This button links to our repository.
        """
        image = load_img(BTN["github"])
        image_hover = load_img(BTN["github-hover"])

        self.github_btn = Button(
            screen=self.screen,
            x=WIDTH - 120,
            y=HEIGHT - 120,
            width=100,
            height=100,
            image=image,
            image_hover=image_hover,
        )
コード例 #8
0
    def __load_images(self) -> None:
        """Loads all main menu button images and their hover states."""
        img_paths = [
            (BTN["play-btn"], BTN["play-btn-hover"]),
            (BTN["options-btn"], BTN["options-btn-hover"]),
            (BTN["credits-btn"], BTN["credits-btn-hover"]),
            (BTN["quit-btn"], BTN["quit-btn-hover"]),
        ]

        # load two types of images for the buttons
        # normal state and hover state
        self.images = [tuple([load_img(j) for j in i]) for i in img_paths]
コード例 #9
0
    def __init__(self, screen: pg.Surface, biomes: List[Biome]):
        self.screen = screen

        self.biomes = biomes

        # Background cloud layer
        self.cloud_layers_bg_pool = [
            load_img(image) for image in CLOUD_LAYERS_BG
        ]
        self.cloud_layers_bg = []
        self.current_cloud_bg_pos = 0

        # Foreground (in front of background :)) cloud layer
        self.cloud_layers_fg_pool = [
            load_img(image) for image in CLOUD_LAYERS_FG
        ]
        self.cloud_layers_fg = []
        self.current_cloud_fg_pos = 0

        # Ozone layer (purple line)
        self.ozone_image = load_img(OZONE_LAYER)
        self.ozone_image = pg.transform.scale(self.ozone_image,
                                              (WIDTH, HEIGHT // 10))
        self.ozone_pos = (0, int(HEIGHT // 3))

        # Polution (yellow screen tint)
        self.polution_image = pg.Surface(
            (WIDTH, int(2 * HEIGHT // 3) - self.ozone_image.get_rect().h // 2))
        self.polution_image.fill(Color.desert)
        self.polution_pos = (0, HEIGHT - self.polution_image.get_height())

        self.indicator_image = load_img(INDICATOR_ARROW)
        self.indicators = []

        self.visible_tiles = []

        self.current_biome_pos = 0
        # Calculate max position by added the width of all bg images
        self.max_position = sum(biome.background.get_width()
                                for biome in self.biomes)
コード例 #10
0
ファイル: sheet.py プロジェクト: skilldeliver/code-jam-5
 def __init__(self, sheet_path: PurePath):
     self.spritesheet = load_img(sheet_path)
コード例 #11
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.game_over = False

        # human, computer and board representation
        self.human = -1
        self.computer = +1
        self.board = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

        # which is going to move first and the side of the board rect
        self.first_move = int()
        side = self.window_rect.height * 0.9

        # create Rect object (square for the board)
        self.board_rect = pg.Rect(
            int((self.window_rect.width - side) / 2 + self.window_rect.left),
            int(self.window_rect.height * 0.05 + self.window_rect.top),
            int(side),
            int(side),
        )

        # calculate the size of each cell and create a list to store them
        self.cell_side = int(self.board_rect.width / 3)
        self.cells = list()

        # create Rect object for each cell
        for y in range(3):
            for x in range(3):
                self.cells.append(
                    pg.Rect(
                        self.board_rect.left + (x * self.cell_side),
                        self.board_rect.top + (y * self.cell_side),
                        self.cell_side,
                        self.cell_side,
                    )
                )
        # save last click time - to prevent too much clicking of the button
        self.last_click = float()

        # get background and hover color from the biome context
        self.bg_color, self.bg_color_hover = self.biome.color

        # create map indexed
        # so we can use int to access the board cell

        # 0 - [0, 0], 1 - [0, 1], 2 - [0, 2]
        # 3 - [0, 0], 4 - [0, 1], 5 - [0, 2]
        # 6 - [0, 0], 7 - [0, 1], 8 - [0, 2]

        self.map_indexes = dict(
            zip(range(0, 9), [(i, j) for i in range(3) for j in range(3)])
        )

        # load the image of the X and O
        # X is always the human
        # O is always the computer

        self.x_image = scale(
            load_img(self.biome.image_from(X), False), [self.cell_side] * 2
        )

        self.o_image = scale(
            load_img(self.biome.image_from(O), False), [self.cell_side] * 2
        )

        # load the square grid image
        self.grid = scale(
            load_img(self.biome.image_from(TTT_GRID)),
            [self.board_rect.width, self.board_rect.height],
        )
コード例 #12
0
    def start(self) -> None:
        """User clicks on task."""
        super().start()

        # set delay timer, mixing animation bool, and the choices of players
        self.delay = time()
        self.mixing = False
        self.choice = None
        self.computer_choice = None

        # other timers and states for the game
        self.game_over = False
        self.win = False
        self.timer = 0
        self.last = 0

        # get the colors from the current biombe
        self.color, self.color_hover = self.biome.color

        # calculate the size of the human choice rects and computer one
        # the human area of rects will be 1/9 of the whole task window
        # the computer area of rects will be 2/3 of the whole task window
        self.choice_rect_side = int(self.window_rect.height / 3)
        self.computer_rect_side = self.window_rect.height

        # store the three human choice rectangles in a list
        self.choice_rects = list()

        # create all human choice rectangles
        # they move from top to bottom on the y axis
        for i in range(3):
            self.choice_rects.append(
                pg.Rect(
                    self.window_rect.left,
                    self.choice_rect_side * i + self.window_rect.top,
                    self.choice_rect_side,
                    self.choice_rect_side,
                )
            )

        # create the large rectangle of the computer choice
        self.computer_rect = pg.Rect(
            self.window_rect.left + self.choice_rect_side,
            self.window_rect.top,
            self.computer_rect_side,
            self.computer_rect_side,
        )

        # the biome getters of the images of elements
        self.images = [ROCK, PAPER, SCISSORS]

        # store the images of the elements with different sizes
        # because the rectanglea are different
        self.choice_images = list()
        self.computer_images = list()

        # iterate the images
        for img in self.images:
            # load it from current biome and
            # scale it for human choice
            self.choice_images.append(
                scale(load_img(self.biome.image_from(img)), [self.choice_rect_side] * 2)
            )
            # load it from current biome and
            # scale it for computer choice
            self.computer_images.append(
                scale(
                    load_img(self.biome.image_from(img)), [self.computer_rect_side] * 2
                )
            )
        # one more extra image for the computer
        # it is a question mark and displays it
        # till the human makes a choice
        self.computer_images.append(
            scale(
                load_img(self.biome.image_from(QUESTION_MARK), False),
                [self.computer_rect_side] * 2,
            )
        )
コード例 #13
0
    def __init__(self, screen: pg.Surface):
        self.screen = screen
        self.event = None

        self.bg_rect_1 = pg.Rect(0, 0, WIDTH, HEIGHT)
        self.bg_rect_2 = pg.Rect(-WIDTH, 0, WIDTH, HEIGHT)

        self.background = load_img(PATH_OPTIONS_BG)

        back_btn_img = load_img(BTN["back-btn"])
        back_btn_img_hover = load_img(BTN["back-btn-hover"])

        vol_btn_img = load_img(BTN["vol-btn"])
        vol_btn_img_hover = load_img(BTN["vol-btn-hover"])

        vol_btn_img_mute = load_img(BTN["vol-btn-mute"])
        vol_btn_img_mute_hover = load_img(BTN["vol-btn-mute-hover"])

        checker_btn = load_img(BTN["checker"])
        checker_btn_hover = load_img(BTN["checker-hover"])

        checker_btn_checked = load_img(BTN["checker-checked"])
        checker_btn_checked_hover = load_img(BTN["checker-checked-hover"])

        fps_label_img = load_img(BTN["show-fps-label"])
        boost_fps_label_img = load_img(BTN["boost-fps-label"])

        sound_label_img = load_img(BTN["sound-label"])
        music_label_img = load_img(BTN["music-label"])

        self.back_btn = Button(
            self.screen,
            x=ButtonProperties.back_btn_x,
            y=ButtonProperties.back_btn_y,
            width=ButtonProperties.back_btn_w,
            height=ButtonProperties.back_btn_h,
            image=back_btn_img,
            image_hover=back_btn_img_hover,
        )

        self.vol_btn = Button(
            self.screen,
            x=ButtonProperties.vol_btn_x,
            y=ButtonProperties.vol_btn_y,
            width=ButtonProperties.vol_btn_w,
            height=ButtonProperties.vol_btn_h,
            image=vol_btn_img,
            image_hover=vol_btn_img_hover,
        )

        self.vol_btn_mute = Button(
            self.screen,
            x=ButtonProperties.vol_btn_x,
            y=ButtonProperties.vol_btn_y,
            width=ButtonProperties.vol_btn_w,
            height=ButtonProperties.vol_btn_h,
            image=vol_btn_img_mute,
            image_hover=vol_btn_img_mute_hover,
        )

        self.fps_checker_btn = Button(
            self.screen,
            x=ButtonProperties.vol_btn_x,
            y=ButtonProperties.vol_btn_y + 260,
            width=ButtonProperties.vol_btn_w,
            height=ButtonProperties.vol_btn_h,
            image=checker_btn,
            image_hover=checker_btn_hover,
        )

        self.fps_checker_checked_btn = Button(
            self.screen,
            x=ButtonProperties.vol_btn_x,
            y=ButtonProperties.vol_btn_y + 260,
            width=ButtonProperties.vol_btn_w,
            height=ButtonProperties.vol_btn_h,
            image=checker_btn_checked,
            image_hover=checker_btn_checked_hover,
        )

        self.boost_fps_checker_btn = Button(
            self.screen,
            x=ButtonProperties.vol_btn_x,
            y=ButtonProperties.vol_btn_y + 390,
            width=ButtonProperties.vol_btn_w,
            height=ButtonProperties.vol_btn_h,
            image=checker_btn,
            image_hover=checker_btn_hover,
        )

        self.boost_fps_checker_checked_btn = Button(
            self.screen,
            x=ButtonProperties.vol_btn_x,
            y=ButtonProperties.vol_btn_y + 390,
            width=ButtonProperties.vol_btn_w,
            height=ButtonProperties.vol_btn_h,
            image=checker_btn_checked,
            image_hover=checker_btn_checked_hover,
        )

        self.fps_label = Button(
            self.screen,
            x=ButtonProperties.vol_btn_x + 100,
            y=ButtonProperties.vol_btn_y + 260,
            width=500,
            height=100,
            image=fps_label_img,
            image_hover=fps_label_img,
        )

        self.boost_fps_label = Button(
            self.screen,
            x=ButtonProperties.vol_btn_x + 100,
            y=ButtonProperties.vol_btn_y + 390,
            width=500,
            height=100,
            image=boost_fps_label_img,
            image_hover=boost_fps_label_img,
        )

        self.vol_btn2 = Button(
            self.screen,
            x=ButtonProperties.vol_btn_x,
            y=ButtonProperties.vol_btn_y + 130,
            width=ButtonProperties.vol_btn_w,
            height=ButtonProperties.vol_btn_h,
            image=vol_btn_img,
            image_hover=vol_btn_img_hover,
        )

        self.vol_btn_mute2 = Button(
            self.screen,
            x=ButtonProperties.vol_btn_x,
            y=ButtonProperties.vol_btn_y + 130,
            width=ButtonProperties.vol_btn_w,
            height=ButtonProperties.vol_btn_h,
            image=vol_btn_img_mute,
            image_hover=vol_btn_img_mute_hover,
        )

        self.sound_label = Button(
            self.screen,
            x=WIDTH - 300,
            y=self.vol_btn.rect.top,
            width=300,
            height=100,
            image=sound_label_img,
            image_hover=sound_label_img,
        )

        self.music_label = Button(
            self.screen,
            x=WIDTH - 300,
            y=self.vol_btn2.rect.top,
            width=300,
            height=100,
            image=music_label_img,
            image_hover=music_label_img,
        )
        self.last_click = int()

        self.slider = Slider(self.screen, 1)
        self.volume_indicator = VolumeIndicator(self.screen, 1)

        self.slider2 = Slider(self.screen, 2)
        self.volume_indicator2 = VolumeIndicator(self.screen, 2)