本文整理汇总了Python中map.Map.setShift方法的典型用法代码示例。如果您正苦于以下问题:Python Map.setShift方法的具体用法?Python Map.setShift怎么用?Python Map.setShift使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类map.Map
的用法示例。
在下文中一共展示了Map.setShift方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Scene
# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import setShift [as 别名]
#.........这里部分代码省略.........
self._client.sendAction('m')
self._last = time.time()
if not self._map and self._playerID == None:
self.surface = self._background.copy()
utils.drawText(self.surface, 'Oczekiwanie na graczy!', 20, (255, 255, 255), (self._resx / 2, self._resy / 2))
updated = []
if self._play:
for submodule in self._submodules:
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)
if not self._play:
time.sleep(5)
self._engine.runLoop = False
from twisted.internet import reactor
reactor.stop()
return
def _process(self, obj):
if isinstance(obj, protocolObjects.Countdown):
return self._countdown(obj)
if isinstance(obj, protocolObjects.Result):
return self._finish(obj)
if isinstance(obj, protocolObjects.Map):
return self._update(obj)
return self._connectionError(obj)
def _connectionError(self, msg):
self._play = False
utils.drawText(self.surface, str(msg), 10, (255, 255, 255), (self._resx / 2, self._resy - 10))
def _countdown(self, countdown):
if not self._map and countdown.number == 1:
self._loadMap(countdown.mapSize.x, countdown.mapSize.y)
if self._playerID == None:
self._playerID = countdown.playerId
self.surface = self._background.copy()
utils.drawText(self.surface, 'Gracz %d. >%d<' % (countdown.playerId, countdown.number), 30, (255, 255, 255), (self._resx / 2, self._resy / 2))
def _finish(self, result):
self.surface = self._background.copy()
utils.drawText(self.surface, 'Gra zakonczona!', 40, (255, 255, 255), (self._resx / 2, self._resy / 2))
if len(result.winners) == 1:
utils.drawText(self.surface, 'Wygral gracz %d!' % result.winners[0], 40, (255, 255, 255), (self._resx / 2, self._resy / 2 + 40))
elif len(result.winners):
utils.drawText(self.surface, 'Wygrali gracze %s!' % (', '.join([str(i) for i in result.winners])), 40, (255, 255, 255), (self._resx / 2, self._resy / 2 + 40))
self._play = False
self._engine.show(self.surface)
def _update(self, map):
if not self._map:
self._play = False
return
for mine in map.mines:
_id = mine.position.x, mine.position.y
if not self._mineLayer.get(_id):
_mine = ObjectsLayer.Sprite(utils.loadImage('data/gfx/bomb.png', alpha = True))
self._mineLayer.add(_id, _mine)
self._mineLayer.move(_id, _id)
for _id, player in enumerate(map.playersPositions):
if not self._heroLayer.get(_id):
self._heroLayer.add(_id, ObjectsLayer.Sprite(utils.loadImage('data/gfx/hero/n.png', alpha = True)))
_hero = self._heroLayer.get(_id)
_pos = _hero.getPos()
self._heroLayer.move(_id, (player.x, player.y))
_newpos = _hero.getPos()
if _pos[0] > _newpos[0]:
_hero.changeImage(utils.loadImage('data/gfx/hero/w.png', alpha = True))
if _pos[0] < _newpos[0]:
_hero.changeImage(utils.loadImage('data/gfx/hero/e.png', alpha = True))
if _pos[1] > _newpos[1]:
_hero.changeImage(utils.loadImage('data/gfx/hero/n.png', alpha = True))
if _pos[1] < _newpos[1]:
_hero.changeImage(utils.loadImage('data/gfx/hero/s.png', alpha = True))
if _id == self._playerID:
_, _, w, h = self._map.getRectangle()
self._map.setShift((w / 2 - _newpos[0], h / 2 - _newpos[1]))
示例2: Scene
# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import setShift [as 别名]
#.........这里部分代码省略.........
utils.drawText(self.surface, 'Wygrali gracze %s!' % (', '.join([str(i) for i in self._client.result.winners])), 40, (255, 255, 255), (self._resx / 2, self._resy / 2 + 40))
self._play = False
self._engine.show(self.surface)
time.sleep(10)
self._engine.previousModule()
raise SceneQuit()
if self._client.map:
if not self._map:
self._engine.previousModule()
self._play = False
raise SceneQuit()
for mine in self._client.map.mines:
_id = mine.position.x, mine.position.y
if not self._mineLayer.get(_id):
_mine = ObjectsLayer.Sprite(utils.loadImage('data/gfx/bomb.png', alpha = True))
self._mineLayer.add(_id, _mine)
self._mineLayer.move(_id, _id)
for _id, player in enumerate(self._client.map.playersPositions):
if not self._heroLayer.get(_id):
self._heroLayer.add(_id, ObjectsLayer.Sprite(utils.loadImage('data/gfx/hero/n.png', alpha = True)))
_hero = self._heroLayer.get(_id)
_pos = _hero.getPos()
self._heroLayer.move(_id, (player.x, player.y))
_newpos = _hero.getPos()
if _pos[0] > _newpos[0]:
_hero.changeImage(utils.loadImage('data/gfx/hero/w.png', alpha = True))
if _pos[0] < _newpos[0]:
_hero.changeImage(utils.loadImage('data/gfx/hero/e.png', alpha = True))
if _pos[1] > _newpos[1]:
_hero.changeImage(utils.loadImage('data/gfx/hero/n.png', alpha = True))
if _pos[1] < _newpos[1]:
_hero.changeImage(utils.loadImage('data/gfx/hero/s.png', alpha = True))
if _id == self._playerID:
_, _, w, h = self._map.getRectangle()
self._map.setShift((w / 2 - _newpos[0], h / 2 - _newpos[1]))
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()
if event.key in (K_w, K_UP):
self._client.sendAction('u')
self._last = time.time()
elif event.key in (K_s, K_DOWN):
self._client.sendAction('d')
self._last = time.time()
elif event.key in (K_a, K_LEFT):
self._client.sendAction('l')
self._last = time.time()
elif event.key in (K_d, K_RIGHT):
self._client.sendAction('r')
self._last = time.time()
elif event.key in (K_RETURN, K_RCTRL, K_LCTRL):
self._client.sendAction('c')
self._last = time.time()
elif event.key == K_q:
self._client.sendAction('e')
self._last = time.time()
if self._last + 1./self._engine.options['fps'] < time.time():
self._client.sendAction('m')
self._last = time.time()
self.surface = self._background.copy()
if not self._map:
utils.drawText(self.surface, 'Oczekiwanie na graczy!', 20, (255, 255, 255), (self._resx / 2, self._resy / 2))
updated = []
for submodule in self._submodules:
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 SceneQuit:
pass
示例3: Scene
# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import setShift [as 别名]
#.........这里部分代码省略.........
if event.type == MOUSEBUTTONDOWN and event.button == 3 and self._map.getRectangle().collidepoint(event.pos): # rzucanie czaru
self._hero.castSpell()
if event.type == MOUSEBUTTONDOWN and event.button == 1 and self._map.getRectangle().collidepoint(event.pos): # atak
self._hero.punch()
if self._hero.getGrid()[2] != self._map.getStorey(): # zmiana poziomu lochu
self._map.removeLayer('Missiles')
self._map.addLayer('Missiles', 3, MissilesLayer(self._map))
self._map.switchStorey(self._hero.getGrid()[2] - self._map.getStorey())
self._shadow.clear()
for _id, _ in self._actual:
self._creatureLayer.remove(_id)
self._actual = []
_counter = 0
_storey = self._map.getStorey()
for _name, _monster in self._monsters:
if _monster.getGrid()[2] == _storey:
self._creatureLayer.add(_name + '_' + str(_counter), _monster.getSprite(self._creatureLayer, _name + '_' + str(_counter)))
self._actual.append((_name + '_' + str(_counter), _monster))
_monster.move((0, 0, 0))
_counter += 1
else:
for key in hero.DIRECTION_KEYS:
if pygame.key.get_pressed()[key]:
self._hero.move(hero.KEY_MAP[key])
if self._hero.getDestination(): # przesuwanie mapy za bohaterem
x, y = self._hero.getPos()
_, _, w, h = self._map.getRectangle()
self._map.setShift((w / 2 - x, h / 2 - y))
if not self._hero.getLife(): # przegrana
utils.drawText(self.surface, "Game Over", 40, (255, 255, 255), (self._resx / 2, self._resy / 2))
self._play = False
self._engine.show(self.surface)
time.sleep(3)
self._engine.previousModule()
raise SceneQuit()
if not self._monsters: # wygrana
utils.drawText(self.surface, "Win", 50, (255, 255, 255), (self._resx / 2, self._resy / 2))
self._play = False
self._engine.show(self.surface)
time.sleep(3)
self._engine.previousModule()
raise SceneQuit()
_hero = self._hero.getPos()
_shift = self._map.getShift()
_hero = _hero[0] + _shift[0], _hero[1] + _shift[1]
_mouse = pygame.mouse.get_pos()
_mouse = _mouse[0] - _hero[0], _mouse[1] - _hero[1]
_angle = utils.vectorAngle((0, 1), _mouse)
if -45 <= _angle < 45:
self._hero.setDirection('s')
elif -135 <= _angle < -45:
self._hero.setDirection('e')
elif 45 <= _angle < 135:
self._hero.setDirection('w')