Esempio n. 1
0
    def load_images(self):
        self.right_frames = []
        self.left_frames = []
        self.up_frames = []
        self.down_frames = []

        frame_rects = [(178, 32, 12, 16), (80, 32, 15, 16), (96, 32, 16, 16),
                       (112, 32, 16, 16)]
        for frame_rect in frame_rects:
            right_image = tools.load_image(
                'D:\\game\\Mario\\resources\\graphics\\mario_bros.png',
                *frame_rect, (0, 0, 0), c.PLAYER_SCALE)
            left_image = pygame.transform.flip(right_image, True, False)
            # pygame.transform.flip(反转对象,左右是否反转,上下是否反转)
            up_image = pygame.transform.rotate(right_image, 90)
            down_image = pygame.transform.rotate(right_image, -90)
            self.right_frames.append(right_image)
            self.left_frames.append(left_image)
            self.up_frames.append(up_image)
            self.down_frames.append(down_image)

        self.frame_index = 0
        self.frames = self.right_frames
        self.image = self.frames[self.frame_index]
        self.rect = self.image.get_rect()
Esempio n. 2
0
    def __init__(self, x, y, box_type, color=None):
        pygame.sprite.Sprite.__init__(self)
        self.name = 'box'
        self.x = x
        self.y = y
        self.box_type = box_type
        self.frame_rects = [
            (384, 0, 16, 16),
            (400, 0, 16, 16),
            (416, 0, 16, 16),
            (432, 0, 16, 16),
        ]

        self.frames = []
        for frame_rect in self.frame_rects:
            self.frames.append(
                tools.load_image(
                    'D:\\game\Mario\\resources\\graphics\\tile_set.png',
                    *frame_rect, (0, 0, 0), c.BRICK_SCALE))

        self.frame_index = 0
        self.image = self.frames[self.frame_index]
        self.rect = self.image.get_rect()
        self.rect.x = self.x
        self.rect.y = self.y
        self.timer = 0
        self.y_vel = 0
        self.y_accel = 0
Esempio n. 3
0
 def setup_cursor(self):
     self.cursor = pygame.sprite.Sprite()
     self.cursor.image = tools.load_image(
         'D:\\game\\Mario\\resources\\graphics\\item_objects.png', 25, 160,
         8, 8, (0, 0, 0), c.PLAYER_SCALE)
     rect = self.cursor.image.get_rect()
     rect.x, rect.y = 220, 360
     self.cursor.rect = rect
     self.cursor.state = '1P'  # 状态机(初始)
Esempio n. 4
0
 def setup_background(self):
     self.BG = pygame.image.load(
         'D:\\game\\Mario\\resources\\graphics\\level_1.png')
     w, h = self.BG.get_size()
     self.BG = pygame.transform.scale(
         self.BG, (int(w * c.BG_SCALE), int(h * c.BG_SCALE)))
     self.viewport = tools.load_image(
         'D:\\game\\Mario\\resources\\graphics\\title_screen.png', 1, 60,
         176, 88, (255, 0, 220), c.BG_SCALE)
Esempio n. 5
0
 def load_frames(self, frame_rects):
     for frame_rect in frame_rects:
         left_frame = tools.load_image(
             'D:\\game\Mario\\resources\\graphics\\enemies.png',
             *frame_rect, (220, 0, 255),
             c.ENEMY_SCALE,
             rgb=(220, 0, 255))
         right_frame = pygame.transform.flip(left_frame, True, False)
         self.left_frames.append(left_frame)
         self.right_frames.append(right_frame)
