I'm trying to make a pygame zelda_like, which can set random rooms and enemies. First, I called the same Enemy_Class for each room, but figured out it modified the overall enemies. So I called the function copy.deepcopy(). Since I had sprites declared in the Enemy_Class, it wouldn't work, so I tried this :
class Enemy(pygame.sprite.Sprite):
def __init__(self, img_list):
self.animation = 0
self.img_ref = 'img_list'
self.animation_list = []
self.img = []
self.ig = []
self.rect = []
self.mask = []
Which is copied like this :
room_number[i].enemy1 = copy.deepcopy(enemy_list[n])
lazy_loading(room_number[i].enemy1)
Enemy_list[x] returns a child from the Enemy_Class. And then the lazy_loading function is supposed to fill all :
def lazy_loading(sprite):
sprite.animation_list = get_lazy_loading(sprite)
sprite.img = sprite.animation_list[sprite.animation]
sprite.ig = pygame.transform.scale(sprite.img, (x, y))
sprite.rect = sprite.ig.get_rect()
sprite.mask = pygame.mask.from_surface(sprite.ig, 127)
get_lazy_loading returns a list of surfaces. Problem is self.img is considered as a NoneType and python doesn't really want it to be a surface...
So the question is, before I get further in vain : is there a way to make it accept a surface, or should I find a better way to load it in the lazy way ? Thank you very much.
edit* : Error I get is the following one :
sprite.img = sprite.animation_list[sprite.animation]
TypeError: 'NoneType' object is not subscriptable