Exemple #1
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.start_shop_pos = [
            random.randint(0, common.WIDTH),
            random.randint(0, common.HEIGHT),
        ]
        self.shop_pos = self.start_shop_pos[:]
        self.shop_rect = pygame.Rect(self.shop_pos[0], self.shop_pos[1], 60,
                                     60)
        self.shop_collision = [None for _ in range(9)]
        self.shop_state = substates.ShopSubstate()

        self.text_message = TextMessage(
            (20, 400),
            760,
            190,
            (128, 128, 128),
            "Are you sure you want to enter the shop? (Enter to enter shop, move away to exit)",
            utils.load_font(50),
            instant_blit=False,
            border_color=(80, 80, 80),
            border_width=10,
        )
        self.player_collide = False

        self.do_collision = False  # Let's not do it for now :kekw:
Exemple #2
0
    def draw(self):
        if self.draw_pause:
            if self.alpha < self.max_alpha:
                self.fade(self.alpha)
            pause_txt = utils.load_font(60).render("Paused", True, (0, 0, 0))
            self.screen.blit(pause_txt, (300, 100))
            self.screen.blit(self.screen_surf, (0, 0))

            for button in self.buttons.values():
                button[0].draw()
 def __init__(self, game_class, screen=common.SCREEN):
     """
     Note: self.buttons is a dictionary of buttons MADE IN BUTTONS.PY.
     To display other things (E.g pygame_gui's elements), manually draw them instead of putting them in the
     dictionary
     """
     self.screen = screen  # sets the screen to be the default screen
     self.font = utils.load_font(60)  # sets default font
     self.next_state = (
         self.__class__
     )  # sets the default state, next_state would change when changing states
     self.game_class = game_class  # Some States may need info on the game class
Exemple #4
0
    def draw(self):
        """Performs all tasks related to drawing related to the Settings Menu."""

        # Blits "Game Settings"
        txt = self.font.render("Game Settings", True, (0, 0, 0))
        draw_utils.blit_on_center(txt, (400, 30))

        fps_txt = utils.load_font(50).render("FPS:", True, (0, 0, 0))
        self.screen.blit(fps_txt, (40, 100))

        self.fps_slider.draw()

        # Draws all buttons
        for button in self.buttons:
            button[0].draw()
Exemple #5
0
    def __init__(self, screen=common.SCREEN):
        """Initializes some class attributes first"""
        self.screen = screen
        self.manager = pygame_gui.UIManager((common.WIDTH, common.HEIGHT))
        self.clock = pygame.time.Clock()
        self.font = utils.load_font(60)
        self.running = True

        self.state = MenuState(self)
        self.debug_game = DebugGame()
        self.process = psutil.Process(os.getpid())
        self.start_time = arrow.get(time.time())

        self.fps_setting = utils.load_setting("fps")

        pygame.display.set_caption(common.TITLE)
    def __init__(
            self,
            coord,
            color,
            length,
            width,
            min_val,
            max_val,
            default_val=None,
            screen=common.SCREEN,
            num_spaces=-1,
            slide_color=None,
            show_value=True,
    ):
        self.coord = coord
        self.color = color
        self.length = length
        self.width = width
        self.min_val = min_val
        self.max_val = max_val
        self.screen = screen
        self.num_spaces = num_spaces
        self.show_value = show_value

        if default_val is None:
            self.default_val = self.min_val
        else:
            self.default_val = default_val

        if slide_color is None:
            self.slide_color = self.color
        else:
            self.slide_color = slide_color
        self.rect_coord = self.coord + (
            self.length,
            self.width,
        )
        self.rect = pygame.Rect(self.rect_coord)
        self.font = utils.load_font(self.width)
        self.is_holding_mouse = False
        self.slide_coord = (
            self.coord[0]
            + (self.default_val - self.min_val) / self.max_val * self.length,
            self.coord[1] - width // 2,
        )
        self.current_val = self.default_val
    def __init__(
            self,
            coordinates,
            beginning_text="",
            inactive_color=pygame.Color("lightskyblue3"),
            active_color=pygame.Color("dodgerblue2"),
            fontsize=60,
    ):
        self.rect = pygame.Rect(coordinates)
        self.text = beginning_text
        self.color = inactive_color
        self.active_color = active_color
        self.inactive_color = inactive_color
        self.active = False
        self.fontsize = fontsize

        self.font = utils.load_font(self.fontsize)
        self.txt_surface = self.font.render(self.text, True, self.color)
