F
funky
import pygame
import random
import time
import sys
black = (0, 0, 0)
white = (255, 255, 255)
red = (255, 0, 0)
class Block(pygame.sprite.Sprite):
def __init__(self, color, width, height):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface([width, height])
self.image.fill(color)
self.rect = self.image.get_rect()
def reset_pos(self):
self.rect.y = -20
self.rect.x = random.randrange(700)
def update(self):
self.rect.y +=1
if self.rect.y > 410:
self.rect.y = -20
self.rect.x = random.randrange(700)
pygame.init()
screen_width = 700
screen_height = 400
screen = pygame.display.set_mode([screen_width, screen_height])
block_list = pygame.sprite.Group()
wall_list = pygame.sprite.Group()
all_sprites_list = pygame.sprite.Group()
for i in range(50):
color = (random.randint(40, 255), random.randint(40, 255), random.randint(40, 255))
block = Block(color, 20, 15)
block.rect.x = random.randrange(screen_width)
block.rect.y = random.randrange(screen_height)
block_list.add(block)
all_sprites_list.add(block)
player = Block(red, 20, 15)
all_sprites_list.add(player)
done = False
clock = pygame.time.Clock()
score = 0
minutes = 0
seconds = 0
time_start = 0
while done == False:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done == True
while True:
sys.stdout.write("\r{minutes} Minutes {seconds} Seconds".format(minutes=minutes, seconds=seconds))
sys.stdout.flush()
time.sleep(1)
seconds = int(time.time() - time_start) - minutes * 60
for x in range(1, 1000):
screen.fill(white)
blocks_hit_list = pygame.sprite.spritecollide(player, block_list, False)
for block in blocks_hit_list:
if block > 0:
score += 1
print score
block.reset_pos()
font = pygame.font.Font(None, 25)
text2 = font.render("time left: " + str(seconds), True, black)
text = font.render("Score: " + str(score), True, black)
screen.blit(text, [20, 20])
screen.blit(text2,[0, 20])
pos = pygame.mouse.get_pos()
player.rect.x=pos[0]
player.rect.y=pos[1]
block_list.update()
all_sprites_list.draw(screen)
clock.tick(120)
pygame.display.flip()
if seconds == 60:
pygame.quit()
import random
import time
import sys
black = (0, 0, 0)
white = (255, 255, 255)
red = (255, 0, 0)
class Block(pygame.sprite.Sprite):
def __init__(self, color, width, height):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.Surface([width, height])
self.image.fill(color)
self.rect = self.image.get_rect()
def reset_pos(self):
self.rect.y = -20
self.rect.x = random.randrange(700)
def update(self):
self.rect.y +=1
if self.rect.y > 410:
self.rect.y = -20
self.rect.x = random.randrange(700)
pygame.init()
screen_width = 700
screen_height = 400
screen = pygame.display.set_mode([screen_width, screen_height])
block_list = pygame.sprite.Group()
wall_list = pygame.sprite.Group()
all_sprites_list = pygame.sprite.Group()
for i in range(50):
color = (random.randint(40, 255), random.randint(40, 255), random.randint(40, 255))
block = Block(color, 20, 15)
block.rect.x = random.randrange(screen_width)
block.rect.y = random.randrange(screen_height)
block_list.add(block)
all_sprites_list.add(block)
player = Block(red, 20, 15)
all_sprites_list.add(player)
done = False
clock = pygame.time.Clock()
score = 0
minutes = 0
seconds = 0
time_start = 0
while done == False:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done == True
while True:
sys.stdout.write("\r{minutes} Minutes {seconds} Seconds".format(minutes=minutes, seconds=seconds))
sys.stdout.flush()
time.sleep(1)
seconds = int(time.time() - time_start) - minutes * 60
for x in range(1, 1000):
screen.fill(white)
blocks_hit_list = pygame.sprite.spritecollide(player, block_list, False)
for block in blocks_hit_list:
if block > 0:
score += 1
print score
block.reset_pos()
font = pygame.font.Font(None, 25)
text2 = font.render("time left: " + str(seconds), True, black)
text = font.render("Score: " + str(score), True, black)
screen.blit(text, [20, 20])
screen.blit(text2,[0, 20])
pos = pygame.mouse.get_pos()
player.rect.x=pos[0]
player.rect.y=pos[1]
block_list.update()
all_sprites_list.draw(screen)
clock.tick(120)
pygame.display.flip()
if seconds == 60:
pygame.quit()