-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.py
85 lines (63 loc) · 2.79 KB
/
game.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
##########################################################################################
# Welcome to official another Python game menu. #
# License will be avaiable on file *LICENSE* #
# However if you have any problems and bugs please Create new issue above #
# NOTE: You can choose any options Like this: Play, settings, Quit and much more! #
# WARNING: Make sure if you have installed pygame, but without pygame isn't recommended. #
# Thanks :) #
##########################################################################################
# Import modules
import pygame, sys
from menu import Menu
from menu_settings import Settings_menu
from settings import *
import time
# Class Application Games
class Game:
def __init__(self):
pygame.init()
self.screen = pygame.display.set_mode((800, 600))
pygame.display.set_caption("Pygame Menu")
self.in_menu = True
self.in_settings = False
self.clock = pygame.time.Clock()
self.menu = Menu()
self.settings = Settings_menu()
def update(self):
self.clock.tick(60)
def check_events_and_drawing(self):
if self.in_menu:
for event in pygame.event.get():
if event.type == pygame.QUIT:
print("Closing Down")
time.sleep(1)
pygame.quit()
sys.exit()
self.menu.handle_events(event)
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RETURN:
if self.menu.options[self.menu.selected] == "Settings":
self.in_settings = True
self.in_menu = False
self.screen.fill(BLACK)
self.menu.draw(self.screen)
pygame.display.update()
if self.in_settings:
for event in pygame.event.get():
if event.type == pygame.QUIT:
print("Closing Down")
pygame.quit()
sys.exit()
self.settings.handle_event(event)
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RETURN:
if self.settings.options[self.settings.selected] == "Back":
self.in_menu = True
self.in_settings = False
self.screen.fill(BLACK)
self.settings.draw(self.screen)
pygame.display.update()
def run(self):
while True:
self.check_events_and_drawing()
self.update()