當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。