예제 #1
0
    def __init__(self, name, group=None):
        self.name = name
        info_path = util.respath('environments', name, 'info.json')
        with pyglet.resource.file(info_path, 'r') as info_file:
            info = json.load(info_file)
            self.background_tile_rows = info['tile_rows']
            self.background_tile_cols = info['tile_columns']
        self.background_batch = pyglet.graphics.Batch()
        self.background_sprites = []
        self.overlay_batch = pyglet.graphics.Batch()
        self.overlay_sprites = []

        self.width = 0
        self.height = 0
        background_sprites_dict = {}
        tile_w = 0
        tile_h = 0
        for x in range(self.background_tile_cols):
            this_y = 0
            for y in range(self.background_tile_rows):
                img = util.load_image(
                    util.respath('environments', name, '%d_%d.png' % (x, y)))
                tile_w, tile_h = img.width, img.height
                new_sprite = pyglet.sprite.Sprite(img,
                                                  x=x * tile_w,
                                                  y=y * tile_h,
                                                  batch=self.background_batch,
                                                  group=group)
                self.background_sprites.append(new_sprite)
                background_sprites_dict[(x, y)] = new_sprite
        for x in range(self.background_tile_cols):
            self.width += background_sprites_dict[(x, 0)].width
        for y in range(self.background_tile_rows):
            self.height += background_sprites_dict[(0, y)].height
        gamestate.camera_max = (self.width - gamestate.norm_w // 2,
                                self.height - gamestate.norm_h // 2)

        for x in range(self.background_tile_cols):
            for y in range(self.background_tile_rows):
                overlay_tile_path = util.respath('environments', name,
                                                 'overlay_%d_%d.png' % (x, y))
                try:
                    img = util.load_image(overlay_tile_path)
                    new_sprite = pyglet.sprite.Sprite(img,
                                                      x=x * tile_w,
                                                      y=y * tile_h,
                                                      batch=self.overlay_batch)
                    self.overlay_sprites.append(new_sprite)
                except pyglet.resource.ResourceNotFoundException:
                    pass  # Ignore if no overlay

        self.draw = self.background_batch.draw
        self.draw_overlay = self.overlay_batch.draw
        self.behind = util.load_image('environments/spacebackground.png')
예제 #2
0
 def __init__(self, name, group=None):
     self.name = name
     info_path = util.respath('environments', name, 'info.json')
     with pyglet.resource.file(info_path, 'r') as info_file:
         info = json.load(info_file)
         self.background_tile_rows = info['tile_rows']
         self.background_tile_cols = info['tile_columns']
     self.background_batch = pyglet.graphics.Batch()
     self.background_sprites = []
     self.overlay_batch = pyglet.graphics.Batch()
     self.overlay_sprites = []
     
     self.width = 0
     self.height = 0
     background_sprites_dict = {}
     tile_w = 0
     tile_h = 0
     for x in range(self.background_tile_cols):
         this_y = 0
         for y in range(self.background_tile_rows):
             img = util.load_image(util.respath('environments', 
                                                      name, 
                                                      '%d_%d.png' % (x, y)))
             tile_w, tile_h = img.width, img.height
             new_sprite = pyglet.sprite.Sprite(img, x=x*tile_w, y=y*tile_h,
                                               batch=self.background_batch,
                                               group=group)
             self.background_sprites.append(new_sprite)
             background_sprites_dict[(x, y)] = new_sprite
     for x in range(self.background_tile_cols):
         self.width += background_sprites_dict[(x, 0)].width
     for y in range(self.background_tile_rows):
         self.height += background_sprites_dict[(0, y)].height
     gamestate.camera_max = (self.width-gamestate.norm_w//2, self.height-gamestate.norm_h//2)
     
     for x in range(self.background_tile_cols):
         for y in range(self.background_tile_rows):
             overlay_tile_path = util.respath('environments', name, 'overlay_%d_%d.png' % (x, y))
             try:
                 img = util.load_image(overlay_tile_path)
                 new_sprite = pyglet.sprite.Sprite(img, x=x*tile_w, y=y*tile_h,
                                                   batch=self.overlay_batch)
                 self.overlay_sprites.append(new_sprite)
             except pyglet.resource.ResourceNotFoundException:
                 pass    # Ignore if no overlay
     
     self.draw = self.background_batch.draw
     self.draw_overlay = self.overlay_batch.draw
     self.behind = util.load_image('environments/spacebackground.png')
예제 #3
0
파일: ui.py 프로젝트: Merfie/Space-Train
 def __init__(self):
     self.cam = None
     self.batch = pyglet.graphics.Batch()
     self.sprites = []
     self.inventory = inventory.Inventory()
     img = util.load_image(util.respath('actors', 'fist', 'stand_front.png'))
     img_data = img.get_image_data()
     img_w = img_data.width
     img_h = img_data.height
     sprite = pyglet.sprite.Sprite(img, x = gamestate.norm_w, y = gamestate.norm_h - img_h, batch=self.batch)
     self.sprites.append(sprite)
예제 #4
0
 def __init__(self, game_handler):
     super(SceneHandler, self).__init__()
     self.scene = None   # Main scene
     self.scenes = []    # Scenes to be drawn
     self.handler = game_handler
     
     self.controller = interpolator.InterpolatorController()
     self.fade_time = 1.0
     self.batch = pyglet.graphics.Batch()
     
     # Build transition sprite(s)
     scene_transition_img = util.load_image(util.respath('environments', 'transitions', 'test.png'))
     self.sprite = pyglet.sprite.Sprite(scene_transition_img, x = 0, y = 0, batch=self.batch)
     self.sprite.opacity = 0