GOTY 2016
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

91 lines
3.8 KiB

import pygame, time, os, random, sys
pygame.init()
if len(sys.argv) < 2:
sys.argv.append('senpai')
values = __import__(sys.argv[1])
#disp = pygame.display.set_mode((1480, 1080), pygame.FULLSCREEN)
disp = pygame.display.set_mode(values.SIZE)
snd = pygame.mixer.Sound('aaa.flac')
TRIGGERED = False
TRIGGERED_TIME = None
TRIGGERED_MOVE = 100
BKD_COL = (255, 255, 255)
joys = [pygame.joystick.Joystick(i) for i in range(pygame.joystick.get_count())]
print(joys)
for joy in joys:
joy.init()
BKGD = pygame.image.load(values.BACKGROUND_PATH).convert_alpha()
LEFT_EYE_FULL = pygame.image.load(values.LEFT_EYE_PATH)
LEFT_EYE = LEFT_EYE_FULL.convert_alpha()
if hasattr(values, 'LE_SIZE'):
LEFT_EYE = pygame.transform.smoothscale(LEFT_EYE, values.LE_SIZE)
RIGHT_EYE_FULL = pygame.image.load(values.RIGHT_EYE_PATH)
RIGHT_EYE = RIGHT_EYE_FULL.convert_alpha()
if hasattr(values, 'RE_SIZE'):
RIGHT_EYE = pygame.transform.smoothscale(RIGHT_EYE, values.RE_SIZE)
EYE_MASK = pygame.image.load(values.EYE_MASK_PATH).convert_alpha()
INV_MASK = pygame.Surface(EYE_MASK.get_size(), pygame.SRCALPHA)
INV_MASK.fill(values.SCLERA_COLOR)
INV_MASK.blit(EYE_MASK, (0, 0), None, pygame.BLEND_RGBA_SUB)
##EYE_SF = 0.15
##EYE = pygame.transform.smoothscale(EYE_FULL, list(map(int, (EYE_SF * EYE_FULL.get_width(), EYE_SF * EYE_FULL.get_height())))).convert_alpha()
LEFT_EYE_OFF = (LEFT_EYE.get_width() / 2, LEFT_EYE.get_height() / 2)
RIGHT_EYE_OFF = (RIGHT_EYE.get_width() / 2, RIGHT_EYE.get_height() / 2)
LE_CEN = values.LE_CEN
RE_CEN = values.RE_CEN
LE_DEL = values.LE_DEL
RE_DEL = values.RE_DEL
msk_tmp = EYE_MASK.copy().convert_alpha()
bkd_tmp = INV_MASK.copy().convert_alpha()
bkd_tmp.blit(INV_MASK, (0, 0))
bkd_tmp.blit(BKGD, (0, 0), None, pygame.BLEND_RGBA_MULT)
wmi = pygame.display.get_wm_info()
while True:
if TRIGGERED:
os.system('xdotool windowmove --relative {} {} {}'.format(wmi['wmwindow'], random.randint(-TRIGGERED_MOVE, TRIGGERED_MOVE), random.randint(-TRIGGERED_MOVE, TRIGGERED_MOVE)))
if time.time() > TRIGGERED_TIME + snd.get_length():
exit()
for ev in pygame.event.get():
print(ev)
if ev.type == pygame.KEYDOWN and ev.key == pygame.K_ESCAPE:
exit()
if ev.type == pygame.JOYBUTTONDOWN:
if ev.button == 0:
wmi = pygame.display.get_wm_info()
for k, v in wmi.items():
print(k, type(v), v)
if ev.button == 5:
for but in (0, 1, 3, 4):
if not joys[0].get_button(but):
break
else:
if not TRIGGERED:
TRIGGERED = True
TRIGGERED_TIME = time.time()
snd.play()
BKD_COL = (255, 0, 0)
red_tmp = pygame.Surface(bkd_tmp.get_size())
red_tmp.fill(BKD_COL)
bkd_tmp.blit(red_tmp, (0, 0), None, pygame.BLEND_RGBA_MULT)
disp.fill(BKD_COL)
##w, h = disp.get_size()
##w2, h2, w4, h4 = w / 2, h / 2, w / 4, h / 4
joy = joys[0]
x1, y1, x2, y2 = map(joy.get_axis, [0, 1, 3, 4])
##pygame.draw.circle(disp, (255, 255, 255), (int(w4 * x1 + w4), int(h2 * y1 + h2)), 15)
##pygame.draw.circle(disp, (255, 255, 255), (int(w4 * x2 + w4 + w2), int(h2 * y2 + h2)), 15)
#msk_tmp.blit(EYE_MASK, (0, 0))
msk_tmp.fill(BKD_COL)
msk_tmp.blit(RIGHT_EYE, (RE_CEN[0] + int(RE_DEL[0] * x1) - RIGHT_EYE_OFF[0], RE_CEN[1] + int(RE_DEL[1] * y1) - RIGHT_EYE_OFF[1]), None, pygame.BLEND_RGBA_MULT)
msk_tmp.blit(LEFT_EYE, (LE_CEN[0] + int(LE_DEL[0] * x2) - LEFT_EYE_OFF[0], LE_CEN[1] + int(LE_DEL[1] * y2) - LEFT_EYE_OFF[1]), None, pygame.BLEND_RGBA_MULT)
disp.blit(msk_tmp, (0, 0))
disp.blit(bkd_tmp, (0, 0))
pygame.display.flip()