-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjustmoove.py
125 lines (92 loc) · 3.44 KB
/
justmoove.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import cv2
import time
import pygame
import sys
import numpy as np
import argparse
from scenes.end_scene import EndScene
from scenes.level_scene import LevelScene
import scenes.title_scene
from pygame.font import Font
from media_library import MediaLibrary
from scenes.game_scene import GameScene
from scenes.scene import SceneBase
from scenes.scenes import get_scene, get_start_scene, set_scene, set_start_scene
from scenes.title_scene import TitleScene
from scenes.url_scene import UrlScene
from scenes.videodl_scene import VideoDlScene
from video_impl import CV2VideoFrames, RecordedCV2VideoFrames, VideoFramesBase
from game_state import GameVideoConfiguration, GameState
from motion_tracker import create_motion_tracker
from media_library import VideoMetadata, PosePosition
from tkinter import Tk
from tkinter import messagebox
Tk().wm_withdraw()
CAMERA_PARAM = 0
try:
from skellytracker.trackers.mediapipe_tracker.mediapipe_holistic_tracker import(
MediapipeHolisticTracker,
)
except:
print("To use mediapipe_holistic_tracker, install skellytracker[mediapipe]")
exit()
def init_game():
pygame.init()
pygame.mixer.init()
pygame.display.set_caption("JustMoove")
pygame.display.set_icon(pygame.image.load("images/icon.png"))
display = pygame.display.set_mode(scenes.title_scene.TITLE_RESOLUTION)
pygame.scrap.init()
video_library = MediaLibrary()
video_library.load_videos()
state = GameState(
pygame.font.Font("fonts/Modak-Regular.ttf", 64), display, video_library
)
video_config = GameVideoConfiguration(30,
state.videos.get_video(0),
RecordedCV2VideoFrames(state.videos.get_video(0)),
CV2VideoFrames(cv2.VideoCapture(CAMERA_PARAM)),
create_motion_tracker()
)
if not video_config.camera.is_open():
messagebox.showerror("Error","Webcam device not found or accessible.")
raise Exception("Could not open video device")
set_scene("Title", TitleScene(state))
set_scene("Game", GameScene(video_config, state))
set_scene("Level", LevelScene(video_config, state))
set_scene("End", EndScene(video_config, state))
set_scene("Url", UrlScene(state))
set_scene("VideoDl", VideoDlScene(video_library, state))
return video_config, state
def game_loop(video_config: GameVideoConfiguration, state: GameState):
scene = get_start_scene()
scene.on_load()
running = True
while running:
start_time = time.time()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
scene.handle_event(event)
scene.update()
scene.render(pygame.display.get_surface())
pygame.display.flip()
next_scene = scene.pop_next_scene()
if next_scene:
scene = next_scene
scene.on_load()
# Wait until it's time for the next frame
elapsed = time.time() - start_time
delay = max(1, int((video_config.frame_interval() - elapsed) * 1000)) # Calculate remaining time in ms
pygame.time.wait(delay)
pygame.quit()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--video", default=None)
parser.add_argument("scene", nargs="?", default="Title")
args = parser.parse_args()
set_start_scene(args.scene)
if args.video:
CAMERA_PARAM = args.video
video_config, state = init_game()
game_loop(video_config, state)