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


Python Map.switchStorey方法代码示例

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


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

示例1: Scene

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import switchStorey [as 别名]
class Scene(engine.Module):
	"""Główny ekran gry."""

	def __init__(self, _engine):
		super(Scene, self).__init__(_engine)
		self.side = utils.loadImage('data/gfx/side.png')
		self._background = pygame.Surface((self._resx, self._resy))
		self._background.blit(self.side, (self._resx - 232, self._resy - 1500))
		self.surface = self._background.copy()
		self._actual = []
		self._level = utils.loadLevel('data/level.dat')
		self._map = Map(_engine, self, self._level)
		self._minimap = Minimap(_engine, self._map)
		self._cursor = Cursor(_engine, self._map)
		self._creatureLayer = CreatureLayer(self._map, self._cursor) # Warstwa potworów
		self._map.addLayer('Creatures', 2, self._creatureLayer)
		self._map.addLayer('Missiles', 3, MissilesLayer(self._map)) # Warstwa pocisków(strzał, kuli ognia itp.)
		self._shadow = ShadowLayer(self._map)
		self._map.addLayer('Shadow', 5, self._shadow) # Mgła wojny
		self._monsters = []
		self._freeobjects = pygame.sprite.Group() # Wolne obiekty na scenie
		_counter = 0
		_start = 0
		# szukanie bohatera w lochu
		for l, storey in enumerate(self._level):
			for row in storey:
				for cell in row:
					if cell.getModifier() & field.MODIFIER_HERO:
						self._hero = hero.Hero(self._map, cell.getGrid() + (l,))
						self._hero.move((0, 0, 0))
						self._map.switchStorey(l)
						_start = l
						self._creatureLayer.add('hero', self._hero.getSprite(self._creatureLayer, 'hero'))
						break

		# szukanie potworów
		for l, storey in enumerate(self._level):
			for row in storey:
				for cell in row:
					if cell.getModifier() & field.MODIFIER_SPIDER:
						_monster = Spider(self._map, cell.getGrid() + (l,))
						self._monsters.append(('spider', _monster))
						if l == _start:
							self._creatureLayer.add('spider_' + str(_counter), _monster.getSprite(self._creatureLayer, 'spider_' + str(_counter)))
							self._actual.append(('spider_' + str(_counter), _monster))
							_monster.move((0, 0, 0))
							_counter += 1

					elif cell.getModifier() & field.MODIFIER_SKELETON:
						_monster = Skeleton(self._map, cell.getGrid() + (l,))
						self._monsters.append(('skeleton', _monster))
						if l == _start:
							self._creatureLayer.add('skeleton_' + str(_counter), _monster.getSprite(self._creatureLayer, 'skeleton_' + str(_counter)))
							self._actual.append(('skeleton_' + str(_counter), _monster))
							_monster.move((0, 0, 0))
							_counter += 1

					elif cell.getModifier() & field.MODIFIER_MAGE:
						_monster = Mage(self._map, cell.getGrid() + (l,))
						self._monsters.append(('mage', _monster))
						if l == _start:
							self._creatureLayer.add('mage_' + str(_counter), _monster.getSprite(self._creatureLayer, 'mage_' + str(_counter)))
							self._actual.append(('mage_' + str(_counter), _monster))
							_monster.move((0, 0, 0))
							_counter += 1

					elif cell.getModifier() & field.MODIFIER_TROLL:
						_monster = Troll(self._map, cell.getGrid() + (l,))
						self._monsters.append(('troll', _monster))
						if l == _start:
							self._creatureLayer.add('troll_' + str(_counter), _monster.getSprite(self._creatureLayer, 'troll_' + str(_counter)))
							self._actual.append(('troll_' + str(_counter), _monster))
							_monster.move((0, 0, 0))
							_counter += 1

		if not self._hero:
			raise Exception('Brak bohatera w lochu!?')

		self._statusbar = StatusBar(_engine, self._hero) # pasek życia/many itp. / statusu
		self.inventory = Inventory(_engine, self._hero, self._hero.inventory, self._freeobjects)
		self.chestitems = ChestItems(_engine, self._hero, self._freeobjects)
		self._submodules = (self._map, self._minimap, self._statusbar, self.inventory, self.chestitems, self._cursor)
		self._play = True
		self._refresh = True

	def isPlaying(self):
		"""Czy gracz nadal gra?"""

		return self._play

	def screenUpdated(self):
		"""Aktualizuje obrazy tła i submoduły."""

		super(Scene, self).screenUpdated()
		self._refresh = True
		self._background = pygame.Surface((self._resx, self._resy))
		self._background.blit(self.side, (self._resx - 232, self._resy - 1500))
		self.surface = pygame.transform.smoothscale(self.surface, (self._resx, self._resy))
		for submodule in self._submodules:
			submodule.screenUpdated()
