代码之家  ›  专栏  ›  技术社区  ›  i need help

有人能解释一下为什么当我的背景出现时,我的骑士不会出现吗

  •  0
  • i need help  · 技术社区  · 1 年前

    所以我将我的战斗系统代码导入到菜单播放屏幕的while循环中,该代码处理所有图像和战斗系统的代码,但由于某种原因,我的背景显示在与骑士相同的battle_systems文件中,但我的骑士没有

    这是所有内容都要导入到的菜单代码

    import sys
    
    import pygame 
    
    import Battle_system 
    from button import Button
    
    pygame.init()
    
    SCREEN = pygame.display.set_mode((1280, 720))
    pygame.display.set_caption("Menu")
    
    BG = pygame.image.load(r"C:\Users\olive\Desktop\Programming project\rpg\Menu\Background1.png")
    SURFACE = pygame.image.load(r'C:\Users\olive\Desktop\Programming project\rpg\Menu\surface.png')
    
    
    def get_font(size):  # Returns Press-Start-2P in the desired size
        return pygame.font.Font(r"C:\Users\olive\Desktop\Programming project\rpg\Menu\font.ttf", size)
    
    
    def play():
        while True:
            PLAY_MOUSE_POS: object = pygame.mouse.get_pos()
    
            #draw background
            PLAY_TEXT = get_font(45).render("This is the PLAY screen.", True, "White")
            PLAY_RECT = PLAY_TEXT.get_rect(center=(640, 260))
            SCREEN.blit(SURFACE, PLAY_RECT)
            Battle_system.draw_bg()
            Battle_system.draw_panel() 
            
    
            #draw characters
            Battle_system.knight.draw
            
    
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    sys.exit()
    
            pygame.display.update()
    
    def new_func():
        Battle_system.knight.draw
    
    
    def options():
        while True:
            OPTIONS_MOUSE_POS = pygame.mouse.get_pos()
    
            SCREEN.fill("white")
    
            OPTIONS_TEXT = get_font(45).render("This is the OPTIONS screen.", True, "Black")
            OPTIONS_RECT = OPTIONS_TEXT.get_rect(center=(640, 260))
            SCREEN.blit(OPTIONS_TEXT, OPTIONS_RECT)
    
            OPTIONS_BACK = Button(image=None, pos=(640, 460),
                                  text_input="BACK", font=get_font(75), base_color="Black", hovering_color="Green")
    
            OPTIONS_BACK.changeColor(OPTIONS_MOUSE_POS)
            OPTIONS_BACK.update(SCREEN)
    
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    sys.exit()
                if event.type == pygame.MOUSEBUTTONDOWN:
                    if OPTIONS_BACK.checkForInput(OPTIONS_MOUSE_POS):
                        main_menu()
    
            pygame.display.update()
    
    
    def main_menu():
        while True:
            SCREEN.blit(BG, (0, 0))
    
            MENU_MOUSE_POS = pygame.mouse.get_pos()
    
            MENU_TEXT = get_font(100).render("MAIN MENU", True, "#b68f40")
            MENU_RECT = MENU_TEXT.get_rect(center=(640, 100))
    
            PLAY_BUTTON = Button(
                image=pygame.image.load(r"C:\Users\olive\Desktop\Programming project\rpg\Menu\Play Rect.png"),
                pos=(640, 250),
                text_input="PLAY", font=get_font(75), base_color="#d7fcd4", hovering_color="White")
            OPTIONS_BUTTON = Button(
                image=pygame.image.load(r"C:\Users\olive\Desktop\Programming project\rpg\Menu\Options Rect.png"),
                pos=(640, 400),
                text_input="OPTIONS", font=get_font(75), base_color="#d7fcd4", hovering_color="White")
            QUIT_BUTTON = Button(
                image=pygame.image.load(r"C:\Users\olive\Desktop\Programming project\rpg\Menu\Quit Rect.png"),
                pos=(640, 550),
                text_input="QUIT", font=get_font(75), base_color="#d7fcd4", hovering_color="White")
    
            SCREEN.blit(MENU_TEXT, MENU_RECT)
    
            for button in [PLAY_BUTTON, OPTIONS_BUTTON, QUIT_BUTTON]:
                button.changeColor(MENU_MOUSE_POS)
                button.update(SCREEN)
    
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    sys.exit()
                if event.type == pygame.MOUSEBUTTONDOWN:
                    if PLAY_BUTTON.checkForInput(MENU_MOUSE_POS):
                        play()
                    if OPTIONS_BUTTON.checkForInput(MENU_MOUSE_POS):
                        options()
                    if QUIT_BUTTON.checkForInput(MENU_MOUSE_POS):
                        pygame.quit()
                        sys.exit()
    
            pygame.display.update()
    
    
    main_menu()
    
    
    

    这就是战斗系统代码本身

    import pygame,sys,random
    
    pygame.init()
    
    SCREEN = pygame.display.set_mode((1280, 720))
    pygame.display.set_caption("Battle")
    
    
    clock = pygame.time.Clock()
    fps = 60
    
    
    
    
    
    
    
    #load images
    #background image
    GBG = pygame.image.load(r'C:\Users\olive\Desktop\Programming project\rpg\setting\Background.png')
    #panel image
    PNL = pygame.image.load(r'C:\Users\olive\Desktop\Programming project\rpg\setting\panel.png')
    
    
    
    
    #function for drawing background
    def draw_bg():
        SCREEN.blit(GBG, (0, 0))
    
    
    #function for drawing panel
    def draw_panel():
        SCREEN.blit(PNL, (0, 500))
    
    
    
    #fighter class
    class Fighter():
        def __init__(self, x, y, name, max_hp, strength, potions):
            self.name = name
            self.max_hp = max_hp
            self.hp = max_hp
            self.strength = strength
            self.start_potions = potions
            self.potions = potions
            self.alive = True
            img = pygame.image.load(f'rpg/{self.name}/idle/0.png')
            self.image = pygame.transform.scale(img, (img.get_width() * 3, img.get_height() * 3))
            self.rect = self.image.get_rect()
            self.rect.center = (x, y)
    
    
        def draw(self):
            SCREEN.blit(self.image, self.rect)
    
    
    knight = Fighter(200, 260, 'Lothric', 30, 10, 3)
    slime1 = Fighter(550, 270, 'Slime', 20, 6, 1)
    slime2 = Fighter(700, 270, 'Slime', 20, 6, 1)
    
    slime_list = []
    slime_list.append(slime1)
    slime_list.append(slime2)
    
    
    
    
    

    整个代码运行正常,没有任何错误,但骑士没有出现,我只是一个执着于答案的人

    1 回复  |  直到 1 年前
        1
  •  2
  •   Franco227    1 年前

    你没有打电话给 draw() 方法,您需要添加括号才能使其实际工作:

    Battle_system.knight.draw()