我试图创建一个游戏服务器学习的目的,我遇到了一个问题,我的更新功能,每(0.05)秒运行,是没有调用任何函数传递变量。你知道吗
def update(self):
print("Match update: %s" % (str(self)))
if (self.pendingShutdown):
cancelShutdown = True
for player in self.players:
if player.protocol == None:
cancelShutdown = False
if (time() > self.shutdownTime):
print("Time elapsed, shutting down match")
#self.quit()
else:
self.sendlocations()
def sendlocations(self):
print("ran new send locations")
for player in self.players:
print(player.posX)
for r in range(0, len(self.players)):
matchPlayer = self.players[r]
#equation for distance between players
x = (player.posX - matchPlayer.posX)**2
y = (player.posY - matchPlayer.posY)**2
distance = math.sqrt(x+y)
#ending equation
if (distance <= 1000):
if (matchPlayer.protocol):
#finding the player index(SENDING PLAYER)
index = 0
for i in matchPlayer.match.players:
if(i.playerId == player.playerId):
matchPlayer.protocol.sendPlayerMoved(index, player.posX, player.posY, player.posZ)
index = index + 1
print("Player moved %s " % (index))
def sendPlayerMoved(self, playerIndex, posX, posY, posZ):
message = MessageWriter()
message.writeByte(MESSAGE_PLAYER_MOVED)
message.writeInt(playerIndex)
message.writeInt(posX)
message.writeInt(posY)
message.writeInt(posZ)
#self.log("Sent PLAYER_MOVED %d %d" % (playerIndex, posX))
self.sendMessage(message)
我可以打电话给你“self.sendlocations文件()“当我没有通过行时,if(distance<;=) 该函数正确地打印出“runnewsendlocations”行,但是添加了这一行之后,就不再打印了。添加行之后,“update”函数也会冻结。我不知道为什么会这样。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