I am working with pygame libary. I have Actor classes (for game objects) and ActorContext classes (for game object lists):
class ActorContext:
list = []
alpha_range = 255
time_diff = 0
alpha_diff = 0
def add(self, obj: Actor):
self.list.append(obj)
In my main app I define objects:
enemy_context = ActorContext()
bullet_context = ActorContext()
dummy_context = ActorContext()
Later, in a loop, I create and add objects to those contexts:
if event.key == pg.K_e:
e = Enemy(img_src=enemy)
e.rand_change()
e.rand_pos()
enemy_context.add(e)
if event.key == pg.K_r:
if len(enemy_list) > 0:
enemy_context.remove(1)
The problem is that when I call enemy_context.add(e)
, the same value is added in all lists of objects: enemy_context, bullet_context and dummy_context