def __touchUp(self, event): player = self._getPlayerForEvent(event) if event.cursorid in self.__touchNodeMapping: node = self.__touchNodeMapping[event.cursorid] del self.__touchNodeMapping[event.cursorid] self.space.delayRemoveComplete(node._body) else: for key in self.__shieldNodeMapping.keys(): id1, id2 = key if id1 == event.cursorid or id2 == event.cursorid: mapping = (id2, id1) firstId = id2 secondId = id1 if id1 < id2: mapping = (id1, id2) firstId = id1 secondId = id2 shield = self.__shieldNodeMapping[mapping] self.space.delayRemove(shield._body.shape, shield._body) shield.unlink(True) del self.__shieldNodeMapping[mapping] if firstId == event.cursorid: node = TouchPointNode(self.space, r=self._touchPointRadius, pos=shield.pos2, parent=self, fillopacity=1, owner=player) node.eventId = secondId self.__touchNodeMapping[secondId] = node else: node = TouchPointNode(self.space, r=self._touchPointRadius, pos=shield.pos1, parent=self, fillopacity=1, owner=player) node.eventId = firstId self.__touchNodeMapping[firstId] = node return
def __touchDown(self, event): for cannon in self._playerCannons: used = cannon.isTouchInCannonArea(event.pos) if used: return player = self._getPlayerForEvent(event) node = TouchPointNode(self.space, r=self._touchPointRadius, pos=event.pos, fillopacity=1, owner=player) node.eventId = event.cursorid for node2 in self.__touchNodeMapping.values(): if (util.getDistance(node.pos, node2.pos) < util.MAX_SHIELD_DISTANCE): del self.__touchNodeMapping[node2.eventId] self.space.delayRemoveComplete(node2._body) self.space.delayRemoveComplete(node._body) mapping = (node2.eventId, node.eventId) if node.eventId < node2.eventId: mapping = (node.eventId, node2.eventId) shield = ShieldNode(self.space, pos1=node.pos, pos2=node2.pos, strokewidth=20, color="FF0000") else: shield = ShieldNode(self.space, pos1=node2.pos, pos2=node.pos, strokewidth=20, color="FF0000") self.__shieldNodeMapping[mapping] = shield self.appendChild(shield) return self.__touchNodeMapping[event.cursorid] = node self.appendChild(node)