-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUI.py
156 lines (129 loc) · 5.71 KB
/
UI.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
import pygame, os, time, random
pygame.init()
screen = pygame.display.set_mode((600, 500))
pygame.display.set_caption('Baseball!!!')
COLOR_INACTIVE = pygame.Color('white')
COLOR_ACTIVE = pygame.Color('black')
FONT = pygame.font.Font(None, 32)
class InputBox:
def __init__(self, x, y, w, h, text=''):
self.rect = pygame.Rect(x, y, w, h)
self.color = COLOR_INACTIVE
self.text = text
self.txt_surface = FONT.render(text, True, self.color)
self.active = False
def handle_event(self, event):
if event.type == pygame.MOUSEBUTTONDOWN:
# If the user clicked on the input_box rect.
if self.rect.collidepoint(event.pos):
# Toggle the active variable.
self.active = not self.active
else:
self.active = False
# Change the current color of the input box.
self.color = COLOR_ACTIVE if self.active else COLOR_INACTIVE
if event.type == pygame.KEYDOWN:
if self.active:
if event.key == pygame.K_BACKSPACE:
self.text = self.text[:-1]
else:
self.text += event.unicode
# Re-render the text.
self.txt_surface = FONT.render(self.text, True, self.color)
def update(self):
# Resize the box if the text is too long.
width = max(150, self.txt_surface.get_width()+10)
self.rect.w = width
def draw(self, screen):
# Blit the text.
screen.blit(self.txt_surface, (self.rect.x+5, self.rect.y+5))
# Blit the rect.
pygame.draw.rect(screen, self.color, self.rect, 2)
def return_str(self):
return self.text
class First_screen():
def __init__(self,screen):
self.clock = pygame.time.Clock()
self.background = pygame.image.load("pic/penguin.jpg")
self.background = pygame.transform.smoothscale(self.background,(600,500))
self.button = pygame.image.load("pic/next.png")
self.button = pygame.transform.smoothscale(self.button,(200,170)).convert_alpha()
self.input_box_name = InputBox(60,140,50,32)
self.input_box_height = InputBox(400,140,50,32)
self.input_boxes = [self.input_box_name, self.input_box_height]
self.done = False
self.remove_screen = False
def routine(self):
while not self.done:
screen.blit(self.background,(0,0))
screen.blit(self.button,(200,300))
text = FONT.render("Enter your name",True,(0,0,0))
screen.blit(text, (43,115))
text = FONT.render("Enter your height", True, (0,0,0))
screen.blit(text, (390,115))
for box in self.input_boxes:
box.update()
box.draw(screen)
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.done = True
for box in self.input_boxes:
box.handle_event(event)
if event.type == pygame.MOUSEBUTTONDOWN:
pos = pygame.mouse.get_pos()
if (267 < pos[0] < 322) and (316 < pos[1] < 360) :
name,height = self.input_boxes[0].return_str(), self.input_boxes[1].return_str()
#go to next screen
self.background.fill((255,255,255))
screen.blit(self.background,(0,0))
print(name,height)
self.done = True
pygame.display.flip()
self.clock.tick(30)
class Menu():
def __init__(self,screen):
self.background = pygame.image.load("pic/menu.JPG")
self.background = pygame.transform.smoothscale(self.background.convert_alpha(),(600,500))
self.start_button = pygame.image.load("pic/white_menu_button.JPG")
self.start_button = pygame.transform.smoothscale(self.start_button.convert_alpha(),(200,100))
self.quit_button = pygame.image.load("pic/quit.JPG")
self.quit_button = pygame.transform.smoothscale(self.quit_button.convert_alpha(),(200,100))
self.done = False
def routine(self):
while not self.done:
screen.blit(self.background,(0,0))
screen.blit(self.start_button,(349,67))
screen.blit(self.quit_button,(349, 350))
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
if (349 < pygame.mouse.get_pos()[0] < 550) and (69 < pygame.mouse.get_pos()[1] < 169):
self.done = True
screen.fill((255,255,255))
# next screen
if (349 < pygame.mouse.get_pos()[0] < 550) and (350 < pygame.mouse.get_pos()[1]<450):
pygame.quit()
pygame.display.flip()
from Gait_Tracking import script
from Collect import collect
class Ball_screen():
def __init__(self,screen):
self.background = pygame.image.load("pic/strike.jpg")
self.background = pygame.transform.smoothscale(self.background,(600,500))
self.baseball_pic = pygame.image.load("pic/baseball.png")
self.baseball_pic = pygame.transform.smoothscale(self.baseball_pic.convert_alpha(),(200,100))
def routine(self):
screen.blit(self.background,(0,0))
screen.blit(self.baseball_pic,(random.randint(280,500),random.randint(191,400)))
pygame.display.flip()
collect()
script.run()
if __name__ == '__main__':
f = First_screen(screen)
a = Menu(screen)
b = Ball_screen(screen)
f.routine()
while 1:
a.done = False
a.routine()
b.routine()
pygame.quit()