def test_draw_level(): # make a dummy level from level import Level tiles = [ "########", "########", "## ##", "##@.$ ##", "## *##", "########", "########", "########" ] tiles = list(map(lambda r: list(r), tiles)) level = Level(tiles, [(3, 3), (4, 5)], (3, 2), [(3, 4), (4, 5)]) # load sprites and canvas with pygame pg.init() BASE_RES = (512, 600) # rectangular to test uncolored area pview.set_mode(BASE_RES) # sheet and expected order of images, flattened filename = '../assets/sokobalt_tilesheet_8px.png' sprites = load_spritesheet(filename, SPR_ORDER, 8) done = False while not done: for event in pg.event.get(): if event.type == pg.QUIT: done = True if event.type == pg.KEYDOWN and event.key == pg.K_ESCAPE: done = True if event.type == pg.KEYDOWN and event.key == pg.K_F11: pview.toggle_fullscreen() # draw every loop, kinda wasteful draw_level(level, pview.screen, sprites) pg.display.flip() # tear down pg.quit()
def test_fullscreen(self): if pygame.display.list_modes(): # platform can full screen def get_flags(): return pygame.display.get_surface().get_flags() self.assertEqual(get_flags() & pygame.FULLSCREEN, 0) # start windowed pview.toggle_fullscreen() self.assertEqual(get_flags() & ~pygame.FULLSCREEN, 0) # full screen pview.toggle_fullscreen() self.assertEqual(get_flags() & pygame.FULLSCREEN, 0) # is windowed
def main(): pg.init() pg.display.set_caption('Pang') pview.set_mode((800, 600)) clock = pg.time.Clock() sm.init() while True: ms = clock.tick(settings.FPS) # throttle outcome = controller.poll() # get player input if outcome == OUT_QUIT: break elif outcome == OUT_FSCR: pview.toggle_fullscreen() outcome = sm.scene_manager.tick(ms) # update scene if outcome == OUT_QUIT: break
def main(): # configure the logger before anything else happens logging.config.fileConfig('logging.conf') # The game logger is configured when the config module is imported. log = logging.getLogger('game') log.info('Main started') # load levels levels = load_level_set(LEVELS_FILENAME, LEVELS_MAXSIZE) # list pg.init() pg.display.set_caption('Sokobalt') pview.set_mode(BASE_RES) clock = pg.time.Clock() scenes = {SCN_MENU: MenuScene(levels), SCN_GAME: GameScene(levels)} cur_scene = scenes[SCN_MENU] while True: ms = clock.tick(FPS) # throttle # poll controls outcome = controller.poll() # get player input if outcome == OUT_QUIT: break elif outcome == OUT_FSCR: pview.toggle_fullscreen() cur_scene.redraw() # tick scene next_scene_id, kwargs = cur_scene.tick(ms) if next_scene_id == SCN_QUIT: # quit via dummy scene constant break elif next_scene_id is not None: # change scene cur_scene.pause() cur_scene = scenes[next_scene_id] cur_scene.resume(**kwargs)
if __name__ == "__main__": import settings pg.init() pview.set_mode((800, 600)) clock = pg.time.Clock() # dummy data class DummyState(): def __init__(self): self.mana = 20 self.mana_max = 100 state = DummyState() hud = Hud(state, (0, 0, 800, 100)) # loop done = False while not done: for event in pg.event.get(): # process inputs if event.type == pg.QUIT: done = True if event.type == pg.KEYDOWN: if event.key == pg.K_ESCAPE: done = True elif event.key == pg.K_F11: pview.toggle_fullscreen() hud.stale = 1 ms = clock.tick(settings.FPS) hud.tick(ms) pg.display.set_caption('game scene %.1f' % clock.get_fps())