diff --git a/game.py b/game.py index e4a4a81..09763b1 100755 --- a/game.py +++ b/game.py @@ -7,6 +7,7 @@ from time import sleep import numpy as np import cv2 import requests +from subprocess import Popen from utils import * @@ -103,7 +104,7 @@ def show_frame(frame: np.ndarray, to_stdout: bool=False) -> None: def collect_vfx() -> None: requests.post('http://10.11.250.225:8080/api/v1/composition/layers/2/clips/5/connect') - sleep(1) + sleep(2) requests.post('http://10.11.250.225:8080/api/v1/composition/layers/2/clips/7/connect') def die_vfx() -> None: @@ -173,7 +174,9 @@ def main() -> int: if music: music.kill() lost_sfx() - die() + # die() + capture.release() + cv2.destroyAllWindows() return score for positions in finger_positions: @@ -191,10 +194,7 @@ def main() -> int: side_len=70, stretch=2.0, ) - if not collected_42 and ( - touches_42(apex_x, apex_y, img42_x, img42_y) - or touches_42(finger_x, finger_y, img42_x, img42_y) - ): + if not collected_42 and touches_42(apex_x, apex_y, img42_x, img42_y): collected_42 = True i = 0 score += 42 @@ -203,6 +203,15 @@ def main() -> int: timer = 60 + (timer - 60) * .9 collect_sfx() green() + if not collected_42 and touches_42(finger_x, finger_y, img42_x, img42_y): + collected_42 = True + i = 0 + score += 42 + if score == 4200 / 4: # that's 25 collects + initiate_rick() + timer = 50 + (timer - 50) * .9 + collect_sfx() + green() show_frame(frame, to_stdout=(not sys.stdout.isatty())) i += 1 diff --git a/start_game.sh b/start_game.sh index d36c40c..8da7cd6 100755 --- a/start_game.sh +++ b/start_game.sh @@ -6,7 +6,7 @@ TERM_FONT='SauceCodePro Nerd Font Mono' TERM_FONT_SIZE='10' OUT_TERM='xterm-mono' -TERM_FULLSCREEN='-fullscreen' +# TERM_FULLSCREEN='-fullscreen' xterm \ -bg black \ -fg white \ @@ -36,5 +36,5 @@ xterm \ --untimed \ --profile=low-latency \ - \ - || { echo "There was an error" 1>&2; read X; }; + || { echo "There was an error" 1>&2; read X; } && { echo "There was no error"; }; }' diff --git a/utils.py b/utils.py index 8a5d870..bd98972 100644 --- a/utils.py +++ b/utils.py @@ -6,8 +6,8 @@ from typing import Generator from types import ModuleType import threading -import sounddevice as sd -import soundfile as sf +# import sounddevice as sd +# import soundfile as sf import numpy as np import mediapipe as mp @@ -44,30 +44,34 @@ def save_score(score: int) -> None: with open('./.score', 'w') as score_file: score_file.write(str(score)) -def play_audio(file_name: str) -> None: - # Read the audio file - data, samplerate = sf.read(file_name) - - # Play the audio file - sd.play(data, samplerate) - sd.wait() # Wait for the audio playback to complete +# def play_audio(file_name: str) -> None: +# # Read the audio file +# data, samplerate = sf.read(file_name) +# +# # Play the audio file +# sd.play(data, samplerate) +# sd.wait() # Wait for the audio playback to complete -def start_game_sfx() -> None: - play_audio('./assets/sound/start.mp3') +def start_game_sfx() -> Popen: + Popen(['paplay', './assets/sound/start.mp3']).communicate() + # play_audio('./assets/sound/start.mp3') time.sleep(.5) - threading.Thread(target=play_audio, args=('./assets/sound/background_music.mp3',), daemon=True).start() + return Popen(['paplay', './assets/sound/background_music.mp3']) + # threading.Thread(target=play_audio, args=('./assets/sound/background_music.mp3',), daemon=True).start() def collect_sfx() -> None: - pass + Popen(['paplay', './assets/sound/collect.mp3']) # threading.Thread(target=play_audio, args=('./assets/sound/collect.mp3',), daemon=True).start() def lost_sfx() -> None: - play_audio('./assets/sound/lost.mp3') + Popen(['paplay', './assets/sound/lost.mp3']).communicate() + # play_audio('./assets/sound/lost.mp3') def show_matrix() -> None: Popen(['tmatrix']) def initiate_rick() -> None: + Popen(['paplay', './assets/sound/rick.mp3']) # threading.Thread(target=play_audio, args=('./assets/sound/rick.mp3',), daemon=True).start() cap = cv2.VideoCapture('./assets/video/rick2.mp4') fps: int = int(cap.get(cv2.CAP_PROP_FPS))