Compare commits
2 Commits
ade4654112
...
fd02dd21d4
| Author | SHA1 | Date |
|---|---|---|
|
|
fd02dd21d4 | |
|
|
a86cc5e4f6 |
27
game.py
27
game.py
|
|
@ -3,8 +3,10 @@
|
||||||
import sys
|
import sys
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
from time import sleep
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import cv2
|
import cv2
|
||||||
|
import requests
|
||||||
|
|
||||||
from utils import *
|
from utils import *
|
||||||
|
|
||||||
|
|
@ -99,11 +101,27 @@ def show_frame(frame: np.ndarray, to_stdout: bool=False) -> None:
|
||||||
cv2.imshow("Image", frame)
|
cv2.imshow("Image", frame)
|
||||||
cv2.waitKey(1)
|
cv2.waitKey(1)
|
||||||
|
|
||||||
|
def collect_vfx() -> None:
|
||||||
|
requests.post('http://10.11.250.225:8080/api/v1/composition/layers/2/clips/5/connect')
|
||||||
|
sleep(1)
|
||||||
|
requests.post('http://10.11.250.225:8080/api/v1/composition/layers/2/clips/7/connect')
|
||||||
|
|
||||||
|
def die_vfx() -> None:
|
||||||
|
requests.post('http://10.11.250.225:8080/api/v1/composition/layers/2/clips/6/connect')
|
||||||
|
sleep(3)
|
||||||
|
requests.post('http://10.11.250.225:8080/api/v1/composition/layers/2/clips/7/connect')
|
||||||
|
|
||||||
|
def green() -> None:
|
||||||
|
threading.Thread(target=collect_vfx).start()
|
||||||
|
|
||||||
|
def die() -> None:
|
||||||
|
threading.Thread(target=die_vfx).start()
|
||||||
|
|
||||||
def main() -> int:
|
def main() -> int:
|
||||||
music = start_game_sfx()
|
music = start_game_sfx()
|
||||||
|
|
||||||
capture: cv2.VideoCapture = cv2.VideoCapture(0)
|
capture: cv2.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=3)
|
||||||
collected_42: bool = True
|
collected_42: bool = True
|
||||||
noise_42img: int = 5
|
noise_42img: int = 5
|
||||||
img42_x: int = -img42_side_len - 1 - noise_42img
|
img42_x: int = -img42_side_len - 1 - noise_42img
|
||||||
|
|
@ -114,7 +132,7 @@ def main() -> int:
|
||||||
finger_y: int = -1
|
finger_y: int = -1
|
||||||
no_collect_ratio = 0
|
no_collect_ratio = 0
|
||||||
no_finger_ratio = 0
|
no_finger_ratio = 0
|
||||||
timer = 1000
|
timer = 200
|
||||||
|
|
||||||
i: int = 0
|
i: int = 0
|
||||||
while True:
|
while True:
|
||||||
|
|
@ -152,8 +170,10 @@ def main() -> int:
|
||||||
no_fingers = 0
|
no_fingers = 0
|
||||||
|
|
||||||
if ratio > 0.99:
|
if ratio > 0.99:
|
||||||
music.kill()
|
if music:
|
||||||
|
music.kill()
|
||||||
lost_sfx()
|
lost_sfx()
|
||||||
|
die()
|
||||||
return score
|
return score
|
||||||
|
|
||||||
for positions in finger_positions:
|
for positions in finger_positions:
|
||||||
|
|
@ -182,6 +202,7 @@ def main() -> int:
|
||||||
initiate_rick()
|
initiate_rick()
|
||||||
timer = 60 + (timer - 60) * .9
|
timer = 60 + (timer - 60) * .9
|
||||||
collect_sfx()
|
collect_sfx()
|
||||||
|
green()
|
||||||
show_frame(frame, to_stdout=(not sys.stdout.isatty()))
|
show_frame(frame, to_stdout=(not sys.stdout.isatty()))
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
absl-py==1.4.0
|
absl-py==1.4.0
|
||||||
attrs==23.1.0
|
attrs==23.1.0
|
||||||
|
certifi==2023.7.22
|
||||||
cffi==1.15.1
|
cffi==1.15.1
|
||||||
|
charset-normalizer==3.2.0
|
||||||
contourpy==1.1.0
|
contourpy==1.1.0
|
||||||
cycler==0.11.0
|
cycler==0.11.0
|
||||||
flatbuffers==23.5.26
|
flatbuffers==23.5.26
|
||||||
fonttools==4.42.0
|
fonttools==4.42.0
|
||||||
|
idna==3.4
|
||||||
kiwisolver==1.4.4
|
kiwisolver==1.4.4
|
||||||
matplotlib==3.7.2
|
matplotlib==3.7.2
|
||||||
mediapipe==0.10.3
|
mediapipe==0.10.3
|
||||||
|
|
@ -20,5 +23,8 @@ pycparser==2.21
|
||||||
PyGObject==3.44.1
|
PyGObject==3.44.1
|
||||||
pyparsing==3.0.9
|
pyparsing==3.0.9
|
||||||
python-dateutil==2.8.2
|
python-dateutil==2.8.2
|
||||||
|
requests==2.31.0
|
||||||
six==1.16.0
|
six==1.16.0
|
||||||
sounddevice==0.4.6
|
sounddevice==0.4.6
|
||||||
|
soundfile==0.12.1
|
||||||
|
urllib3==2.0.4
|
||||||
|
|
|
||||||
23
utils.py
23
utils.py
|
|
@ -6,10 +6,13 @@ from typing import Generator
|
||||||
from types import ModuleType
|
from types import ModuleType
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
import sounddevice as sd
|
||||||
|
import soundfile as sf
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import mediapipe as mp
|
import mediapipe as mp
|
||||||
import cv2
|
import cv2
|
||||||
from playsound import playsound
|
# from playsound import playsound
|
||||||
|
|
||||||
mp_hands = mp.solutions.hands
|
mp_hands = mp.solutions.hands
|
||||||
mp_draw: ModuleType = mp.solutions.drawing_utils
|
mp_draw: ModuleType = mp.solutions.drawing_utils
|
||||||
|
|
@ -41,23 +44,31 @@ def save_score(score: int) -> None:
|
||||||
with open('./.score', 'w') as score_file:
|
with open('./.score', 'w') as score_file:
|
||||||
score_file.write(str(score))
|
score_file.write(str(score))
|
||||||
|
|
||||||
|
def play_audio(file_name: str) -> None:
|
||||||
|
# Read the audio file
|
||||||
|
data, samplerate = sf.read(file_name)
|
||||||
|
|
||||||
|
# Play the audio file
|
||||||
|
sd.play(data, samplerate)
|
||||||
|
sd.wait() # Wait for the audio playback to complete
|
||||||
|
|
||||||
def start_game_sfx() -> None:
|
def start_game_sfx() -> None:
|
||||||
playsound('./assets/sound/start.mp3')
|
play_audio('./assets/sound/start.mp3')
|
||||||
time.sleep(.5)
|
time.sleep(.5)
|
||||||
threading.Thread(target=playsound, args=('./assets/sound/background_music.mp3',), daemon=True).start()
|
threading.Thread(target=play_audio, args=('./assets/sound/background_music.mp3',), daemon=True).start()
|
||||||
|
|
||||||
def collect_sfx() -> None:
|
def collect_sfx() -> None:
|
||||||
pass
|
pass
|
||||||
threading.Thread(target=playsound, args=('./assets/sound/collect.mp3',), daemon=True).start()
|
# threading.Thread(target=play_audio, args=('./assets/sound/collect.mp3',), daemon=True).start()
|
||||||
|
|
||||||
def lost_sfx() -> None:
|
def lost_sfx() -> None:
|
||||||
playsound('./assets/sound/lost.mp3')
|
play_audio('./assets/sound/lost.mp3')
|
||||||
|
|
||||||
def show_matrix() -> None:
|
def show_matrix() -> None:
|
||||||
Popen(['tmatrix'])
|
Popen(['tmatrix'])
|
||||||
|
|
||||||
def initiate_rick() -> None:
|
def initiate_rick() -> None:
|
||||||
threading.Thread(target=playsound, args=('./assets/sound/rick.mp3',), daemon=True).start()
|
# threading.Thread(target=play_audio, args=('./assets/sound/rick.mp3',), daemon=True).start()
|
||||||
cap = cv2.VideoCapture('./assets/video/rick2.mp4')
|
cap = cv2.VideoCapture('./assets/video/rick2.mp4')
|
||||||
fps: int = int(cap.get(cv2.CAP_PROP_FPS))
|
fps: int = int(cap.get(cv2.CAP_PROP_FPS))
|
||||||
desired_delay: float = 1 / fps
|
desired_delay: float = 1 / fps
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue