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


Python Map.load方法代码示例

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


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

示例1: LoadGame

# 需要导入模块: import Map [as 别名]
# 或者: from Map import load [as 别名]
def LoadGame():
    if not reloadGame:
        loadHolder = maps.load() 
        maps.new_blocks = loadHolder[0]
        player.rect = loadHolder[1]
        objects.all_objects = loadHolder[2]
    else:
        maps.loadMap()
开发者ID:Kanon121,项目名称:TheGame-Multiplayer,代码行数:10,代码来源:Globals.py

示例2: execute

# 需要导入模块: import Map [as 别名]
# 或者: from Map import load [as 别名]
def execute(server, iterator, source):
    server.playersinlobby.remove(source)

    mapnames = [m.split('.')[0] for m in os.listdir(GAME+'/maps')]

    maps = []
    for mapname in mapnames:
        mp = Map.load(mapname)
        del mp['tiles']
        maps.append(mp)

    server.send.MAP_LIST(maps, source)
开发者ID:gaconkzk,项目名称:tethical,代码行数:14,代码来源:GET_MAPS.py

示例3: Editor

# 需要导入模块: import Map [as 别名]
# 或者: from Map import load [as 别名]
class Editor():
	pygame.mixer.pre_init(44100, -16, 2, 1024)
	pygame.mixer.init()

	def __init__(self, levelPreset = "empty"):
		self.screen = pygame.display.get_surface()

		self.backgroundImage, self.backgroundRect = loadPNG("background.png")

		self.blockList = [Object(type = "earth"), Object(type = "boing"), Object(type = "ice")]

		self.currentBlockNumber = 0
		self.currentBlock = self.blockList[self.currentBlockNumber]
		self.currentSpriteBlock = pygame.sprite.RenderPlain(self.currentBlock)

		self.buttonSound = pygame.mixer.Sound("resources/sound/button.wav")
		self.buttonSound.set_volume(float(Resources.getOptionValue("sound"))/100)

		self.grid = False

		self.level = Map(True)

		self.active = True

		self.pauseMenu = PauseEditorMenu()

		self.toolbar = EditorToolbar()

		if levelPreset != "empty":
			self.level.load(levelPreset)
		
		pygame.display.flip()

	def update(self):
		key = pygame.key.get_pressed()
		mouse = pygame.mouse.get_pressed()

		if self.active:
			pygame.mouse.set_cursor(*pygame.cursors.arrow)
			
			for event in pygame.event.get():
				mse = pygame.mouse.get_pos()
				self.currentBlock.rect.topleft = ((int(mse[0]) / 50)*50, (int(mse[1]) / 50)*50)

				if event.type == QUIT or (key[K_F4] and key[K_LALT]):
					return False, self

				elif key[K_LCTRL] and key[K_s]:
					return True, SaveLevelMenu(self.level)

				elif key[K_LCTRL] and key[K_l]:
					return True, LoadLevelMenu()

				elif event.type == MOUSEBUTTONDOWN:
					if event.button == 5:
						self.currentBlockNumber = (self.currentBlockNumber - 1) % len(self.blockList)
					if event.button == 4:
						self.currentBlockNumber = (self.currentBlockNumber + 1) % len(self.blockList)
					if event.button == 3:
						self.level.removeObjectFromPos(mse)
					if event.button == 1:
						if not any(obj.rect.collidepoint(mse) for obj in self.level.objectList):
							if self.currentBlock.getType() == "boing":
								if self.level.getObjectFromPos((mse[0], mse[1] + 50)).getType() != "boing":
									if not self.level.isInBlock(mse[0], mse[1] - 50):
										self.level.addObject(self.currentBlock.rect.x, self.currentBlock.rect.y, self.currentBlock.getType())
							else:
								if self.level.getObjectFromPos((mse[0], mse[1] + 50)).getType() != "boing":
									self.level.addObject(self.currentBlock.rect.x, self.currentBlock.rect.y, self.currentBlock.getType())

					self.currentBlock = self.blockList[self.currentBlockNumber]
					self.currentSpriteBlock = pygame.sprite.RenderPlain(self.currentBlock)
					self.currentBlock.rect.topleft = ((int(mse[0]) / 50)*50, (int(mse[1]) / 50)*50)

				elif event.type == MOUSEMOTION:
					if mouse[0]:
						if not any(obj.rect.collidepoint(mse) for obj in self.level.objectList):
							if self.currentBlock.getType() == "boing":
								if self.level.getObjectFromPos((mse[0], mse[1] + 50)).getType() != "boing":
									if not self.level.isInBlock(mse[0], mse[1] - 50):
										self.level.addObject(self.currentBlock.rect.x, self.currentBlock.rect.y, self.currentBlock.getType())
							else:
								if self.level.getObjectFromPos((mse[0], mse[1] + 50)).getType() != "boing":
									self.level.addObject(self.currentBlock.rect.x, self.currentBlock.rect.y, self.currentBlock.getType())

					elif mouse[2]:
						self.level.removeObjectFromPos(mse)

				elif event.type == KEYDOWN:
					if event.key == K_g:
						if self.grid:
							self.grid = False
						else:
							self.grid = True

					elif event.key == K_ESCAPE:
						self.active = False
						self.level.save("last")

			self.screen.blit(self.backgroundImage, self.backgroundRect, self.backgroundRect)
