Exemplo n.º 1
0
 def __init__(self, config_filename=None, quit=True, **kwargs):
     self.config = {}  # deprecated!
     if config_filename:
         self.parse_config(config_filename)
     self.screen = Screen()
     self.frame = Frame(self.screen, config.FRAME)
     self.tile_factory = TileFactory()
     self._exit = False
     self._quit = quit  # terminate PyGame when event loop expires
Exemplo n.º 2
0
 def __init__(self):
     self.screen = Screen(Vector(600, 400), 'data/background.png')
     self.frame = Frame(self.screen, Rect(64, 64, 320, 320))
     tile_factory = TileFactory('data/tiles.conf')
     self.tm = TiledMap(self.frame, tile_factory)
     self.player = Sprite(self.frame, tile_factory.get('b.tail'), Vector(4, 1), speed=2)
     self.tm.set_map(BOXMAP)
     self.draw()
     self.events = None
Exemplo n.º 3
0
 def __init__(self, screen):
     self.screen = screen
     self.frame = Frame(self.screen, Rect(64, 64, 320, 320))
     tile_factory = TileFactory('data/tiles.conf')
     self.tm = TiledMap(self.frame, tile_factory)
     self.player = Sprite(self.frame, tile_factory.get('b.pac_right'), Vector(4, 1), speed=2)
     self.tm.set_map(FRUITMAP)
     self.draw()
     self.events = None
     self.score = 0
Exemplo n.º 4
0
    def complete_level(self, current_level):
        self.current_level = current_level + 1
        if self.current_level > 7:
            pygame.quit()
            exit()
        self.frame = Frame(self.screen, Rect(32, 32, 720, 720))
        self.tile_factory = TileFactory('data/colortiles.conf')
        self.level_loader = levels

        self.level = None
        self.player = None
        self.events = None
        self.ghosts = []
        self.update_mode = None
        self.status_box = None

        self.create_level()
        self.create_player()
        self.create_ghosts()
        self.create_status_box()

        self.collided = False
        self.mode = None
        self.update_mode = self.update_ingame
        self.run()
Exemplo n.º 5
0
    def __init__(self, screen):
        self.screen = screen
        self.tile_factory = TileFactory()

        self.starscape = None
        self.level = None
        self.spaceship = None
        self.status_box = None
        self.events = None
        self.score = 0

        self.create_starscape()
        self.create_level()
        self.create_status_box()

        self.update_mode = self.update_ingame
        self.move_delay = MOVE_DELAY
        self.delay = MOVE_DELAY
Exemplo n.º 6
0
    def __init__(self, screen):
        self.screen = screen
        self.frame = Frame(self.screen, Rect(20, 20, 800, 700))
        self.tile_factory = TileFactory('data/colortiles.conf')
        self.current_level = 2
        self.level_loader = levels
        self.score = 0

        self.level = None
        self.player = None
        self.events = None
        self.ghosts = []
        self.update_mode = None
        self.status_box = None
        self.image_box = None

        self.create_level()
        self.create_player()
        self.create_ghosts()
        self.create_status_box()

        self.collided = False
        self.mode = None
        self.update_mode = self.update_ingame
Exemplo n.º 7
0
 def __init__(self):
     pygame.init()
     self.screen = Screen()
     self.tile_factory = TileFactory()
     self.game = Game()
Exemplo n.º 8
0
class Game:
    def __init__(self, config_filename=None, quit=True, **kwargs):
        self.config = {}  # deprecated!
        if config_filename:
            self.parse_config(config_filename)
        self.screen = Screen()
        self.frame = Frame(self.screen, config.FRAME)
        self.tile_factory = TileFactory()
        self._exit = False
        self._quit = quit  # terminate PyGame when event loop expires

    def get_tile(self, key):
        return self.tile_factory.get(key)

    def get_tile_surface(self, key):
        return self.tile_factory.get_surface(key)

    def parse_config(self, config_filename):
        """
        Adds contents of config file to config dictionary.
        """
        warnings.warn('Game.parse_config has been deprecated!')
        path, fn = os.path.split(config_filename)
        self.path = path + os.sep
        before = set(dir())
        conf = open(config_filename).read()
        exec(conf)
        after = set(dir())
        for name in after - before:
            self.config[name] = eval(name)

    def event_loop(self,
                   figure_moves=None,
                   exit=True,
                   draw_func=None,
                   keymap=None,
                   delay=20):
        self.events = EventGenerator()
        if figure_moves:
            self.events.add_listener(FigureMoveListener(figure_moves))
        if keymap:
            self.events.add_listener(EventListener(keymap=keymap))
        if exit:
            self.events.add_listener(ExitListener(self.events.exit_signalled))
        with draw_timer(draw_func, self.events, delay=delay):
            self.events.event_loop()

    def exit(self):
        self.events.exit_signalled()
        # if self._quit:
        #    pygame.quit()

    def wait_for_move(self, move=None, draw_func=None, delay=0.01):
        if type(move) is list:
            move = MoveGroup(move)
        while not move.finished:
            move.move()
            if draw_func:
                self.screen.clear()
                draw_func()
            move.draw()
            pygame.display.update()
            time.sleep(delay)