[Tutor] [pygame] Fwd: A more Pythonic way to do this

R. Alan Monroe amonroe at columbus.rr.com
Wed Jul 6 04:47:12 CEST 2005

> should be returning each to its original starting position. Since I
> create initialx/initialy for each enemy when the screen full of
> enemies is drawn (and I know I do create a new initialx/initialy for
> each one - because I had it print the initialx, initialy when the
> screen was drawn and I get 40 sets of values printed for the 40
> enemies on the screen), wouldnt each instance of the Enemy class store
> its own initialx initialy so that when I called
>                         each.rect.centerx = Enemy.initialx
>                         each.rect.centery = Enemy.initialy
> .. it would return each to its own starting position?

> Right now, it seems to be printing them all right on top of the other,
> in one enemy position.  At first I thought I was redrawing only one
> enemy, but I shot it, and there seems to be another underneath it. A
> lot of others, actually.  So I can't even see if it is drawing just
> the ones that havent been killed yet or a whole new batch.  And,
> obviously, it's not relocating them correctly :P

Did you inadvertently set the initialx & initialy on a class-wide
basis (within the class's definition), when you meant to set it on a
per-instance basis (within each enemy one at a time)?


More information about the Tutor mailing list