mercredi 29 juillet 2015

Need help creating random explosions

I am creating a spaceship game where you go along and shoot down asteroids. I have created a couple of explosion classes, however no matter what I do I cannot get them show up randomly.

So what happens is I run my main program I shoot an asteroid and the first explosion is random, but for every explosion after that is the same as the first one. What is driving me crazy is that the sounds are playing randomly, but the visual explosion is not random. Both the sound and visual are in the same part of my "if, else" logic, but they don't match.

Here is the part of the code that I use that I am talking about:

for self.bullet_shot in self.bullet_list:
       bullet_hit_evil_space_ship = pygame.sprite.spritecollide(self.bullet_shot,self.enemy_list,True)
            self.explosion_pick = random.randint(0,1)
            for enemy in bullet_hit_evil_space_ship:

                if self.explosion_pick == 0:
                    explosion = explosions.Explosion_10()
                    explosion.rect.x = self.bullet_shot.rect.x - 10
                    explosion.rect.y = self.bullet_shot.rect.y - 60
                    self.explosion_list.add(explosion)
                    self.all_sprites_list.add(explosion)
                    constants.explosion_3.play()

                elif self.explosion_pick == 1:
                    explosion = explosions.Explosion_9()
                    explosion.rect.x = self.bullet_shot.rect.x - 10
                    explosion.rect.y = self.bullet_shot.rect.y - 60
                    self.explosion_list.add(explosion)
                    self.all_sprites_list.add(explosion)
                    constants.explosion_2.play()


                self.bullet_shot.kill()

So again, the sound plays randomly, but the explosion that appears is only random once (the first explosion) then they all are the same after that.

Any ideas on what is going on?




Aucun commentaire:

Enregistrer un commentaire