-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
54 lines (43 loc) · 1.32 KB
/
main.py
File metadata and controls
54 lines (43 loc) · 1.32 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
import logging
import sys
import pygame
from zelda.log import setup_logging
from zelda.settings import SCREEN_WIDTH, SCREEN_HEIGHT, FPS, GAME_TITLE
from zelda.data.color import WATER_COLOR
from zelda.data.controls import *
from zelda.level import Level
# from zelda.debug import debug
logging.getLogger(__name__)
class Game:
def __init__(self):
# general setup
pygame.init()
self.screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption(GAME_TITLE)
self.clock = pygame.time.Clock()
self.level = Level()
def run(self):
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == CONTROLS[Controls.TOGGLE_MENU]:
self.level.toggle_menu()
self.screen.fill(WATER_COLOR)
self.clock.tick(FPS)
self.level.run()
pygame.display.update()
def run_game():
try:
setup_logging()
game = Game()
game.run()
except KeyboardInterrupt:
sys.exit()
except Exception as e:
logging.error(e)
raise e
if __name__ == '__main__':
run_game()