-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paththe_expression.py
163 lines (131 loc) · 5.24 KB
/
the_expression.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import pygame
import pygame.camera
import numpy as np
import argparse
import os
from Game_Data.UI import *
from Model.models import AV_Estimator, Face_Detector
#Init Camera
def camera_setup():
pygame.camera.init()
list_pycam = pygame.camera.list_cameras()
if (len(list_pycam) == 0):
print("ERROR: No camera detected!")
return False
os.system('cls||clear')
print("List camera available:")
for camera_idx in range(len(list_pycam)):
print(camera_idx,". ",list_pycam[camera_idx], sep = '')
while (True):
pycamera = input("Enter camera number: ")
if int(pycamera) >= len(list_pycam) or int(pycamera) < 0:
print("ERROR: Camera is not available!")
else:
break
pycamera = pygame.camera.Camera(list_pycam[int(pycamera)])
pycamera.start()
return pycamera
#Setting up game window
def setup():
pygame.init()
pygame.display.init()
screen = pygame.display.set_mode()
pygame.mixer.init()
clock = pygame.time.Clock()
return screen, clock
#Load models Arousal_Valence Estimator and Face Detector
AV = AV_Estimator(path = "Model/trained_VGG16-VA.h5")
FD = Face_Detector()
pycamera = camera_setup()
#Quit if no camera detected
if type(pycamera) is bool:
quit()
#Initialization
screen, clock = setup()
camera = Camera(screen, pycamera, flip_x = False, flip_y = False, rotating_state = 0)
background = Animated_Background(screen = screen)
menu = Main_Menu(screen)
click_sound = pygame.mixer.Sound("Game_Data/sound/mixkit-game-click-1114.wav")
bgms = ["Game_Data/sound/bensound-acousticbreeze.mp3", "Game_Data/sound/bensound-jazzyfrenchy.mp3"]
pygame.mixer.music.load(bgms[0])
pygame.mixer.music.set_volume(0.3)
pygame.mixer.music.play()
def update():
menu.update()
def draw():
background.draw(screen)
menu.draw(screen)
pygame.display.update()
return 0
if __name__ == "__main__":
exit = False
FPS = 60
#menu_indicator: 0 Main Menu, 1 is Play Menu, 2 Camera Calibration Menu
current_menu = 0
while (not(exit)):
for event in pygame.event.get():
# detect quit event
if event.type == pygame.QUIT:
exit = True
# detect mouse click event
if (event.type == pygame.MOUSEBUTTONUP):
flag = 0
#Main Menu button click
if (current_menu == 0):
if (menu.buttons[0].on_hover()): #Play button
current_menu = 1
menu = Play_Menu(AV, FD, camera, screen)
pygame.mixer.music.unload()
pygame.mixer.music.load(bgms[1])
pygame.mixer.music.play()
pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_ARROW)
flag = 1
elif (menu.buttons[1].on_hover()): #Camera Setting button
current_menu = 2
menu = Camera_Menu(camera, screen, FD)
pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_ARROW)
flag = 1
elif (menu.buttons[2].on_hover()): #Exit button
exit = True
flag = 1
#Play Menu
elif (current_menu == 1):
if (menu.round.isEnd()): #Only allow click if the game ends
if (menu.buttons[0].on_hover()): #Replay
menu = Play_Menu(AV, FD, camera, screen)
pygame.mixer.music.unload()
pygame.mixer.music.load(bgms[1])
pygame.mixer.music.play()
pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_ARROW)
flag = 1
elif (menu.buttons[1].on_hover()): #Back to Main Menu
current_menu = 0
menu = Main_Menu(screen)
pygame.mixer.music.unload()
pygame.mixer.music.load(bgms[0])
pygame.mixer.music.play()
pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_ARROW)
flag = 1
#Camera Settings
elif (current_menu == 2):
if (menu.buttons[0].on_hover()):
camera.rotate()
flag = 1
elif (menu.buttons[1].on_hover()):
camera.flip_on_x()
flag = 1
elif (menu.buttons[2].on_hover()):
camera.flip_on_y()
flag = 1
elif (menu.buttons[3].on_hover()):
current_menu = 0
menu = Main_Menu(screen)
pygame.mouse.set_cursor(pygame.SYSTEM_CURSOR_ARROW)
flag = 1
if (flag == 1):
click_sound.play()
update() #Components update their status every frame
draw() #draw components every frame
clock.tick(FPS)
pygame.quit()
quit