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


Python Player.setAngle方法代码示例

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


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

示例1: listener

# 需要导入模块: import Player [as 别名]
# 或者: from Player import setAngle [as 别名]
 def listener(self, packet):
     self.clientSocket.clientLock()
     if isinstance(packet, Packets.RequestGameStatePacket):
         w, h = self.getGame().getSize()
         self.player = Player(
             self.getGame(), [w/2, h/2], Color(255, 255, 255)
         )
         self.player.setPlayerName(self.username)
         self.bullets = {}
         self.bonuses = {}
         self.players = {}
     elif isinstance(packet, Packets.PlayerInfoPacket):
         if packet.isMe():
             self.player.setHealth(packet.getHealth())
             self.player.setDeath(packet.getDeath())
             self.player.setRespawnTime(packet.getRespawnTime())
         else:
             if packet.getPlayerId() not in self.players:
                 player = Player(self.getGame())
                 player.setPlayerName(packet.getPlayerName())
                 self.players[packet.getPlayerId()] = player
             else:
                 player = self.players[packet.getPlayerId()]
             player.setDelegate(lambda p, k: self.playerDelegate(p, k))
             player.setPosition(packet.getPosition())
             player.setVelocity(packet.getVelocity())
             player.setAngle(packet.getAngle())
             player.setHealth(packet.getHealth())
             player.setDeath(packet.getDeath())
             player.resetTimeout()
     elif isinstance(packet, Packets.BulletInfoPacket):
         if packet.getBulletId() not in self.bullets:
             bullet = Bullet()
             self.bullets[packet.getBulletId()] = bullet
         else:
             bullet = self.bullets[packet.getBulletId()]
         bullet.setPosition(packet.getPosition())
         bullet.setVelocity(packet.getVelocity())
         bullet.resetTimeout()
         if not packet.isAlive():
             bullet.kill()
     elif isinstance(packet, Packets.BonusInfoPacket):
         if packet.getBonusId() not in self.bonuses:
             bonus = Bonus()
             self.bonuses[packet.getBonusId()] = bonus
         else:
             bonus = self.bonuses[packet.getBonusId()]
         bonus.setPosition(packet.getPosition())
         bonus.resetTimeout()
         if not packet.isAlive():
             bonus.kill()
     elif isinstance(packet, Packets.PlayerGunPacket):
         self.player.getGun().setReload(packet.isReloading())
         self.player.getGun().setBulletInMagazine(
             packet.getBulletInMagazine()
         )
         self.player.getGun().setTotalBullet(packet.getTotalBullet())
     elif packet is not None:
         print("Packet received (type " + str(packet) + ")")
     self.clientSocket.clientUnlock()
开发者ID:spywhere,项目名称:Pew-Pew,代码行数:62,代码来源:GameScene.py

示例2: listener

# 需要导入模块: import Player [as 别名]
# 或者: from Player import setAngle [as 别名]
 def listener(self, client, packet):
     self.serverSocket.serverLock()
     if isinstance(packet, Packets.PlayerInfoPacket):
         if packet.getHealth() > 0:
             if client not in self.players:
                 player = Player(
                     self.getGame(),
                     color=Color(
                         random.randint(127, 255),
                         random.randint(127, 255),
                         random.randint(127, 255)
                     )
                 )
                 player.setPlayerId(self.pid)
                 player.setPlayerName(packet.getPlayerName())
                 self.pid += 1
                 self.players[client] = player
             else:
                 player = self.players[client]
             player.setPosition(packet.getPosition())
             player.setAngle(packet.getAngle())
         self.packetCount += 1
     elif isinstance(packet, Packets.PlayerGunPacket):
         player = self.players[client]
         bullets = player.shoot()
         for bullet in bullets:
             bullet.setBulletId(self.bid)
             self.bid += 1
         self.bullets += bullets
         self.packetCount += 1
     elif packet is not None:
         self.packetCount += 1
         print("Packet received (type " + str(packet) + ")")
     self.serverSocket.serverUnlock()
开发者ID:spywhere,项目名称:Pew-Pew,代码行数:36,代码来源:GameServerScene.py

示例3: GameScene

# 需要导入模块: import Player [as 别名]
# 或者: from Player import setAngle [as 别名]
class GameScene(Scene):
    player = None
    bullets = {}
    bonuses = {}
    players = {}
    show_info = False

    def __init__(self, username, clientSocket):
        self.username = username
        self.clientSocket = clientSocket
        self.clientSocket.setListener(self.listener)

    def playerDelegate(self, player, key):
        if key == "HealthBar":
            return self.show_info
        return True

    def listener(self, packet):
        self.clientSocket.clientLock()
        if isinstance(packet, Packets.RequestGameStatePacket):
            w, h = self.getGame().getSize()
            self.player = Player(
                self.getGame(), [w/2, h/2], Color(255, 255, 255)
            )
            self.player.setPlayerName(self.username)
            self.bullets = {}
            self.bonuses = {}
            self.players = {}
        elif isinstance(packet, Packets.PlayerInfoPacket):
            if packet.isMe():
                self.player.setHealth(packet.getHealth())
                self.player.setDeath(packet.getDeath())
                self.player.setRespawnTime(packet.getRespawnTime())
            else:
                if packet.getPlayerId() not in self.players:
                    player = Player(self.getGame())
                    player.setPlayerName(packet.getPlayerName())
                    self.players[packet.getPlayerId()] = player
                else:
                    player = self.players[packet.getPlayerId()]
                player.setDelegate(lambda p, k: self.playerDelegate(p, k))
                player.setPosition(packet.getPosition())
                player.setVelocity(packet.getVelocity())
                player.setAngle(packet.getAngle())
                player.setHealth(packet.getHealth())
                player.setDeath(packet.getDeath())
                player.resetTimeout()
        elif isinstance(packet, Packets.BulletInfoPacket):
            if packet.getBulletId() not in self.bullets:
                bullet = Bullet()
                self.bullets[packet.getBulletId()] = bullet
            else:
                bullet = self.bullets[packet.getBulletId()]
            bullet.setPosition(packet.getPosition())
            bullet.setVelocity(packet.getVelocity())
            bullet.resetTimeout()
            if not packet.isAlive():
                bullet.kill()
        elif isinstance(packet, Packets.BonusInfoPacket):
            if packet.getBonusId() not in self.bonuses:
                bonus = Bonus()
                self.bonuses[packet.getBonusId()] = bonus
            else:
                bonus = self.bonuses[packet.getBonusId()]
            bonus.setPosition(packet.getPosition())
            bonus.resetTimeout()
            if not packet.isAlive():
                bonus.kill()
        elif isinstance(packet, Packets.PlayerGunPacket):
            self.player.getGun().setReload(packet.isReloading())
            self.player.getGun().setBulletInMagazine(
                packet.getBulletInMagazine()
            )
            self.player.getGun().setTotalBullet(packet.getTotalBullet())
        elif packet is not None:
            print("Packet received (type " + str(packet) + ")")
        self.clientSocket.clientUnlock()

    def onInit(self):
        w, h = self.getGame().getSize()
        self.player = Player(self.getGame(), [w/2, h/2], Color(255, 255, 255))
        self.player.setPlayerName(self.username)

    def onRender(self, renderer, delta):
        px, py = self.player.getPosition()
        renderer.drawString(
            (10, 20), "Player Position: " + str(px) + ", " + str(py)
        )
        renderer.drawString(
            (10, 35), "Bullets on screen: " + str(len(self.bullets))
        )
        renderer.drawString(
            (10, self.getGame().getSize()[1]-20),
            "Health: " + str(self.player.getHealth())
        )
        if self.show_info:
            offset = 0
            for player in [self.player] + list(self.players.values()):
                import Tkinter as tk
                renderer.drawString(
#.........这里部分代码省略.........
开发者ID:spywhere,项目名称:Pew-Pew,代码行数:103,代码来源:GameScene.py


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