Advertisement
Teiji_W

Corrida - Glitch

Sep 12th, 2017
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.15 KB | None | 0 0
  1. import pygame
  2. import time
  3. import random
  4.  
  5. def pontuação(pont):
  6.     fontearial = pygame.font.Font(r"C:\Windows\Fonts\arial.ttf", 25)
  7.     texto2 = fontearial.render(("Pontuação: " + str(pont)), 1, (0,0,0))
  8.     tela.blit(texto2, (0, 0))
  9.     pygame.display.update()
  10.  
  11. def fcarro(x, y):
  12.     tela.blit(carro, (x,y))
  13.  
  14. def coisas(coisax, coisay, coisalargura, coisaaltura, cor):
  15.     pygame.draw.rect(tela, cor, [coisax, coisay, coisalargura, coisaaltura])
  16.  
  17. def quebrado():
  18.     global fontearial
  19.     fontepadrao = pygame.font.get_default_font()
  20.     fontearial = pygame.font.Font(r"C:\Windows\Fonts\arial.ttf", 45)
  21.     texto = fontearial.render("Bateu", 1, (0, 0, 0))
  22.     tela.blit(texto, (240, 50))
  23.     relogio.tick(120)
  24.     pygame.display.update()
  25.     time.sleep(1.5)
  26.  
  27. def mestre():
  28.     pygame.init()
  29.  
  30.     global tela_largura, tela_altura
  31.     tela_largura = 600
  32.     tela_altura = 300
  33.  
  34.     branca = (255,255,255)
  35.     azul = (0,92,230)
  36.     vermelha = (255,0,0)
  37.     verde = (0,153,0)
  38.     preta = (0,0,0)
  39.  
  40.     global tela,relogio
  41.     tela = pygame.display.set_mode((tela_largura, tela_largura))
  42.     pygame.display.set_caption("Corrida")
  43.     relogio = pygame.time.Clock()
  44.  
  45.     global carro
  46.     carro = pygame.image.load("carro.png")
  47.     carro = pygame.transform.scale(carro, (50,80))
  48.  
  49.     carro_largura = 50
  50.  
  51.     x = (tela_largura * 0.45)
  52.     y = (tela_altura * 1.68)
  53.  
  54.     coisa_xstart = random.randrange(0, tela_largura)
  55.     coisa_ystart = -300
  56.     coisa_velocidade = 6
  57.     coisa_largura = 100
  58.     coisa_altura = 100
  59.  
  60.     x_change = 0
  61.     pont = 0
  62.  
  63.     sair = False
  64.  
  65.     while not sair:
  66.         for evento in pygame.event.get():
  67.             if evento.type == pygame.QUIT:
  68.                 sair = True
  69.  
  70.             if evento.type is pygame.KEYDOWN:
  71.                 if evento.key == pygame.K_LEFT:
  72.                     x_change = -4
  73.                 if evento.key == pygame.K_RIGHT:
  74.                     x_change = 4
  75.             if evento.type is pygame.KEYUP: #Aqui ocorre o Glitch
  76.                 if evento.key == pygame.K_LEFT:
  77.                     x_change = 0
  78.                     print("kleft")
  79.                 if evento.key == pygame.K_RIGHT:
  80.                     print("kright")
  81.                     x_change = 0
  82.  
  83.         x += x_change
  84.         tela.fill(branca)
  85.  
  86.         coisas(coisa_xstart, coisa_ystart, coisa_largura, coisa_altura, azul)
  87.         coisa_ystart += coisa_velocidade
  88.  
  89.         fcarro(x, y)
  90.         pontuação(pont)
  91.  
  92.         if x > tela_largura - carro_largura or x < 0:
  93.             quebrado()
  94.             sair = True
  95.         if coisa_ystart > tela_altura + 300:
  96.             coisa_ystart = 0 - coisa_altura
  97.             coisa_xstart = random.randrange(0, tela_largura)
  98.             pont += 1
  99.             coisa_velocidade += 0.02
  100.             coisa_largura += (pont * 1)
  101.  
  102.         if y < coisa_ystart + coisa_altura:
  103.             if x > coisa_xstart and x < coisa_xstart + coisa_largura or x + carro_largura > coisa_xstart and x + carro_largura < coisa_xstart + coisa_largura:
  104.                 quebrado()
  105.                 sair = True
  106.  
  107.         relogio.tick(120)
  108.         pygame.display.update()
  109.     pygame.quit()
  110. mestre()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement