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.

senpai_simulator.py 3.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import pygame, time, os, random, sys
  2. pygame.init()
  3. if len(sys.argv) < 2:
  4. sys.argv.append('senpai')
  5. values = __import__(sys.argv[1])
  6. #disp = pygame.display.set_mode((1480, 1080), pygame.FULLSCREEN)
  7. disp = pygame.display.set_mode(values.SIZE)
  8. snd = pygame.mixer.Sound('aaa.flac')
  9. TRIGGERED = False
  10. TRIGGERED_TIME = None
  11. TRIGGERED_MOVE = 100
  12. BKD_COL = (255, 255, 255)
  13. joys = [pygame.joystick.Joystick(i) for i in range(pygame.joystick.get_count())]
  14. print(joys)
  15. for joy in joys:
  16. joy.init()
  17. BKGD = pygame.image.load(values.BACKGROUND_PATH).convert_alpha()
  18. LEFT_EYE_FULL = pygame.image.load(values.LEFT_EYE_PATH)
  19. LEFT_EYE = LEFT_EYE_FULL.convert_alpha()
  20. if hasattr(values, 'LE_SIZE'):
  21. LEFT_EYE = pygame.transform.smoothscale(LEFT_EYE, values.LE_SIZE)
  22. RIGHT_EYE_FULL = pygame.image.load(values.RIGHT_EYE_PATH)
  23. RIGHT_EYE = RIGHT_EYE_FULL.convert_alpha()
  24. if hasattr(values, 'RE_SIZE'):
  25. RIGHT_EYE = pygame.transform.smoothscale(RIGHT_EYE, values.RE_SIZE)
  26. EYE_MASK = pygame.image.load(values.EYE_MASK_PATH).convert_alpha()
  27. INV_MASK = pygame.Surface(EYE_MASK.get_size(), pygame.SRCALPHA)
  28. INV_MASK.fill(values.SCLERA_COLOR)
  29. INV_MASK.blit(EYE_MASK, (0, 0), None, pygame.BLEND_RGBA_SUB)
  30. ##EYE_SF = 0.15
  31. ##EYE = pygame.transform.smoothscale(EYE_FULL, list(map(int, (EYE_SF * EYE_FULL.get_width(), EYE_SF * EYE_FULL.get_height())))).convert_alpha()
  32. LEFT_EYE_OFF = (LEFT_EYE.get_width() / 2, LEFT_EYE.get_height() / 2)
  33. RIGHT_EYE_OFF = (RIGHT_EYE.get_width() / 2, RIGHT_EYE.get_height() / 2)
  34. LE_CEN = values.LE_CEN
  35. RE_CEN = values.RE_CEN
  36. LE_DEL = values.LE_DEL
  37. RE_DEL = values.RE_DEL
  38. msk_tmp = EYE_MASK.copy().convert_alpha()
  39. bkd_tmp = INV_MASK.copy().convert_alpha()
  40. bkd_tmp.blit(INV_MASK, (0, 0))
  41. bkd_tmp.blit(BKGD, (0, 0), None, pygame.BLEND_RGBA_MULT)
  42. wmi = pygame.display.get_wm_info()
  43. while True:
  44. if TRIGGERED:
  45. os.system('xdotool windowmove --relative {} {} {}'.format(wmi['wmwindow'], random.randint(-TRIGGERED_MOVE, TRIGGERED_MOVE), random.randint(-TRIGGERED_MOVE, TRIGGERED_MOVE)))
  46. if time.time() > TRIGGERED_TIME + snd.get_length():
  47. exit()
  48. for ev in pygame.event.get():
  49. print(ev)
  50. if ev.type == pygame.KEYDOWN and ev.key == pygame.K_ESCAPE:
  51. exit()
  52. if ev.type == pygame.JOYBUTTONDOWN:
  53. if ev.button == 0:
  54. wmi = pygame.display.get_wm_info()
  55. for k, v in wmi.items():
  56. print(k, type(v), v)
  57. if ev.button == 5:
  58. for but in (0, 1, 3, 4):
  59. if not joys[0].get_button(but):
  60. break
  61. else:
  62. if not TRIGGERED:
  63. TRIGGERED = True
  64. TRIGGERED_TIME = time.time()
  65. snd.play()
  66. BKD_COL = (255, 0, 0)
  67. red_tmp = pygame.Surface(bkd_tmp.get_size())
  68. red_tmp.fill(BKD_COL)
  69. bkd_tmp.blit(red_tmp, (0, 0), None, pygame.BLEND_RGBA_MULT)
  70. disp.fill(BKD_COL)
  71. ##w, h = disp.get_size()
  72. ##w2, h2, w4, h4 = w / 2, h / 2, w / 4, h / 4
  73. joy = joys[0]
  74. x1, y1, x2, y2 = map(joy.get_axis, [0, 1, 3, 4])
  75. ##pygame.draw.circle(disp, (255, 255, 255), (int(w4 * x1 + w4), int(h2 * y1 + h2)), 15)
  76. ##pygame.draw.circle(disp, (255, 255, 255), (int(w4 * x2 + w4 + w2), int(h2 * y2 + h2)), 15)
  77. #msk_tmp.blit(EYE_MASK, (0, 0))
  78. msk_tmp.fill(BKD_COL)
  79. 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)
  80. 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)
  81. disp.blit(msk_tmp, (0, 0))
  82. disp.blit(bkd_tmp, (0, 0))
  83. pygame.display.flip()