예제 #1
0
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()
예제 #2
0
    def main():
        from settings import FPS, BASE_RES

        pg.init()
        pview.set_mode(BASE_RES)
        clock = pg.time.Clock()
        levels = [1, 2, 3, 4, 5, 6]
        scene = MenuScene(levels)
        while not pg.event.peek([pg.QUIT, pg.KEYDOWN]):
            ms = clock.tick(FPS)
            scene_id, kwargs = scene.tick(ms)
예제 #3
0
 def setUp(self):
     #         drivers = ['windib', 'directx', 'x11', 'dga', 'fbcon', 'directfb',
     #                    'ggi', 'vgl', 'svgalib', 'aalib', 'dummy']
     #         for driver in drivers:
     #             if not os.getenv('SDL_VIDEODRIVER'):
     #                 os.putenv('SDL_VIDEODRIVER', driver)
     #             try:
     #                 pygame.display.init()
     #             except pygame.error:
     #                 print('Driver: {0} failed.'.format(driver))
     #                 continue
     #             print('Driver: {0} loaded.'.format(driver))
     #             break
     pygame.display.init()  # this errors in Travis CI.
     # baseline resolution is 640x480 and actual resolution is 1280x960
     pview.set_mode(size0=(640, 480), height=960)
예제 #4
0
파일: main.py 프로젝트: gentimouton/pang
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
예제 #5
0
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)
예제 #6
0
파일: hud.py 프로젝트: gentimouton/olympus
        v = self.vfunc()
        vmax = self.vmaxfunc()
        if self.v != v or self.vmax != vmax:  # values changed in game state
            self.v = v
            self.vmax = vmax
            w, h = self.rect0.size  # rect0 from parent class
            fh = h * v // self.vmax  # height of full part, in base resolution
            shape = Shape('rect', (0, h - fh, w, fh), self._gauge_color)
            self.set_shapes([shape])
        NeatSprite.update(self)


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:
예제 #7
0
 def test_change_mode(self):
     base_h = pview.h
     pview.set_mode(height=200)
     self.assertEqual(pview.h, 200)
     pview.set_mode(height=base_h)
     self.assertEqual(pview.h, base_h)
예제 #8
0
        # TODO: level navigator menu (can replay any unlocked one)

    def redraw(self):
        # TODO: recompute/redraw bg
        # self._draw()
        pass


if __name__ == "__main__":
    from constants import OUT_QUIT, OUT_FSCR
    from settings import LEVELS_FILENAME, LEVELS_MAXSIZE
    from level import load_level_set

    pg.init()
    pview.set_mode(BASE_RES)
    clock = pg.time.Clock()
    levels = load_level_set(LEVELS_FILENAME, LEVELS_MAXSIZE)  # list
    scene = GameScene(levels)
    while True:
        ms = clock.tick(30)
        outcome = controller.poll()  # get player input
        if outcome == OUT_QUIT:
            break
        elif outcome == OUT_FSCR:
            pview.toggle_fullscreen()
            scene.redraw()

        next_scene_id, kwargs = scene.tick(ms)
        if next_scene_id == SCN_GAME:  # level completed, switch to game scene
            scene.resume(**kwargs)
예제 #9
0
import pygame, sys, random
import pview
from pview import T

pygame.display.init()
pygame.display.set_caption("Floppy Blard")
pygame.font.init()
forceres = "--forceres" in sys.argv
pview.set_mode((600, 400), forceres=forceres)

fonts = {}


def write(text, fontsize, pos=None, **kw):
    if fontsize not in fonts:
        fonts[fontsize] = pygame.font.Font(None, fontsize)
    surf = fonts[fontsize].render(text, True, (255, 255, 255))
    pview.screen.blit(surf, pos or surf.get_rect(**kw))


x, y, vx, vy, slope = 0, 200, 80, 0, 0
clock = pygame.time.Clock()
alive = True
playing = True
while playing:
    dt = clock.tick() * 0.001
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                playing = False
            if event.key == pygame.K_1:
예제 #10
0
                            color=color,
                            txt=txt,
                            fontsize=24,
                            txt_positioning='center',
                            bcol=(111, 111, 55),
                            bthick=2)


if __name__ == "__main__":
    import settings
    import random
    from game_model import ENC_DFLT
    random.seed(2)
    pg.init()
    res = 800, 600
    pview.set_mode(res)
    clock = pg.time.Clock()

    # dummy data
    class DummyState():
        def __init__(self):
            self.cur_enc = ENC_DFLT

    state = DummyState()
    enc = EncounterRenderer(state, (0, 100, 800, 500))
    # loop
    done = False
    while not done:
        for event in pg.event.get():  # process inputs
            if event.type == pg.QUIT:
                done = True