Esempio n. 6
0
 def setup_background(self):
     self.name = 'background_items'
     self.BG = pygame.image.load(
         'D:\\game\\Mario\\resources\\graphics\\level_1.png')
     w, h = self.BG.get_size()
     self.BG = pygame.transform.scale(
         self.BG, (int(w * c.BG_SCALE), int(h * c.BG_SCALE)))
     self.viewport = tools.load_image(
         'D:\\game\\Mario\\resources\\graphics\\title_screen.png', 1, 60,
         176, 88, (255, 0, 220), c.BG_SCALE)
     self.BG_rect = self.BG.get_rect()
     self.game_window = setup.SCREEN.get_rect()
     self.bg = pygame.Surface(
         (self.BG_rect.width, self.BG_rect.height))  # 创建一个大小和游戏背景图一致的黑色对象
Esempio n. 7
0
    def load_images(self):

        frame_rects = self.player_data['image_frames']

        # 建立帧库

        self.right_small_normal_frames = []
        self.right_big_normal_frames = []
        self.right_big_fire_frames = []
        self.left_small_normal_frames = []
        self.left_big_normal_frames = []
        self.left_big_fire_frames = []

        self.small_normal_frames = [self.right_small_normal_frames, self.left_small_normal_frames]
        self.big_normal_frames = [self.right_big_normal_frames, self.left_big_normal_frames]
        self.big_fire_frames = [self.right_big_fire_frames, self.left_big_fire_frames]

        self.all_frames = [
            self.right_small_normal_frames,
            self.right_big_normal_frames,
            self.right_big_fire_frames,
            self.left_small_normal_frames,
            self.left_big_normal_frames,
            self.left_big_fire_frames
            ]

        self.right_frames = self.right_small_normal_frames
        self.left_frames = self.left_small_normal_frames

        for group, group_frame_rects in frame_rects.items():
            for frame_rect in group_frame_rects:
                right_image = tools.load_image('D:\\game\\Mario\\resources\\graphics\\mario_bros.png', frame_rect['x'],frame_rect['y'],frame_rect['width'],frame_rect['height'],(0,0,0),c.PLAYER_SCALE)
                left_image = pygame.transform.flip(right_image,True,False)
                if group == 'right_small_normal':
                    self.right_small_normal_frames.append(right_image)
                    self.left_small_normal_frames.append(left_image)
                elif group == 'right_big_normal':
                    self.right_big_normal_frames.append(right_image)
                    self.left_big_normal_frames.append(left_image)
                elif group == 'right_big_fire':
                    self.right_big_fire_frames.append(right_image)
                    self.left_big_fire_frames.append(left_image)

        self.frame_index = 0
        self.frames = self.right_frames
        self.image = self.frames[self.frame_index]
        self.rect = self.image.get_rect()
Esempio n. 8
0
    def __init__(self, x, y, brick_type, color=None):
        pygame.sprite.Sprite.__init__(self)
        self.name = 'brick'
        self.x = x
        self.y = y
        self.brick_type = brick_type
        bright_rect_frames = [(16, 0, 16, 16), (48, 0, 16, 16)]
        dark_rect_frames = [(16, 32, 16, 16), (48, 32, 16, 16)]

        if not color:
            self.frame_rects = bright_rect_frames
        else:
            self.frame_rects = dark_rect_frames

        self.frames = []
        for frame_rect in self.frame_rects:
            self.frames.append(tools.load_image('D:\\game\Mario\\resources\\graphics\\tile_set.png', *frame_rect, (0, 0, 0),c.BRICK_SCALE))

        self.frame_index = 0
        self.image = self.frames[self.frame_index]
        self.rect = self.image.get_rect()
        self.rect.x = self.x
        self.rect.y = self.y
Esempio n. 9
0
 def load_frames(self, frame_rects):
     for frame_rect in frame_rects:
         self.frames.append(
             tools.load_image(
                 'D:\\game\\Mario\\resources\\graphics\\item_objects.png',
                 *frame_rect, (0, 0, 0), c.PLAYER_SCALE))  # *解包
Esempio n. 10
0
 def player(self):
     self.palyer = tools.load_image(
         'D:\\game\\Mario\\resources\\graphics\\mario_bros.png', 178, 32,
         12, 16, (0, 0, 0), c.PLAYER_SCALE)