Import Random #-WPS Office
Import Random #-WPS Office
import pygame
FPS = 32
SCREENWIDTH = 289
SCREENHEIGHT = 511
GAME_SPRITES = {}
GAME_SOUNDS = {}
PLAYER = 'gallery/sprites/bird.png'
BACKGROUND = 'gallery/sprites/background.png'
PIPE = 'gallery/sprites/pipe.png'
def welcomeScreen():
"""
"""
playerx = int(SCREENWIDTH/5)
basex = 0
while True:
pygame.quit()
sys.exit()
# If the user presses space or up key, start the game for them
return
else:
SCREEN.blit(GAME_SPRITES['message'], (messagex,messagey ))
pygame.display.update()
FPSCLOCK.tick(FPS)
def mainGame():
score = 0
playerx = int(SCREENWIDTH/5)
playery = int(SCREENWIDTH/2)
basex = 0
# Create 2 pipes for blitting on the screen
newPipe1 = getRandomPipe()
newPipe2 = getRandomPipe()
upperPipes = [
lowerPipes = [
pipeVelX = -4
playerVelY = -9
playerMaxVelY = 10
playerMinVelY = -8
playerAccY = 1
pygame.quit()
sys.exit()
if playery > 0:
playerVelY = playerFlapAccv
playerFlapped = True
GAME_SOUNDS['wing'].play()
crashTest = isCollide(playerx, playery, upperPipes, lowerPipes) # This function will return true if the
player is crashed
if crashTest:
return
score +=1
playerVelY += playerAccY
if playerFlapped:
playerFlapped = False
playerHeight = GAME_SPRITES['player'].get_height()
upperPipe['x'] += pipeVelX
lowerPipe['x'] += pipeVelX
# Add a new pipe when the first is about to cross the lefmost part of the screen
if 0<upperPipes[0]['x']<5:
newpipe = getRandomPipe()
upperPipes.append(newpipe[0])
lowerPipes.append(newpipe[1])
upperPipes.pop(0)
lowerPipes.pop(0)
width = 0
width += GAME_SPRITES['numbers'][digit].get_width()
Xoffset += GAME_SPRITES['numbers'][digit].get_width()
pygame.display.update()
FPSCLOCK.tick(FPS)
GAME_SOUNDS['hit'].play()
return True
pipeHeight = GAME_SPRITES['pipe'][0].get_height()
GAME_SOUNDS['hit'].play()
return True
GAME_SOUNDS['hit'].play()
return True
return False
def getRandomPipe():
"""
Generate positions of two pipes(one bottom straight and one top rotated ) for blitting on the screen
"""
pipeHeight = GAME_SPRITES['pipe'][0].get_height()
offset = SCREENHEIGHT/3
pipeX = SCREENWIDTH + 10
y1 = pipeHeight - y2 + offset
pipe = [
return pipe
if __name__ == "__main__":
# This will be the main point from where our game will start
FPSCLOCK = pygame.time.Clock()
GAME_SPRITES['numbers'] = (
pygame.image.load('gallery/sprites/0.png').convert_alpha(),
pygame.image.load('gallery/sprites/1.png').convert_alpha(),
pygame.image.load('gallery/sprites/2.png').convert_alpha(),
pygame.image.load('gallery/sprites/3.png').convert_alpha(),
pygame.image.load('gallery/sprites/4.png').convert_alpha(),
pygame.image.load('gallery/sprites/5.png').convert_alpha(),
pygame.image.load('gallery/sprites/6.png').convert_alpha(),
pygame.image.load('gallery/sprites/7.png').convert_alpha(),
pygame.image.load('gallery/sprites/8.png').convert_alpha(),
pygame.image.load('gallery/sprites/9.png').convert_alpha(),
GAME_SPRITES['message'] =pygame.image.load('gallery/sprites/message.png').convert_alpha()
GAME_SPRITES['base'] =pygame.image.load('gallery/sprites/base.png').convert_alpha()
pygame.image.load(PIPE).convert_alpha()
# Game sounds
GAME_SOUNDS['die'] = pygame.mixer.Sound('gallery/audio/die.wav')
GAME_SOUNDS['hit'] = pygame.mixer.Sound('gallery/audio/hit.wav')
GAME_SOUNDS['point'] = pygame.mixer.Sound('gallery/audio/point.wav')
GAME_SOUNDS['swoosh'] = pygame.mixer.Sound('gallery/audio/swoosh.wav')
GAME_SOUNDS['wing'] = pygame.mixer.Sound('gallery/audio/wing.wav')
GAME_SPRITES['background'] = pygame.image.load(BACKGROUND).convert()
GAME_SPRITES['player'] = pygame.image.load(PLAYER).convert_alpha()
while True: