Exemplo n.º 1
0
 def loadSound(file, volume=0.5):
     if file in SoundPlayer.sounds:
         sound = SoundPlayer.sound[file]
     else:
         sound = pyglet.media.load(Game.getResource(file))
         sound.volume = volume
     return sound
Exemplo n.º 2
0
    def loadImage(file, size=None, xCenterAnchor=True, yCenterAnchor=True, flip=None):
        if file in Renderer.imageCache:
            image = Renderer.imageCache[file]
        else:
            image = pyglet.image.load(Game.getResource(file))
            Renderer.imageCache[file] = image
        
        _image=image
#        if flip:
#            _image = _image.texture.get_transform(flip_x=True).get_region(0, 0, image.width, image.height)

        if size:
            _image= _image.get_texture()
            _image.width=int(size[0])
            _image.height=int(size[1])

        if xCenterAnchor:
            _image.anchor_x = _image.width / 2
        if yCenterAnchor:
            _image.anchor_y = _image.height / 2
        
#        image =image.get_texture()
#        if size:
#            image.width=size[0]
#            image.height=size[1]
        sprite = pyglet.sprite.Sprite(_image)
#        if size:
#            sprite.scale = float(size[0]) / image.width
#            _image=sprite.image.get_texture()
#            _image.width=int(size[0])
#            _image.height=int(size[1])
#            sprite.image=_image
#        
        return sprite
Exemplo n.º 3
0
 def _loadImage(file, size=None, centerAnchor=True, flip=None):
     if file in Renderer.imageCache:
         image = Renderer.imageCache[file]
     else:
         image = pyglet.image.load(Game.getResource(file))
         Renderer.imageCache[file] = image
         
     image.anchor_x = image.width / 2
     image.anchor_y = image.height / 2            
     return image.get_texture()
Exemplo n.º 4
0
    def loadLevel(self, levelNo, isRestart=False):
        
        _file = 'map' + str(levelNo) + '.svg'
        parser = SvgParser(Game.getResource(_file))
        parser.parse()
        w,h=parser.width, parser.height
 
        if isRestart or levelNo>1:
            self.clean()
#            pass
        else:
            WorldConfig.init(width=w, height=h)
            
        self.mainLayer.setText(levels[levelNo]['message'])
        self.mainLoop.executeAfter(lambda dt=0: self.mainLayer.setText(None), 2)
            
        self.enemyCnt=0
        self.foundEnemyCnt=0  
        self.countDown=levels[levelNo]['countDown']     
        
        for shape in parser.shape_list:    
            if shape.role=='player':
                self.player=Player(shape)
            elif shape.role=='ballgen':
                BallGen(shape, delay=max(1, 3-(0.5*levelNo)))
                self.enemyCnt+=1         
            elif shape.role=='launcher':
                Launcher(shape, delay=max(1, 2-(0.3*levelNo)))   
                self.enemyCnt+=1
            elif shape.role=='piston':
                Piston(shape, num=3+random.randrange(0, 4), delay=max(0.5, 2-(0.3*levelNo)))
                self.enemyCnt+=1
            elif shape.role=='rockgen':
                RockGen(shape)    
            else:
                Wall(shape)
                
#        Game.soundPlayer.playSound('32953__HardPCM__Chip053.ogg')

            
        return True