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


Python InstructionGroup.remove方法代码示例

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


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

示例1: SelectAttackState

# 需要导入模块: from kivy.graphics.instructions import InstructionGroup [as 别名]
# 或者: from kivy.graphics.instructions.InstructionGroup import remove [as 别名]
class SelectAttackState(TurnAction):
    def __init__(self, target, **kwargs):
        super(SelectAttackState, self).__init__(target, **kwargs)
        self.amount = self.target.map.tile_width
        self.moving = False
        self.velocity = [0, 0]
        self.layer = self.target.map.layers.by_name['below']
        self.foreshadowed = self.layer.get_at(*target.center)
        self.move_keys = [Keyboard.keycodes['left'], Keyboard.keycodes['right'],
                          Keyboard.keycodes['up'], Keyboard.keycodes['down'], Keyboard.keycodes['enter']]
        self.travelled = set()
        self.checked = set()
        self.index = {}
        self.instructions = InstructionGroup()
        self.layer = self.target.map.layers.by_name['below']
        self.confirmed = False
        self.effect = MeleeDamage
        tile = self.layer.get_at(*self.target.pos)
        self.cursor = Sprite(pos=[tile.px, tile.py],
                             size=self.target.size, texture=images['cursor'], opacity=0.5)
        self.current_tile = self.target.get_current_cell()
        self.target.game.layer_widgets['sprite_layer'].add_widget(self.cursor)
        self.get_tiles_in_range(tile, 0)
        self.selected = None
        self.last_touched = None
        self.highlight_tiles()

    def highlight_tiles(self):
        for tile in self.travelled:
            self.instructions.add(Color(rgba=[1, .4, .3, .3]))
            self.instructions.add(Rectangle(pos=(tile.px, tile.py), size=(tile.px_width, tile.px_height)))
        self.target.game.layer_widgets['below'].canvas.add(self.instructions)
        # print(self.travelled, self.foreshadowed)

    @memoized
    def get_tiles_in_range(self, tile, moved):
        self.travelled.add(tile)
        if moved < 2:
            for neighbor in self.layer.get_neighbor_cells(tile):
                # if not self.target.map.layers['objects'].collide(Rect(*neighbor.center + (8, 8)), 'wall'):
                self.get_tiles_in_range(neighbor, moved + 1)

    def touch(self, touch, *args):
        print('touch!', touch)
        pos = self.target.map.pixel_from_screen(*touch.pos)
        cell = self.target.map.layers.by_name['below'].get_at(*pos)
        print('at {}.  Found?  {}'.format(pos, cell))
        if cell is not None and cell in self.travelled:
            print('cell not none, found in travels')
            self.cursor.pos = (cell.px, cell.py)
            if cell is self.last_touched:
                if self.get_selected():
                    self.confirm()
            else:
                self.last_touched = cell
                self.highlight_selected(cell)

    def highlight_selected(self, tile):
            if self.selected:
                for s in self.selected:
                    self.instructions.remove(s)
            self.selected = [Color(rgba=[6, .3, .2, .6]),
                             Rectangle(pos=(tile.px, tile.py), size=(tile.px_width, tile.px_height))]
            for a in self.selected:
                self.instructions.add(a)

    def get_selected(self):
        self.selected_targets = []
        for battler in self.target.game.entities:
            # TODO - figure out why this code is selecting both characters...
            print('checks say:', battler is not self.target, not battler.incapacitated,
                  self.cursor.collide_point(*battler.center))
            if battler is not self.target and not battler.incapacitated and self.cursor.collide_point(*battler.center):
                self.selected_targets.append(battler)
        print('selected targets:', self.selected_targets)
        return self.selected_targets

    def update(self, dt):
        if not self.confirmed:
            if not self.moving:
                self.velocity = [0, 0]
                if keys.get(Keyboard.keycodes['left']):
                    self.velocity = self.velocity_dict['left']
                elif keys.get(Keyboard.keycodes['right']):
                    self.velocity = self.velocity_dict['right']
                elif keys.get(Keyboard.keycodes['up']):
                    self.velocity = self.velocity_dict['up']
                elif keys.get(Keyboard.keycodes['down']):
                    self.velocity = self.velocity_dict['down']
                elif keys.get(Keyboard.keycodes['enter']):
                    print('battle_entities currently:', self.target.game.entities)
                    if self.get_selected():
                        self.confirm()
                    else:
                        pass
                elif keys.get(Keyboard.keycodes['backspace']):
                    print('pressed backspace')
                    self.end()
                else:
                    return
