Advertisement
Teiji_W

Corrida - Tabs e Espaços

Sep 24th, 2017
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.19 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 unpause():
  28.     global pause
  29.     if pause == True:
  30.         pause = False
  31.  
  32. def pause():
  33.  
  34.     pygame.init()
  35.     global pause
  36.    
  37.     pause = True
  38.    
  39.     retanguloverde = pygame.Rect(150, 300, 100, 50)
  40.     retanguloverdecentro = retanguloverde.centerx
  41.    
  42.     retangulovermelho = pygame.Rect(330, 300, 100, 50)
  43.     retangulovermelhocentro = retangulovermelho.centerx  
  44.    
  45.     while pause:
  46.         global evento
  47.         for evento in pygame.event.get():
  48.             if evento.type == pygame.QUIT:
  49.                 pygame.quit()
  50.                 quit()
  51.                
  52.                
  53.         tela.fill(branca)
  54.        
  55.         fontearial = pygame.font.Font(r"C:\Windows\Fonts\arial.ttf", 60)
  56.        
  57.         texto = fontearial.render("Pause", 1, (0, 0, 0))
  58.         textol = texto.get_width()
  59.        
  60.         tela.blit(texto, ((tela_largura/2 - textol/2), tela_altura/2))
  61.  
  62.         mouse = pygame.mouse.get_pos()
  63.  
  64.    
  65.         if 150 + 100 > mouse[0] > 150 and 300 + 50 > mouse[1] > 300:
  66.             pygame.draw.rect(tela, contraste_verde, retanguloverde)
  67.             if evento.type is pygame.MOUSEBUTTONDOWN:
  68.                 unpause()
  69.         else:
  70.             pygame.draw.rect(tela, verde, retanguloverde)
  71.  
  72.         if 330+100 > mouse[0] > 330 and 300 + 50 > mouse[1] > 300:
  73.             pygame.draw.rect(tela, contraste_vermelha, retangulovermelho)
  74.             if evento.type is pygame.MOUSEBUTTONDOWN:
  75.                 pygame.quit()
  76.         else:
  77.             pygame.draw.rect(tela,vermelha, retangulovermelho)
  78.  
  79.         fontearial = pygame.font.Font(r"C:\Windows\Fonts\ariblk.ttf", 15)
  80.        
  81.         textosair = fontearial.render("EXIT", 1, (0, 0, 0))
  82.         textosairl = textosair.get_width()
  83.         tela.blit(textosair, (retangulovermelhocentro - textosairl/2,315))
  84.        
  85.         textovoltar = fontearial.render("CONTINUE", 1, (0,0,0))
  86.         textovoltarl = textovoltar.get_width()
  87.         tela.blit(textovoltar, (retanguloverdecentro - textovoltarl/2, 315))
  88.        
  89.         relogio.tick(120)
  90.         pygame.display.update()
  91.  
  92. def menu():
  93.  
  94.     pygame.init()
  95.     intro = True
  96.    
  97.     retanguloverde = pygame.Rect(150, 300, 100, 50)
  98.     retanguloverdecentro = retanguloverde.centerx
  99.    
  100.     retangulovermelho = pygame.Rect(330, 300, 100, 50)
  101.     retangulovermelhocentro = retangulovermelho.centerx  
  102.    
  103.     while intro:
  104.         for evento in pygame.event.get():
  105.             if evento.type == pygame.QUIT:
  106.                 pygame.quit()
  107.                 quit()
  108.         tela.fill(branca)
  109.        
  110.         fontearial = pygame.font.Font(r"C:\Windows\Fonts\arial.ttf", 60)
  111.        
  112.         texto = fontearial.render("Menu", 1, (0, 0, 0))
  113.         textol = texto.get_width()
  114.        
  115.         tela.blit(texto, ((tela_largura/2 - textol/2), tela_altura/2))
  116.  
  117.         mouse = pygame.mouse.get_pos()
  118.  
  119.         if 150 + 100 > mouse[0] > 150 and 300 + 50 > mouse[1] > 300:
  120.             pygame.draw.rect(tela, contraste_verde, retanguloverde)
  121.             if evento.type is pygame.MOUSEBUTTONDOWN:
  122.                 intro = False
  123.         else:
  124.             pygame.draw.rect(tela, verde, retanguloverde)
  125.  
  126.         if 330+100 > mouse[0] > 330 and 300 + 50 > mouse[1] > 300:
  127.             pygame.draw.rect(tela, contraste_vermelha, retangulovermelho)
  128.             if evento.type is pygame.MOUSEBUTTONDOWN:
  129.                 pygame.quit()
  130.         else:
  131.             pygame.draw.rect(tela,vermelha, retangulovermelho)
  132.  
  133.         fontearial = pygame.font.Font(r"C:\Windows\Fonts\ariblk.ttf", 15)
  134.        
  135.         textosair = fontearial.render("EXIT", 1, (0, 0, 0))
  136.         textosairl = textosair.get_width()
  137.         tela.blit(textosair, (retangulovermelhocentro - textosairl/2,315))
  138.        
  139.         textoentrar = fontearial.render("GO!", 1, (0,0,0))
  140.         textoentrarl = textoentrar.get_width()
  141.         tela.blit(textoentrar, (retanguloverdecentro - textoentrarl/2, 315))
  142.        
  143.         relogio.tick(120)
  144.         pygame.display.update()
  145.  
  146. def mestre():
  147.     pygame.init()
  148.  
  149.     global tela_largura, tela_altura
  150.     tela_largura = 600
  151.     tela_altura = 300
  152.  
  153.     global branca,azul,vermelha,verde,preta,contraste_verde,contraste_vermelha
  154.     branca = (255,255,255)
  155.     azul = (0,92,230)
  156.     vermelha = (200,0,0)
  157.     verde = (0,200,0)
  158.     preta = (0,0,0)
  159.     contraste_vermelha = (255,0,0)
  160.     contraste_verde = (0,255,0)
  161.  
  162.     global tela,relogio
  163.     tela = pygame.display.set_mode((tela_largura, tela_largura))
  164.     pygame.display.set_caption("Corrida")
  165.     relogio = pygame.time.Clock()
  166.  
  167.     menu()
  168.  
  169.     global carro
  170.     carro = pygame.image.load("carro.png")
  171.     carro = pygame.transform.scale(carro, (50,80))
  172.  
  173.     carro_largura = 50
  174.  
  175.     x = (tela_largura * 0.45)
  176.     y = (tela_altura * 1.68)
  177.  
  178.     coisa_xstart = random.randrange(0, tela_largura)
  179.     coisa_ystart = -300
  180.     coisa_velocidade = 6
  181.     coisa_largura = 100
  182.     coisa_altura = 100
  183.  
  184.     x_change1 = 0
  185.     x_change2 = 0
  186.     pont = 0
  187.  
  188.     sair = False
  189.  
  190.     while not sair:
  191.         global evento
  192.     for evento in pygame.event.get():
  193.         if evento.type == pygame.QUIT:
  194.         sair = True
  195.  
  196.         if evento.type is pygame.KEYDOWN:
  197.         if evento.key == pygame.K_LEFT:
  198.             x_change1 = -6 + (pont/10)
  199.         if evento.key == pygame.K_RIGHT:
  200.             x_change2 = 6 + (pont/10)
  201.         if evento.key == pygame.K_p:
  202.             unpause()
  203.             pause()
  204.        
  205.         if evento.type is pygame.KEYUP:
  206.         if evento.key == pygame.K_LEFT:
  207.             x_change1 = 0
  208.         if evento.key == pygame.K_RIGHT:
  209.             x_change2 = 0
  210.    
  211.     x += x_change1
  212.         x += x_change2
  213.        
  214.     tela.fill(branca)
  215.  
  216.         coisas(coisa_xstart, coisa_ystart, coisa_largura, coisa_altura, azul)
  217.         coisa_ystart += coisa_velocidade
  218.  
  219.         fcarro(x, y)
  220.         pontuação(pont)
  221.  
  222.         if x > tela_largura - carro_largura or x < 0:
  223.             quebrado()
  224.             sair = True
  225.         if coisa_ystart > tela_altura + 300:
  226.             coisa_ystart = 0 - coisa_altura
  227.             coisa_xstart = random.randrange(0, tela_largura)
  228.             pont += 1
  229.             coisa_velocidade += 0.02
  230.             coisa_largura += (pont * 1)
  231.             carro
  232.  
  233.         if y < coisa_ystart + coisa_altura:
  234.             if x > coisa_xstart and x < coisa_xstart + coisa_largura or x + carro_largura > coisa_xstart and x + carro_largura < coisa_xstart + coisa_largura:
  235.                 quebrado()
  236.                 sair = True
  237.  
  238.         relogio.tick(120)
  239.         pygame.display.update()
  240.     pygame.quit()
  241. mestre()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement