pgfw/pgfw/Game.py

62 lines
1.8 KiB
Python

import pygame
from pygame.time import get_ticks, wait
from pygame.locals import *
from GameChild import GameChild
from Mainloop import Mainloop
from Audio import Audio
from Display import Display
from Configuration import Configuration
from Delegate import Delegate
from Input import Input
from ScreenGrabber import ScreenGrabber
class Game(GameChild):
resource_path = None
def __init__(self, config_rel_path=None, type_declarations=None):
GameChild.__init__(self)
self.print_debug(pygame.version.ver)
self.config_rel_path = config_rel_path
self.type_declarations = type_declarations
self.set_configuration()
pygame.init()
self.set_children()
self.subscribe(self.end, QUIT)
self.subscribe(self.end)
self.delegate.enable()
def set_configuration(self):
self.configuration = Configuration(self.config_rel_path,
self.resource_path,
self.type_declarations)
def set_children(self):
self.delegate = Delegate(self)
self.display = Display(self)
self.mainloop = Mainloop(self)
self.input = Input(self)
self.audio = Audio(self)
self.screen_grabber = ScreenGrabber(self)
def frame(self):
self.delegate.dispatch()
self.update()
def run(self):
self.mainloop.run()
def update(self):
pass
def blit(self, source, destination, area=None, special_flags=0):
self.get_screen().blit(source, destination, area, special_flags)
def get_rect(self):
return self.get_screen().get_rect()
def end(self, evt):
if evt.type == QUIT or self.delegate.compare(evt, "quit"):
self.mainloop.stop()