forked from Johnidel/Python-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenuHandler.py
More file actions
58 lines (44 loc) · 1.2 KB
/
Copy pathmenuHandler.py
File metadata and controls
58 lines (44 loc) · 1.2 KB
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
import pygame
import time
import sys
from menu import Menu
from instructions import Instructions
from credits import Credits
class MenuHandler:
def __init__(self):
self.PLAY_STATE = 3
self.INSTRUCTIONS_STATE = 2
self.CREDITS_STATE = 1
self.MENU_STATE = 0
self.menus = [Menu(self), Credits(self), Instructions(self)]
self.curState = self.MENU_STATE
def draw(self, screen):
self.menus[self.curState].draw(screen)
def update(self):
if self.curState == self.PLAY_STATE:
import Main
sys.exit()
self.menus[self.curState].update()
pygame.init()
size = (1024,768)
pygame.display.set_caption("Body Game")
screen = pygame.display.set_mode(size)
FRAMES_PER_SECOND = 30
TIME_PER_FRAME = 1.0 / 30
time_start = 0
timeS = time.time()
playing = True
handler = MenuHandler()
while playing:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
playing = False
handler.update()
handler.draw(screen)
pygame.display.flip()
if TIME_PER_FRAME - (time.time() - time_start) > .0005:
time.sleep(TIME_PER_FRAME - (time.time() - time_start))
timeSlept += TIME_PER_FRAME - (time.time() - time_start)