#.........这里部分代码省略.........
开发者ID:spinningD20,项目名称:kivy_rpg,代码行数:103,代码来源:turn.py

示例2: LetterGrid

# 需要导入模块: from kivy.graphics.instructions import InstructionGroup [as 别名]
# 或者: from kivy.graphics.instructions.InstructionGroup import remove [as 别名]

#.........这里部分代码省略.........
        """Adds a new cell to the letter grid.
        
        The letter grid has s as its initial text.
        
        If the cell already exists, it replaces the text with s.
        
        Precondition: row and col are valid indices in the grid.  s is a string."""
        assert row >= 0 and row < self.rows, 'Row '+`row`+' is out of range [0,'+`self.rows`+']'
        assert col >= 0 and col < self.cols, 'Row '+`col`+' is out of range [0,'+`self.cols`+']'
        if (col,row) in self._labels:
            self._labels[(col,row)].text = s
            return
        
        label = LetterBox(text=s, fontsize=self.font_size, color=self.textcolor)
        label.bold   = self.bold
        label.italic = self.italic
        label.size   = self.cellsize
        x = self.pos[0] + col*self.cellsize[0]
        y = self.pos[1] + row*self.cellsize[1]
        label.pos = [x,y]
        self._labels[(col,row)] = label
        self._back.add(label.canvas)
    
    def delete_cell(self, col, row):
        """Deletes the LetterBox at col and row.
        
        If there is no LetterBox at that position, this method does nothing.
        
        Precondition: row and col are valid indices in the grid."""
        if not (col, row) in self._labels:
            return
        
        label = self._labels[(col,row)]
        self._back.remove(label.canvas)
        del self._labels[(col,row)]
    
    def get_cell(self, col, row):
        """Returns the LetterBox at col and row.
        
        If there is no LetterBox at that position, it returns None.
        
        Precondition: row and col are valid indices in the grid."""
        assert row >= 0 and row < self.rows, 'Row '+`row`+' is out of range [0,'+`self.rows`+']'
        assert col >= 0 and col < self.cols, 'Row '+`col`+' is out of range [0,'+`self.cols`+']'

        if not (col, row) in self._labels:
            return None
            
        return self._labels[(col,row)]
    
    def toggle_cell(self, col, row):
        """Toggles the state of the LetterBox at col and row.
        
        If there is no LetterBox at that position, it does nothing.
        
        Precondition: row and col are valid indices in the grid."""
        if not (col, row) in self._labels:
            return
        
        label = self._labels[(col,row)]
        label.state = not label.state
        tmp = label.foreground
        label.foreground = label.background
        label.background = tmp
        tmp = label.textcolor
        tmp = map(lambda x: 1-x, tmp[:-1])+tmp[-1:]
开发者ID:michellehn,项目名称:wordpuzzle-solver,代码行数:70,代码来源:lettergui.py

示例3: SelectMoveState

