This commit is contained in:
cubernetes 2023-08-11 04:23:17 +02:00
parent 40b0e585e6
commit ba24bbdf9a
4 changed files with 18 additions and 8 deletions

Binary file not shown.

18
game.py
View File

@ -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:

View File

@ -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:

View File

@ -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'])