rishabbansal21

Day-10

Jan 19th, 2021 (edited)
431
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pygame, random
  2. pygame.init()
  3.  
  4. clock = pygame.time.Clock()
  5.  
  6. sw = 800
  7. sh = 600
  8. screen = pygame.display.set_mode((sw,sh))
  9. pygame.display.set_caption("TILE SMASHERS")
  10.  
  11. score = 0
  12. font_32 = pygame.font.Font('freesansbold.ttf', 32)
  13. font_64 = pygame.font.Font('freesansbold.ttf', 64)
  14.  
  15.  
  16. #ARCADE MODE
  17. life = 10
  18. clicked = False
  19. def Arcade_mode():
  20.     global clicked, font_32, font_64, life, score
  21.  
  22.     xy = [random.randint(50,700),random.randint(50,500)]
  23.     sCoord = (10,10)
  24.     def score_print(scr):
  25.         screen.blit(font_32.render("Score: "+str(scr), True, (0,0,0)), sCoord)
  26.  
  27.     def generate_box(x,y):
  28.         return(pygame.Rect(x,y,100,100))
  29.  
  30.     def isClicked(cxy, cmx, cmy):
  31.         if cxy[0] < cmx < cxy[0] + 100 and cxy[1] < cmy < cxy[1] + 100:
  32.             return True
  33.         return False
  34.  
  35.     def draw_lifes(l):
  36.         for i in range(l):
  37.             pygame.draw.circle(screen, (100,100,0), (760 - 30*i, 20), 15)
  38.  
  39.     start = pygame.time.get_ticks()
  40.     MainRun = True
  41.     while MainRun:
  42.         screen.fill((200,200,200))
  43.         for event in pygame.event.get():
  44.             if event.type == pygame.QUIT:
  45.                 MainRun = False
  46.             if event.type == pygame.MOUSEBUTTONDOWN:
  47.                 if event.button == 1:
  48.                     clicked = True
  49.             if event.type == pygame.MOUSEBUTTONUP:
  50.                 if event.button == 1:
  51.                     clicked = False
  52.  
  53.         box = generate_box(xy[0], xy[1])
  54.         pygame.draw.rect(screen, (255,0,0), box)
  55.  
  56.         mx,my = pygame.mouse.get_pos()
  57.         current_time = pygame.time.get_ticks()
  58.         if (current_time - start > 2000):
  59.             if clicked == False:
  60.                 life -= 1
  61.             start = pygame.time.get_ticks()
  62.             xy = [random.randint(50,700), random.randint(50,500)]
  63.  
  64.         if clicked:
  65.             if (current_time - start < 2000) and isClicked(xy, mx, my):
  66.                 pygame.draw.rect(screen, (0,255,0), box)
  67.                 clicked = False
  68.                 score += 1
  69.                 start = pygame.time.get_ticks()
  70.                 xy = [random.randint(50,700), random.randint(0,500)]
  71.  
  72.             elif (current_time - start < 2000) and not(isClicked(xy, mx, my)):
  73.                 clicked = False
  74.                 life -= 1
  75.                 print(life)
  76.                 xy = [random.randint(50,700), random.randint(50,500)]
  77.                 start = pygame.time.get_ticks()
  78.  
  79.         draw_lifes(life)
  80.  
  81.         if life <= 0:
  82.             screen.fill((200,200,200))
  83.             msg = font_64.render("GAME OVER!!", True, (0,0,0))
  84.             screen.blit(msg, (180,200))
  85.  
  86.             fsc = font_32.render("FINAL SCORE: "+str(score), True, (0,0,0))
  87.             screen.blit(fsc, (280,300))
  88.  
  89.         score_print(score)
  90.         clock.tick(60)
  91.         pygame.display.update()
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98. clicked = False
  99. mode = 0
  100. state = 0
  101. MainRun = True
  102. while MainRun:
  103.     screen.fill((200,200,200))
  104.     for event in pygame.event.get():
  105.         if event.type == pygame.QUIT:
  106.             MainRun = False
  107.  
  108.         if event.type == pygame.MOUSEBUTTONDOWN:
  109.             if event.button == 1:
  110.                 clicked = True
  111.         if event.type == pygame.MOUSEBUTTONUP:
  112.             if event.button == 1:
  113.                 clicked = False
  114.  
  115.     mx, my = pygame.mouse.get_pos()
  116.  
  117.     if clicked and state == 0:
  118.         if 285<mx<420 and sh-360<my<sh-323: mode = 1
  119.         elif 285<mx<420 and sh-320<my<sh-283: mode = 2
  120.         elif sw//2-95 < mx < sw//2+95 and sh-150 < my <sh-30: state = 1
  121.  
  122.     if mode == 1:
  123.         pygame.draw.rect(screen, (255,0,0), pygame.Rect(285,sh-365,200,37),2)
  124.     elif mode == 2:
  125.         pygame.draw.rect(screen, (255,0,0), pygame.Rect(285,sh-325,200,37), 2)
  126.  
  127.     if state == 1:
  128.         pygame.draw.rect(screen, (0,255,0), pygame.Rect(sw//2-95,sh-107,230,70),  2)
  129.         if mode == 1:
  130.             MainRun = False
  131.             #Time_out_mode()
  132.  
  133.         if mode == 2:
  134.             MainRun = False
  135.             Arcade_mode()
  136.  
  137.  
  138.     Welcome_Message = font_64.render("TILE SMASHERS", True, (0,0,200))
  139.     screen.blit(Welcome_Message, (150, 20))
  140.  
  141.     Select_Mode = font_32.render("SELECT MODE:", True, (0,0,200))
  142.     screen.blit(Select_Mode, (10, sh-400))
  143.  
  144.     Time_out = font_32.render("TIME-OUT", True, (0,0,200))
  145.     screen.blit(Time_out, (290, sh-360))
  146.  
  147.     Arcade = font_32.render("ARCADE", True, (0,0,200))
  148.     screen.blit(Arcade, (290, sh- 320))
  149.  
  150.     Start = font_64.render("START", True, (0,0,200))
  151.     screen.blit(Start, (sw//2 - 80, sh-100))
  152.    
  153.     clock.tick(10)
  154.     pygame.display.update()
RAW Paste Data