#.........这里部分代码省略.........
开发者ID:Barbatos,项目名称:BumpNJump,代码行数:103,代码来源:Editor.py

示例4: processData

# 需要导入模块: import Map [as 别名]
# 或者: from Map import load [as 别名]
    def processData(self, datagram):
        iterator = PyDatagramIterator(datagram)
        source = datagram.getConnection()
        msgID = iterator.getUint8()
        
        if msgID == LOGIN_MESSAGE:

            login = iterator.getString()
            password = iterator.getString()

            if login != password:
                myPyDatagram = PyDatagram()
                myPyDatagram.addUint8(LOGIN_FAIL)
                myPyDatagram.addString('Wrong credentials.')
                self.cWriter.send(myPyDatagram, source)
            elif self.sessions.has_key(source):
                myPyDatagram = PyDatagram()
                myPyDatagram.addUint8(LOGIN_FAIL)
                myPyDatagram.addString('Already logged in.')
                self.cWriter.send(myPyDatagram, source)
            elif login in self.players.keys():
                myPyDatagram = PyDatagram()
                myPyDatagram.addUint8(LOGIN_FAIL)
                myPyDatagram.addString('Username already in use.')
                self.cWriter.send(myPyDatagram, source)
            else:
                self.players[login] = source
                self.sessions[source] = {}
                self.sessions[source]['login'] = login
                print login, 'logged in.'
                myPyDatagram = PyDatagram()
                myPyDatagram.addUint8(LOGIN_SUCCESS)
                self.cWriter.send(myPyDatagram, source)
        
        elif msgID == CREATE_PARTY:

            name = iterator.getString()
            mapname = iterator.getString()
            
            party = {
                'name': name,
                'mapname': mapname,
                'map' : Map.load(mapname),
                'chars': {},
                'log': {},
                'creator': self.sessions[source]['login'],
                'players': [],
            }
            party['players'].append(self.sessions[source]['login'])

            self.parties[name] = party
            self.sessions[source]['party'] = name
            self.sessions[source]['player'] = len(party['players'])-1
            
            self.updateAllPartyLists()
            
            print self.sessions[source]['login'], "created the party", name, "using the map", mapname
            myPyDatagram = PyDatagram()
            myPyDatagram.addUint8(PARTY_CREATED)
            myPyDatagram.addString32(json.dumps(party))
            self.cWriter.send(myPyDatagram, source)

        elif msgID == GET_MAPS:
            self.playersinlobby.remove(source)

            mapnames = map( lambda m: m.split('.')[0], os.listdir(GAME+'/maps'))

            maps = []
            for mapname in mapnames:
                mp = Map.load(mapname)
                del mp['tiles']
                maps.append(mp)

            myPyDatagram = PyDatagram()
            myPyDatagram.addUint8(MAP_LIST)
            myPyDatagram.addString(json.dumps(maps))
            self.cWriter.send(myPyDatagram, source)
        
        elif msgID == GET_PARTIES:
            self.playersinlobby.append(source)

            parties = deepcopy(self.parties)
            for party in parties.values():
                del party['map']['tiles']

            myPyDatagram = PyDatagram()
            myPyDatagram.addUint8(PARTY_LIST)
            myPyDatagram.addString32(json.dumps(parties))
            self.cWriter.send(myPyDatagram, source)
        
        elif msgID == JOIN_PARTY:
        
            name = iterator.getString()
            party = self.parties[name]
            
            if len(party['players']) >= len(party['map']['chartiles']):
                parties = deepcopy(self.parties)
                for party in parties.values():
                    del party['map']['tiles']
                myPyDatagram = PyDatagram()
