本文整理汇总了Python中Map.Map.addPlayer方法的典型用法代码示例。如果您正苦于以下问题:Python Map.addPlayer方法的具体用法?Python Map.addPlayer怎么用?Python Map.addPlayer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Map.Map
的用法示例。
在下文中一共展示了Map.addPlayer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from Map import Map [as 别名]
# 或者: from Map.Map import addPlayer [as 别名]
class Game(object):
def __init__(self):
pygame.init()
#self.screen = pygame.display.set_mode((1024, 768), pygame.FULLSCREEN)
self.screen = pygame.display.set_mode(bounds)
self.clock = pygame.time.Clock()
self.state = JOIN
mapRect = pygame.Rect(0, 0, bounds[0], bounds[1])
self.map = Map(mapRect)
self.quit = False
UDP_IP = "0.0.0.0"
UDP_PORT = 5005
self.sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
self.sock.settimeout(.1)
self.sock.bind((UDP_IP, UDP_PORT))
pygame.mouse.set_visible(False)
self.joinPage = JoinPage(bounds)
self.mutex = Lock()
t = Thread(target = Game.netThread, args = (self,))
t.start()
self.countDown()
def countDown(self):
self.joinPage.startCountDown(10)
while True:
self.mutex.acquire()
if self.joinPage.ready:
self.mutex.release()
break
self.screen.blit(self.joinPage.drawSurface(), (0,0))
self.mutex.release()
pygame.display.flip()
self.play()
def netThread(self):
while True:
# Check for quit
self.mutex.acquire()
if self.quit:
self.map.destroy()
self.mutex.release()
break
self.mutex.release()
# handle single packet
data = ''
try:
data, addr = self.sock.recvfrom(1024) # buffer size is 1024 bytes
except socket.timeout:
pass
# parse packet data
d = data.split(':')
player = ''
action = ''
if len(d) == 2:
player = d[0]
action = d[1]
# perform the action
hor = 0
vert = 0
if self.state == PLAY:
if action == 'left': hor = -5
if action == 'right': hor = 5
if action == 'up': vert = -5
if action == 'down': vert = 5
self.mutex.acquire()
if action == 'join':
if self.state == JOIN:
self.map.addPlayer(player)
self.joinPage.addPlayer(player)
elif self.state == PLAY:
try:
self.map.players[player].setVelocity(hor, vert)
except Exception:
pass
self.mutex.release()
def play(self):
self.state = PLAY
while 1:
#.........这里部分代码省略.........