本文整理汇总了Python中map.Map.getLayer方法的典型用法代码示例。如果您正苦于以下问题:Python Map.getLayer方法的具体用法?Python Map.getLayer怎么用?Python Map.getLayer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类map.Map
的用法示例。
在下文中一共展示了Map.getLayer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Scene
# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import getLayer [as 别名]
#.........这里部分代码省略.........
for submodule in self._submodules:
submodule.screenUpdated()
def show(self):
if not self._play:
self._engine.previousModule()
return
try:
while self._engine.tick():
for event in self._engine.events():
if event.type == QUIT:
raise engine.EngineQuit()
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
self._engine.previousModule()
raise SceneQuit()
elif event.key in hero.MAGIC_KEYS:
self._hero.setSpell(hero.KEY_MAP[event.key])
if event.type in (MOUSEMOTION, MOUSEBUTTONDOWN, MOUSEBUTTONUP):
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)
if submodule == self._map and event.type == MOUSEBUTTONDOWN and _pos: # obsługa otwierania skrzynki(głównie)
_field = self._map.getLayer('Fields').get(_pos, True)
if _field:
_field.getLogic().clicked(self, self._hero)
if submodule == self._map and event.type == MOUSEBUTTONUP and event.button == 1 and _pos: # upuszczanie przedmiotu
_field = self._map.getLayer('Fields').get(_pos, True)
if _field:
_field = _field.getLogic()
if _field and utils.distance(_field.getGrid()[:2], self._hero.getGrid()[:2]) <= 1:
for _obj in self._freeobjects:
if not _obj.attach(_field):
_obj.attach(_obj.getAttached())
else:
for _obj in self._freeobjects:
_obj.attach(_obj.getAttached())
if submodule == self.inventory and event.type == MOUSEBUTTONUP and event.button == 1 and _pos: # ↑
for _obj in self._freeobjects:
if not _obj.attach(self.inventory.getCell(_pos)):
_obj.attach(_obj.getAttached())
if submodule == self.chestitems and event.type == MOUSEBUTTONUP and event.button == 1 and _pos: # ↑
for _obj in self._freeobjects:
if not self.chestitems.opened or not _obj.attach(self.chestitems.getCell(_pos)):
_obj.attach(_obj.getAttached())
for _obj in self._freeobjects:
_obj.mouseEvent(event)
if event.type == MOUSEBUTTONDOWN and event.button == 3 and self._map.getRectangle().collidepoint(event.pos): # rzucanie czaru
self._hero.castSpell()
示例2: Editor
# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import getLayer [as 别名]
class Editor(engine.Module):
"""Edytor lochów."""
def __init__(self, _engine):
super(Editor, 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._level = utils.loadLevel('data/level.dat') or [[[Field((x, y)) for x in xrange(MAP_SIZE)] for y in xrange(MAP_SIZE)]]
self._map = Map(_engine, self, self._level, True)
self._cursor = Cursor(_engine, self._map)
self._minimap = Minimap(_engine, self._map)
self._tiles = TilesGrid(_engine, self, self._map)
self._menu = EditorMenu(_engine, self)
self._submodules = (self._map, self._minimap, self._tiles, self._menu, self._cursor)
self._refresh = True
def screenUpdated(self):
"""Aktualizuje obrazy tła i submoduły."""
super(Editor, 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()
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)
#.........这里部分代码省略.........