#.........这里部分代码省略.........
开发者ID:Ultimoore,项目名称:tethical,代码行数:103,代码来源:main.py

示例5: MultiClientGame

# 需要导入模块: import Map [as 别名]
# 或者: from Map import load [as 别名]
class MultiClientGame():
	pygame.mixer.pre_init(44100, -16, 2, 1024)
	pygame.mixer.init()

	def __init__(self, color):
		self.butterflies = []

		self.screen = pygame.display.get_surface()

		self.backgroundImage, self.backgroundRect = loadPNG("background.png")

		self.buttonSound = pygame.mixer.Sound("resources/sound/button.wav")
		self.buttonSound.set_volume(float(Resources.getOptionValue("sound"))/100)

		self.active = True

		self.level = Map(True)

		self.toolbar = GameToolbar()

		self.client = Client('localhost')
		self.client.connect()
		self.client.recieve()
		self.client.send(b"connexion avec serveur : OK")

		#MAP STRING RECIEVE
		mapStr = self.client.recieve(4096)
		mapStr = struct.unpack(str(len(mapStr)) + "s", mapStr)[0]

		#LOAD MAP FROM STRING
		self.level.saveFromStr("tempClient", mapStr)
		self.level.load("tempClient")

		#CREATE CLIENT RABBIT
		self.regis = Rabbit(1, "regis" , color, self.level.objectList, self.level.objectSpritesList)

		#SERVER RABBIT COLOR RECIEVE
		serverCol = self.client.recieve()
		serverCol = struct.unpack("iii", serverCol)

		#CLIENT RABBIT COLOR SEND
		self.client.send(struct.pack("iii", self.regis.color[0], self.regis.color[1], self.regis.color[2]))

		#CREATE SERVER RABBIT
	 	self.john = Rabbit(2, "john" , serverCol, self.level.objectList, self.level.objectSpritesList, True)

		self.regis.appendRabbit(self.john)
	 	self.john.appendRabbit(self.regis)

	 	self.pauseMenu = PauseGameMenu()

	# 	for l in range(0, 6):
	# 		while True:
	# 			randPos = random.randint(0, 16)
	# 			if not self.level.isInBlock(self.level.objectList[randPos].getX() + 10, self.level.objectList[randPos].getY() - 26):
	# 				break

	# 		butterfly = Butterfly(self.level.objectList[randPos].getX() + 10, self.level.objectList[randPos].getY() - 26, (255, 10, 100), self.level.objectList, self.level.objectSpritesList)
	# 		self.butterflies.append(butterfly)

	 	pygame.display.flip()

	def update(self):
	 	key = pygame.key.get_pressed()

	 	if self.active:
	 		pygame.mouse.set_visible(0)

	 		for event in pygame.event.get():
	 			if event.type == QUIT or (key[K_F4] and key[K_LALT]):
	 				return False, self

	 			elif event.type == KEYDOWN:
	 				if event.key == K_UP:
	 					self.regis.jump()
	 				if event.key == K_LEFT:
	 					self.regis.moveLeftStart()
	 				if event.key == K_RIGHT:
						self.regis.moveRightStart()
	 				if event.key == K_KP0:
	 					self.regis.throwCarrot()

	 			elif event.type == KEYUP:
					if event.key == K_LEFT:
						self.regis.moveLeftStop()
					if event.key == K_RIGHT:
						self.regis.moveRightStop()

	# 			#IF A RABBIT IS TOUCHED
	# 			elif event.type == USEREVENT + 1:
	# 				print "touche"
	# 				if self.john.isTouched():
	# 					self.john.moveLeftStop()
	# 					self.john.moveRightStop()

	# 				elif self.regis.isTouched():
	# 					self.regis.moveLeftStop()
	# 					self.regis.moveRightStop()

	# 			elif event.type == USEREVENT + 2:
#.........这里部分代码省略.........
开发者ID:Barbatos,项目名称:BumpNJump,代码行数:103,代码来源:MultiClientGame.py


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