class Application: """Base class of the game. Here is the game loop""" defaultWidth = 1280 defaultHeight = 800 def __init__(self): self.window = ApplicationWindow(self, Application.defaultWidth, Application.defaultHeight) self.keys = self.setupKeyboard() self.controller = Level(self.window, self.keys, "resources/levels/level1-1.tmx") self.start() def start(self): self.running = True pyglet.clock.set_fps_limit(60) self.window.switch_to() fps = pyglet.clock.ClockDisplay() while self.running: pyglet.clock.tick() self.window.dispatch_events() self.controller.update() fps.draw() self.window.dispatch_event("on_draw") self.window.flip() def setupKeyboard(self): keys = key.KeyStateHandler() self.window.push_handlers(keys) return keys def on_draw(self): self.window.clear() self.controller.draw() def on_mouse_press(self, x, y, button, modifier): self.controller.handleMouse(x, y, button, modifier) def on_close(self): print("Exited") self.window.close() self.running = False
def __init__(self): self.window = ApplicationWindow(self, Application.defaultWidth, Application.defaultHeight) self.keys = self.setupKeyboard() self.controller = Level(self.window, self.keys, "resources/levels/level1-1.tmx") self.start()