Compare commits
2 Commits
12214b7097
...
90a8828dc7
| Author | SHA1 | Date |
|---|---|---|
|
|
90a8828dc7 | |
|
|
fb18e01440 |
31
\
31
\
|
|
@ -1,31 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
from time import sleep
|
|
||||||
from typing import NoReturn
|
|
||||||
|
|
||||||
from utils import *
|
|
||||||
|
|
||||||
def start_game() -> None:
|
|
||||||
proc = Popen(['./start_game.sh'])
|
|
||||||
proc.communicate()
|
|
||||||
|
|
||||||
def show_highscore() -> None:
|
|
||||||
Popen([
|
|
||||||
'tmux',
|
|
||||||
'display-popup',
|
|
||||||
'-E',
|
|
||||||
'watch',
|
|
||||||
'-tcn0',
|
|
||||||
r"""sh -c 'for _ in $(seq $(($(tput lines) / 3))); do printf "\n"; done; figlet -w $(tput cols) -c $(cat "/home/tosuman/42/hackthelobby/.score")'""",
|
|
||||||
])
|
|
||||||
|
|
||||||
def main() -> NoReturn:
|
|
||||||
show_matrix()
|
|
||||||
show_highscore()
|
|
||||||
while True:
|
|
||||||
if found_hands():
|
|
||||||
start_game()
|
|
||||||
sleep(1)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
||||||
Binary file not shown.
Binary file not shown.
23
game.py
23
game.py
|
|
@ -38,7 +38,7 @@ def get_42_img(
|
||||||
|
|
||||||
return img
|
return img
|
||||||
|
|
||||||
img42_side_len: int = 70
|
img42_side_len: int = 100
|
||||||
img42: np.ndarray = get_42_img(
|
img42: np.ndarray = get_42_img(
|
||||||
"./assets/img/42.png",
|
"./assets/img/42.png",
|
||||||
margin_top = 100 + 20,
|
margin_top = 100 + 20,
|
||||||
|
|
@ -96,13 +96,14 @@ def show_frame(frame: np.ndarray, to_stdout: bool=False) -> None:
|
||||||
cv2.waitKey(1)
|
cv2.waitKey(1)
|
||||||
|
|
||||||
def main() -> int:
|
def main() -> int:
|
||||||
start_sfx()
|
start_game_sfx()
|
||||||
|
|
||||||
capture: VideoCapture = cv2.VideoCapture(0)
|
capture: VideoCapture = cv2.VideoCapture(0)
|
||||||
hands: mp.solutions.hands.Hands = mp_hands.Hands(max_num_hands=2)
|
hands: mp.solutions.hands.Hands = mp_hands.Hands(max_num_hands=1)
|
||||||
collected_42: bool = True
|
collected_42: bool = True
|
||||||
img42_x: int = -img42_side_len - 1
|
noise_42img: int = 5
|
||||||
img42_y: int = -img42_side_len - 1
|
img42_x: int = -img42_side_len - 1 - noise_42img
|
||||||
|
img42_y: int = -img42_side_len - 1 - noise_42img
|
||||||
no_fingers: int = 0
|
no_fingers: int = 0
|
||||||
score: int = 0
|
score: int = 0
|
||||||
|
|
||||||
|
|
@ -120,9 +121,11 @@ def main() -> int:
|
||||||
frame_height, frame_width = frame.shape[:2]
|
frame_height, frame_width = frame.shape[:2]
|
||||||
img42_x = random.randint(0, frame_width - img42_side_len - 1)
|
img42_x = random.randint(0, frame_width - img42_side_len - 1)
|
||||||
img42_y = random.randint(0, frame_height - img42_side_len - 1)
|
img42_y = random.randint(0, frame_height - img42_side_len - 1)
|
||||||
|
rand_noise_y = random.randint(0, noise_42img)
|
||||||
|
rand_noise_x = random.randint(0, noise_42img)
|
||||||
frame[
|
frame[
|
||||||
img42_y : img42_y+img42_side_len,
|
img42_y + rand_noise_y : img42_y + img42_side_len + rand_noise_y,
|
||||||
img42_x : img42_x+img42_side_len,
|
img42_x + rand_noise_x : img42_x + img42_side_len + rand_noise_x,
|
||||||
] = img42
|
] = img42
|
||||||
|
|
||||||
finger_positions = list(get_finger_positions(frame, hands, add_landmarks=True))
|
finger_positions = list(get_finger_positions(frame, hands, add_landmarks=True))
|
||||||
|
|
@ -130,7 +133,7 @@ def main() -> int:
|
||||||
no_fingers += 1
|
no_fingers += 1
|
||||||
else:
|
else:
|
||||||
no_fingers = 0
|
no_fingers = 0
|
||||||
if no_fingers > 70:
|
if no_fingers > 200:
|
||||||
return score
|
return score
|
||||||
|
|
||||||
for positions in finger_positions:
|
for positions in finger_positions:
|
||||||
|
|
@ -160,7 +163,5 @@ def main() -> int:
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
score: int = main()
|
save_score(main())
|
||||||
with open('./.score', 'w') as score_file:
|
|
||||||
score_file.write(str(score))
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ def show_highscore() -> None:
|
||||||
'-E',
|
'-E',
|
||||||
'watch',
|
'watch',
|
||||||
'-tcn.5',
|
'-tcn.5',
|
||||||
r"""sh -c 'for _ in $(seq $(($(tput lines) / 3))); do printf "\n\033[31m"; done; figlet -w $(tput cols) -c $(cat "/home/tosuman/42/hackthelobby/.score")'""",
|
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!";'""",
|
||||||
])
|
])
|
||||||
|
|
||||||
def main() -> NoReturn:
|
def main() -> NoReturn:
|
||||||
|
|
|
||||||
11
utils.py
11
utils.py
|
|
@ -1,3 +1,4 @@
|
||||||
|
from time import sleep
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
from typing import Generator
|
from typing import Generator
|
||||||
|
|
@ -34,13 +35,17 @@ class FingerType(Enum):
|
||||||
PINKY_KNUCKLE_2 = 19
|
PINKY_KNUCKLE_2 = 19
|
||||||
PINKY_TIP = 20
|
PINKY_TIP = 20
|
||||||
|
|
||||||
|
def save_score(score: int) -> None:
|
||||||
|
with open('./.score', 'w') as score_file:
|
||||||
|
score_file.write(str(score))
|
||||||
|
|
||||||
|
def start_game_sfx() -> None:
|
||||||
|
Popen(['paplay', './assets/sfx/start.mp3'])
|
||||||
|
Popen(['paplay', './assets/sfx/background_music.mp3'])
|
||||||
|
|
||||||
def collect_sfx() -> None:
|
def collect_sfx() -> None:
|
||||||
Popen(['paplay', './assets/sfx/collect.mp3'])
|
Popen(['paplay', './assets/sfx/collect.mp3'])
|
||||||
|
|
||||||
def start_sfx() -> None:
|
|
||||||
Popen(['paplay', './assets/sfx/start.mp3'])
|
|
||||||
|
|
||||||
def show_matrix() -> None:
|
def show_matrix() -> None:
|
||||||
Popen(['tmatrix'])
|
Popen(['tmatrix'])
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue