Exemplo n.º 1
0
	def __init__(self, addr, port = DEFAULT_CLIENT_LISTEN_PORT, name = "player", ex = "", super = ""):
		Game.__init__(self, 0)
		#self.net = NetClient(int(port))
		self.net = NetClient(random.randint(2113, 5000))
		self.net.connect(addr)
		#time.sleep(1)
		self.net.sendPlayerInfo(name, ex, super)
		self.controller = None
		g.SERVER = False

		self.typingMode = False
		self.typingModeText = ""
		self.typingModeFont = pygame.font.Font("visitor1.ttf", 10)
		self.pauseInput = False
Exemplo n.º 2
0
class Client(Game):
	def __init__(self, addr, port = DEFAULT_CLIENT_LISTEN_PORT, name = "player", ex = "", super = ""):
		Game.__init__(self, 0)
		#self.net = NetClient(int(port))
		self.net = NetClient(random.randint(2113, 5000))
		self.net.connect(addr)
		#time.sleep(1)
		self.net.sendPlayerInfo(name, ex, super)
		self.controller = None
		g.SERVER = False

		self.typingMode = False
		self.typingModeText = ""
		self.typingModeFont = pygame.font.Font("visitor1.ttf", 10)
		self.pauseInput = False

	def handleEvent(self, evt):
		if evt.type == pygame.KEYDOWN:
			if self.typingMode:

				allkeys = pygame.key.get_pressed()
				if allkeys[pygame.K_LSHIFT] or allkeys[pygame.K_RSHIFT]:
					if pygame.key.name(evt.key) in shiftKeys:
						self.typingModeText += shiftKeys[pygame.key.name(evt.key)]
					elif pygame.key.name(evt.key) in unShiftKeys:
						self.typingModeText += pygame.key.name(evt.key)
				else:
					if pygame.key.name(evt.key) in unShiftKeys:
						self.typingModeText += pygame.key.name(evt.key)

				if evt.key == pygame.K_SPACE:
					self.typingModeText += " "

				if evt.key == pygame.K_BACKSPACE:
					self.typingModeText = self.typingModeText[:-1]

				if evt.key == pygame.K_RETURN:
					self.typingMode = False
					self.net.sendToServer({"type":"chat", "text":self.typingModeText})
					self.typingModeText = ""
			else:
				if evt.key == pygame.K_SPACE and not self.started:
					self.net.sendToServer({"type":"start"})

				if evt.key == pygame.K_RETURN and self.started:
					self.typingMode = True
					self.net.sendDirectionInput(0,0,self.controller.player.position)

				if evt.key == pygame.K_d:
					self.debugMode = not self.debugMode					


		if self.controller and not self.typingMode and not self.pauseInput:
			self.controller.getEvent(evt)

	def preUpdate(self, dt):
		if self.controller and not self.typingMode and not self.pauseInput:
			self.controller.update(dt)


	def postDraw(self):
		Game.postDraw(self)
		if self.typingMode:
			surf = self.typingModeFont.render(">"+self.typingModeText, False, (39, 65, 62))
			self.screen.blit(surf, (1,1))

		if self.debugMode:
			surf = self.debugFont.render("%d ms" % (self.net.latency * 1000, ), False, (255, 0, 0))
			self.screen.blit(surf, (240, 13))