#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    6
    Rep Power
    0

    Moving between splash screen to playing game and end screen


    Hi

    I have created a basic space game from a number of different tutorials and have learnt a lot about sprites .I am having trouble with switching between 3 screens.Game starts with a splash screen and pressing the space bar starts the game and when player has no more lives an end screen opens summarising the scoring. But when the space bar is pressed in the end screen the game starts up it immediately
    goes back to the end screen. Here is my code, thanks in advance for looking.

    Code:
    import os, sys, pygame
    from pygame.locals import *
    
    import random
    #direction = 'right'
    # Define some colors
    black    = (   0,   0,   0)
    white    = ( 255, 255, 255)
    red      = ( 255,   0,   0)
    blue     = (   0,   0, 255)
    yellow = (255,255,0)
    global count
    global endscreen
    global startscreen
    global introscreen
    introscreen = 'true'
    endscreen = 'false'
    startscreen = 'false'
    direction = ''
    countframes = 0
    done = False
    screen_width = 640
    screen_height = 480
    global gameLevel
    gameLevel = 1
    playerscore = 1
    timerufo = 0
    timeralien = 0
    global playerHealth
    playerHealth = 100
    global playerlife
    playerlife = 3
    global alienssavednumber
    alienssavednumber = 0
    numerofenemieskilled = 0
    numerofufoskilled = 0
    global finished
    #finished = 'false'
    #intro = 'true'
    #global intro
    #end = 'false'
    #global end
    
    # --- Sprite lists
     
    
     
    all_sprites_list = pygame.sprite.Group()
    
    enemy_list = pygame.sprite.Group()
    ship_list = pygame.sprite.Group() 
    bullet_list = pygame.sprite.Group()
    score_list = pygame.sprite.Group()
    lives_list = pygame.sprite.Group()
    health_list = pygame.sprite.Group()
    enemy_bullet_list = pygame.sprite.Group()
    enemy_bullet_hit_list =  pygame.sprite.Group()
    allsprites = pygame.sprite.RenderUpdates()
    ufo_list =  pygame.sprite.Group()
    ufo_hit_list = pygame.sprite.Group()
    ufo_explosion_list = pygame.sprite.Group()
    ufo_alien_list = pygame.sprite.Group()
    ufo_alien_hit_list = pygame.sprite.Group()
    #ufo_explosion_list = pygame.sprite.Group()
    #EnemyExplosion.containers = allsprites
    enemy_explosion_list= pygame.sprite.Group()
    alienssaved_list = pygame.sprite.Group()
    ufo_bad_alien_list = pygame.sprite.Group()
    
    #ship_explosion_list = pygame.sprite.Group()
    
    
    #ufos.SetPosition(200,200)
    class Health(pygame.sprite.Sprite):
        image = ""
        rect = ""
    
        def __init__(self):
            pygame.sprite.Sprite.__init__(self)
            self.font = pygame.font.Font(None, 20)
            self.color = Color('YELLOW')
            self.update()
            self.rect = self.image.get_rect().move(250, 1)
    
        def update(self):
            msg = "Health: %d" % playerHealth
            self.image = self.font.render(msg, 0, self.color)
    
    
    class Ufos(pygame.sprite.Sprite):
        change_x=0
        change_y=0
        frame = 0
        images =[]
        image = ''
        rect = ''
        lives = 20
        
        def __init__(self,):
            # Call the parent class (Sprite) constructor
            pygame.sprite.Sprite.__init__(self) 
     
            # List that the cat images will be saved in.
            self.images=[]
            
            for i in range(1,6):
                img = pygame.image.load("ufo"+str(i)+".png")
                img.set_colorkey(white)
                self.images.append(img)
             
            # By default, use image 0
            self.image = self.images[0]
            self.rect = self.image.get_rect()
    
        def move(self,x,y):
            self.change_x+=x
            self.change_y+=y
            
        def update(self):
         
            self.rect.x = self.rect.x - self.change_x
            self.frame += 1
                 
            if self.frame > 4*2:
                self.frame = 0
                     
            self.image = self.images[self.frame//2]
            
    
    def SpawnUfos():
        ufo = Ufos()
        ufo_list.add(ufo)
        ufo.rect.x=600
        ufo.rect.y=10
        ufo.move(20,10)
        all_sprites_list.add(ufo)
        all_sprites_list.update()
        
        
    
    def SpawnEnemies(level):
    
    
        enemycount = 1 + level
        while enemycount > 0:
            enemy = Enemy()
            enemy_list.add(enemy)
            all_sprites_list.add(enemy)
            enemycount = enemycount - 1
        x = 200
        y = 200
        for enemy in enemy_list:
            enemy.SetPosition()
            
    def DelayTimer(intervalnumber):
        global interval
        interval = random.randrange(0,intervalnumber)
        
        return interval
       
    
    
    class Lives(pygame.sprite.Sprite):
        image = ""
        rect = ""
    
        def __init__(self):
            pygame.sprite.Sprite.__init__(self)
            self.font = pygame.font.Font(None, 20)
            self.color = Color('blue')
            self.update()
            self.rect = self.image.get_rect().move(150, 1)
    
        def update(self):
            msg = "Lives: %d" % playerlife
            self.image = self.font.render(msg, 0, self.color)
    
    
    class Score(pygame.sprite.Sprite):
        global playerscore
        image = ""
        rect = ""
    
        def __init__(self):
            pygame.sprite.Sprite.__init__(self)
            self.font = pygame.font.Font(None, 20)
            self.color = Color('red')
            self.update()
            self.rect = self.image.get_rect().move(75, 1)
           
    
        def update(self):
            msg = "Score: %d" % playerscore
            self.image = self.font.render(msg, 0, self.color)
    
    class AliensSaved(pygame.sprite.Sprite):
        global alienssavednumber
        image = ""
        rect = ""
    
        def __init__(self):
            pygame.sprite.Sprite.__init__(self)
            self.font = pygame.font.Font(None, 20)
            self.color = Color('white')
            self.update()
            self.rect = self.image.get_rect().move(380, 1)
           
    
        def update(self):
            msg = "Aliens Saved: %d" % alienssavednumber
            self.image = self.font.render(msg, 0, self.color)
            
    class ShipExplosion(pygame.sprite.Sprite):
        defaultlife = 9
        animcycle = 3
        images = []
    
        def __init__(self, actor):
            pygame.sprite.Sprite.__init__(self, self.containers)
           
           
           
            self.images.append(pygame.image.load('enemy2.png'))
            self.images.append(pygame.image.load('enemy3.png'))
            self.images.append(pygame.image.load('enemy4.png'))
            self.image = self.images[0]
            self.rect = self.image.get_rect()
            self.life = self.defaultlife
            self.rect.center = actor.rect.center
    
        def update(self):
            self.life = self.life - 1
            self.image = self.images[self.life//self.animcycle%3]
            if self.life <= 0: self.kill()
    
    class EnemyExplosion(pygame.sprite.Sprite):
        defaultlife = 9
        animcycle = 3
        images = []
    
        def __init__(self, actor):
            pygame.sprite.Sprite.__init__(self, self.containers)
          
            self.images.append(pygame.image.load('enemy2.png'))
            self.images.append(pygame.image.load('enemy3.png'))
            self.images.append(pygame.image.load('enemy4.png'))
            self.image = self.images[0]
            self.rect = self.image.get_rect()
            self.life = self.defaultlife
            self.rect.center = actor.rect.center
    
        def update(self):
            self.life = self.life - 1
            self.image = self.images[self.life//self.animcycle%3]
            if self.life <= 0: self.kill()
    
    class UfoExplosion(pygame.sprite.Sprite):
        defaultlife = 9
        animcycle = 3
        images = []
    
        def __init__(self, actor):
            pygame.sprite.Sprite.__init__(self, self.containers)
            # define our explosion animation frames
            #self.explosion_sound = load_sound('explos.wav')
            #self.explosion_sound.play()
            self.images.append(pygame.image.load('ufoexplosion1.png'))
            self.images.append(pygame.image.load('ufoexplosion2.png'))
            self.images.append(pygame.image.load('ufoexplosion3.png'))
            self.image = self.images[0]
            self.rect = self.image.get_rect()
            self.life = self.defaultlife
            self.rect.center = actor.rect.center
    
        def update(self):
            self.life = self.life - 1
            self.image = self.images[self.life//self.animcycle%3]
            if self.life <= 0: self.kill()
    
              
    class Enemy(pygame.sprite.Sprite):
        """ This class represents the Enemy. """
        def __init__(self):
    
    
            pygame.sprite.Sprite.__init__(self) 
            self.image = pygame.image.load('enemy1.png')
          
            self.rect = self.image.get_rect()
            
        def SetPosition(self):
            
            x = random.randint(1,500)
            y = random.randint(1,500)
            self.rect.left = x
            self.rect.top = -y
            
        def update(self):
            y = random.randint(5,20)
            self.rect.y += y
    
    class UfoAlien(pygame.sprite.Sprite):
        x=0
        """ This class represents the bullet . """
        def __init__(self):
            
            pygame.sprite.Sprite.__init__(self) 
            self.image = pygame.image.load('alien.png')
            self.rect = self.image.get_rect()
    
        def update(self):
            
            self.rect.y += 5
            
            if self.rect.y <300:
                self.rect.y += 5
                
            else :
                self.rect.y = 360
                self.rect.x -= random.randint(1,50)
    
    class UfoBadAlien(pygame.sprite.Sprite):
        x=0
      
        def __init__(self):
            
            pygame.sprite.Sprite.__init__(self) 
            self.image = pygame.image.load('alienbad.png')
            self.rect = self.image.get_rect()
    
        def update(self):
            
            self.rect.y += 5
            
            if self.rect.y <300:
                self.rect.y += 5
                
            else :
                self.rect.y = 360
                self.rect.x -= random.randint(1,50)
      
    class EnemyBullet(pygame.sprite.Sprite):
    
        def __init__(self):
            
            pygame.sprite.Sprite.__init__(self) 
            self.image = pygame.image.load('bullet.png').convert()
            self.rect = self.image.get_rect()
    
        def update(self):
            """ Move the bullet. """
            self.rect.y += 25
           
    
            
    class Ship(pygame.sprite.Sprite):
        global direction
        lives = 3
        #image = ''
        #rect = ''
      
         
        def __init__(self):
            """ Set up the Ship on creation. """
            
            pygame.sprite.Sprite.__init__(self) 
            self.image = pygame.image.load('jet1.gif').convert()
            self.rect = self.image.get_rect()
            
        def SetPosition(self, x, y):
         
            self.rect.left = x
            self.rect.top = y 
             
        def update(self):
             
           
            if direction == 'up':
                self.rect.y -= 10
            if direction == 'down':
                self.rect.y += 10
            if direction == 'right':
                self.rect.x += 10
            if direction == 'left':
                self.rect.x -= 10
                
        def Explode(self):
            self.lives = self.lives - 1  
             
    class Bullet(pygame.sprite.Sprite):
       
        def __init__(self):
            
            pygame.sprite.Sprite.__init__(self) 
            self.image = pygame.image.load('bullet.png').convert()
            self.rect = self.image.get_rect()
    
        def update(self):
            """ Move the bullet. """
            self.rect.y -= 15
    
    #Intro Screen
    def EndScreen():
        global alienssavednumber 
        global numerofenemieskilled 
        global numerofufoskilled
        global finished
        global endscreen
        global startscreen
        global introscreen 
        endscreen = 'false'
        startscreen = 'false'
        introscreen = 'true'
        #finished = 'true'
        # Initialize everything
        pygame.init()
        screen = pygame.display.set_mode((screen_width, screen_height))
        pygame.display.set_caption('Invaders Invictus')
        pygame.mixer.music.load("introMusic.ogg")
        pygame.mixer.music.play()
        # Create the backgound surface
        background = pygame.Surface(screen.get_size())
        background = background.convert()
        background = pygame.image.load('spacebackground.png')
        screen.blit(background, (0, 0))
        
    
        font = pygame.font.Font(None, 40)
        text = font.render("Press SPACE to play", 1, (250, 250, 0))
       
        textpos = text.get_rect()
      
        textpos.centerx = background.get_rect().centerx
        #this puts the centre of the text rectangel in the center of the screen
        textpos.centery = 400
      
        background.blit(text, textpos)
        
        ###### Main title ############ 
        font = pygame.font.Font(None, 40)
        
        text = font.render("Invaders From Space", 2, (0, 250, 0))
        
        textpos = text.get_rect()
        # creates a border around the text and stores as textpos
        textpos.centerx = background.get_rect().centerx
         #this puts the centre of the text rectange in the center of the screen
        textpos.centery = 100
        # this sets the text box 40 pixels from the top
        background.blit(text, textpos)
        
        ##############Player Image   #########
        
        playerimage = pygame.image.load('player.png')
        background.blit(playerimage, (50, 100))
        
    
        font = pygame.font.Font(None, 40)
        msgscore = "Total Scored : %d" #% score.update()
        text1 = font.render(msgscore, 1, (250, 250, 250))
        text2 = font.render('3 lives per game', 1, (250, 250, 250))
        background.blit(text1, (160,145)) # 160 px from left and 145 from top of screem ( i.e x and y position)
        background.blit(text2, (160,180))
        
    
        
        playerimage = pygame.image.load('enemy.png')
        background.blit(playerimage, (55, 220))
        enemiesskilledmsg = "Number of Enemies : %d" % numerofenemieskilled
        text1 = font.render(enemiesskilledmsg, 1, (250, 250, 250))
        background.blit(text1, (160,250))
    
        
        
        playerimage = pygame.image.load('ufo.png')
        background.blit(playerimage, (55, 320))
        ufoskilledmsg = "Number of Enemies : %d" % numerofufoskilled
        text1 = font.render(ufoskilledmsg, 1, (250, 250, 250))
        background.blit(text1, (160,320))
    
        background.blit(text, textpos)
        screen.blit(background,(0,0))
        pygame.display.flip()
        while 1:
         
            
            
            for event in pygame.event.get():
                
                if event.type == pygame.QUIT:
                    return 0
                if event.type == pygame.KEYDOWN and event.key == pygame.K_q:
                    return 0
                if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
                    IntroScreen()
                    return 2
                
              
                   
                
            
    def IntroScreen():
        # Initialize everything
        global finished
        #finished = 'false'
        global endscreen
        global introscreen
        global startscreen
        endscreen = 'false'
        startscreen = 'true'
        introscreen = 'false'
        pygame.init()
        screen = pygame.display.set_mode((screen_width, screen_height))
        pygame.display.set_caption('Invaders Invictus')
        pygame.mixer.music.load("introMusic.ogg")
        pygame.mixer.music.play()
        # Create the backgound surface
        background = pygame.Surface(screen.get_size())
        background = background.convert()
        background = pygame.image.load('spacebackground.png')
        screen.blit(background, (0, 0))
        
    
        
        font = pygame.font.Font(None, 40)
        
        text = font.render("Invaders From Space", 2, (0, 250, 0))
        
        textpos = text.get_rect()
        # creates a border around the text and stores as textpos
        textpos.centerx = background.get_rect().centerx
        #this puts the centre of the text rectange in the center of the screen
        textpos.centery = 100
        # this sets the text box 40 pixels from the top
        background.blit(text, textpos)
        
        
       
        playerimage = pygame.image.load('player.png')
        background.blit(playerimage, (50, 100))
        
     
        font = pygame.font.Font(None, 40)
        text1 = font.render('Move  Player with arrow keys', 1, (250, 250, 250))
        text2 = font.render('3 lives per game', 1, (250, 250, 250))
        background.blit(text1, (160,145)) # 160 px from left and 145 from top of screem ( i.e x and y position)
        background.blit(text2, (160,180))
        
        
        
        playerimage = pygame.image.load('enemy.png')
        background.blit(playerimage, (55, 220))
        text1 = font.render('Shoot this enemy gains 10 points', 1, (250, 250, 250))
        background.blit(text1, (160,250))
    
        ####### enemy 2  picture
        
        playerimage = pygame.image.load('ufo.png')
        background.blit(playerimage, (55, 320))
        text1 = font.render('Shoot this enemy gains 100 points', 1, (250, 250, 250))
        background.blit(text1, (160,320))
    
    
        
        # Display some text
        font = pygame.font.Font(None, 40)
        text = font.render("Press SPACE to play", 1, (250, 250, 0))
        #text = font.render("Press SPACE to play", 1, (100, 250, 100))
        textpos = text.get_rect()
        # creates a border around the text and stores as textpos
        textpos.centerx = background.get_rect().centerx
        #this puts the centre of the text rectangel in the center of the screen
        textpos.centery = 400
        # this sets the text box 20 pixels from the top
        background.blit(text, textpos)
        
        # Display some text
        font = pygame.font.Font(None, 40)
        text = font.render("Press Q to quit", 1, (250, 0, 250))
        textpos = text.get_rect()
        textpos.centerx = background.get_rect().centerx
        textpos.centery = 500
        background.blit(text, textpos)
        screen.blit(background,(0,0))
        pygame.display.flip()
    
        while 1:
         
            # Handle input events
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    return 0
                elif event.type == pygame.KEYDOWN and event.key == pygame.K_q:
                    return 0
                elif event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
                    PlayGame(gameLevel)
                    return 2
    
    def PlayGame(gamelevel):
        global playerlife
        global direction
        global playerHealth
        global playerscore
        global alienssavednumber
        global interval_ufo_alien
        global playerscore
        global numerofenemieskilled
        global numerofufoskilled
            
        global endscreen
        global startscreen
        global introscreen 
        endscreen = 'true'
        startscreen = 'false'
        introscreen = 'false'
        #global finished
    
        ship = Ship()
        score = Score()
        lives = Lives()
        health = Health()
        alienssaved = AliensSaved()
        
        all_sprites_list.add(score)
        all_sprites_list.add(lives)
        all_sprites_list.add(health)
        all_sprites_list.add(alienssaved)
        
        alienssaved = AliensSaved()
        allsprites = pygame.sprite.RenderUpdates()
        ShipExplosion.containers = allsprites
        EnemyExplosion.containers = allsprites
        UfoExplosion.containers = allsprites
        
        pygame.init()
        clock = pygame.time.Clock()
        ship.SetPosition(200,200) 
        ship_list.add(ship)
    # Set the height and width of the screen
        screen_width = 700
        screen_height = 400
        screen = pygame.display.set_mode([screen_width, screen_height])
       
        
        pygame.display.flip()
        
        SpawnEnemies(2)
        all_sprites_list.add(ship)
        ship.rect.y = 370
    
        all_sprites_list.draw(screen) 
        all_sprites_list.update()
    
    
    # -------- Main Program Loop -----------
        # Main Loop
        while 1:
            clock.tick(10)
            global countframes
            countframes +=1
            
            if countframes == 40:
                SpawnEnemies(20)
            if countframes == 60:
                SpawnEnemies(20)
            # Handle input events
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    return 0
                elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
                    return 0
               
                
     
    
            if event.type == pygame.KEYDOWN:
    
                if event.key == pygame.K_SPACE:
           
                # Fire a bullet if the user clicks the mouse button
                    sound = pygame.mixer.Sound('laser_human.ogg')
                    sound.play()
                    bullet = Bullet()
                    
                # Set the bullet so it is where the Ship is
                    bullet.rect.x = ship.rect.x
                    bullet.rect.y = ship.rect.y
                # Add the bullet to the lists
                    all_sprites_list.add(bullet)
                    bullet_list.add(bullet)
                    ship.update()
                    
                if event.key == pygame.K_RIGHT:
                    direction = 'right'
                    ship.update()
                    
                if event.key == pygame.K_LEFT:
                    direction = 'left'
                    ship.update()
                    
                    
                if event.key == pygame.K_UP:
                    direction = 'up'
                    ship.update()
                if event.key == pygame.K_DOWN:
                    direction = 'down'
                    ship.update()
        
           
        
        # --- Game logic
         
        # Call the update() method on all the sprites
            ship_list.add(ship)
            all_sprites_list.update()
            screen.fill(black)
                
         
        # Calculate mechanics for each bullet
            for bullet in bullet_list:
                
            # See if it hit a Enemy
                enemy_hit_list = pygame.sprite.spritecollide(bullet, enemy_list, True)
             
            # For each Enemy hit, remove the bullet and add to the score
                for enemy in enemy_hit_list:
                  
                    enemy_explosion_list.add(EnemyExplosion(enemy))
                    bullet_list.remove(bullet)
                    all_sprites_list.remove(bullet)
                    playerscore += 1
                    numerofenemieskilled +=1
    
                     
                   
            # Remove the bullet if it flies up off the screen
                    if bullet.rect.y < 100:
                        bullet_list.remove(bullet)
                        all_sprites_list.remove(bullet)
                
                        
                ufo_hit_list = pygame.sprite.spritecollide(bullet, ufo_list, True)
                
                for ufo in ufo_hit_list:
                    ufo_explosion_list.add(UfoExplosion(ufo))
                    bullet_list.remove(bullet)
                    all_sprites_list.remove(bullet)
                    playerscore += 50
                    numerofufoskilled +=1
    
                        
            for ship in ship_list:
                    
                enemy_hit_list = pygame.sprite.spritecollide(ship, enemy_list, True)
             
            
                for enemy in enemy_hit_list:
                    playerHealth -=20
                    ShipExplosion(ship)
                    
                    if playerHealth ==0:
                        ship.Explode()
                        playerlife -=1
                        playerHealth = 200
                    
                    if playerlife  <= 0:
                        
                        gameLevel = 1
                        startscreen = 'false'
                        endscreen = 'false'
                        introscreen = 'true'
                        EndScreen()
                        
                    
            for enemy in enemy_list:
                interval = 20
                enemybullet = EnemyBullet()
                random_number = random.randrange(0,interval+10)
                if random_number == interval:
                    enemybullet.rect.x = enemy.rect.x + 20
                    enemybullet.rect.y = enemy.rect.y -20
                    enemy_bullet_list.add(enemybullet)
                    enemybullet.update()
                    all_sprites_list.add(enemybullet)
                  
            for ship in ship_list:
                ship_enemy_bullet_hit_list = pygame.sprite.spritecollide(ship, enemy_bullet_list, True)
                
                for enemybullet  in ship_enemy_bullet_hit_list:
                 
                    playerHealth -=20
                    ShipExplosion(ship)
                    
                    if playerHealth ==0:
                        ship.Explode()
                        playerlife -=1
                        playerHealth = 200
                    
                    if playerlife  <= 0:
                        gameLevel = 1
                        
                        startscreen = 'false'
                        endscreen = 'false'
                        introscreen = 'true'
                        EndScreen()
                        #end = 'false'
                     
            timerufo = DelayTimer(100)
            timeralien = DelayTimer(30)
            timerbadalien = DelayTimer(60)
    
            if timerufo == 90:
                SpawnUfos()
                     
            for ufo in ufo_list:
                if timeralien == 8:
                    ufoalien = UfoAlien()
                    ufoalien.rect.x = ufo.rect.x + 20
                    ufoalien.rect.y = ufo.rect.y -20
                    ufo_alien_list.add(ufoalien)
                    all_sprites_list.add(ufoalien)
                    ufo_alien_list.update()
                    
                       
              
            for ufo in ufo_list:
                if timerbadalien == 25:
                    ufobadalien = UfoBadAlien()
                    ufobadalien.rect.x = ufo.rect.x + 20
                    ufobadalien.rect.y = ufo.rect.y -20
                    ufo_bad_alien_list.add(ufobadalien)
                    all_sprites_list.add(ufobadalien)
                    ufo_bad_alien_list.update()
           
               
            for ufoalien in ufo_alien_list:
                ufo_alien_hit_list = pygame.sprite.spritecollide(ship, ufo_alien_list, True)
    
                for ufoalien in ufo_alien_hit_list:
                    
                    sound = pygame.mixer.Sound('alien-noise-01.ogg')
                    sound.play()
                    playerscore +=20
                    alienssavednumber +=1
                    alienssaved_list.add(alienssaved)
                    all_sprites_list.add(alienssaved)
                    ufo_alien_list.remove(ufoalien)
    
            for ufobadalien in ufo_bad_alien_list:
                ufo_bad_alien_hit_list = pygame.sprite.spritecollide(ship, ufo_bad_alien_list, True)
    
                for ufobadalien in ufo_bad_alien_hit_list:
                    
                    sound = pygame.mixer.Sound('alien-noise-01.ogg')
                    sound.play()
                    ufo_bad_alien_list.remove(ufobadalien)
                    playerscore -=20
                    playerHealth -=20
                    
                    if playerHealth ==0:
                        ship.Explode()
                        playerlife -=1
                        playerHealth = 200
                    
                    if playerlife  <= 0:
    
                        startscreen = 'false'
                        endscreen = 'false'
                        introscreen = 'true'
                        EndScreen()
    
                        
                
            all_sprites_list.draw(screen)
            allsprites.update()
            dirty = allsprites.draw(screen)
            pygame.display.update(dirty)
            pygame.display.flip()
      
            
    while 1:
      
    
        if introscreen == 'true':   
            exitcode = IntroScreen()# Menu and returns a number depending on if the players presses
            if exitcode == 0: # the space bar to start a game - so a 2 is returned or a 0 if they want
                          #to quit
                sys.exit(0)
            elif exitcode == 2:
                introscreen = 'false'
                endscreen = 'false'
                startscreen = 'true'
            # player has chosen to play!
                exitcode = 2
                startgame = 'true'
    
            gamelevel = 1
            playerScore = 0
        
            while exitcode == 2:
                
                #if endscreen == 'true':
                    #exitcode = EndScreen()
                    
                if startgame == 'true':
                    print ('Going to level', gamelevel)
                    exitcode = PlayGame(gamelevel)
            
                if exitcode == 0:
                # player asked to quit, return to the intro screen
                    exitcode == 2
                elif exitcode == 1:
                # end of game, player has died
                    break
                elif exitcode == 2:
                # level cleared, go to the next
                    gamelevel = gamelevel + 1
                #elif player.live <= 0:
                #gamelevel = 1
    '''        
    
    
    while 1:
        if intro == 'true':
            introexitcode = IntroScreen()
            print('true')
        if end == 'endtrue':
            endexitcode = EndScreen()
    
        
        if  introexitcode== 0:
    
            pygame.quit()
            break;
        elif introexitcode == 2:
            # player has chosen to play!
            exitcode = 2
    
        gamelevel = 1
        playerScore = 0
        while introexitcode == 2:
            print ('Going to level', gamelevel)
            introexitcode = PlayGame(gamelevel)
         
            if introexitcode == 0:
                
                # player asked to quit, return to the intro screen
                introexitcode = 2
            elif introexitcode == 1:
               
                break
            elif introexitcode == 2:
                # level cleared, go to the next
                gamelevel = gamelevel + 1
            elif ship.live <= 0:
           
                EndScreen()
                gamelevel = 1
    '''
    
    
    pygame.quit()
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    14
    Rep Power
    0
    Dude, we're not reading your entire code.... Try to me more specific about what the problem is or at least crop the piece of code in which you think the problem might be.

    Help us help ya.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    194
    Rep Power
    2

    o,_,0


    Yeah, definitely not going through that; especially without code tags.

    Here is an example template for a multi-scene pygame project:
    https://github.com/Mekire/pygame-mut...ate-with-movie

    We'll start with that.
    -Mek

IMN logo majestic logo threadwatch logo seochat tools logo