1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| import pygame, pygame.locals, random, time
import numpy as np
KEY_UP = (pygame.locals.K_UP,pygame.locals. K_z)
KEY_DOWN = (pygame.locals.K_DOWN, pygame.locals.K_s)
KEY_RIGHT = (pygame.locals.K_RIGHT, pygame.locals.K_d)
KEY_LEFT = (pygame.locals.K_LEFT, pygame.locals.K_q)
GREY = (72,70,74)
COLOR = (230, 200, 100)
COORDS = (96, 54)
POINT = 0
pygame.init()
pygame.font.init()
font = pygame.font.SysFont('Agency', 30)
pygame.mixer.init()
pygame.mixer.music.load('1983.mp3')
pygame.mixer.music.play(-1)
SCREEN = pygame.display.set_mode((500, 500), pygame.NOFRAME)
def random_rect(start=False):
global BACKGROUND, size, x, y, COLOR
BACKGROUND = pygame.Surface((500,500))
BACKGROUND.fill(GREY)
size = random.randint(10,100)
x, y = random.choices(range(0,500-size), k=2)
if not start:
red = random.randint(0,255)
green = random.randint(0,255)
blue = random.randint(0,255)
COLOR = red, green , blue
pygame.draw.rect(BACKGROUND, COLOR, pygame.Rect(x, y, size, size), width=2)
SCREEN.blit(BACKGROUND, (0,0))
pygame.draw.circle(SCREEN, COLOR, COORDS, 5)
text = font.render('Total : ' +str(int(POINT)) + ' pt(s)', True, (255,255,255))
text2 = font.render('Slow motion : Left Ctrl | New rect : Spacebar ', True, (255,255,255))
SCREEN.blit(text, (0,0))
SCREEN.blit(text2, (0,480))
pygame.display.update()
def move(coords):
global COORDS, POINT, t0
NEW_COORDS = COORDS[0]+coords[0], COORDS[1]+coords[1]
if NEW_COORDS[0] > 5 and NEW_COORDS[0] < 495 and NEW_COORDS[1] > 5 and NEW_COORDS[1] < 495:
COORDS = NEW_COORDS
SCREEN.blit(BACKGROUND, (0,0))
pygame.draw.circle(SCREEN, COLOR, COORDS, 5)
pygame.display.update(COORDS[0]-10, COORDS[1]-10, 20, 20)
text = font.render('Total : ' +str(int(POINT)) + ' pt(s)', True, (255,255,255))
text2 = font.render('Slow motion : Left Ctrl | New rect : Spacebar ', True, (255,255,255))
SCREEN.blit(text, (0,0))
SCREEN.blit(text2, (0,480))
pygame.display.update(0,0,250,30)
pygame.display.update(0,480,500,30)
if COORDS[0] > x and COORDS[0] < x+size and COORDS[1] > y and COORDS[1] < y+size:
a = np.array(GREY)
b = np.array(COLOR)
dist = np.linalg.norm(a-b)
POINT += max(0, 100000/(size*30+dist*20+(time.time()-t0)*5))
t0 = time.time()
random_rect()
random_rect(True)
keys_pressed = {}
pygame.key.set_repeat(100,5)
t0 = time.time()
SPEED = 1000
while 1:
pygame.time.Clock().tick(SPEED)
for event in pygame.event.get():
if event.type == pygame.locals.KEYDOWN :
keys_pressed[event.key] = True
if event.key == pygame.locals.K_ESCAPE:
pygame.quit()
break
elif event.type == pygame.locals.KEYUP :
keys_pressed[event.key] = False
if event.key == pygame.locals.K_SPACE:
POINT -= 100
random_rect()
if event.key == pygame.locals.K_LCTRL:
SPEED = 1000
for key in keys_pressed:
if keys_pressed[key]:
if key == pygame.locals.K_LCTRL :
SPEED = max(50,SPEED-1)
POINT = POINT-(10/SPEED)
if key in KEY_UP:
move((0,-1))
if key in KEY_DOWN:
move((0,1))
if key in KEY_RIGHT:
move((1,0))
if key in KEY_LEFT:
move((-1,0)) |
Partager