当前位置: 首页>>代码示例>>Python>>正文


Python Background.move方法代码示例

本文整理汇总了Python中background.Background.move方法的典型用法代码示例。如果您正苦于以下问题:Python Background.move方法的具体用法?Python Background.move怎么用?Python Background.move使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在background.Background的用法示例。


在下文中一共展示了Background.move方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: RootWidget

# 需要导入模块: from background import Background [as 别名]
# 或者: from background.Background import move [as 别名]
class RootWidget(Widget):

    def __init__(self, **kw):
        super(RootWidget, self).__init__(**kw)
        self.level = 1
        self.seconds = 0
        self.combo = 1
        self.score = 0
        self.hits = 0
        self.cons = 0
        self.rainboxes = [Rainbox(pos=(-500, 0)) for i in range(10)]
        self.powerup = Powerup()
        self.miniball = Rainball(size=(60, 60), name='mini')
        self.miniball.speed = 20
        self.maxiball = Rainball(size=(120, 120), name='maxi', element='stone')
        self.background = Background(size=Window.size)
        self.target_l = Image(source='img/target_l.zip', size=(60, 60))
        self.lbl_fps = Label(pos=(Window.width -100, 0))
        self.lbl_level = PopLabel(
            pos=(100, Window.height-100),
            font_name='font/Mouser.ttf')
        self.lbl_hits = PopLabel(
            pos=(100, Window.height-140),
            font_name='font/Mouser.ttf')
        self.lbl_combo = PopLabel(
            pos=(100, Window.height-180),
            font_name='font/Mouser.ttf')
        self.lbl_score = PopLabel(
            pos=(100, Window.height-220),
            font_name='font/Mouser.ttf')
        self.add_widget(self.background, canvas='before')
        self.add_widget(self.target_l)
        self.add_widget(self.miniball)
        self.add_widget(self.maxiball)
        self.add_widget(self.lbl_fps)
        self.add_widget(self.lbl_level)
        self.add_widget(self.lbl_hits)
        self.add_widget(self.lbl_combo)
        self.add_widget(self.lbl_score)
        self.add_widget(self.powerup)
        for i in range(10):
            self.add_widget(self.rainboxes[i])
        self._keyboard = Window.request_keyboard(
            self._keyboard_closed, self, 'text')
        self._keyboard.bind(on_key_down=self._on_key_down)
        sounds['music'].loop = True
        sounds['music'].play()
        Clock.schedule_interval(self.update, 1/60.)

    def update(self, dt):
        self.background.move()
        miniball = self.miniball
        self.miniball.move()
        maxiball = self.maxiball
        maxiball.move()
        # powerup collision
        powerup = self.powerup
        powerup.move()
        d_maxi =  distance(powerup, maxiball)
        if d_maxi < powerup.hitbox + maxiball.hitbox:
            self.combo += 1
            sounds['powerup'].play()
            maxiball.color = powerup.fg_img.color
            maxiball.element = powerup.element
            if powerup.element == 'ice':
                for i in range(self.level):
                    self.rainboxes[i].frozen = 180
            print miniball.hitbox
            miniball.deployed = powerup.element == 'fire'
            print miniball.hitbox
            powerup.reset()
        # mistake mini
        d_mini =  distance(powerup, miniball)
        if d_mini < powerup.hitbox + miniball.hitbox:
            self.combo = 1
            sounds['hurt'].play()
            powerup.reset()
            if maxiball.element == 'stone':
                self.end_game()
            else: maxiball.element = 'stone'
            miniball.deployed = False
        # box collision
        for i in range(self.level):
            rainbox = self.rainboxes[i]
            rainbox.move()
            d_mini =  distance(rainbox, miniball)
            if d_mini < rainbox.hitbox + miniball.hitbox:
                print rainbox.hitbox, miniball.hitbox
                self.hits += 1
                self.cons += 1
                if self.cons == 10:
                    self.level += 1
                    sounds['levelup'].play()
                self.score += self.hits * self.combo
                sounds['hit'].play()
                rainbox.reset()
            # mistake maxi
            d_maxi =  distance(rainbox, maxiball)
            if d_maxi < rainbox.hitbox + maxiball.hitbox:
                self.cons = 0
#.........这里部分代码省略.........
开发者ID:victor-rene,项目名称:ld-rainballz,代码行数:103,代码来源:rootwidget.py

示例2: __init__

# 需要导入模块: from background import Background [as 别名]
# 或者: from background.Background import move [as 别名]
class Avata:
    def __init__(self):
        self.background = Background()
        self.shot = Fire()
        self.senary = Senary()
        self.trilha = pygame.mixer.Sound(os.path.join("sound","trilha.wav"))
        self.tiro = pygame.mixer.Sound(os.path.join("sound",'tiro.wav'))
        self.porrada = pygame.mixer.Sound(os.path.join("sound",'porrada.wav'))
        self.morreu = pygame.mixer.Sound(os.path.join("sound",'morreu.wav'))
        self.trilha.play(-1)
        self.img = pygame.Surface((80,120))
        self.img = pygame.image.load(os.path.join("img",'joao1.png'))
        self.imgS = pygame.image.load(os.path.join("img",'joao2.png'))
        self.imgC = pygame.image.load(os.path.join("img",'joao1c.png'))
        self.imgSC = pygame.image.load(os.path.join("img",'joao2c.png'))
        self.img.set_colorkey((10,255,0),0)
        self.img.set_alpha(255,0)
        self.img2 = pygame.Surface((80,120))
        self.img2.set_colorkey((10,255,0),0)
        self.img2.set_alpha(255,0)
        self.pos = pygame.Rect((120,320,80,120))
        self.jump = 0
        self.jump_h = 11
        self.life = 5
        self.face = 1
        self.x = 0
        self.contx = 0
        self.step = 1
        self.score = 0
        self.moveActivedJump = 1 
        draw(self.img,(self.pos.left,self.pos.top))
        self.background.sky()
        self.drawLife()
    def move(self,key):
        self.background.redraw()
        if key == 273 and (self.jump_h == 11 or not self.moveActivedJump):
            self.jump = 1
            if self.moveActivedJump:
                self.jump_h = 0
            else:
                self.jump_h = 4
        elif key == 275:
            self.moveActived = 1
            self.step *= -1
            for i in range(len(self.senary.stone)-1):
                if self.pos.collidepoint(self.senary.stone[i].left-10,self.senary.stone[i].top):
                    self.moveActived = 0
            if self.moveActived:
                if self.pos.left >= 200:
                    self.background.move(key)
                    self.senary.move(-1)
                else:
                    self.pos.move_ip(10,0)
                self.face = 1
        elif key == 276:
            self.moveActived = 1
            self.step *= -1
            for i in range(len(self.senary.stone)-1):
                if self.pos.collidepoint(self.senary.stone[i].right,self.senary.stone[i].top):
                    self.moveActived = 0
            if self.moveActived:
                if self.pos.left == 100:
                    self.background.move(key)
                    self.senary.move(1)
                else:
                    self.pos.move_ip(-10,0)
                self.face = 0
        if self.jump:
            self.pos.move_ip(0,-20)
        if self.jump_h < 10: self.jump_h +=1
        self.moveActivedJump = 1
        for i in range(len(self.senary.stone)-1):
            if self.pos.collidepoint(self.senary.stone[i].right,self.senary.stone[i].top-10) or self.pos.collidepoint(self.senary.stone[i].left,self.senary.stone[i].top-10):
                self.moveActivedJump = 0
        if self.jump_h == 10 and self.moveActivedJump:
            if self.pos.top < 320:
                self.pos.move_ip(0,20)
            else : self.jump_h += 1
            self.jump = 0
        if key == 32:
            self.tiro.play()
            self.shot.fire(self.pos.center,self.face,1)
        self.ia()
        if len(self.shot.dir):
            self.shot.move()
            i=-1
            while i != len(self.shot.dir)-1:
                i+=1
                for j in range(len(self.senary.stone)-1):
                    if self.shot.pos[i].colliderect(self.senary.stone[j]):
                        self.shot.dir.pop(i)
                        self.shot.pos.pop(i)
                        self.shot.origem.pop(i)
                        i-=1
                        break
            i=-1
            while i != len(self.shot.dir)-1:
                i+=1 
                for j in range(len(self.senary.inimigo)-1):
                    if self.shot.pos[i].colliderect(self.senary.inimigo[j]) and self.shot.origem[i]:
#.........这里部分代码省略.........
开发者ID:pugpe,项目名称:auto_da_compadecida,代码行数:103,代码来源:avata.py


注:本文中的background.Background.move方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。