Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame, random
- pygame.init()
- clock = pygame.time.Clock()
- sw = 800
- sh = 600
- screen = pygame.display.set_mode((sw,sh))
- pygame.display.set_caption("TILE SMASHERS")
- score = 0
- font_32 = pygame.font.Font('freesansbold.ttf', 32)
- font_64 = pygame.font.Font('freesansbold.ttf', 64)
- #ARCADE MODE
- life = 10
- clicked = False
- def Arcade_mode():
- global clicked, font_32, font_64, life, score
- xy = [random.randint(50,700),random.randint(50,500)]
- sCoord = (10,10)
- def score_print(scr):
- screen.blit(font_32.render("Score: "+str(scr), True, (0,0,0)), sCoord)
- def generate_box(x,y):
- return(pygame.Rect(x,y,100,100))
- def isClicked(cxy, cmx, cmy):
- if cxy[0] < cmx < cxy[0] + 100 and cxy[1] < cmy < cxy[1] + 100:
- return True
- return False
- def draw_lifes(l):
- for i in range(l):
- pygame.draw.circle(screen, (100,100,0), (760 - 30*i, 20), 15)
- start = pygame.time.get_ticks()
- MainRun = True
- while MainRun:
- screen.fill((200,200,200))
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- MainRun = False
- if event.type == pygame.MOUSEBUTTONDOWN:
- if event.button == 1:
- clicked = True
- if event.type == pygame.MOUSEBUTTONUP:
- if event.button == 1:
- clicked = False
- box = generate_box(xy[0], xy[1])
- pygame.draw.rect(screen, (255,0,0), box)
- mx,my = pygame.mouse.get_pos()
- current_time = pygame.time.get_ticks()
- if (current_time - start > 2000):
- if clicked == False:
- life -= 1
- start = pygame.time.get_ticks()
- xy = [random.randint(50,700), random.randint(50,500)]
- if clicked:
- if (current_time - start < 2000) and isClicked(xy, mx, my):
- pygame.draw.rect(screen, (0,255,0), box)
- clicked = False
- score += 1
- start = pygame.time.get_ticks()
- xy = [random.randint(50,700), random.randint(0,500)]
- elif (current_time - start < 2000) and not(isClicked(xy, mx, my)):
- clicked = False
- life -= 1
- print(life)
- xy = [random.randint(50,700), random.randint(50,500)]
- start = pygame.time.get_ticks()
- draw_lifes(life)
- if life <= 0:
- screen.fill((200,200,200))
- msg = font_64.render("GAME OVER!!", True, (0,0,0))
- screen.blit(msg, (180,200))
- fsc = font_32.render("FINAL SCORE: "+str(score), True, (0,0,0))
- screen.blit(fsc, (280,300))
- score_print(score)
- clock.tick(60)
- pygame.display.update()
- clicked = False
- mode = 0
- state = 0
- MainRun = True
- while MainRun:
- screen.fill((200,200,200))
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- MainRun = False
- if event.type == pygame.MOUSEBUTTONDOWN:
- if event.button == 1:
- clicked = True
- if event.type == pygame.MOUSEBUTTONUP:
- if event.button == 1:
- clicked = False
- mx, my = pygame.mouse.get_pos()
- if clicked and state == 0:
- if 285<mx<420 and sh-360<my<sh-323: mode = 1
- elif 285<mx<420 and sh-320<my<sh-283: mode = 2
- elif sw//2-95 < mx < sw//2+95 and sh-150 < my <sh-30: state = 1
- if mode == 1:
- pygame.draw.rect(screen, (255,0,0), pygame.Rect(285,sh-365,200,37),2)
- elif mode == 2:
- pygame.draw.rect(screen, (255,0,0), pygame.Rect(285,sh-325,200,37), 2)
- if state == 1:
- pygame.draw.rect(screen, (0,255,0), pygame.Rect(sw//2-95,sh-107,230,70), 2)
- if mode == 1:
- MainRun = False
- #Time_out_mode()
- if mode == 2:
- MainRun = False
- Arcade_mode()
- Welcome_Message = font_64.render("TILE SMASHERS", True, (0,0,200))
- screen.blit(Welcome_Message, (150, 20))
- Select_Mode = font_32.render("SELECT MODE:", True, (0,0,200))
- screen.blit(Select_Mode, (10, sh-400))
- Time_out = font_32.render("TIME-OUT", True, (0,0,200))
- screen.blit(Time_out, (290, sh-360))
- Arcade = font_32.render("ARCADE", True, (0,0,200))
- screen.blit(Arcade, (290, sh- 320))
- Start = font_64.render("START", True, (0,0,200))
- screen.blit(Start, (sw//2 - 80, sh-100))
- clock.tick(10)
- pygame.display.update()
Add Comment
Please, Sign In to add comment