Пример #1
0
    def __init__(self,
                 screen: pygame.SurfaceType,
                 msg: str,
                 size=48,
                 b_color=(-1, -1, -1)):
        self.screen = screen
        self.screen_rect = screen.get_rect()

        # Properties of button.
        self.button_transparency = 80
        self.button_color = (0, 255, 0) if b_color == (-1, -1, -1) else b_color
        if len(self.button_color) == 3:
            self.button_color += (self.button_transparency,
                                  )  # add alpha channel
        self.text_color = (255, 255, 255)

        self.font = pygame.font.Font('fonts/RussoOne.ttf', size)

        self.prep_msg(msg)

        button_width = self.msg_image_rect.width + 30
        button_height = self.msg_image_rect.height + 10

        self.rect = pygame.Rect(0, 0, button_width, button_height)
        self.rect.center = self.msg_image_rect.center
Пример #2
0
    def __init__(self,
                 ai_settings: Settings,
                 screen: pygame.SurfaceType,
                 image_name='images/alien1.png'):
        """Initialize the alien and set its starting position."""

        super().__init__()
        self.screen = screen
        self.ai_settings = ai_settings
        self.screen_rect = screen.get_rect()

        # Load the alien image and set its rect attribute.
        fullname = os.path.join('.', image_name)
        try:
            self.image = pygame.image.load(fullname)
        except pygame.error:
            print('Cannot load image:', image_name)
            raise SystemExit
        self.image = pygame.transform.scale(self.image, ai_settings.alien_size)
        self.rect = self.image.get_rect()

        # Start each new alien near the top left of the screen.
        self.rect.x = self.rect.width
        self.rect.y = self.rect.height

        self.x = float(self.rect.x)
        self.y = float(self.rect.y)

        self.drop_dist = self.y + self.ai_settings.alien_drop_dist
Пример #3
0
    def __init__(self,
                 ai_settings: Settings,
                 screen: pygame.SurfaceType,
                 size=(0, 0),
                 image_name="alien-invasion/images/ship1.png"):
        """Initialize the ship and set its starting position."""
        super().__init__()
        self.screen = screen
        self.ai_settings = ai_settings

        # Load the ship image and get its rect.
        # fullname = os.path.join(os.getcwd(), image_name
        try:
            self.image = pygame.image.load(image_name)
        except pygame.error as e:
            print('Cannot load image: ', image_name)
            print(e)
            raise SystemExit
        if size == (0, 0):
            size = ai_settings.ship_size
        self.image = pygame.transform.scale(self.image, size)

        self.rect = self.image.get_rect()
        self.screen_rect = screen.get_rect()

        # Start each new ship at the bottom center of the screen.
        self.rect.centerx = self.screen_rect.centerx
        self.rect.bottom = self.screen_rect.bottom

        # Store a float value for the ship's center.
        self.center = float(self.rect.centerx)

        # Movement Flags.
        self.moving_right = False
        self.moving_left = False
Пример #4
0
    def __init__(self, screen: pygame.SurfaceType):
        """ Inicializa a espaçonave e define sua posição inicial """
        self.screen = screen

        # Carrega a imagem da espaçonave e obtém seu rect
        self.image = pygame.image.load('images/ship70x70.bmp')
        self.rect = self.image.get_rect()
        self.screen_rect = screen.get_rect()

        # Inicializa cada nova espaçonave na parte inferior central da tela
        self.rect.centerx = self.screen_rect.centerx
        self.rect.bottom = self.screen_rect.bottom
Пример #5
0
    def __init__(self, ai_settings: Settings, screen: SurfaceType, msg: str):
        self._screen = screen
        self._screen_rect = screen.get_rect()

        self._width, self._height = 200, 50
        self._button_color = (0, 255, 0)
        self._text_color = (255, 255, 255)
        self._font = SysFont(None, 48)

        self.rect = pygame.Rect(0, 0, self._width, self._height)
        self.rect.center = self._screen_rect.center

        self._prep_msg(msg)
Пример #6
0
    def __init__(self, ai_settings: Settings, screen: SurfaceType,
                 stats: GameStats):
        self._screen = screen
        self._screen_rect = screen.get_rect()
        self._ai_settings = ai_settings
        self._stats = stats

        self._text_color = 90, 200, 50
        self._font = SysFont(None, 48)

        self.prep_score()
        self.prep_high_score()
        self.prep_level()
        self.prep_ships()
Пример #7
0
    def __init__(self, ai_settings: Settings, stats: GameStats, screen: pygame.SurfaceType):

        self.screen = screen
        self.screen_rect = screen.get_rect()
        self.ai_settings = ai_settings
        self.stats = stats
        self.score_ship_size = self.ai_settings.score_ship_size  # size of ship in the scoreboard.
        self.dur_highscore_msg = 3000        # duration of highscore msg = 3 sec

        # Font settings.
        font_name = 'fonts/PoiretOne.ttf'       # try changing the font
        self.font_color = self.ai_settings.score_font_color
        self.font = pygame.font.Font(font_name, self.ai_settings.score_font_size)

        # Prepare the initial score image.
        self.prep_images()
Пример #8
0
    def resize_tags(self, image: pg.SurfaceType, is_cross: bool) -> pg.SurfaceType:
        """
        Funckja zmieniajaca rozmiar obrazkow X oraz O
        :param image: klasa pygame reprezentujaca obraz
        :param size: rozmiar planszy
        :param is_cross: ktory obraz przyjmuje X czy O
        :return: obraz o zmienionej wielkosci
        """
        if is_cross:
            x = 1.38
            y = 1.38
        else:
            x = 1.87
            y = 1.87

        image_rect = image.get_rect()
        image = pg.transform.scale(image, (int(x / self.size * image_rect.width), int(y / self.size * image_rect.height)))
        return image
Пример #9
0
    def resize_tags(self, image: pg.SurfaceType,
                    is_cross: bool) -> pg.SurfaceType:
        """
        Function that is responsible for resizing the passed image. The app is build the way, that only cross or circle
        are possible to be passed.

        :param image: This is the pygames class, that represents image
        :param size: Size of game board
        :param is_cross: Deciding which image is passed
        :return: Resized image
        """
        if is_cross:
            x = 1.38
            y = 1.38
        else:
            x = 1.87
            y = 1.87

        image_rect = image.get_rect()
        image = pg.transform.scale(image,
                                   (int(x / self.size * image_rect.width),
                                    int(y / self.size * image_rect.height)))
        return image