def end(score , board): level = board.getLevel()#gets level of player instance created in "board.py" life = board.player.life#gets life's of player instance created in "board.py" pygame.init()#Initialized Pygame clock = pygame.time.Clock()#Initialize pygame clock which is used to control frames per second and bunch of different time realted things music = musicloader("game_over.ogg")#loads the music and is basically a call to the class musicloader in loader.py music.play()#starts the music screen = pygame.display.set_mode((SCREENWIDTH , SCREENHEIGHT))#sets up the pygame screen , all the constant with capital letter are defined inside of constant.py running = True#Loop runner background = pygame.Surface(screen.get_size())#gets size of the pygame surface background = background.convert()#converts background , which is faster for blitting sprites onto it background.fill(BLACK)#fills the background with BLACK COLOR and is defined inside of constant.py while running : for event in pygame.event.get():#checks for the interrupts raised by I/O devices if event.type == pygame.QUIT :#checks if the cross button on the top of the window is hitted sys.exit()#exits everything elif event.type == pygame.KEYDOWN :#checks if the any key is pressed down if event.key == pygame.K_ESCAPE :#checks if escape button is pressed down sys.exit() font = pygame.font.Font(None, 48)#sets font size with None effect (Means just Normal Text) font2 = pygame.font.Font(None, 96) if level == 3 and life >0 : text2 = font2.render( "YOU WON ! " , 1, GREEN)#basically renders the word with GREEN color else : text2 = font2.render( "YOU LOST ! " , 1, RED) text = font.render( "You score: %s" %str(score), 1, BLUE ) #in both the textpos we have overriden the centerx and centery to make the text position beautiful and have exctracted background's width and height textpos = text.get_rect(centerx=background.get_width()/2 -50 , centery=background.get_height()/2+50) textpos2 = text.get_rect(centerx=background.get_width()/2 -100 , centery=background.get_height()/2-50) screen.blit(text, textpos)#kind of attach/render it to screen screen.blit(text2 , textpos2) pygame.display.update()#Keep on updating the screen because it will be rendered everytime it will be run clock.tick(FPSLOW)#set's the frame per second to the variable FPSLOW (look constant.py) music.stop()#stops the music (defined in musicloader class in loader.py file)
def __init__(self , width , height ,level , life ,coins): pygame.init()#initialises pygame self.height = height self.width = width self.screen = pygame.display.set_mode((self.width,self.height))#sets up display for pygame self.clock = pygame.time.Clock()#Initialize pygame clock which is used to control frames per second and bunch of different time realted things self.firelist = []#Contain all the sprites of fire self.running = 1 #loop running variable self.__level = level # private variable and sets it to current level self.score = 0 #score of player self.theme_music = musicloader("main_theme.ogg")#loads in the music from musicloader class of "loader.py" self.coin_sound = soundloader("coin.ogg")#loads in the coin taking sound from soundloader class of "loader.py" #difference between music and sound is that music is like game song and sound is like sound effects , only one music can be loaded and #hence played at a time and at max eight sounds can be played together self.theme_music.play()#playes in the music self.play(life , coins)#calls play function if self.__level <=2 and self.player.life:#if life is > 0 and level is less or equal to 2 start(self.__level , self.player.life , self.player.coins) self.theme_music.stop()#stops the music end(self.score , self)#calls in end function from "end.py"
def intro(): pygame.init() #Initialized Pygame clock = pygame.time.Clock() #Initialize pygame clock which is used to control frames per second and bunch of different time realted things music = musicloader("invincible.ogg")#loads the music and is basically a call to the class musicloader in loader.py music.play()#starts the music screen = pygame.display.set_mode((SCREENWIDTH , SCREENHEIGHT))#sets up the pygame screen , all the constant with capital letter are defined inside of constant.py running = True#Loop runner flag = 0 background = pygame.Surface(screen.get_size())#gets size of the pygame surface background = background.convert()#converts background , which is faster for blitting sprites onto it background.fill(BLACK)#fills the background with BLACK COLOR and is defined inside of constant.py while running : for event in pygame.event.get():#checks for the interrupts raised by I/O devices if event.type == pygame.QUIT :#checks if the cross button on the top of the window is hitted sys.exit()#exits everything elif event.type == pygame.KEYDOWN :#checks if the any key is pressed down if event.key == pygame.K_RETURN :#checks if enter button is hit running = False#stops the loop si that the program terminates and the game starts (look main.py) elif event.key == pygame.K_ESCAPE :#checks if escape button is hitted down sys.exit() font = pygame.font.Font(None, 96)#sets font size with None effect (Means just Normal Text) font2 = pygame.font.Font(None, 24) flag ^=1 if flag : text = font.render("DONKEY-KONG" , 1, BLUE)#basically renders the word with BLUE color else: text = font.render("DONKEY-KONG" , 1, GREEN) text2 = font2.render("PRESS ENTER TO START THE GAME" , 1, WHITE) #in both the textpos we have overriden the centerx and centery to make the text position beautiful and have exctracted background's width and height textpos2 = text.get_rect(centerx=background.get_width()/2 + 100, centery=background.get_height()/2 + 100) textpos = text.get_rect(centerx=background.get_width()/2 , centery=background.get_height()/2 - 50) screen.blit(text, textpos)#kind of attach/render it to screen screen.blit(text2, textpos2) pygame.display.update()#Keep on updating the screen because it will be rendered everytime it will be run clock.tick(FPSLOW)#set's the frame per second to the variable FPSLOW (look constant.py) music.stop()#stops the music (defined in musicloader class in loader.py file)