當前位置: 首頁>>代碼示例>>Python>>正文


Python Snake.respawn方法代碼示例

本文整理匯總了Python中snake.Snake.respawn方法的典型用法代碼示例。如果您正苦於以下問題:Python Snake.respawn方法的具體用法?Python Snake.respawn怎麽用?Python Snake.respawn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在snake.Snake的用法示例。


在下文中一共展示了Snake.respawn方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: PlayerBase

# 需要導入模塊: from snake import Snake [as 別名]
# 或者: from snake.Snake import respawn [as 別名]

#.........這裏部分代碼省略.........
            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."""
        if not self.snake:
            return

        self.snake.update(delta_time)

        self.weapons[0].update(delta_time)

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

        if self.boost < BOOST_COST * delta_time:
            self.boosting = False
            self.snake.speed_bonus = 0

        if self.boosting:
            boost = self.boost - BOOST_COST * delta_time
            if boost < BOOST_COST * delta_time:
                self.boost = 0
            else:
                self.boost = boost
        else:
            self.boost = self.boost + BOOST_GAIN * delta_time

    def draw(self, offset):
        """Draw snake and UI."""
        if not self.snake:
            return

        self.snake.draw()

        gfx = self.game.graphics

        gfx.draw_string(add_vecs((2, 2), offset),
                        'Player{0}'.format(self.pid), self.color)

        gfx.draw_string(add_vecs((56, 2), offset),
                        '{0:.2f}'.format(self.snake.speed), WHITE)

        gfx.draw_string(add_vecs((2, 18), offset),
                        'Points: {0}'.format(self.points), WHITE)

        pygame.draw.rect(self.game.screen, ORANGE,
                         pygame.Rect(add_vecs((100, 2), offset),
                                     (104, 20)))

        # Draw life bar. TODO: Make this some kinda class.
        width = int(self.snake.hitpoints / float(MAX_HITPOINTS) * 100)
        rect = pygame.Rect(add_vecs((102, 4), offset), (width, 7))
        pygame.draw.rect(self.game.screen, RED, rect)

        if self.boost_enabled:
            width = int(self.boost / float(MAX_BOOST) * 100)
            rect = pygame.Rect(add_vecs((102, 13), offset), (width, 7))
            pygame.draw.rect(self.game.screen, BLUE, rect)

        gfx.draw_string(add_vecs((208, 2), offset),
                        '{0} {1}'.format(self.weapons[0].wtype,
                                         self.weapons[0].ammo), WHITE)

        for index in range(self.lifes):
            gfx.draw('life16x16', add_vecs((100, 24), offset),
                     gridcoords=False, offset=(index*18, 0))

    def snake_killed(self, killed_by):
        """Snake killed event handler."""
        if self.lifes > 0:
            self.lifes -= 1
            self.boost = MAX_BOOST
            self.snake.respawn(self.tilemap.get_spawnpoint())
        else:
            self.dead_handler()
開發者ID:Phosphenius,項目名稱:battle-snakes,代碼行數:104,代碼來源:player.py

示例2: PlayerBase

# 需要導入模塊: from snake import Snake [as 別名]
# 或者: from snake.Snake import respawn [as 別名]

#.........這裏部分代碼省略.........
        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

        if self.boost < BOOST_COST * delta_time:
            self.boosting = False
            self.snake.speed_bonus = 0

        if self.boosting:
            boost = self.boost - BOOST_COST * delta_time
            if boost < BOOST_COST * delta_time:
                self.boost = 0
            else:
                self.boost = boost
        else:
            self.boost = self.boost + BOOST_GAIN * delta_time

    def draw(self, offset):
        """Draw snake and UI."""
        self.snake.draw()
        self.game.draw_string('Player{0}'.format(self.pid),
                              add_vecs((2, 2), offset), self.color)
        self.game.draw_string('{0:.2f}'.format(self.snake.speed),
                              add_vecs((56, 2), offset), WHITE)
        self.game.draw_string('Points: {0}'.format(self.points),
                              add_vecs((2, 18), offset), WHITE)

        pygame.draw.rect(self.game.screen, ORANGE,
                         pygame.Rect(add_vecs((100, 2), offset), (104, 20)))

        pygame.draw.rect(self.game.screen, RED,
                         pygame.Rect(add_vecs((102, 4), offset), (int(
                             self.snake.hitpoints /
                             float(MAX_HITPOINTS) * 100), 7)))

        pygame.draw.rect(self.game.screen, BLUE,
                         pygame.Rect(add_vecs((102, 13), offset), (int(
                             self.boost / float(MAX_BOOST) * 100), 7)))

        self.game.draw_string('{0} {1}'.format(self.weapons[0].wtype,
                                               self.weapons[0].ammo),
                              add_vecs((208, 2), offset), WHITE)

        for i in range(self.lifes):
            self.game.graphics.draw('life16x16', add_vecs((100, 24), offset),
                                    gridcoords=False, offset=(i*18, 0))

    def snake_killed(self, killed_by):
        """Snake killed event handler."""
        if self.lifes > 0:
            self.lifes -= 1
            self.boost = MAX_BOOST
            self.snake.respawn(self.game.get_spawnpoint())
開發者ID:YiYiWu,項目名稱:battle-snakes,代碼行數:104,代碼來源:player.py


注:本文中的snake.Snake.respawn方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。