예제 #1
0
파일: Game.py 프로젝트: Anakonda/pixelords
	def event(self): # Handle keyboard events
		for event in pygame.event.get():
			self.engine.globalEvent(event)

			# Menu keys:
			if self.inMenu:
				if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
					self.running = False
				elif event.type == pygame.KEYDOWN or event.type == pygame.KEYUP:
					for player in self.players:
						player.event(event)

			# In-game keys
			else:
				if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
					self.running = False
				elif event.type == pygame.KEYDOWN and event.key == pygame.K_F10:
					path = os.path.join("maps", "saved")
					try:
						os.mkdir(path)
					except:
						pass
					pygame.image.save(self.map.mask.make_surface(), os.path.join(path, "mask.png"))
					pygame.image.save(self.map.visual, os.path.join(path, "visual.png"))
					pygame.image.save(self.map.background.make_surface(), os.path.join(path, "background.png"))
					self.engine.messageBox.addMessage("Current map saved to " + path + ".")
				elif event.type == pygame.KEYDOWN and event.key == pygame.K_F11:
					path = Functions.saveNameIncrement("screenshots", "fullmap", "png")
					pygame.image.save(self.map.screenImage, path)
					self.engine.messageBox.addMessage("Screenshot saved to " + path + ".")
				elif (event.type == pygame.KEYDOWN or event.type == pygame.KEYUP) and not(self.gameOver):
					for player in self.players:
						if player.ship.active:
							player.event(event)
예제 #2
0
파일: Game.py 프로젝트: Mreikon/pixelords
	def handleEvents(self): # Handle keyboard events
		for event in pygame.event.get():
			# General events:
			if event.type == pygame.constants.USEREVENT:
				self.sound.loadMusic()

			# Global keys:
			if event.type == pygame.KEYDOWN and event.key == pygame.K_F12:
				path = Functions.saveNameIncrement("screenshots", "screen", "png")
				pygame.image.save(self.screen, path)
				self.messageBox.addMessage("Screenshot saved to " + path + ".")
			elif event.type == pygame.KEYDOWN and event.key == pygame.K_F5:
				if Settings.sound:
					if Settings.music:
						Settings.music = False
						pygame.mixer.music.stop()
					else:
						Settings.music = True
						self.sound.loadMusic()
				else:
					print "Warning: Can't enable music (sounds are not enabled)"
			elif event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN and pygame.key.get_mods() & pygame.KMOD_ALT:
				if Settings.fullscreen == 1 or Settings.fullscreen == 2:
					Settings.fullscreen = 0
				elif Settings.fullscreen == 0:
					Settings.fullscreen = 1
				self.initScreen()

			# Menu keys:
			if self.inMenu:
				if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
					self.running = False
					print "Terminating..."
				elif event.type == pygame.KEYDOWN or event.type == pygame.KEYUP:
					for player in self.players:
						player.event(event)

			# In-game keys
			else:
				if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
					self.__init__()
				elif event.type == pygame.KEYDOWN and event.key == pygame.K_F1:
					self.messageBox.showForce = True
					self.infoOverlay.show = True
				elif event.type == pygame.KEYUP and event.key == pygame.K_F1:
					self.messageBox.showForce = False
					self.infoOverlay.show = False
				elif event.type == pygame.KEYDOWN and event.key == pygame.K_F10:
					path = os.path.join("maps", "saved")
					try:
						os.mkdir(path)
					except:
						pass
					pygame.image.save(self.map.mask.make_surface(), os.path.join(path, "mask.png"))
					pygame.image.save(self.map.visual, os.path.join(path, "visual.png"))
					pygame.image.save(self.map.background.make_surface(), os.path.join(path, "background.png"))
					self.messageBox.addMessage("Current map saved to " + path + ".")
				elif event.type == pygame.KEYDOWN and event.key == pygame.K_F11:
					path = Functions.saveNameIncrement("screenshots", "fullmap", "png")
					pygame.image.save(self.map.screenImage, path)
					self.messageBox.addMessage("Screenshot saved to " + path + ".")
				elif (event.type == pygame.KEYDOWN or event.type == pygame.KEYUP) and not(self.gameOver):
					for player in self.players:
						if player.ship.active:
							player.event(event)