dimanche 12 juin 2016

Is it possible to have an if-statement in a dictionary?

I'm trying to make a game using pygame and so far so good, but i ran into a problem. The problem is I have 2 character sprites one for facing left and one for facing right and I have a dictionary in my code to set up new zombies and one of the lines in my dictionary defines whether i use the left facing sprite or the right facing one. i was just wondering if we can use an if statement with a dictionary to decide that. The dictionary is:

newZombie = {'rect': pygame.rect(side, 0+zombiesize, zombiesize/2, zombiesize),
             'speed':zombiespeed,
             'surface':zombielft if side==1000 else zombielft }

I found out you can do this in python 2.7 (thats what i believe I read) but i was just wondering for python 3.2. If you guys can help me with my problem i will be grateful.

Aucun commentaire:

Enregistrer un commentaire