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


Python Snake.take_damage方法代码示例

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


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

示例1: PlayerBase

# 需要导入模块: from snake import Snake [as 别名]
# 或者: from snake.Snake import take_damage [as 别名]
class PlayerBase(object):

    """
    Player base class.
    """

    def __init__(self, game_mode, dead_handler, **kwargs):
        self.game = game_mode.game
        self.tilemap = game_mode.tilemap
        self.pid = kwargs['id']
        self.color = kwargs['color']
        self.snake_skin = kwargs['skin']
        self.snake = None
        self.snake_config = kwargs.get('snake_config', {})
        self._lifes = kwargs.get('lifes', INIT_LIFES)
        self.points = 0
        self.boost_enabled = kwargs.get('boost_enabled', True)
        self._boost = INIT_BOOST
        self.boosting = False
        self.dead_handler = dead_handler
        # TODO: Add weapons from kwargs
        self.weapons = deque(maxlen=5)
        self.weapons.append(Weapon(game_mode.game, self, DUMMY))
        self.pwrup_targets = {'points': 'points', 'grow': 'snake.grow',
                              'speed': 'snake.speed', 'boost': 'boost',
                              'lifes': 'lifes', 'hp': 'snake.hitpoints'}

    def start(self):
        self.snake = Snake(self.game, self.tilemap.get_spawnpoint(),
                           self.snake_skin, self.pid,
                           self.snake_killed, self.snake_config)

    @property
    def lifes(self):
        """Return lifes."""
        return self._lifes

    @lifes.setter
    def lifes(self, value):
        """Set lifes."""
        if value > MAX_LIFES:
            self._lifes = MAX_LIFES
        elif value < 0:
            self._lifes = 0
        else:
            self._lifes = value

    @property
    def boost(self):
        """Return boost energy."""
        return self._boost

    @boost.setter
    def boost(self, value):
        """Set boost energy."""
        if value > MAX_BOOST:
            self._boost = MAX_BOOST
        elif value < 0:
            self._boost = 0
        else:
            self._boost = value

    def coll_check_head(self, collobjs):
        """Handle collisions for the snake's head."""
        for tag, obj in collobjs:
            if (tag.endswith('-body') or tag.endswith('-head')) and \
                    tag != self.snake.head_tag:
                obj.take_damage(35, self.snake.head_tag, False, True,
                                0.7, shrink=1, slowdown=0.03)
            elif tag == PORTAL_TAG:
                self.snake.heading = obj[1]
                self.snake[0] = add_vecs(obj[0], self.snake.heading)
            elif tag == PWRUP_TAG:
                for action in obj.actions:
                    target = self.pwrup_targets[action['target']]
                    if '.' in target:
                        target1, target2 = target.split('.')
                        attr = getattr(getattr(self, target1), target2)
                        setattr(getattr(self, target1),
                                target2, attr + action['value'])
                    else:
                        attr = getattr(self, target)
                        setattr(self, target, attr + action['value'])
                obj.collect()
            elif tag == SHOT_TAG:
                self.handle_shot(obj)

    def coll_check_body(self, collobjs):
        """Handle collisions for the snakes's body."""
        for tag, obj in collobjs:
            if tag == SHOT_TAG:
                self.handle_shot(obj)

    def handle_shot(self, shot):
        """Handle shot."""
        self.snake.take_damage(shot.damage, shot.tag, False, True, 1.2,
                               slowdown=shot.slowdown, shrink=1)
        shot.hit()

    def update(self, delta_time):
#.........这里部分代码省略.........
开发者ID:Phosphenius,项目名称:battle-snakes,代码行数:103,代码来源:player.py

示例2: PlayerBase

# 需要导入模块: from snake import Snake [as 别名]
# 或者: from snake.Snake import take_damage [as 别名]
class PlayerBase(object):

    """
    Player base class.
    """

    def __init__(self, game, config):
        self.game = game
        self.pid = config['id']
        self.color = config['color']
        self.snake = Snake(game, game.get_spawnpoint(),
                           config['tex'], self.pid, self.snake_killed)
        self._lifes = INIT_LIFES
        self.points = 0
        self._boost = INIT_BOOST
        self.boosting = False
        self.weapons = deque((
            Weapon(self.game, self, STD_MG),
            Weapon(self.game, self, H_GUN),
            Weapon(self.game, self, PLASMA_GUN)))
        self.pwrup_targets = {'points': 'points', 'grow': 'snake.grow',
                              'speed': 'snake.speed', 'boost': 'boost',
                              'lifes': 'lifes', 'hp': 'snake.hitpoints'}

    @property
    def lifes(self):
        """Return lifes."""
        return self._lifes

    @lifes.setter
    def lifes(self, value):
        """Set lifes."""
        if value > MAX_LIFES:
            self._lifes = MAX_LIFES
        elif value < 0:
            self._lifes = 0
        else:
            self._lifes = value

    @property
    def boost(self):
        """Return boost energy."""
        return self._boost

    @boost.setter
    def boost(self, value):
        """Set boost energy."""
        if value > MAX_BOOST:
            self._boost = MAX_BOOST
        elif value < 0:
            self._boost = 0
        else:
            self._boost = value

    def coll_check_head(self, collobjs):
        """Handle collisions for the snake's head."""
        for tag, obj in collobjs:
            if (tag.endswith('-body') or tag.endswith('-head')) and \
                    tag != self.snake.head_tag:
                obj.take_damage(35, self.snake.head_tag, False, True,
                                0.7, shrink=1, slowdown=0.03)
            elif tag == PORTAL_TAG:
                self.snake.heading = obj[1]
                self.snake[0] = add_vecs(obj[0], self.snake.heading)
            elif tag == PWRUP_TAG:
                for action in obj.actions:
                    target = self.pwrup_targets[action['target']]
                    if '.' in target:
                        target1, target2 = target.split('.')
                        attr = getattr(getattr(self, target1), target2)
                        setattr(getattr(self, target1),
                                target2, attr + action['value'])
                    else:
                        attr = getattr(self, target)
                        setattr(self, target, attr + action['value'])
                obj.collect()
            elif tag == SHOT_TAG:
                self.handle_shot(obj)

    def coll_check_body(self, collobjs):
        """Handle collisions for the snakes's body."""
        for tag, obj in collobjs:
            if tag == SHOT_TAG:
                self.handle_shot(obj)

    def handle_shot(self, shot):
        """Handle shot."""
        self.snake.take_damage(shot.damage, shot.tag, False, True, 1.2,
                               slowdown=shot.slowdown, shrink=1)
        shot.hit()

    def update(self, delta_time):
        """Update player, move snake."""
        self.snake.update(delta_time)

        self.weapons[0].update(delta_time)

        if self.snake.heading != self.snake.prev_heading:
            self.snake.ismoving = True

#.........这里部分代码省略.........
开发者ID:YiYiWu,项目名称:battle-snakes,代码行数:103,代码来源:player.py


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