def __init__(self, name): FSM.__init__(self, name) PandaNode.__init__(self, name) DirectObject.__init__(self) self.active = True self.lastClickState = PGButton.SReady self.clickState = PGButton.SReady self.__hovering = False self.clickEvent = '' self.clickExtraArgs = [] self.contents = NodePath.anyPath(self).attachNewNode('contents') # Create a MouseWatcherRegion: self.regionName = self.getUniqueName() + '-region' self.region = MouseWatcherRegion(self.regionName, 0, 0, 0, 0) base.mouseWatcherNode.addRegion(self.region) # Accept the mouse events: enterPattern = base.mouseWatcherNode.getEnterPattern() leavePattern = base.mouseWatcherNode.getLeavePattern() buttonDownPattern = base.mouseWatcherNode.getButtonDownPattern() buttonUpPattern = base.mouseWatcherNode.getButtonUpPattern() self.accept(enterPattern.replace('%r', self.regionName), self.__handleMouseEnter) self.accept(leavePattern.replace('%r', self.regionName), self.__handleMouseLeave) self.accept(buttonDownPattern.replace('%r', self.regionName), self.__handleMouseDown) self.accept(buttonUpPattern.replace('%r', self.regionName), self.__handleMouseUp)
def __init__(self, name): PandaNode.__init__(self, name) DirectObject.__init__(self) self.fsm = ClassicFSM(name, [ State('off', self.enterOff, self.exitOff), State('rollover', self.enterRollover, self.exitRollover), State('ready', self.enterReady, self.exitReady), State('depressed', self.enterDepressed, self.exitDepressed), State('inactive', self.enterInactive, self.exitInactive)], 'off', 'off') self.fsm.enterInitialState() self.active = True self.lastClickState = PGButton.SReady self.clickState = PGButton.SReady self.__hovering = False self.clickEvent = '' self.clickExtraArgs = [] self.contents = NodePath.anyPath(self).attachNewNode('contents') # Create a MouseWatcherRegion: self.regionName = self.getUniqueName() + '-region' self.region = MouseWatcherRegion(self.regionName, 0, 0, 0, 0) base.mouseWatcherNode.addRegion(self.region) # Accept the mouse events: enterPattern = base.mouseWatcherNode.getEnterPattern() leavePattern = base.mouseWatcherNode.getLeavePattern() buttonDownPattern = base.mouseWatcherNode.getButtonDownPattern() buttonUpPattern = base.mouseWatcherNode.getButtonUpPattern() self.accept(enterPattern.replace('%r', self.regionName), self.__handleMouseEnter) self.accept(leavePattern.replace('%r', self.regionName), self.__handleMouseLeave) self.accept(buttonDownPattern.replace('%r', self.regionName), self.__handleMouseDown) self.accept(buttonUpPattern.replace('%r', self.regionName), self.__handleMouseUp)
def onContactAdded(self, node1, node2): isMyCarColliding = False if node1.notifiesCollisions() and node2.notifiesCollisions(): isEnable = True list2 = [node1.getName(), node2.getName()] for nodeSet in self.nodeFilterList: if (list2[0] == nodeSet[0]) or (list2[0] == nodeSet[1]): if (list2[1] == nodeSet[0]) or (list2[1] == nodeSet[1]): isEnable = False if isEnable: isMyCarColliding = False npA = NodePath.anyPath(node1) npB = NodePath.anyPath(node2) message = "" if node1.getName() == self.login: nodeA = node1 nodeB = node2 isMyCarColliding = True elif node2.getName() == self.login: nodeA = node2 nodeB = node1 isMyCarColliding = True if isMyCarColliding: print "isMyCarColliding: True" name1 = node1.getTag("username") vehicle1 = self.vehicleList[name1] vehicle1.props.setVelocity(node1.getLinearVelocity().length()) name2 = node2.getTag("username") vehicle2 = self.vehicleList[name2] vehicle2.props.setVelocity(node2.getLinearVelocity().length()) self.calculateDamage(vehicle1, vehicle2) self.nodeFilterList.append((node1.getName(), node2.getName())) thread = Thread(target=self.removeCollisionSet, args=(1,)) self.collisionThreadSet.append(thread) thread.start()
def onContactAdded(self, node1, node2): isMyCarColliding = False if node1.notifiesCollisions() and node2.notifiesCollisions(): isEnable = True list2 = [node1.getName(), node2.getName()] for nodeSet in self.nodeFilterList: if (list2[0] == nodeSet[0]) or (list2[0] == nodeSet[1]): if (list2[1] == nodeSet[0]) or (list2[1] == nodeSet[1]): isEnable = False if isEnable: npA = NodePath.anyPath(node1) npB = NodePath.anyPath(node2) message = "" if node1.getName() == self.login: nodeA = node1 nodeB = node2 isMyCarColliding = True elif node2.getName() == self.login: nodeA = node2 nodeB = node1 isMyCarColliding = True if isMyCarColliding: name1 = node1.getTag("username") vehicle1 = self.vehicleList[name1] vehicle1.props.setVelocity(node1.getLinearVelocity().length()) name2 = node2.getTag("username") vehicle2 = self.vehicleList[name2] vehicle2.props.setVelocity(node2.getLinearVelocity().length()) self.calculateDamage(vehicle1, vehicle2) self.nodeFilterList.append((node1.getName(), node2.getName())) thread = Thread(target=self.removeCollisionSet, args=(1, )) self.collisionThreadSet.append(thread) thread.start()