-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
57 lines (47 loc) · 1.48 KB
/
main.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
import logging
import os
from src.config import Config, GameState
from src.game_service import Game
def main():
log.info("Game start.")
pygame.init()
# pygame event handling
pygame.event.set_blocked(None)
pygame.event.set_allowed([pygame.QUIT, pygame.KEYDOWN, pygame.KEYUP])
pygame.key.set_repeat()
pygame.mouse.set_visible(False)
# initialise objects
game = Game()
clock = pygame.time.Clock()
while game.running:
if Config.status is GameState.GAME_END:
game.death()
elif Config.status == GameState.GAME_PLAY:
if game.paused:
game.pause()
else:
game.run()
pygame.display.flip()
clock.tick(Config.FPS)
log.debug(f"FPS: {clock.get_fps()}")
# exit
log.info("Game end.")
pygame.quit()
raise SystemExit
if __name__ == "__main__":
# setup logger
log_format = "%(asctime)s - %(levelname)s - %(name)s - %(filename)s - %(lineno)d - %(message)s"
log = logging.getLogger("runningman")
log.setLevel(Config.log_level)
if not os.path.isdir("logs"):
os.mkdir("logs")
file_handler = logging.FileHandler("logs/app.log", mode='w')
formatter = logging.Formatter(log_format)
file_handler.setFormatter(formatter)
log.addHandler(file_handler)
if Config.log:
logging.disable(logging.NOTSET)
elif Config.log is False:
logging.disable(logging.CRITICAL)
main()