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)
- #TIME-OUT-MODE
- def Time_out_mode(st):
- print("HERE")
- global font_64, font_32, clock
- start_time = st
- xy = [random.randint(50,700), random.randint(50,500)]
- def print_score(scr):
- screen.blit(font_32.render("SCORE: "+str(scr), True, (0,0,0)), (10,10))
- def generate_box(x,y):
- return(pygame.Rect(x,y,100,100))
- def isClicked(xy,mx,my):
- global score
- if xy[0] < mx < xy[0]+100 and xy[1] < my < xy[1]+100:
- score += 1
- print(score)
- return True
- return False
- clicked = False
- TimeoutMode = True
- start = pygame.time.get_ticks()
- while TimeoutMode:
- screen.fill((200,200,200))
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- TimeoutMode = 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 > 1000:
- start = pygame.time.get_ticks()
- xy = [random.randint(0,700), random.randint(0,500)]
- if clicked:
- if (current_time-start<1000) and isClicked(xy,mx,my):
- xy = [random.randint(0,700), random.randint(0,500)]
- pygame.draw.rect(screen, (255,0,0), box)
- start = pygame.time.get_ticks()
- game_time = pygame.time.get_ticks()
- if game_time - start_time > 60000:
- screen.fill((200,200,200))
- msg = pygame.font.Font('freesansbold.ttf',64)
- screen.blit(msg.render("GAME OVER!!", True, (0,0,0)), (180,200))
- fsc = pygame.font.Font('freesansbold.ttf', 32)
- screen.blit(fsc.render("FINAL SCORE: "+str(score), True, (0,0,0)), (280,300))
- print_score(score)
- clock.tick(20)
- pygame.display.update()
- #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, w, h):
- if cxy[0] < cmx < cxy[0] + w and cxy[1] < cmy < cxy[1] + h:
- 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
- w = 150
- h = 150
- box state = 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)
- if score%10==0 and score>0 and boxstate == True:
- boxstate = False
- w -= 20
- h -= 20
- if score%10==1:
- boxstate = True
- 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, w, h):
- 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, w, h)):
- 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(pygame.time.get_ticks())
- 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