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


Python Map.generate方法代码示例

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


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

示例1: init

# 需要导入模块: import Map [as 别名]
# 或者: from Map import generate [as 别名]
def init(): # Defini les variables de depart
    global descript, myBackground
    myBackground=Background.create("background","victoire","defaite","menu")
    Background.show(myBackground,"menu")
    Player.setName()
    Player.setHealth()
    Player.setPower()
    Map.generate(6)
    descript = descript()
    tty.setcbreak(sys.stdin.fileno())
    return descript
开发者ID:ValentinPearce,项目名称:The-Shades,代码行数:13,代码来源:OriginalGame.py

示例2: __init__

# 需要导入模块: import Map [as 别名]
# 或者: from Map import generate [as 别名]

#.........这里部分代码省略.........
		self.spriteBanc = sf.Sprite(self.textureBanc)
		self.spriteLit = sf.Sprite(self.textureLit)
		self.spriteLitMedecin = sf.Sprite(self.textureLitMedecin)
		self.spriteLitPsy = sf.Sprite(self.textureLit)
		self.spriteChaise = sf.Sprite(self.textureChaise)
		self.spriteChaiseEcole = sf.Sprite(self.textureChaiseEcole)
		self.spriteChaiseMedecin = sf.Sprite(self.textureChaiseMedecin)
		self.spriteChaisePsy = sf.Sprite(self.textureChaisePsy)
		self.spriteTable = sf.Sprite(self.textureTable)
		self.spriteTableEcole = sf.Sprite(self.textureTableEcole)
		self.spriteFour = sf.Sprite(self.textureFour)
		self.spriteTableau = sf.Sprite(self.textureTableau)
		self.spriteBancPeche = sf.Sprite(self.textureBancPeche)
		
		
		# Scrolling :
		
		self.xMin = 0
		self.yMin = 0
		
	# Mise en place du jeu :
		
	def play(self):
		
		# Ecran d'acceuil :
		
		self.window.draw(self.spriteVodak)
		self.window.display()
		sf.sleep(sf.seconds(2))
		self.window.clear()
		
		# Génération de la map :
		
		self.Map.generate()

		# Disposition des maisons :
		for i in range(20):
			self.Map.maison()
		
		# Invocation des IA sur la map
		
		for i in range(3):
			x = randint(0, 95)
			y = randint(0, 71)
			
			while self.Map.map[x][y].Bloc != Bloc.Herbe and self.Map.map[x][y].Bloc != Bloc.Plancher and self.Map.map[x][y].Bloc != Bloc.Sable:
				
				x = randint(0, 95)
				y = randint(0, 71)
				
			self.Map.map[x][y].IA = IA(x, y, 21 * [randint(0, 100)])
		
		# Boucle principale :
		
		while self.window.is_open:
			
			# gestion des evenements
			
			for event in self.window.events:
			
				if type(event) is sf.CloseEvent:
					self.window.close()
				
				elif type(event) is sf.KeyEvent:
					if event.code is sf.Keyboard.ESCAPE:
						self.window.close()
开发者ID:Vodak,项目名称:SINS,代码行数:70,代码来源:Game.py

示例3: createPlayer

# 需要导入模块: import Map [as 别名]
# 或者: from Map import generate [as 别名]

#.........这里部分代码省略.........
									self.player.addItem(self.map.getBlocks()[y][x].getTile(), 1)
									self.map.getBlocks()[y][x].setTile(0)
									if (self.map.getBlocks()[y][x].getBody() != None):
										self.world.DestroyBody(self.map.getBlocks()[y][x].getBody())
										self.map.getBlocks()[y][x].setBody(None)
								elif self.player.getSelected().getId() != 0:
									if (self.map.getBlocks()[y][x].getBody() == None):
										self.map.getBlocks()[y][x].setTile(self.player.getSelected().getId())
										self.map.getBlocks()[y][x].setBody(self.createStatic(x * 10, y * 10))
										self.player.removeItem(self.player.getSelected().getId(), 1)
							return
									
	def on_loop(self):
		pass
		
	def on_render(self):
		self._display_surf.fill((255,255,255))
		#render blocks
		for y in range(len(self.map.getBlocks())):
			for x in range(len(self.map.getBlocks()[y])):
				block = self.map.getBlocks()[y][x]
				blockX = block.getX()
				blockY = block.getY()
				color = (255, 255, 255)
				if block.getTile() == 1:
					color = color = (255, 0, 255)
				if block.getTile() == 2:
					color = color = (0, 0, 255)
				pygame.draw.rect(self._display_surf, color, (blockX * 10, blockY * 10 + 15, 10, 10))
			
		i = 0
		for item in self.player.getItems():
			if self.player.getSelected() != None and self.player.getSelected().getId() == item.getId():
				pygame.draw.rect(self._display_surf, (125, 225, 125), [10 + i * 25 + 5, 10, 25, 25])
			else:
				pygame.draw.rect(self._display_surf, (225, 225, 225), [10 + i * 25 + 5, 10, 25, 25])
			pygame.draw.rect(self._display_surf, (0, 0, 0), [10 + i * 25 + 5, 10, 25, 25], 2)
			color = (255, 255, 255)
			if item.getId() == 1:
				color = color = (255, 0, 255)
			if item.getId() == 2:
				color = color = (0, 0, 255)
			pygame.draw.rect(self._display_surf, color, [10 + i * 25 + 10, 10 + 5, 15, 15])
			i += 1
		#render player		
		body = self.player.getBody()
		pygame.draw.rect(self._display_surf, (125, 125, 125), (body.position.x, body.position.y, 10, 20))
		vel = body.linearVelocity
		vel.x += self.h_speed
		if abs(body.linearVelocity.y) < .5:
			vel.y += self.v_speed	
			body.linearVelocity = vel
		self.v_speed = 0
		
		pygame.display.flip()
	def on_cleanup(self):
		pygame.quit()

	def on_execute(self):
		if self.on_init() == False:
			self._running = False
		self.clock = pygame.time.Clock()
		#generate map and create player
		self.map = Map("test")
		self.map.generate(200, 75)
		self.boxes = []
		self.createPlayer(100, 100)
		
		print self.player.getSelected()
		print self.player.getItems()
		
		#add static bodies to map
		for y in range(len(self.map.getBlocks())):
			for x in range(len(self.map.getBlocks()[y])):
				block = self.map.getBlocks()[y][x]
				if int(block.getTile()) != 0:
					#print "Creating static", block.getTile()
					block.setBody(self.createStatic(x * 10, y * 10))
					#print "Static created"				
		timeStep = 1.0 / 30
		vel_iters, pos_iters = 1, 1
		
		#while out game is playing
		while( self._running ):
			self.clock.tick(60)
			#step physics
			self.world.Step(timeStep, vel_iters, pos_iters)
			#clear forces on objects
			self.world.ClearForces()
			
			#loop through keyboard/mouse events
			for event in pygame.event.get():
				self.on_event(event)
				
			#game loop
			self.on_loop()
			
			#render objects
			self.on_render()
		self.on_cleanup()
开发者ID:sritzow,项目名称:pygame,代码行数:104,代码来源:game.py


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