-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.py
57 lines (50 loc) · 2.22 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
import pygame
from menu import *
class Game():
def __init__(self):
pygame.init()
self.running, self.playing = True, False
self.UP_KEY, self.DOWN_KEY, self.START_KEY, self.BACK_KEY = False, False, False, False
self.DISPLAY_W, self.DISPLAY_H = 480, 270
self.display = pygame.Surface((self.DISPLAY_W, self.DISPLAY_H))
self.window = pygame.display.set_mode(((self.DISPLAY_W, self.DISPLAY_H)))
self.font_name = '8-BIT WONDER.TTF'
# self.font_name = pygame.font.get_default_font()
self.BLACK, self.WHITE = (0, 0, 0), (255, 255, 255)
self.main_menu = MainMenu(self)
self.options = OptionsMenu(self)
self.credits = CreditsMenu(self)
self.curr_menu = self.main_menu
def game_loop(self):
while self.playing:
self.check_events()
if self.START_KEY:
self.playing = False
self.display.fill(self.BLACK)
self.draw_text('Thanks for Playing', 20, self.DISPLAY_W / 2, self.DISPLAY_H / 2)
self.window.blit(self.display, (0, 0))
pygame.display.update()
self.reset_keys()
def check_events(self):
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.running, self.playing = False, False
self.curr_menu.run_display = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RETURN:
self.START_KEY = True
if event.key == pygame.K_BACKSPACE:
self.BACK_KEY = True
if event.key == pygame.K_DOWN:
self.DOWN_KEY = True
if event.key == pygame.K_UP:
self.UP_KEY = True
def reset_keys(self):
self.UP_KEY, self.DOWN_KEY, self.START_KEY, self.BACK_KEY = False, False, False, False
def draw_text(self, text, size, x, y):
#font = pygame.font.Font(self.font_name, size)
font = pygame.font.Font("./Graphics/8-BIT WONDER.TTF", size)
text_surface = font.render(text, True, self.WHITE)
text_rect = text_surface.get_rect()
text_rect.center = (x, y)
self.display.blit(text_surface, text_rect)