SHARE
TWEET

LABIRINTO PYGAME

jpvieiraa Jun 4th, 2018 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pygame, sys
  2. from pygame.locals import*
  3. import time
  4.  
  5. pygame.init()
  6. tela=pygame.display.set_mode([600,450])
  7.  
  8. FPS = 60
  9. fpsClock = pygame.time.Clock()
  10. pygame.display.set_caption("LABIRINTO ANTI-COLISÃO")
  11. relogio = pygame.time.Clock()
  12.  
  13. BLACK = ( 0, 0, 0)
  14. WHITE = (255, 255, 255)
  15. RED = (255, 0, 0)
  16. GREEN = ( 0, 255, 0)
  17. BLUE = (33, 175, 222)
  18. YELLOW=(255,255,0)
  19.  
  20. sup = pygame.Surface((600,450))
  21. sup.fill(BLUE)
  22.  
  23. frame_count = 0
  24. frame_rate = 60
  25.  
  26. menor=float("inf")
  27.  
  28. pygame.font.init()
  29. pygame.mouse.set_pos(0,0)
  30.  
  31. ret = pygame.Rect(0,0,30,30)
  32. ret2 = pygame.Rect(10,40,100,20)
  33. ret3 = pygame.Rect(150,40,50,20)
  34. ret4 = pygame.Rect(240,40,70,20)
  35. ret5 = pygame.Rect(340,40,30,100)
  36. ret6 = pygame.Rect(410,40,30,50)
  37. ret7 = pygame.Rect(470,40,100,20)
  38. ret8 = pygame.Rect(10,80,100,20)
  39. ret9 = pygame.Rect(150,80,75,30)
  40. ret10 = pygame.Rect(270,80,50,50)
  41. ret11 = pygame.Rect(410,130,50,20)
  42. ret12 = pygame.Rect(495,80,150,20)
  43. ret13 = pygame.Rect(10,150,200,40)
  44. ret14 = pygame.Rect(250,160,30,50)
  45. ret15 = pygame.Rect(500,160,30,100)
  46. ret16 = pygame.Rect(70,230,150,20)
  47. ret17 = pygame.Rect(270,80,50,50)
  48. ret19 = pygame.Rect(340,200,40,150)
  49. ret20 = pygame.Rect(500,120,100,20)
  50. ret21 = pygame.Rect(250,160,30,50)
  51. ret22 = pygame.Rect(520,160,30,100)
  52. ret23 = pygame.Rect(0,40,1,450)
  53. ret24 = pygame.Rect(0,450,600,0)
  54. ret25 = pygame.Rect(600,40,1,410)
  55. ret26 = pygame.Rect(570,420,30,30)
  56. ret27 = pygame.Rect(60,285,60,30)
  57. ret28 = pygame.Rect(0,330,80,30)
  58. ret29 = pygame.Rect(140,285,150,30)
  59. ret30 = pygame.Rect(230,330,80,30)
  60. ret31 = pygame.Rect(120,330,80,30)
  61. ret31 = pygame.Rect(370,40,10,50)
  62. ret32 = pygame.Rect(400,170,60,60)
  63. ret33 = pygame.Rect(400,260,60,150)
  64. ret34 = pygame.Rect(500,295,60,120)
  65.  
  66. font = pygame.font.Font(None, 25)
  67.  
  68. def menu():
  69.     menu = True
  70.     texto = "Pressiona C para continuar e S para sair"
  71.     texto2 = "Trabalho realizado por: João Vieira"
  72.     texto3 = "Este jogo pretende que arrastando um quadrado verde com o rato,"
  73.     texto4 = " ultrapasse os obstáculos sem tocar neles nem nas bordas chegando"
  74.     texto5 = " ao quadrado amarelo."
  75.     while menu:
  76.         tela.fill(WHITE)
  77.         text = font.render(texto, True, BLACK)
  78.         text2 = font.render(texto2, True, BLACK)
  79.         text3 = font.render(texto3, True, BLACK)
  80.         text4 = font.render(texto4, True, BLACK)
  81.         text5 = font.render(texto5, True, BLACK)
  82.         tela.blit(text, [135,280])
  83.         tela.blit(text2, [150,100])
  84.         tela.blit(text3, [25,150])
  85.         tela.blit(text4, [15,190])
  86.         tela.blit(text5, [200,230])
  87.         for event in pygame.event.get():
  88.             if event.type == QUIT:
  89.                 pygame.quit()
  90.                 sys.exit()
  91.             if event.type == pygame.KEYDOWN:
  92.                 if event.key == pygame.K_s:
  93.                     pygame.quit()
  94.                     sys.exit()
  95.                 if event.key == pygame.K_c:
  96.                     menu = False
  97.         pygame.display.update()
  98.         fpsClock.tick(FPS)
  99. def menuf():
  100.     menuf = True
  101.     texto = "O seu tempo foi de: {} minutos e {} segundos".format(minutes,seconds)
  102.     texto4= "Trabalho realizado por : João Vieira"
  103.     texto3="Pressione R para Recomeçar e S para Sair"
  104.     texto2="O melhor tempo foi de {} minutos e de {} segundos".format(w,y)
  105.     while menuf:
  106.         tela.fill(WHITE)
  107.         text = font.render(texto, True, BLACK)
  108.         text2 = font.render(texto2, True, BLACK)
  109.         text3 = font.render(texto3, True, BLACK)
  110.         text4 = font.render(texto4, True, BLACK)
  111.         tela.blit(text, [120,150])
  112.         tela.blit(text2, [110,200])
  113.         tela.blit(text3, [130,250])
  114.         tela.blit(text4, [150,300])
  115.        
  116.         for event in pygame.event.get():
  117.             if event.type == QUIT:
  118.                 pygame.quit()
  119.                
  120.                 sys.exit()
  121.             if event.type == pygame.KEYDOWN:
  122.                
  123.                    
  124.                 if event.key == pygame.K_s:
  125.                     pygame.quit()
  126.                     sys.exit()
  127.                 if event.key == pygame.K_r:
  128.                     menuf = False
  129.         pygame.display.update()
  130.         fpsClock.tick(FPS)      
  131. clock = pygame.time.Clock()
  132. menu()
  133. while True:
  134.     for event in pygame.event.get():
  135.         if event.type == QUIT:
  136.             pygame.quit()
  137.             sys.exit()
  138.     relogio.tick(60)
  139.     tela.blit(sup, [0,0])
  140.    
  141.     (xanterior, yanterior)=(ret.left, ret.top)
  142.     (ret.left, ret.top)=pygame.mouse.get_pos()
  143.    
  144.     ret.left-=ret.width/2
  145.     ret.top-=ret.height/2
  146.    
  147.     if(ret.colliderect(ret2) or ret.colliderect(ret3) or ret.colliderect(ret4) or ret.colliderect(ret5) or ret.colliderect(ret6) or ret.colliderect(ret7) or ret.colliderect(ret8) or ret.colliderect(ret9) or ret.colliderect(ret10) or ret.colliderect(ret11) or ret.colliderect(ret12) or ret.colliderect(ret13) or ret.colliderect(ret14) or ret.colliderect(ret15) or ret.colliderect(ret16) or ret.colliderect(ret17) or ret.colliderect(ret19) or ret.colliderect(ret20) or ret.colliderect(ret21) or ret.colliderect(ret22) or ret.colliderect(ret23) or ret.colliderect(ret24) or ret.colliderect(ret25) or ret.colliderect(ret27) or ret.colliderect(ret28) or ret.colliderect(ret29) or ret.colliderect(ret30) or ret.colliderect(ret31) or ret.colliderect(ret32) or ret.colliderect(ret33) or ret.colliderect(ret34)):
  148.         (ret.left, ret.top) = (xanterior, yanterior)
  149.         pygame.mouse.set_pos(0,0)
  150.  
  151.     pygame.draw.rect(tela,GREEN, ret)
  152.     pygame.draw.rect(tela,RED, ret2)
  153.     pygame.draw.rect(tela,RED, ret3)
  154.     pygame.draw.rect(tela,RED, ret4)
  155.     pygame.draw.rect(tela,RED, ret5)
  156.     pygame.draw.rect(tela,RED, ret6)
  157.     pygame.draw.rect(tela,RED, ret7)
  158.     pygame.draw.rect(tela,RED, ret8)
  159.     pygame.draw.rect(tela,RED, ret9)
  160.     pygame.draw.rect(tela,RED, ret10)
  161.     pygame.draw.rect(tela,RED, ret11)
  162.     pygame.draw.rect(tela,RED, ret12)
  163.     pygame.draw.rect(tela,RED, ret13)
  164.     pygame.draw.rect(tela,RED, ret14)
  165.     pygame.draw.rect(tela,RED, ret15)
  166.     pygame.draw.rect(tela,RED, ret16)
  167.     pygame.draw.rect(tela,RED, ret17)
  168.     pygame.draw.rect(tela,RED, ret19)
  169.     pygame.draw.rect(tela,RED, ret20)
  170.     pygame.draw.rect(tela,RED, ret21)
  171.     pygame.draw.rect(tela,RED, ret22)
  172.     pygame.draw.rect(tela,BLUE, ret23)
  173.     pygame.draw.rect(tela,BLUE, ret24)
  174.     pygame.draw.rect(tela,RED,ret25)
  175.     pygame.draw.rect(tela,YELLOW,ret26)
  176.     pygame.draw.rect(tela,RED,ret27)
  177.     pygame.draw.rect(tela,RED,ret28)
  178.     pygame.draw.rect(tela,RED,ret29)
  179.     pygame.draw.rect(tela,RED,ret30)
  180.     pygame.draw.rect(tela,RED,ret31)
  181.     pygame.draw.rect(tela,RED,ret32)
  182.     pygame.draw.rect(tela,RED,ret33)
  183.     pygame.draw.rect(tela,RED,ret34)
  184.    
  185.     total_seconds = frame_count // frame_rate
  186.  
  187.     minutes = total_seconds // 60
  188.  
  189.     seconds = total_seconds % 60
  190.  
  191.     output_string = "Time: {0:02}:{1:02}".format(minutes, seconds)
  192.  
  193.     text = font.render(output_string, True, BLACK)
  194.     tela.blit(text, [500, 0])
  195.  
  196.     frame_count += 1
  197.    
  198.     if ret.colliderect(ret26):
  199.         m=minutes
  200.         s=seconds
  201.         if((m*60+s)<menor):
  202.             menor=total_seconds
  203.             w=m
  204.             y=s
  205.  
  206.         menuf()
  207.         frame_count = 0
  208.         pygame.mouse.set_pos(0,0)
  209.         total_seconds=0
  210.  
  211.    
  212.     pygame.display.update()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top