So, i'm trying to import my main.py working file in pygame to another file called player.py. However,i get an error of Exception has occurred: ImportError cannot import name 'Level' from partially initialized module 'level' (most likely due to a circular import) Code in level.py:
import pygame
from tiles import Tile
from map import level_map,tile_size,screen_width
from player import Player
class Level:
def __init__(self,level_data,surface):
self.display_surface=surface
self.level_building(level_data)
self.world_shift=0
code in Player.py:
import pygame
from level import *
from tiles import Tile
from main import *
class bullets(pygame.sprite.Sprite):
def __init___(self,pos):
super().__innit__()
self.image=pygame.Surface((8,8))
self.rect=self.image.get_rect(topleft=(pos))
self.direction=0
self.speed=8
self.distcount=0
code in main.py:
import pygame
from colors import *
from map import *
from colors import *
from tiles import Tile
from level import Level
from player import *
#initialisation for pygame
pygame.init()
screen=pygame.display.set_mode((screen_width,screen_height))
sky_surface=pygame.image.load('Graphics/background.jpg')
pygame.display.set_caption('Test 1')
clock= pygame.time.Clock()
level=Level(level_map,screen)
Sorry for how long the code is i don't know whats important or not but if you'd like to see more to know the problem i'll add on more