#.........这里部分代码省略.........
开发者ID:Neverous,项目名称:ii-python11,代码行数:103,代码来源:scene.py

示例2: Editor

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

#.........这里部分代码省略.........
			submodule.screenUpdated()

	def setField(self, _l, _x, _y, _new):
		"""Ustawia pole w pozycji (_x, _y, _l) [_l to poziom lochu] na _new."""

		self._level[_l][_y][_x] = _new
		self._map.getLayer('Fields').set((_x, _y), _new.getSprite(True))

	def saveLevel(self):
		"""Zapisuje poziom na dysku."""

		return utils.saveLevel('data/level.dat', self._level)

	def clearLevel(self):
		"""Tworzy pusty poziom."""

		self._level = [[[Field((x, y)) for x in xrange(MAP_SIZE)] for y in xrange(MAP_SIZE)]]
		self._map = Map(self._engine, self, self._level, True)
		self._cursor = Cursor(self._engine, self._map)
		self._minimap = Minimap(self._engine, self._map)
		self._tiles = TilesGrid(self._engine, self, self._map)
		self._menu = EditorMenu(self._engine, self)
		self._submodules = (self._map, self._minimap, self._tiles, self._menu, self._cursor)
		self._refresh = True

	def show(self):
		"""Wyświetla edytor poziomów."""

		try:
			while self._engine.tick():
				self.events = self._engine.events()
				for event in self.events:
					if event.type == QUIT:
						raise engine.EngineQuit()

					if event.type == KEYUP and event.key == K_ESCAPE:
						self._engine.previousModule()
						raise EditorQuit()

					if event.type in (MOUSEMOTION, MOUSEBUTTONDOWN, MOUSEBUTTONUP):
						if event.type == MOUSEBUTTONDOWN and event.button in (4, 5): # zmiana poziomów kółkiem myszy, dodawanie w razie potrzeby
							_step = 0
							if event.button == 4:
								if self._map.getStorey() == 0 and len(self._level) < LEVEL_LIMIT:
									self._level.insert(0, [[Field((x, y)) for x in xrange(MAP_SIZE)] for y in xrange(MAP_SIZE)])
									self._map.updateLevel(self._level)
									_step += 1

								else:
									if self._map.getStorey() + 1 == self._map.getStoreys() and utils.emptyStorey(self._level[-1]):
										del self._level[-1]
										self._map.updateLevel(self._level)

									while len(self._level) > 1 and utils.emptyStorey(self._level[0]):
										del self._level[0]
										self._map.updateLevel(self._level)
										_step -= 1

							elif event.button == 5:
								if self._map.getStorey() + 1 == self._map.getStoreys() and len(self._level) < LEVEL_LIMIT:
									self._level.append([[Field((x, y)) for x in xrange(MAP_SIZE)] for y in xrange(MAP_SIZE)])
									self._map.updateLevel(self._level)

								else:
									if self._map.getStorey() == 0 and utils.emptyStorey(self._level[0]):
										del self._level[0]
										self._map.updateLevel(self._level)
										_step -= 1

									while len(self._level) > 1 and utils.emptyStorey(self._level[-1]):
										del self._level[-1]
										self._map.updateLevel(self._level)

							self._map.switchStorey(_step + (event.button == 4 and -1 or 1))

						for submodule in self._submodules:
							if submodule.getRectangle().collidepoint(event.pos):
								x, y, _, _ = submodule.getRectangle()
								_pos = event.pos[0] - x, event.pos[1] - y

							else:
								_pos = None

							submodule.mouseEvent(event, _pos)

				self.surface = self._background.copy()
				updated = []
				for submodule in (self._map, self._minimap, self._tiles, self._menu, self._cursor):
					updated.extend(submodule.update())
					submodule.draw(self.surface)

				if self._refresh:
					self._engine.show(self.surface)
					self._refresh = False

				else:
					self._engine.show(self.surface, updated)

		except EditorQuit:
			pass
开发者ID:Neverous,项目名称:ii-python11,代码行数:104,代码来源:editor.py


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