[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

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



Shandy, 

Thanks, that was the push in the right direction I was looking for.  Now I have:

                    for enemy in (enemyship_sprites.sprites()):
                        print enemy.initialx, enemy.initialy
                        enemy.rect.centerx = enemy.initialx
                        enemy.rect.centery = enemy.initialy

However.... when it prints the initialx, initialy, it's giving me 0,0
- the initial default value for initialx, initialy in the Enemy's
init, which is updated with the new value when the enemies are
created:

            Enemy.initialx = (cols*60)+20
            Enemy.initialy = (rows*40)+30
            enemyship_sprites.add(Enemy(Enemy.initialx, Enemy.initialy, level))
            print Enemy.initialx,
            print Enemy.initialy

At this point, it does give me all of the different coordinates for
the different starting points for each ship.  But then when I take my
current set of ships-that-havent-been-killed-yet
(enemyship_sprites.sprites()), when it looks at each, it's now telling
me initialx/initialy is 0/0.

Any idea why?  I can send the full code if it's necessary to see the
progression of steps.

~Denise

On 7/6/05, Shandy Brown <sjbrown@xxxxxxxxx> wrote:
> >
> >                     for each in (enemyship_sprites.sprites()):
> >                         each.rect.centerx = Enemy.initialx
> >                         each.rect.centery = Enemy.initialy
> 
> Hi Denise.
> 
> This code above is the part where you're using initialx and initialy as
> class attributes.  You probably want something like
> 
>        each.rect.centerx = each.initialx
> 
> instead.
> 
> -sjbrown
>