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


Python Map.getRectangle方法代码示例

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


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

示例1: Scene

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import getRectangle [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]))
开发者ID:Neverous,项目名称:ii-tieto12-python,代码行数:104,代码来源:scene.py

示例2: Scene

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import getRectangle [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
开发者ID:Neverous,项目名称:ii-tieto12-python,代码行数:104,代码来源:scene.py

示例3: Scene

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

#.........这里部分代码省略.........

	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()

	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:
开发者ID:Neverous,项目名称:ii-python11,代码行数:70,代码来源:scene.py


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