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


Python Player.respawn方法代码示例

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


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

示例1: quit

# 需要导入模块: import Player [as 别名]
# 或者: from Player import respawn [as 别名]
                if s.rect.colliderect(snb.rect) and s.active == True:
                    snb.alive = False
                for b in blocks:
                    if s.rect.colliderect(b.rect):
                        s.active = False
    
        for h in shards:
            h.draw()
            if h.rect.colliderect(snb.rect):
                finish.play()
                LevelComplete = True

    
        if snb.alive == False:
            time = 0 
            snb.respawn(pstart[0], pstart[1])
    
        snb.update(pressed, screenDimensions)
        snb.draw()
    
        pygame.display.flip()

        for event in pygame.event.get():
            if event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    quit()
                if event.key == K_LEFT:
                    pressed['Left'] = True
                elif event.key == K_RIGHT:
                    pressed['Right'] = True
                elif event.key == K_LSHIFT:
开发者ID:nchen24,项目名称:superninjaboy,代码行数:33,代码来源:game.py

示例2: GameScene

# 需要导入模块: import Player [as 别名]
# 或者: from Player import respawn [as 别名]

#.........这里部分代码省略.........

        self.player.onRender(renderer)
        if self.player.getRespawnTime() > 0:
            import Tkinter as tk
            renderer.drawString(
                [px, py], "%.2fs" % (self.player.getRespawnTime()),
                anchor=tk.CENTER
            )

    def onUpdate(self, gameInput, delta):
        self.clientSocket.clientLock()
        vx = 0
        vy = 0
        if gameInput.isKeyDown("d"):
            vx += self.player.getSpeed()
        elif gameInput.isKeyDown("a"):
            vx -= self.player.getSpeed()
        if gameInput.isKeyDown("s"):
            vy += self.player.getSpeed()
        elif gameInput.isKeyDown("w"):
            vy -= self.player.getSpeed()
        self.show_info = gameInput.isKeyDown("space")
        self.player.setVelocity([vx, vy])
        self.player.onUpdate(delta)
        self.clientSocket.sendPacket(PlayerInfoPacket(
            self.player.getPlayerName(),
            self.player.getPosition(), self.player.getVelocity(),
            self.player.getAngle(), self.player.getHealth()
        ))

        px, py = self.player.getPosition()
        x, y = gameInput.getMousePosition()
        angle = math.atan2(x-px, y-py)
        self.player.setAngle(angle)
        self.player.resetTimeout()
        if gameInput.isMouseDown(cooldown=5):
            self.clientSocket.sendPacket(PlayerGunPacket())

        new_bullets = {}
        for bid in self.bullets:
            bullet = self.bullets[bid]
            bullet.onUpdate(delta)
            w, h = self.getGame().getSize()
            x, y = bullet.getPosition()
            if (x < -(bullet.getSize()/2) or x > w+(bullet.getSize()/2) or
                    y < -(bullet.getSize()/2) or y > h+(bullet.getSize()/2)):
                bullet.kill()

            for clientid in self.players:
                player = self.players[clientid]
                if player.isIntersectObject(bullet):
                    bullet.kill()
            if bullet.isAlive() and not bullet.isTimeout():
                new_bullets[bid] = bullet
        self.bullets = new_bullets

        new_bonuses = {}
        for bid in self.bonuses:
            bonus = self.bonuses[bid]
            bonus.onUpdate(delta)

            for clientid in self.players:
                player = self.players[clientid]
                if player.isIntersectObject(bonus):
                    bonus.kill()
            if bonus.isAlive() and not bonus.isTimeout():
                new_bonuses[bid] = bonus
        self.bonuses = new_bonuses

        new_players = {}
        for pid in self.players:
            player = self.players[pid]
            if not player.isDead():
                new_players[pid] = player
        self.players = new_players

        if self.player.isDead():
            w, h = self.getGame().getSize()
            self.player.respawn([w/2, h/2])
        if not self.clientSocket.isServerAlive():
            from ServerConnectScene import ServerConnectScene
            self.getGame().enterScene(
                ServerConnectScene(
                    self.username,
                    self.clientSocket.host,
                    self.clientSocket.port,
                    "Server timeout"
                )
            )
        self.clientSocket.clientUnlock()
        if gameInput.isKeyDown("escape"):
            self.getGame().stopGame()

    def onExit(self):
        self.clientSocket.closeSocket()
        import time
        disconnectTimeout = time.time()
        while (self.clientSocket.isConnected() and
                disconnectTimeout+3.0 > time.time()):
            continue
开发者ID:spywhere,项目名称:Pew-Pew,代码行数:104,代码来源:GameScene.py


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