def setup_cursor(self): self.cursor=pygame.sprite.Sprite() self.cursor.image =tools.get_image(setup.GRAPHICS['item_objects'],25,160,8,8,(0,0,0),C.PLAYER_MULTI) rect=self.cursor.image.get_rect() rect.x,rect.y=(220,360) self.cursor.rect=rect self.cursor.state='1P'
def setup_background(self): self.background=setup.GRAPHICS['level_1'] self.background_rect=self.background.get_rect() self.background=pygame.transform.scale(self.background,(int(self.background_rect.width *C.BG_MULTI),int(self.background_rect.height *C.BG_MULTI))) self.viewport = setup.SCREEN.get_rect() self.caption = tools.get_image(setup.GRAPHICS['title_screen'],1,60,176,88,(255,0,220),C.BG_MULTI)
def create_player_image(self): self.life_times_image = tools.get_image(setup.GFX['text_images'], 75, 247, 6, 6, (92, 148, 252), 2.9) self.life_times_rect = self.life_times_image.get_rect(center=(378, 295)) self.life_total_label = [] self.create_label(self.life_total_label, str(self.total_lives), 450, 285) if self.game_info[c.PLAYER_NAME] == c.PLAYER_MARIO: rect = (178, 32, 12, 16) else: rect = (178, 128, 12, 16) self.player_image = tools.get_image(setup.GFX['mario_bros'], *rect, (92, 148, 252), 2.9) self.player_rect = self.player_image.get_rect(center=(320, 290))
def load_frames(self): sheet = setup.GFX[c.ITEM_SHEET] frame_rect_list = [(3, 98, 9, 13), (19, 98, 9, 13), (35, 98, 9, 13), (51, 98, 9, 13)] for frame_rect in frame_rect_list: self.frames.append(tools.get_image(sheet, *frame_rect, c.BLACK, c.BRICK_SIZE_MULTIPLIER))
def load_frames(self): sheet = setup.GFX[c.ITEM_SHEET] frame_rect_list = [(1, 160, 5, 8), (9, 160, 5, 8), (17, 160, 5, 8), (9, 160, 5, 8)] for frame_rect in frame_rect_list: self.frames.append(tools.get_image(sheet, *frame_rect, c.BLACK, c.BRICK_SIZE_MULTIPLIER))
def load_frames(self): sheet = setup.GFX[c.ITEM_SHEET] frame_rect_list = [(52, 113, 8, 14), (4, 113, 8, 14), (20, 113, 8, 14), (36, 113, 8, 14)] for frame_rect in frame_rect_list: self.frames.append(tools.get_image(sheet, *frame_rect, c.BLACK, c.BRICK_SIZE_MULTIPLIER))
def setup_cursor(self): self.cursor = pg.sprite.Sprite() self.cursor.image = tools.get_image(setup.GFX[c.ITEM_SHEET], 24, 160, 8, 8, c.BLACK, 3) rect = self.cursor.image.get_rect() rect.x, rect.y = (220, 358) self.cursor.rect = rect self.cursor.state = c.PLAYER1
def load_frames(self): sheet = setup.GFX['tile_set'] frame_rect_list = [(384, 0, 16, 16), (400, 0, 16, 16), (416, 0, 16, 16), (400, 0, 16, 16), (432, 0, 16, 16)] for frame_rect in frame_rect_list: self.frames.append( tools.get_image(sheet, *frame_rect, c.BLACK, c.BRICK_SIZE_MULTIPLIER))
def update(self, surface): ''' :param surface: 屏幕 :return: ''' # 加载背景图片\ backgroundimg = tools.get_image(self.backgroundimg, 0, 0, CO.SCR_X, CO.SCR_Y, 'NULL', 1) surface.blit(backgroundimg, (0, 0), backgroundimg.get_rect()) # 图像,绘制的位置,绘制的截面框
def setup_player(self): self.player_list = [] player_rect_info = [(178, 32, 12, 16), (178, 128, 12, 16)] for rect in player_rect_info: image = tools.get_image(setup.GFX['mario_bros'], *rect, c.BLACK, 2.9) rect = image.get_rect() rect.x, rect.bottom = 110, c.GROUND_HEIGHT self.player_list.append((image, rect)) self.player_index = 0
def create_images_dict(self): self.image_dict = {} digit_rect_list = [(1, 168, 3, 8), (5, 168, 3, 8), (8, 168, 4, 8), (0, 0, 0, 0), (12, 168, 4, 8), (16, 168, 5, 8), (0, 0, 0, 0), (0, 0, 0, 0), (20, 168, 4, 8), (0, 0, 0, 0)] digit_string = '0123456789' for digit, image_rect in zip(digit_string, digit_rect_list): self.image_dict[digit] = tools.get_image(setup.GFX[c.ITEM_SHEET], *image_rect, c.BLACK, c.BRICK_SIZE_MULTIPLIER)
def update(self, surface, pos): ''' :param surface: 屏幕 :param pos: 鼠标位置 :return: ''' # print(backgroundimg.get_rect()) # 加载背景图片\ backgroundimg = tools.get_image(self.backgroundimg, 0, 0, CO.SCR_X, CO.SCR_Y, 'NULL', 1) surface.blit(backgroundimg, (0, 0), backgroundimg.get_rect()) # 图像,绘制的位置,绘制的截面框 mouse_x = pos[0] mouse_y = pos[1] print("==", pos) # 554 * 94 # (CO.SCR_Y//2 + 94//2 <= mouse_x <= (CO.SCR_Y//2 + 800)) if (mouse_x >= CO.SCR_X //2 - 554//2 and mouse_x <= CO.SCR_X//2 +554//2 ) and\ (mouse_y >= CO.SCR_Y//2 and mouse_y<= CO.SCR_Y //2 + 94): # 判断鼠标是否在开始按钮之上 stimg = pygame.image.load(CO.STPATH1) stimg = tools.get_image(stimg, 0, 0, stimg.get_rect()[2], stimg.get_rect()[3], CO.COLOR_LU, 1) # surface.blit(stimg, (CO.SCR_X // 2 - 554 // 2, CO.SCR_Y // 2), stimg.get_rect()) if self.sound != '0': self.sound.play() self.sound = '0' else: self.sound = pygame.mixer.Sound(CO.ST_SOUND) stimg = pygame.image.load(CO.STPATH2) stimg = tools.get_image(stimg, 0, 0, stimg.get_rect()[2], stimg.get_rect()[3], CO.COLOR_LU, 1) print("st -", stimg.get_rect()) surface.blit(stimg, (CO.SCR_X // 2 - 554 // 2, CO.SCR_Y // 2), stimg.get_rect())
def create_font_image_dict(self): self.image_dict = {} image_list = [] image_rect_list = [ # 0 - 9 (3, 230, 7, 7), (12, 230, 7, 7), (19, 230, 7, 7), (27, 230, 7, 7), (35, 230, 7, 7), (43, 230, 7, 7), (51, 230, 7, 7), (59, 230, 7, 7), (67, 230, 7, 7), (75, 230, 7, 7), # A - Z (83, 230, 7, 7), (91, 230, 7, 7), (99, 230, 7, 7), (107, 230, 7, 7), (115, 230, 7, 7), (123, 230, 7, 7), (3, 238, 7, 7), (11, 238, 7, 7), (20, 238, 7, 7), (27, 238, 7, 7), (35, 238, 7, 7), (44, 238, 7, 7), (51, 238, 7, 7), (59, 238, 7, 7), (67, 238, 7, 7), (75, 238, 7, 7), (83, 238, 7, 7), (91, 238, 7, 7), (99, 238, 7, 7), (108, 238, 7, 7), (115, 238, 7, 7), (123, 238, 7, 7), (3, 246, 7, 7), (11, 246, 7, 7), (20, 246, 7, 7), (27, 246, 7, 7), (48, 246, 7, 7), # -* (68, 249, 6, 2), (75, 247, 6, 6) ] character_string = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ -*' for character, image_rect in zip(character_string, image_rect_list): self.image_dict[character] = tools.get_image( setup.GFX['text_images'], *image_rect, (92, 148, 252), 2.9)
def map_loade(self, surface): ''' :param surface: 屏幕 :return: ''' # 加载地图图片 backgroundimg = get_image(self.lv0_backgroundimg, 0, 0, self.lv0_rect_x, self.lv0_rect_y, 'NULL', 2) # self.lv_x = self.lv_x+30 surface.blit(backgroundimg, (0, 0), (self.lv_x_speed, self.lv_y_speed, self.lv0_rect_x, CO.SCR_Y)) # 图像,绘制的位置,绘制的截面框
def load_images(self): sheet = setup.GFX['mario_bros'] frames_list = self.player_data[c.PLAYER_FRAMES] self.right_frames = [] self.left_frames = [] self.right_small_normal_frames = [] self.left_small_normal_frames = [] self.right_big_normal_frames = [] self.left_big_normal_frames = [] self.right_big_fire_frames = [] self.left_big_fire_frames = [] for name, frames in frames_list.items(): for frame in frames: image = tools.get_image(sheet, frame['x'], frame['y'], frame['width'], frame['height'], c.BLACK, c.SIZE_MULTIPLIER) left_image = pg.transform.flip(image, True, False) if name == c.RIGHT_SMALL_NORMAL: self.right_small_normal_frames.append(image) self.left_small_normal_frames.append(left_image) elif name == c.RIGHT_BIG_NORMAL: self.right_big_normal_frames.append(image) self.left_big_normal_frames.append(left_image) elif name == c.RIGHT_BIG_FIRE: self.right_big_fire_frames.append(image) self.left_big_fire_frames.append(left_image) 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_images = [ self.right_small_normal_frames, self.left_small_normal_frames, self.right_big_normal_frames, self.left_big_normal_frames, self.right_big_fire_frames, self.left_big_fire_frames ] self.right_frames = self.small_normal_frames[0] self.left_frames = self.small_normal_frames[1]
def __init__(self, x, y, sheet, image_rect_list, scale, textsurface=None): pg.sprite.Sprite.__init__(self) self.frames = [] self.frame_index = 0 for image_rect in image_rect_list: self.frames.append( tools.get_image(sheet, *image_rect, c.BLACK, scale)) self.image = self.frames[self.frame_index] self.rect = self.image.get_rect() self.rect.x = x self.rect.y = y if textsurface is not None and c.PRINT_Q_VALUES: self.image.blit(textsurface, (3, 15))
def setup_background(self): self.background = setup.GFX['level_1'] self.background_rect = self.background.get_rect() self.background = pg.transform.scale( self.background, (int(self.background_rect.width * c.BACKGROUND_MULTIPLER), int(self.background_rect.height * c.BACKGROUND_MULTIPLER))) self.viewport = setup.SCREEN.get_rect(bottom=setup.SCREEN_RECT.bottom) self.image_dict = {} image = tools.get_image(setup.GFX['title_screen'], 1, 60, 176, 88, (255, 0, 220), c.SIZE_MULTIPLIER) rect = image.get_rect() rect.x, rect.y = (170, 100) self.image_dict['GAME_NAME_BOX'] = (image, rect)
def setup_player(self): self.player_image =tools.get_image(setup.GRAPHICS['mario_bros'],178,32,12,16,(0,0,0),C.PLAYER_MULTI)
def load_frames(self, sheet, frame_rect_list): for frame_rect in frame_rect_list: self.frames.append( tools.get_image(sheet, *frame_rect, c.BLACK, c.BRICK_SIZE_MULTIPLIER))