so I'm importing my battle system code which deals with all the images and code for the battle system into the while loop of the play screen for my menu but for some reason my background appears that's in the same Battle_systems file as the knight but my knight doesn't
this is the menu code that everything is being imported into to
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()
and this is the battle system code itself
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)
the whole code runs and works without any errors but the knight doesn't show up and I'm a it stuck on the answer
You are not calling the draw()
method, you need to add parenthesis for it to actually work :
Battle_system.knight.draw()