# 需要导入模块: from kivy.graphics.instructions import InstructionGroup [as 别名]
# 或者: from kivy.graphics.instructions.InstructionGroup import remove [as 别名]
class SelectMoveState(State):
    def __init__(self, target, **kwargs):
        super(SelectMoveState, self).__init__(target, **kwargs)
        self.amount = self.target.map.tile_width
        self.moving = False
        self.velocity = [0, 0]
        self.layer = self.target.map.layers.by_name['below']
        self.foreshadowed = self.layer.get_at(*target.center)
        self.current_tile = self.target.get_current_cell()
        self.move_keys = [Keyboard.keycodes['left'], Keyboard.keycodes['right'],
                          Keyboard.keycodes['up'], Keyboard.keycodes['down'], Keyboard.keycodes['enter']]
        self.travelled = set()
        self.checked = set()
        self.index = {}
        self.instructions = InstructionGroup()
        self.layer = self.target.map.layers.by_name['below']
        tile = self.layer.get_at(*self.target.pos)
        self.get_tiles_in_range(tile, 0)
        self.last_touched = None
        self.selected = []
        self.highlight_tiles()

    def touch(self, touch, *args):
        print('touch!', touch)
        pos = self.target.map.pixel_from_screen(*touch.pos)
        cell = self.target.map.layers.by_name['below'].get_at(*pos)
        print('at {}.  Found?  {}'.format(pos, cell))
        if cell is not None and cell in self.travelled:
            print('cell not none, found in travels')
            if cell is self.last_touched:
                self.target.set_position(cell.px, cell.py)
                self.end()
            else:
                self.last_touched = cell
                self.highlight_selected(cell)

    def highlight_selected(self, tile):
            if self.selected:
                for s in self.selected:
                    self.instructions.remove(s)
            self.selected = [Color(rgba=[6, .3, .2, .6]),
                             Rectangle(pos=(tile.px, tile.py), size=(tile.px_width, tile.px_height))]
            for a in self.selected:
                self.instructions.add(a)

    def highlight_tiles(self):
        for tile in self.travelled:
            self.instructions.add(Color(rgba=[.3, .5, .8, .5]))
            self.instructions.add(Rectangle(pos=(tile.px, tile.py), size=(tile.px_width, tile.px_height)))
        self.target.game.layer_widgets['below'].canvas.add(self.instructions)

    @memoized
    def get_tiles_in_range(self, tile, moved):
        self.travelled.add(tile)
        # did this to keep smallest range possible to reach selected tile, for calculating cost at end of move state
        self.index[tile] = min(self.index.get(tile, 1000), moved)
        if moved < self.target.move_range():
            for neighbor in self.layer.get_neighbor_cells(tile):
                self.get_tiles_in_range(neighbor, moved + 1)

    def update(self, dt):
        if not self.moving:
            pressed = [key for key in self.move_keys if keys.get(key)]
            if pressed:
                self.velocity = [0, 0]
                if Keyboard.keycodes['left'] in pressed:
                    self.target.set_face('left')
                    self.velocity = self.velocity_dict['left']
                elif Keyboard.keycodes['right'] in pressed:
                    self.target.set_face('right')
                    self.velocity = self.velocity_dict['right']
                elif Keyboard.keycodes['up'] in pressed:
                    self.target.set_face('up')
                    self.velocity = self.velocity_dict['up']
                elif Keyboard.keycodes['down'] in pressed:
                    self.target.set_face('down')
                    self.velocity = self.velocity_dict['down']
                elif keys.get(Keyboard.keycodes['enter']):
                    self.end()
                    return
                self.current_tile = self.target.get_current_cell()
                new_x = self.current_tile.x + self.velocity[0]
                new_y = self.current_tile.y + self.velocity[1]
                # print('new not none')
                new_target = self.layer.get_tile(new_x, new_y)
                if new_target and new_target.tile.is_passable() and not new_target.occupied:
                    # print('starting to move!')
                    self.foreshadowed = new_target
                if self.foreshadowed in self.travelled:
                    self.start_moving()
            else:
                if self.target.anim_delay > 0:
                    self.target.reload()  # reset animation
                self.target.anim_delay = -1
        else:
            self.move(dt)

    def move(self, dt):
        done = move(dt, self.target, self.foreshadowed.px, self.foreshadowed.py)
        if done:
#.........这里部分代码省略.........
开发者ID:spinningD20,项目名称:kivy_rpg,代码行数:103,代码来源:turn.py


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