From ba24bbdf9af013438b719682806d9043ec90c65e Mon Sep 17 00:00:00 2001 From: cubernetes Date: Fri, 11 Aug 2023 04:23:17 +0200 Subject: [PATCH] Idk --- __pycache__/utils.cpython-310.pyc | Bin 2904 -> 2928 bytes game.py | 18 ++++++++++++++---- master.py | 4 ++-- utils.py | 4 ++-- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/__pycache__/utils.cpython-310.pyc b/__pycache__/utils.cpython-310.pyc index b61fb91e11ebe77cf1ba1d5b207e4bc8643037f4..0c06fe94a3349f42ecffcbcb3d6734cbcef43180 100644 GIT binary patch delta 185 zcmca1_CbsN5|ekbitw-jb*w7FOhv3f4Y#hYOHwEAV%2140g4JR z3QT^(TEnO}Ig>4y(Qxy1HdaPPlg)S8g_#&_H-F?zW|ZM#0YYXzW+on%zbuSQ|2deL O{xLB#{gq None: cv2.waitKey(1) def main() -> int: - start_game_sfx() + music = start_game_sfx() capture: VideoCapture = cv2.VideoCapture(0) hands: mp.solutions.hands.Hands = mp_hands.Hands(max_num_hands=1) @@ -106,6 +110,8 @@ def main() -> int: img42_y: int = -img42_side_len - 1 - noise_42img no_fingers: int = 0 score: int = 0 + finger_x: int = -1 + finger_y: int = -1 i: int = 0 while True: @@ -119,8 +125,11 @@ def main() -> int: if collected_42: collected_42 = False frame_height, frame_width = frame.shape[:2] - img42_x = random.randint(0, frame_width - img42_side_len - 1) - img42_y = random.randint(0, frame_height - img42_side_len - 1) + img42_x = random.randint(0, frame_width - img42_side_len - 1 - noise_42img) + img42_y = random.randint(0, frame_height - img42_side_len - 1 - noise_42img) + while ((finger_x - img42_x) ** 2 + (finger_y - img42_y) ** 2) ** .5 < 200: + img42_x = random.randint(0, frame_width - img42_side_len - 1 - noise_42img) + img42_y = random.randint(0, frame_height - img42_side_len - 1 - noise_42img) rand_noise_y = random.randint(0, noise_42img) rand_noise_x = random.randint(0, noise_42img) frame[ @@ -134,6 +143,7 @@ def main() -> int: else: no_fingers = 0 if no_fingers > 200: + music.kill() return score for positions in finger_positions: diff --git a/master.py b/master.py index 8b9093f..292aed5 100755 --- a/master.py +++ b/master.py @@ -15,8 +15,8 @@ def show_highscore() -> None: 'display-popup', '-E', 'watch', - '-tcn.5', - r"""sh -c 'for _ in $(seq $(($(tput lines) / 3 - 1))); do printf "\n\033[31m"; done; printf "%$(($(tput cols) / 2 + 5))s\n" "Highscore:"; figlet -w $(tput cols) -c $(cat "/home/tosuman/42/hackthelobby/.score"); printf "\n%$(($(tput cols) / 2 + 8))s\n" "Show your hands!";'""", + '-tcn.6', + r"""bash -c 'for _ in $(seq $(($(tput lines) / 3 - 1))); do printf "\n\033[31m"; done; printf "%$(($(tput cols) / 2 + 5))s\n" "Highscore:"; figlet -w $(tput cols) -c $(cat "/home/tosuman/42/hackthelobby/.score"); printf "\n\033[3$((RANDOM % 7 + 1))m%$(($(tput cols) / 2 + 4 + RANDOM % 8))s\n" "Show your hands!";'""", ]) def main() -> NoReturn: diff --git a/utils.py b/utils.py index 612ea8b..9da1b57 100644 --- a/utils.py +++ b/utils.py @@ -39,10 +39,10 @@ def save_score(score: int) -> None: with open('./.score', 'w') as score_file: score_file.write(str(score)) -def start_game_sfx() -> None: +def start_game_sfx() -> Popen: Popen(['paplay', './assets/sfx/start.mp3']).communicate() sleep(.5) - Popen(['paplay', './assets/sfx/background_music.mp3']) + return Popen(['paplay', './assets/sfx/background_music.mp3']) def collect_sfx() -> None: Popen(['paplay', './assets/sfx/collect.mp3'])