diff --git a/__pycache__/utils.cpython-310.pyc b/__pycache__/utils.cpython-310.pyc index 0c06fe9..b399cf8 100644 Binary files a/__pycache__/utils.cpython-310.pyc and b/__pycache__/utils.cpython-310.pyc differ diff --git a/assets/sfx/background_music.mp3 b/assets/sound/background_music.mp3 similarity index 100% rename from assets/sfx/background_music.mp3 rename to assets/sound/background_music.mp3 diff --git a/assets/sfx/collect.mp3 b/assets/sound/collect.mp3 similarity index 100% rename from assets/sfx/collect.mp3 rename to assets/sound/collect.mp3 diff --git a/assets/sound/lost.mp3 b/assets/sound/lost.mp3 new file mode 100644 index 0000000..bd5c42f Binary files /dev/null and b/assets/sound/lost.mp3 differ diff --git a/assets/sound/rick.mp3 b/assets/sound/rick.mp3 new file mode 100644 index 0000000..70f1c5e Binary files /dev/null and b/assets/sound/rick.mp3 differ diff --git a/assets/sfx/start.mp3 b/assets/sound/start.mp3 similarity index 100% rename from assets/sfx/start.mp3 rename to assets/sound/start.mp3 diff --git a/assets/video/rick.mp4 b/assets/video/rick.mp4 new file mode 100644 index 0000000..86e60ba Binary files /dev/null and b/assets/video/rick.mp4 differ diff --git a/assets/video/rick2.mp4 b/assets/video/rick2.mp4 new file mode 100644 index 0000000..0927819 Binary files /dev/null and b/assets/video/rick2.mp4 differ diff --git a/game.py b/game.py index b503af0..f2d84ef 100755 --- a/game.py +++ b/game.py @@ -2,6 +2,7 @@ import sys import random +import psutil import numpy as np import cv2 @@ -102,6 +103,7 @@ def show_frame(frame: np.ndarray, to_stdout: bool=False) -> None: def main() -> int: music = start_game_sfx() + music_p = psutil.Process(pid=music.pid) capture: VideoCapture = cv2.VideoCapture(0) hands: mp.solutions.hands.Hands = mp_hands.Hands(max_num_hands=1) @@ -115,6 +117,7 @@ def main() -> int: finger_y: int = -1 no_collect_ratio = 0 no_finger_ratio = 0 + timer = 100 i: int = 0 while True: @@ -124,6 +127,8 @@ def main() -> int: if not success: continue + ratio = max(no_finger_ratio, no_collect_ratio) + frame = cv2.addWeighted(frame, 1 - ratio, np.ones(frame.shape, dtype=frame.dtype), ratio, 0) if i > 30: if collected_42: collected_42 = False @@ -139,7 +144,7 @@ def main() -> int: img42_y + rand_noise_y : img42_y + img42_side_len + rand_noise_y, img42_x + rand_noise_x : img42_x + img42_side_len + rand_noise_x, ] = img42 - no_collect_ratio = min(i, 200) / 200 + no_collect_ratio = min(i, timer) / timer finger_positions = list(get_finger_positions(frame, hands, add_landmarks=True)) if finger_positions == []: @@ -147,12 +152,12 @@ def main() -> int: no_finger_ratio = min(no_fingers, 255) / 255 else: no_fingers = 0 - if no_fingers > 255: - music.kill() - return score - ratio = max(no_finger_ratio, no_collect_ratio) - frame = cv2.addWeighted(frame, 1 - ratio, np.ones(frame.shape, dtype=frame.dtype), ratio, 0) + if ratio > 0.99: + music.kill() + lost_sfx() + return score + for positions in finger_positions: index_knuckle_1_pos: tuple[int, int] = (-1, -1) @@ -176,6 +181,11 @@ def main() -> int: collected_42 = True i = 0 score += 42 + if score == 4200 / 4: # that's 25 collects + music_p.suspend() + initiate_rick() + music_p.resume() + timer = 60 + (timer - 60) * .9 collect_sfx() show_frame(frame, to_stdout=(not sys.stdout.isatty())) i += 1 diff --git a/master.py b/master.py index 93eeee9..cdc645c 100755 --- a/master.py +++ b/master.py @@ -15,6 +15,8 @@ def start_game() -> None: proc.communicate() def show_highscore() -> None: + with open('./.score', 'w') as f: + f.write('0') Popen([ 'tmux', 'display-popup', @@ -30,7 +32,7 @@ def main() -> NoReturn: while True: if found_hands(): start_game() - sleep(1) + sleep(2) if __name__ == '__main__': main() diff --git a/mpv-shot0001.jpg b/mpv-shot0001.jpg new file mode 100644 index 0000000..7c7bb3f Binary files /dev/null and b/mpv-shot0001.jpg differ diff --git a/mpv-shot0002.jpg b/mpv-shot0002.jpg new file mode 100644 index 0000000..b969354 Binary files /dev/null and b/mpv-shot0002.jpg differ diff --git a/mpv-shot0003.jpg b/mpv-shot0003.jpg new file mode 100644 index 0000000..b969354 Binary files /dev/null and b/mpv-shot0003.jpg differ diff --git a/mpv-shot0004.jpg b/mpv-shot0004.jpg new file mode 100644 index 0000000..f901b58 Binary files /dev/null and b/mpv-shot0004.jpg differ diff --git a/mpv-shot0005.jpg b/mpv-shot0005.jpg new file mode 100644 index 0000000..e03ed07 Binary files /dev/null and b/mpv-shot0005.jpg differ diff --git a/requirements.txt b/requirements.txt index d5104ec..26044ad 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,6 +14,7 @@ opencv-python==4.8.0.76 packaging==23.1 Pillow==10.0.0 protobuf==3.20.3 +psutil==5.9.5 pycparser==2.21 pyparsing==3.0.9 python-dateutil==2.8.2 diff --git a/start_game.sh b/start_game.sh index fa41ab6..5ce3c15 100755 --- a/start_game.sh +++ b/start_game.sh @@ -5,7 +5,7 @@ TERM_FONT='SauceCodePro Nerd Font Mono' TERM_FONT_SIZE='10' -OUT_TERM='xterm-mono' +OUT_TERM='vt100' TERM_FULLSCREEN='-fullscreen' xterm \ -bg black \ diff --git a/utils.py b/utils.py index 9da1b57..6e8fa21 100644 --- a/utils.py +++ b/utils.py @@ -1,4 +1,5 @@ -from time import sleep +import sys +import time from enum import Enum from subprocess import Popen from typing import Generator @@ -40,16 +41,37 @@ def save_score(score: int) -> None: score_file.write(str(score)) def start_game_sfx() -> Popen: - Popen(['paplay', './assets/sfx/start.mp3']).communicate() - sleep(.5) - return Popen(['paplay', './assets/sfx/background_music.mp3']) + Popen(['paplay', './assets/sound/start.mp3']).communicate() + time.sleep(.5) + return Popen(['paplay', './assets/sound/background_music.mp3']) def collect_sfx() -> None: - Popen(['paplay', './assets/sfx/collect.mp3']) + Popen(['paplay', './assets/sound/collect.mp3']) + +def lost_sfx() -> None: + Popen(['paplay', './assets/sound/lost.mp3']).communicate() def show_matrix() -> None: Popen(['tmatrix']) +def initiate_rick() -> None: + Popen(['paplay', './assets/sound/rick.mp3']) + cap = cv2.VideoCapture('./assets/video/rick2.mp4') + fps: int = int(cap.get(cv2.CAP_PROP_FPS)) + desired_delay: float = 1 / fps + + while True: + start_time = time.time() + ret, frame = cap.read() + if not ret: + break + sys.stdout.buffer.write(frame.tobytes()) + elapsed_time = time.time() - start_time + remaining_delay = max(desired_delay - elapsed_time, 0) + time.sleep(remaining_delay) + cap.release() + + def found_hands() -> bool: capture: VideoCapture = cv2.VideoCapture(0) hands = mp_hands.Hands(max_num_hands=1)