pneuma-pygame/game.py

66 lines
1.5 KiB
Python
Raw Normal View History

import os
2023-12-10 13:12:14 +00:00
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
2023-11-19 03:27:47 +00:00
import sys
import pygame
from level import Level
2023-11-19 03:27:47 +00:00
from configs.system.window_config import WIDTH,\
HEIGHT,\
WATER_COLOR,\
FPS
2023-11-19 03:27:47 +00:00
class Game:
def __init__(self, show_pg=False, n_players=1,):
print(f"Initializing Pneuma with {n_players} player(s).\
\nShowing PyGame screen: {'True' if show_pg else 'False'}")
2023-11-19 03:27:47 +00:00
pygame.init()
if show_pg:
2023-11-19 03:27:47 +00:00
self.screen = pygame.display.set_mode(
(WIDTH, HEIGHT)
)
2023-11-19 03:27:47 +00:00
else:
self.screen = pygame.display.set_mode(
(WIDTH, HEIGHT),
pygame.HIDDEN
)
2023-11-23 15:37:02 +00:00
pygame.display.set_caption("Pneuma")
2023-11-23 15:37:02 +00:00
img = pygame.image.load(os.path.join('assets',
'graphics',
'icon.png'))
pygame.display.set_icon(img)
self.level = Level(n_players)
2023-11-19 03:27:47 +00:00
def run(self):
self.clock = pygame.time.Clock()
2023-11-19 03:27:47 +00:00
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.quit()
elif event.type == pygame.KEYDOWN:
2023-11-19 03:27:47 +00:00
if event.key == pygame.K_m:
self.level.pause()
2023-11-19 03:27:47 +00:00
self.screen.fill(WATER_COLOR)
self.level.run('observer', self.clock.get_fps())
2023-11-19 03:27:47 +00:00
pygame.display.update()
self.clock.tick(FPS)
def quit(self):
pygame.quit()
sys.exit()