diff --git a/__pycache__/utils.cpython-310.pyc b/__pycache__/utils.cpython-310.pyc index b61fb91..0c06fe9 100644 Binary files a/__pycache__/utils.cpython-310.pyc and b/__pycache__/utils.cpython-310.pyc differ diff --git a/game.py b/game.py index 3449d05..f1d3331 100755 --- a/game.py +++ b/game.py @@ -70,8 +70,12 @@ def add_directional_triangle( ]).astype(np.float64) # normalize - dir_vector /= np.linalg.norm(dir_vector) + norm = np.linalg.norm(dir_vector) + dir_vector /= norm + # TODO: Fix type issue + side_len *= norm / 15 + stretch /= (norm/30) triangle_height: float = side_len * (3**0.5) / 2 half_base: float = side_len / 2 @@ -96,7 +100,7 @@ def show_frame(frame: np.ndarray, to_stdout: bool=False) -> 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'])