Exemple #8
0
    def draw(self):
        """Performs all draw related tasks related to the "New Game" Menu."""

        # Gets delta time
        dt = self.clock.tick(30) / 1000

        # Renders and blits text
        new_game_txt = utils.load_font(51).render(
            "Enter File name for new game:", True, (0, 0, 0))
        new_game_txt_rect = new_game_txt.get_rect(center=(self.screen_width //
                                                          2, 40))
        self.screen.blit(new_game_txt, new_game_txt_rect)

        # Draws buttons
        for button in self.buttons.values():
            button[0].draw()

        self.manager.update(dt)
        self.manager.draw_ui(self.screen)

        pygame.display.update()
Exemple #9
0
    def draw(self):
        """Performs all drawing related tasks related to the Main Menu."""

        # Draws the version at the bottom right
        version_txt = utils.load_font(15, "PixelMillenium").render(
            f"Version {common.__version__}", True, (0, 0, 0))
        version_txt_rect = version_txt.get_rect(bottomright=(common.WIDTH,
                                                             common.HEIGHT))

        self.screen.blit(version_txt, version_txt_rect)

        # Updates the title
        self.update_title()

        # Loops through all buttons
        for dict_key, button in self.buttons.items():
            # The button is a tuple of two things: the actual button, and the action
            if self.selection == list(self.buttons).index(dict_key):
                button[0].draw((0, 128, 0))
            else:
                button[0].draw()
Exemple #10
0
    def draw(self, information: dict):
        debug_surf = pygame.Surface(
            (400, 230))  # lgtm [py/call/wrong-arguments]
        debug_surf.fill((128, 128, 128))

        debug_title_txt = utils.load_font(50).render("Debug Screen", True,
                                                     (0, 0, 0))
        debug_title_txt_pos = debug_title_txt.get_rect()
        debug_title_txt_pos.center = (175, 20)
        debug_surf.blit(debug_title_txt, debug_title_txt_pos)

        debug_state_txt = utils.load_font(16).render(
            f"State: {information['state']}", True, (0, 0, 0))
        debug_surf.blit(debug_state_txt, (15, 60))

        debug_fps_txt = utils.load_font(20).render(
            f"Frames per second: {str(round(information['fps'], 5))}", True,
            (0, 0, 0))
        debug_surf.blit(debug_fps_txt, (15, 90))

        debug_cpu_txt = utils.load_font(20).render(
            f"CPU Percentage: {information['cpu']}%", True, (0, 0, 0))
        debug_surf.blit(debug_cpu_txt, (15, 120))

        debug_mem_txt = utils.load_font(20).render(
            f"RAM Taken Up: {utils.format_byte(information['mem'][0])} "
            f"({round(information['mem'][0] / information['mem'][1] * 100, 3)}% of "
            f"{utils.format_byte(information['mem'][1])})",
            True,
            (0, 0, 0),
        )
        debug_surf.blit(debug_mem_txt, (15, 150))

        debug_time_txt = utils.load_font(20).render(
            f"Time Played: {information['time'][0].humanize(information['time'][1], only_distance=True)}",
            True,
            (0, 0, 0),
        )
        debug_surf.blit(debug_time_txt, (15, 180))

        debug_surf.set_alpha(220)

        self.screen.blit(debug_surf, (0, 0))
 def __init__(self, screen=common.SCREEN):
     self.screen = screen
     self.font = utils.load_font(60)
     self.next_state = self.__class__
Exemple #12
0
    def draw(self):
        self.screen.fill((0, 255, 0))

        shop_txt = utils.load_font(80).render("Shop", True, (0, 0, 0))
        shop_txt_rect = shop_txt.get_rect(center=(common.WIDTH // 2, 40))
        self.screen.blit(shop_txt, shop_txt_rect)