Advertisement
TWTsnoW

"FLAPPY BIRD" EM PYTHON

Sep 9th, 2017
1,144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.29 KB | None | 0 0
  1. //IMPORTANDO BIBLIOTECAS
  2. import pygame
  3. from random import randint
  4.  
  5. //DEFININDO CORES
  6. black = (0,0,0)
  7. white = (255,255,255)
  8. green = (0,255,0)
  9. red = (255,0,0)
  10.  
  11. //INICIANDO O PYGAME
  12. pygame.init()
  13.  
  14. //DEFININDO TAMANHO DA TELA,TELA E O NOME DA JANELA
  15. size = 700,500
  16. screen = pygame.display.set_mode(size)
  17. pygame.display.set_caption("Flappy Bird")
  18.  
  19. done = False
  20. clock = pygame.time.Clock()
  21.  
  22. //MANDANDO O PYGAME ESCREVER UM CIRCULO TODA VEZ QUE EU CHAMAR A FUNÇAO ball()
  23. def ball(x,y):
  24.     pygame.draw.circle(screen,black,(x,y), 20)
  25.  
  26. def gameover():
  27.     font = pygame.font.SysFont(None,75)
  28.     text = font.render("Game Over", True, red)
  29.     screen.blit(text, [150, 250])
  30.  
  31. def obstacle(xloc, yloc, xsize, ysize):
  32.     pygame.draw.rect(screen, green, [xloc,yloc,xsize,ysize])
  33.     pygame.draw.rect(screen, green, [xloc, int(yloc+ysize+space),xsize, ysize+500])
  34.  
  35. def Score(score):
  36.     font = pygame.font.SysFont(None, 45)
  37.     text = font.render("Pontuação: "+str(score),True,black)
  38.     screen.blit(text, [0, 0])
  39.  
  40. x = 350
  41. y=  250
  42. x_speed = 0
  43. y_speed = 0
  44. ground = 477
  45. xloc = 600
  46. yloc = 0
  47. xsize = 80
  48. ysize = randint(0,350)
  49. space = 100
  50. obspeed = 2.0
  51. score = 0
  52.  
  53. while not done:
  54.     for event in pygame.event.get():
  55.         if event.type == pygame.QUIT:
  56.             done = True
  57.  
  58.         if event.type == pygame.KEYDOWN:
  59.             if event.key == pygame.K_UP:
  60.                 y_speed = -10
  61.         if event.type == pygame.KEYUP:
  62.             if event.key == pygame.K_UP:
  63.                 y_speed = 5
  64.  
  65.     screen.fill(white)
  66.     obstacle(xloc, yloc, xsize, ysize)
  67.     ball(x,y)
  68.     Score(score)
  69.  
  70.     y -= y_speed
  71.     xloc -= obspeed
  72.  
  73.     if y > ground:
  74.         gameover()
  75.         y_speed = 0
  76.         obspeed = 0
  77.  
  78.     if x+20 > xloc and y-20 < ysize and x-15 < xsize+xloc:
  79.         gameover()
  80.         obspeed = 0
  81.         y_speed = 0
  82.  
  83.     else:
  84.         xloc -= obspeed
  85.         y += y_speed
  86.  
  87.     if x+20 > xloc and y+20 > ysize+space and x-15 < xsize+xloc:
  88.         gameover()
  89.         obspeed = 0
  90.         y_speed = 0
  91.  
  92.     else:
  93.         xloc -= obspeed
  94.         y += y_speed
  95.  
  96.     if xloc < -80:
  97.         xloc = 700
  98.         ysize = randint(0,350)
  99.  
  100.     if x > xloc and x < xloc+3:
  101.         score = (score + 1)
  102.  
  103.     pygame.display.flip()
  104.     clock.tick(60)
  105.  
  106. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement