class BulletCollision: def __init__(self, bullet): self.bullet = bullet self.setup_collision() self.queue = CollisionHandlerQueue() self.traverser = CollisionTraverser('Collision Traverser') self.traverser.showCollisions(render) self.traverser.add_collider(self.target_nodepath, self.queue) base.taskMgr.add(self.collide, "Collision Task") def setup_collision(self): self.target = CollisionSphere(0, 0, 0, 0.1) self.target_node = CollisionNode('collision_bullet') self.target_node.setFromCollideMask(ENEMIES) self.target_node.setIntoCollideMask(ALLIES) self.target_nodepath = self.bullet.model.attach_new_node( self.target_node) self.target_nodepath.node().addSolid(self.target) self.target_nodepath.show() def collide(self, task): self.traverser.traverse(render) for entry in self.queue.get_entries(): #print("Bullet:") #print(entry) self.bullet.model.removeNode() return task.cont
class EntityCollision: def __init__(self, entity): self.entity = entity self.setup_collision() self.queue = CollisionHandlerQueue() self.traverser = CollisionTraverser('Collision Traverser') self.traverser.showCollisions(render) self.traverser.add_collider(self.target_nodepath, self.queue) base.taskMgr.add(self.collide, "Collision Task") def setup_collision(self): self.target = CollisionSphere(0, 0, 0, 1) self.target_node = CollisionNode('collision_entity') self.target_node.setFromCollideMask(ALLIES) # unused self.target_node.setIntoCollideMask(ENEMIES) self.target_nodepath = self.entity.model.attach_new_node( self.target_node) self.target_nodepath.node().addSolid(self.target) self.target_nodepath.show() def collide(self, task): self.traverser.traverse(render) for entry in self.queue.get_entries(): # print("Entity:") pos = entry.getSurfacePoint(self.entity.model) pos_x = pos[0] pos_z = pos[2] self.entity.spawn_particles(pos_x, pos_z) self.entity.life -= 1 return task.cont
def initHero(self): self.hero = loader.loadModel("charaRoot") self.hero.reparentTo(self.stage) model = base.gameData.heroModel self.heroArmature = Actor( "{}".format(model), { "idle": "{}-idle".format(model), "walk": "{}-run".format(model) }) self.heroArmature.reparentTo(self.hero) self.hero.setPos(self.startPos) cNode = CollisionNode('hero') cNode.addSolid(CollisionSphere(0, 0, 1.5, 1)) heroCollision = self.hero.attachNewNode(cNode) ######################################################### # heroCollision.show() self.pusher.addCollider( heroCollision, self.hero, base.drive.node()) base.cTrav.addCollider(heroCollision, self.pusher) heroGroundRay = CollisionRay() heroGroundRay.setOrigin(0, 0, 9) heroGroundRay.setDirection(0, 0, -1) heroGroundCol = CollisionNode('heroRay') heroGroundCol.addSolid(heroGroundRay) heroGroundCol.setFromCollideMask(CollideMask.bit(0)) heroGroundCol.setIntoCollideMask(CollideMask.allOff()) heroGroundColNp = self.hero.attachNewNode(heroGroundCol) ######################################################### # heroGroundColNp.show() base.cTrav.addCollider(heroGroundColNp, self.heroGroundHandler) self.controlCamera()
def placeHealthItems(self): self.placeholder = render.attachNewNode("HealthItem-Placeholder") self.placeholder.setPos(0,0,0) # Add the health items to the placeholder node for i in range(5): # Load in the health item model self.foodchick = loader.loadModel("models/chicken2") self.foodchick.setPos(0,0,0) self.foodchick.reparentTo(self.placeholder) #self.tex2=self.setTexture("models/orange.jpg") #self.foodchick.setTexture(self.tex2,1) #self.tex2= loader.loadTexture("models/orange.jpg") #self.foodchick.setTexture(self.tex1,1) self.placeItem(self.foodchick) # Add spherical collision detection healthSphere = CollisionSphere(0,0,0,1) sphereNode = CollisionNode('healthSphere') sphereNode.addSolid(healthSphere) sphereNode.setFromCollideMask(BitMask32.allOff()) sphereNode.setIntoCollideMask(BitMask32.bit(0)) sphereNp = self.foodchick.attachNewNode(sphereNode) sphereColHandler = CollisionHandlerQueue()
def placeCollectibles(self): self.placeCol = render.attachNewNode("Collectible-Placeholder") self.placeCol.setPos(0,0,0) # Add the health items to the placeCol node for i in range(self.numObjects): # Load in the health item model self.collect = loader.loadModel("models/trex") self.collect.setPos(0,0,0) self.collect.reparentTo(self.placeCol) self.collect.setScale(0.1) self.tex3= loader.loadTexture("models/Face.jpg") self.collect.setTexture(self.tex3,1) self.placeItem(self.collect) # Add spherical collision detection colSphere = CollisionSphere(0,0,0,1) sphereNode = CollisionNode('colSphere') sphereNode.addSolid(colSphere) sphereNode.setFromCollideMask(BitMask32.allOff()) sphereNode.setIntoCollideMask(BitMask32.bit(0)) sphereNp = self.collect.attachNewNode(sphereNode) sphereColHandler = CollisionHandlerQueue()
def startSeeking(self): if not self.avatar: return self.cleanupShadow() self.buildShadow() scale = self.dropShadow.getScale() if scale < 1.0: self.maxDistance += 40 x, y, z = self.avatar.getPos(render) self.dropShadow.reparentTo(render) self.dropShadow.setPos(x, y + 5, z + 2) self.cameraNode = CollisionNode('coll_camera') self.cameraNode.setFromCollideMask(CIGlobals.WallBitmask) self.cameraRay = CollisionRay() self.cameraNode.addSolid(self.cameraRay) self.cameraNP = camera.attachNewNode(self.cameraNode) base.cTrav.addCollider(self.cameraNP, CollisionHandlerQueue()) if not self.legacyMode: shadowNode = CollisionNode('coll_shadow') self.shadowRay = CollisionRay(0, 0, 6, 0, 0, -1) shadowNode.addSolid(self.shadowRay) shadowNode.setFromCollideMask(CIGlobals.FloorBitmask) self.shadowNP = self.dropShadow.attachNewNode(shadowNode) base.cTrav.addCollider(self.shadowNP, self.collHdlFl) base.taskMgr.add(self.__moveShadow, self.moveShadowTaskName) self.avatar.acceptOnce('mouse1', self.locationChosen)
def set_controls(self): """Configure common game controls. Configure major keys, collisions system and controls to manipulate characters. """ base.accept("f1", self._show_keys) # noqa: F821 base.accept("escape", base.main_menu.show) # noqa: F821 base.accept("r", self._show_char_relations) # noqa: F821 base.accept("m", base.world.rails_scheme.show) # noqa: F821 base.accept("j", base.journal.show) # noqa: F821 # configure mouse collisions col_node = CollisionNode("mouse_ray") col_node.setIntoCollideMask(NO_MASK) col_node.setFromCollideMask(MOUSE_MASK) self._mouse_ray = CollisionRay() col_node.addSolid(self._mouse_ray) # set common collisions handler handler = CollisionHandlerEvent() handler.addInPattern("%fn-into") handler.addAgainPattern("%fn-again") handler.addOutPattern("%fn-out") self.traverser = CollisionTraverser("traverser") self.traverser.addCollider( base.cam.attachNewNode(col_node), handler # noqa: F821 ) self.set_mouse_events() taskMgr.doMethodLater(0.03, self._collide_mouse, "collide_mouse") # noqa: F821 taskMgr.doMethodLater(0.04, self._traverse, name="main_traverse") # noqa: F821
def getObjectsInBox(self, mins, maxs): objects = [] # Create a one-off collision box, traverser, and queue to test against all MapObjects box = CollisionBox(mins, maxs) node = CollisionNode("selectToolCollBox") node.addSolid(box) node.setFromCollideMask(self.Mask) node.setIntoCollideMask(BitMask32.allOff()) boxNp = self.doc.render.attachNewNode(node) queue = CollisionHandlerQueue() base.clickTraverse(boxNp, queue) queue.sortEntries() key = self.Key entries = queue.getEntries() # Select every MapObject our box intersected with for entry in entries: np = entry.getIntoNodePath().findNetPythonTag(key) if not np.isEmpty(): obj = np.getPythonTag(key) actual = self.getActualObject(obj, entry) if isinstance(actual, list): for a in actual: if not any(a == x[0] for x in objects): objects.append((a, entry)) else: objects.append((actual, entry)) boxNp.removeNode() return objects
def __init__(self, cr): DistributedObject.__init__(self, cr) #self.model = loader.loadModel('environment') #self.model.setZ(0) #self.builder = Builder(self, "map.txt", "development") plane = CollisionPlane(Plane(Vec3(0, 0, 1), Point3(0, 0, 0))) cnode = CollisionNode('cnode') cnode.setIntoCollideMask(BitMask32.bit(1)) cnode.setFromCollideMask(BitMask32.bit(1)) cnode.addSolid(plane) self.planeNP = self.model.attachNewNode(cnode) self.planeNP.show() # Setup a traverser for the picking collisions self.picker = CollisionTraverser() # Setup mouse ray self.pq = CollisionHandlerQueue() # Create a collision Node pickerNode = CollisionNode('MouseRay') # set the nodes collision bitmask pickerNode.setFromCollideMask(BitMask32.bit(1)) # create a collision ray self.pickerRay = CollisionRay() # add the ray as a solid to the picker node pickerNode.addSolid(self.pickerRay) # create a nodepath with the camera to the picker node self.pickerNP = base.camera.attachNewNode(pickerNode) # add the nodepath to the base traverser self.picker.addCollider(self.pickerNP, self.pq) print "model loaded" #TODO: check how to load multiple levels and set players in specific levels! self.accept("mouse1", self.mouseClick)
def __init__(self): colliderNode = CollisionNode(self.colliderName + "WallCollider") colliderNode.addSolid(CollisionSphere(0, 0, 0, 0.3)) self.collider = self.root.attachNewNode(colliderNode) self.collider.setPythonTag(TAG_OWNER, self) colliderNode.setFromCollideMask(MASK_WALLS) colliderNode.setIntoCollideMask(0) self.collider.setZ(self.height * 0.5) base.pusher.addCollider(self.collider, self.root) base.traverser.addCollider(self.collider, base.pusher) self.ray = CollisionRay(0, 0, self.height / 2, 0, 0, -1) rayNode = CollisionNode(self.colliderName + "Ray") rayNode.addSolid(self.ray) rayNode.setFromCollideMask(MASK_FLOORS) rayNode.setIntoCollideMask(0) self.rayNodePath = self.root.attachNewNode(rayNode) self.rayQueue = CollisionHandlerQueue() base.traverser.addCollider(self.rayNodePath, self.rayQueue)
def __init__(self, base, player): self.base=base self.player=player # actor self.actor=Actor("models/zorrito") self.actor.reparentTo(self.base.render) self.actor.setScale(0.15) # collision # ray collRay=CollisionRay(0, 0, 1.5, 0, 0, -1) collRayN=CollisionNode("playerCollRay") collRayN.addSolid(collRay) collRayN.setFromCollideMask(1) collRayN.setIntoCollideMask(CollideMask.allOff()) #collRayNP=self.actor.attachNewNode(collRayN) self.collQRay=CollisionHandlerQueue() #self.base.cTrav.addCollider(collRayNP, self.collQRay) # ai self.aiWorld=AIWorld(self.base.render) self.aiChar=AICharacter("aiZorrito", self.actor, 150, 0.05, 6) self.aiWorld.addAiChar(self.aiChar) self.aiBehaviors=self.aiChar.getAiBehaviors() self.aiBehaviors.initPathFind("models/navmesh.csv") # state self.distanceToPlayer=1000 self.zOffset=0 self.terrainSurfZ=0 self.state=Zorrito.STATE_IDLE self.currentStateTimeout=4+6*random.random() # uptade task self.base.taskMgr.add(self.update, "zorritoUpdateTask")
def initCollisionSphere(obj, desc, radiusMultiplier, intoMask=BitMask32(0x1), isFromCollider=False): # Get the size of the object for the collision sphere. bounds = obj.getChild(0).getBounds() center = bounds.getCenter() radius = bounds.getRadius() * radiusMultiplier # Create a collision sphere and name it something understandable. collSphereStr = desc cNode = CollisionNode(collSphereStr) cNode.addSolid(CollisionSphere(center, radius)) if not isFromCollider: cNode.setFromCollideMask(BitMask32(0x0)) cNode.setIntoCollideMask(intoMask) cNodepath = obj.attachNewNode(cNode) # if show: #cNodepath.show() # Return a tuple with the collision node and its corrsponding string so # that the bitmask can be set. return cNodepath, collSphereStr
def start(self): base.camLens.setNear(0.1) self.shooterTrav = CollisionTraverser('ToonFPS.shooterTrav') ray = CollisionRay() rayNode = CollisionNode('ToonFPS.rayNode') rayNode.addSolid(ray) rayNode.setCollideMask(BitMask32(0)) rayNode.setFromCollideMask(CIGlobals.WallBitmask | CIGlobals.FloorBitmask) self.shooterRay = ray self.shooterRayNode = base.camera.attachNewNode(rayNode) self.shooterHandler = CollisionHandlerQueue() self.shooterTrav.addCollider(self.shooterRayNode, self.shooterHandler) self.firstPerson.start() self.v_model_root.reparentTo(base.camera) self.v_model.reparentTo(self.v_model_root) if self.weaponName == "pistol": self.v_model_root.setZ(-1.8) self.v_model_root.setY(0.3) self.v_model_root.setX(-0.1) self.v_model_root.setH(2) elif self.weaponName == "sniper": self.v_model_root.setPos(-0.42, -0.81, -1.7) self.v_model_root.setHpr(359, 352.87, 0.00) elif self.weaponName == "shotgun": self.v_model_root.setPos(-0.42, -0.81, -1.7) self.v_model_root.setHpr(359, 352.87, 0.00) self.gui.start() self.firstPerson.disableMouse() self.aliveFSM.request('draw')
class ShipCollision: def __init__(self, ship): self.ship = ship self.setup_collision() self.queue = CollisionHandlerQueue() self.traverser = CollisionTraverser('Collision Traverser') self.traverser.showCollisions(render) self.traverser.add_collider(self.target_nodepath, self.queue) base.taskMgr.add(self.collide, "Collision Task") def setup_collision(self): self.target = CollisionSphere(0, 0, 0, 0.5) self.target_node = CollisionNode('collision_ship') self.target_node.setFromCollideMask(ENEMIES) self.target_node.setIntoCollideMask(ALLIES) self.target_nodepath = self.ship.model.attach_new_node(self.target_node) self.target_nodepath.node().addSolid(self.target) #self.target_nodepath.show() def collide(self, task): self.traverser.traverse(render) for entry in self.queue.get_entries(): #print("Ship:") #print(entry) self.ship.model.cleanup() self.ship.model.removeNode() return task.cont
def __init__(self, cr): DistributedObject.__init__(self, cr) #self.model = loader.loadModel('environment') #self.model.setZ(0) #self.builder = Builder(self, "map.txt", "development") plane = CollisionPlane(Plane(Vec3(0, 0, 1), Point3(0, 0, 0))) cnode = CollisionNode('cnode') cnode.setIntoCollideMask(BitMask32.bit(1)) cnode.setFromCollideMask(BitMask32.bit(1)) cnode.addSolid(plane) self.planeNP = self.model.attachNewNode(cnode) self.planeNP.show() # Setup a traverser for the picking collisions self.picker = CollisionTraverser() # Setup mouse ray self.pq = CollisionHandlerQueue() # Create a collision Node pickerNode = CollisionNode('MouseRay') # set the nodes collision bitmask pickerNode.setFromCollideMask(BitMask32.bit(1)) # create a collision ray self.pickerRay = CollisionRay() # add the ray as a solid to the picker node pickerNode.addSolid(self.pickerRay) # create a nodepath with the camera to the picker node self.pickerNP = base.camera.attachNewNode(pickerNode) # add the nodepath to the base traverser self.picker.addCollider(self.pickerNP, self.pq) print "model loaded" #TODO: check how to load multiple levels and set players in specific levels! self.accept("mouse1", self.mouseClick)
def generate(self): data = CIGlobals.SuitBodyData[self.SUIT] type = data[0] team = data[1] self.team = team self.level = 12 self.suit = type Suit.generate(self, SuitBank.MrHollywood, 0, hideFirst=False) self.suit = type base.taskMgr.add(self.__viewDistance, self.viewDistanceTaskName) self.setPythonTag('guard', self) self.eyeLight = Spotlight('eyes') self.eyeLens = PerspectiveLens() self.eyeLens.setMinFov(90.0 / (4.0 / 3.0)) self.eyeLight.setLens(self.eyeLens) self.eyeNode = self.headModel.attachNewNode(self.eyeLight) self.eyeNode.setZ(-5) self.eyeNode.setY(-4.5) self.trav = CollisionTraverser(self.uniqueName('eyeTrav')) ray = CollisionRay(0, 0, 0, 0, 1, 0) rayNode = CollisionNode('ToonFPS.rayNode') rayNode.addSolid(ray) rayNode.setFromCollideMask(CGG.GuardBitmask | CIGlobals.WallBitmask) rayNode.setIntoCollideMask(BitMask32.allOff()) self.rayNP = base.camera.attachNewNode(rayNode) self.rayNP.setZ(3) self.queue = CollisionHandlerQueue() self.trav.addCollider(self.rayNP, self.queue) self.trav.addCollider(self.gameWorld.mg.avatarBody, self.queue) self.request('Guard')
class EntityCollision: def __init__(self, entity): self.entity = entity self.setup_collision() self.queue = CollisionHandlerQueue() self.traverser = CollisionTraverser('Collision Traverser') self.traverser.showCollisions(render) self.traverser.add_collider(self.target_nodepath, self.queue) base.taskMgr.add(self.collide, "Collision Task") def setup_collision(self): self.target = CollisionSphere(0, 0, 0, 1) self.target_node = CollisionNode('collision_entity') self.target_node.setFromCollideMask(ALLIES) # unused self.target_node.setIntoCollideMask(ENEMIES) self.target_nodepath = self.entity.model.attach_new_node(self.target_node) self.target_nodepath.node().addSolid(self.target) self.target_nodepath.show() def collide(self, task): self.traverser.traverse(render) for entry in self.queue.get_entries(): # print("Entity:") pos = entry.getSurfacePoint(self.entity.model) pos_x = pos[0] pos_z = pos[2] self.entity.spawn_particles(pos_x, pos_z) self.entity.life -= 1 return task.cont
def startSeeking(self): if not self.avatar: return self.cleanupShadow() self.buildShadow() # Let's increase the distance if the shadow is smaller than expected. scale = self.dropShadow.getScale() if scale < 1.0: self.maxDistance += 40 # Let's setup the drop shadow's initial position. x, y, z = self.avatar.getPos(render) self.dropShadow.reparentTo(render) self.dropShadow.setPos(x, y + 5, z + 2) # Let's setup the collisions for the mouse. self.cameraNode = CollisionNode('coll_camera') self.cameraNode.setFromCollideMask(CIGlobals.WallBitmask) self.cameraRay = CollisionRay() self.cameraNode.addSolid(self.cameraRay) self.cameraNP = camera.attachNewNode(self.cameraNode) base.cTrav.addCollider(self.cameraNP, CollisionHandlerQueue()) if not self.legacyMode: # Let's setup the collisions for the shadow. shadowNode = CollisionNode('coll_shadow') self.shadowRay = CollisionRay(0, 0, 6, 0, 0, -1) shadowNode.addSolid(self.shadowRay) shadowNode.setFromCollideMask(CIGlobals.FloorBitmask) self.shadowNP = self.dropShadow.attachNewNode(shadowNode) base.cTrav.addCollider(self.shadowNP, self.collHdlFl) # Finally, let's start moving the shadow with the mouse and accept left mouse clicks. base.taskMgr.add(self.__moveShadow, self.moveShadowTaskName) self.avatar.acceptOnce('mouse1', self.locationChosen)
def startSeeking(self): if not self.avatar: return self.cleanupShadow() self.buildShadow() scale = self.dropShadow.getScale() if scale < 1.0: self.maxDistance += 40 x, y, z = self.avatar.getPos(render) self.dropShadow.reparentTo(render) self.dropShadow.setPos(x, y + 5, z + 2) self.cameraNode = CollisionNode('coll_camera') self.cameraNode.setFromCollideMask(CIGlobals.WallBitmask) self.cameraRay = CollisionRay() self.cameraNode.addSolid(self.cameraRay) self.cameraNP = camera.attachNewNode(self.cameraNode) base.cTrav.addCollider(self.cameraNP, CollisionHandlerQueue()) if not self.legacyMode: shadowNode = CollisionNode('coll_shadow') self.shadowRay = CollisionRay(0, 0, 6, 0, 0, -1) shadowNode.addSolid(self.shadowRay) shadowNode.setFromCollideMask(CIGlobals.FloorBitmask) self.shadowNP = self.dropShadow.attachNewNode(shadowNode) base.cTrav.addCollider(self.shadowNP, self.collHdlFl) base.taskMgr.add(self.__moveShadow, self.moveShadowTaskName) self.avatar.acceptOnce('mouse1', self.locationChosen)
class ShipCollision: def __init__(self, game): self.game = game self.setup_collision() self.queue = CollisionHandlerQueue() self.traverser = CollisionTraverser('Collision Traverser') self.traverser.showCollisions(render) self.traverser.add_collider(self.target_nodepath, self.queue) base.taskMgr.add(self.collide, "Collision Task") def setup_collision(self): self.target = CollisionSphere(0, 0, 0, 0.5) self.target_node = CollisionNode('collision_ship') self.target_node.setFromCollideMask(ENEMIES) self.target_node.setIntoCollideMask(ALLIES) self.target_nodepath = self.game.ship.model.attach_new_node( self.target_node) self.target_nodepath.node().addSolid(self.target) self.target_nodepath.show() def collide(self, task): self.traverser.traverse(render) for entry in self.queue.get_entries(): print("Ship:") print(entry) return task.cont
def __init__(self,gmap,gaming_zone): DirectObject.__init__(self) #gaming zone (used for mouse movement), as a tools.Rectangle self.gaming_zone=gaming_zone #actual camera node self.p3dcam=base.camera #what the cam is oriented to self._target=base.render.attachNewNode('GaminCam.target') #range=[0,1] between min and max closeness to ground self.level=.7 # #keys_down acts as a pool containing keys (+mouse buttons) currently down self.keys_down=[] update_list.append(self.update) #setup for mouse picking picker_node=CollisionNode('gcam_to_mouse_ray')#general collision node picker_node.setFromCollideMask(GeomNode.getDefaultCollideMask()) self.picker_ray=CollisionRay()#solid ray to attach to coll node picker_node.addSolid(self.picker_ray) self.picker_np=self.p3dcam.attachNewNode(picker_node)#attach this node to gcam self.collision_queue=CollisionHandlerQueue()#stores collisions self.collision_traverser=CollisionTraverser('gcam_traverser')#actual computer self.collision_traverser.addCollider(self.picker_np,self.collision_queue) base.cTrav=self.collision_traverser self.gmap=gmap #stack of states (state=pos+zoom) self.states_stack=[] #enable the cam to move according to keyboard and mouse self.move_enabled=True
def __init__(self, widget, axis): NodePath.__init__(self, "transformWidgetAxis") self.reparentTo(widget) self.widget = widget vec = Vec3(0) vec[axis] = 1.0 self.direction = vec self.defaultColor = Vec4(vec[0], vec[1], vec[2], 1.0) self.rolloverColor = Vec4(vec + 0.5, 1.0) self.downColor = Vec4(vec - 0.5, 1.0) self.lookAt(vec) self.setTransparency(1) self.axisIdx = axis box = CollisionBox(*self.getClickBox()) cnode = CollisionNode("pickBox") cnode.addSolid(box) cnode.setIntoCollideMask(LEGlobals.ManipulatorMask) cnode.setFromCollideMask(BitMask32.allOff()) self.pickNp = self.attachNewNode(cnode) self.pickNp.setPythonTag("widgetAxis", self) self.state = Ready self.setState(Ready)
def __init__(self, pos, modelName, maxHealth, maxSpeed, colliderName, size): GameObject.__init__( self, pos, modelName, None, maxHealth, maxSpeed, colliderName, MASK_INTO_ENEMY | MASK_FROM_PLAYER | MASK_FROM_ENEMY, size) ArmedObject.__init__(self) self.colliderNP.node().setFromCollideMask(MASK_WALLS | MASK_FROM_ENEMY) Common.framework.pusher.addCollider(self.colliderNP, self.root) Common.framework.traverser.addCollider(self.colliderNP, Common.framework.pusher) colliderNode = CollisionNode("lock sphere") solid = CollisionSphere(0, 0, 0, size * 2) solid.setTangible(False) colliderNode.addSolid(solid) self.lockColliderNP = self.root.attachNewNode(colliderNode) self.lockColliderNP.setPythonTag(TAG_OWNER, self) colliderNode.setFromCollideMask(0) colliderNode.setIntoCollideMask(MASK_ENEMY_LOCK_SPHERE) self.setFlinchPool(10, 15) self.attackAnimsPerWeapon = {} self.flinchAnims = [] self.flinchTimer = 0 self.shields = [] self.shieldDuration = 0.5 self.movementNames = ["walk"] self.setupExplosion()
def __init__(self, nick): self.player = player.Player(nick=nick) self.controller = controller.ClientController(self.player) self.handgui = hand.HandGUI(self.player.hand) camera.setPos(0, -20, 0) self.accept("turn_time_changed", self.update_turn_time) self.turn_timer = TurnTimer() # Mouse detection: base.cTrav = CollisionTraverser() self.mouse_ray_handler = CollisionHandlerQueue() mouse_ray_node = CollisionNode('mouse_ray') mouse_ray_np = camera.attachNewNode(mouse_ray_node) mouse_ray_node.setFromCollideMask(GeomNode.getDefaultCollideMask()) mouse_ray_node.setIntoCollideMask(0) self.mouse_ray = CollisionRay() mouse_ray_node.addSolid(self.mouse_ray) base.cTrav.addCollider(mouse_ray_np, self.mouse_ray_handler) self.mouse_overed_entry = None self.accept("mouse_enter", self.enlarge_entry) self.accept("mouse_leave", self.shrink_entry) self.accept("p-up", self.change_card_picture) taskMgr.doMethodLater(0.1, self.check_mouse_over, "check_mouse_over")
class Wall(DirectObject): def __init__(self, x, y, angle): self.wall = base.loader.loadModel('models/wall') self.wall.setPos(x, y, 0) self.wall.setScale(10, 10, 10) self.wall.setH(angle) self.wall.reparentTo(render) # image taken from https://www.pinterest.com/pin/685602743251144929/?lp=true wallTexture = loader.loadTexture('models/walltest.jpg') self.wall.setTexGen(TextureStage.getDefault(), TexGenAttrib.MWorldCubeMap) self.wall.setTexProjector(TextureStage.getDefault(), render, self.wall) self.wall.setTexture(wallTexture) self.wallCollide = CollisionRay() self.wallNode = CollisionNode('wall') self.wallNode.addSolid(self.wallCollide) self.wallNode.setFromCollideMask(CollideMask.bit(0)) self.wallNode.setIntoCollideMask(CollideMask.allOff()) self.wallCollider = self.wall.attachNewNode(self.wallNode) # move the wall to create a new room def move(self, newPos): nx, ny, nAngle = newPos self.wall.setPos(nx, ny, 0) self.wall.setH(nAngle)
def __init__(self): self.accept('mouse1', self.onMouse1Down, []) # Left click self.accept('mouse1-up', self.onMouse1Up, []) self.accept('mouse3', self.onMouse3Down, []) # Right click self.showCollisions = False pickerNode = CollisionNode('mouseRay') pickerNP = camera.attachNewNode(pickerNode) pickerNode.setFromCollideMask(cardBuilder.cardCollisionMask) self.pickerRay = CollisionRay() pickerNode.addSolid(self.pickerRay) base.cTrav.addCollider(pickerNP, base.handler) if self.showCollisions: base.cTrav.showCollisions(render) base.disableMouse() self.activeCard = None self._targeting = False self._dragging = None # Counts down between clicks to detect double click self.doubleClickTimer = -1.0 self.doubleClickInterval = 1.0 self.line = attackLine.Line()
def _prepare_arrow(self, name, arrow_pos): """Prepare a manipulating arrow for this part. Args: name (str): Name of the part. arrow_pos (dict): Arrow position. Returns: panda3d.core.NodePath: Arrow node. """ arrow = loader.loadModel(address("train_part_arrow")) # noqa: F821 arrow.setPos(*arrow_pos) arrow.setH(self.angle) arrow.clearLight() # set manipulating arrow collisions # used to detect pointing the arrow by mouse col_node = CollisionNode(name) col_node.setFromCollideMask(NO_MASK) col_node.setIntoCollideMask(MOUSE_MASK) col_node.addSolid( CollisionPolygon( Point3(-0.06, -0.06, 0), Point3(-0.06, 0.06, 0), Point3(0.06, 0.06, 0), Point3(0.06, -0.06, 0), ) ) arrow.attachNewNode(col_node) return arrow
def generate(self): self.level = 12 self.maxHealth = 200 self.health = 200 Suit.generate(self, FactorySneakGuardSuit.SUIT, FactorySneakGuardSuit.VARIANT, hideFirst=False) self.setName(self.suitPlan.getName(), None) self.cleanupPropeller() base.taskMgr.add(self.__viewDistance, self.viewDistanceTaskName) self.setPythonTag('guard', self) self.eyeLight = Spotlight('eyes') self.eyeLens = PerspectiveLens() self.eyeLens.setMinFov(90.0 / (4. / 3.)) self.eyeLight.setLens(self.eyeLens) self.eyeNode = self.headModel.attachNewNode(self.eyeLight) self.eyeNode.setZ(-5) self.eyeNode.setY(-4.5) self.trav = CollisionTraverser(self.uniqueName('eyeTrav')) ray = CollisionRay(0, 0, 0, 0, 1, 0) rayNode = CollisionNode('ToonFPS.rayNode') rayNode.addSolid(ray) rayNode.setFromCollideMask(CGG.GuardBitmask | CIGlobals.WallBitmask) rayNode.setIntoCollideMask(BitMask32.allOff()) self.rayNP = base.camera.attachNewNode(rayNode) self.rayNP.setZ(3) self.queue = CollisionHandlerQueue() self.trav.addCollider(self.rayNP, self.queue) self.trav.addCollider(self.gameWorld.mg.avatarBody, self.queue) self.request('Guard')
def __init__(self): GameObject.__init__(self, Vec3(0, 0, 0), "Models/PandaChan/act_p3d_chan", { "stand" : "Models/PandaChan/a_p3d_chan_idle", "walk" : "Models/PandaChan/a_p3d_chan_run" }, 5, 10, "player") self.actor.getChild(0).setH(180) mask = BitMask32() mask.setBit(1) self.collider.node().setIntoCollideMask(mask) mask = BitMask32() mask.setBit(1) self.collider.node().setFromCollideMask(mask) base.pusher.addCollider(self.collider, self.actor) base.cTrav.addCollider(self.collider, base.pusher) self.lastMousePos = Vec2(0, 0) self.groundPlane = Plane(Vec3(0, 0, 1), Vec3(0, 0, 0)) self.ray = CollisionRay(0, 0, 0, 0, 1, 0) rayNode = CollisionNode("playerRay") rayNode.addSolid(self.ray) mask = BitMask32() mask.setBit(2) rayNode.setFromCollideMask(mask) mask = BitMask32() rayNode.setIntoCollideMask(mask) self.rayNodePath = render.attachNewNode(rayNode) self.rayQueue = CollisionHandlerQueue() base.cTrav.addCollider(self.rayNodePath, self.rayQueue) self.beamModel = loader.loadModel("Models/Misc/bambooLaser") self.beamModel.reparentTo(self.actor) self.beamModel.setZ(1.5) self.beamModel.setLightOff() self.beamModel.hide() self.damagePerSecond = -5.0 self.yVector = Vec2(0, 1) self.actor.loop("stand")
def initCollisionRay(self, originZ, dirZ): ray = CollisionRay(0,0,originZ,0,0,dirZ) collNode = CollisionNode('playerRay') collNode.addSolid(ray) collNode.setFromCollideMask(BitMask32.bit(1)) collNode.setIntoCollideMask(BitMask32.allOff()) collRayNP = self.playerNode.attachNewNode(collNode) collRayNP.show() return collRayNP
class EntityCollision: def __init__(self, entity): self.target = CollisionSphere(0, 0, 0, 1) self.target_node = CollisionNode('collision_entity') self.target_node.setFromCollideMask(0) # unused self.target_node.setIntoCollideMask(ENEMIES) self.target_nodepath = entity.model.attach_new_node(self.target_node) self.target_nodepath.node().addSolid(self.target) self.target_nodepath.show()
def attachCollisionRay(self, name, ox, oy, oz, dx, dy, dz, fromCollide, intoCollide): from panda3d.core import CollisionRay from panda3d.core import CollisionNode coll = CollisionRay(ox, oy, oz, dx, dy, dz) collNode = CollisionNode(name) collNode.addSolid(coll) collNode.setFromCollideMask(fromCollide) collNode.setIntoCollideMask(intoCollide) collNodePath = self.attachNewNode(collNode) return collNodePath
def attachCollisionSegment(self, name, ax, ay, az, bx, by, bz, fromCollide, intoCollide): from panda3d.core import CollisionSegment from panda3d.core import CollisionNode coll = CollisionSegment(ax, ay, az, bx, by, bz) collNode = CollisionNode(name) collNode.addSolid(coll) collNode.setFromCollideMask(fromCollide) collNode.setIntoCollideMask(intoCollide) collNodePath = self.attachNewNode(collNode) return collNodePath
def attachCollisionSphere(self, name, cx, cy, cz, r, fromCollide, intoCollide): from panda3d.core import CollisionSphere from panda3d.core import CollisionNode coll = CollisionSphere(cx, cy, cz, r) collNode = CollisionNode(name) collNode.addSolid(coll) collNode.setFromCollideMask(fromCollide) collNode.setIntoCollideMask(intoCollide) collNodePath = self.attachNewNode(collNode) return collNodePath
def setupPicker(self): self.pickerTrav = CollisionTraverser('LT.pickerTrav') self.pickerRay = CollisionRay() rayNode = CollisionNode('LT.pickerNode') rayNode.addSolid(self.pickerRay) rayNode.setCollideMask(BitMask32(0)) rayNode.setFromCollideMask(CIGlobals.WallBitmask) self.pickerRayNode = base.camera.attachNewNode(rayNode) self.pickerHandler = CollisionHandlerQueue() self.pickerTrav.addCollider(self.pickerRayNode, self.pickerHandler)
def attachCollisionSphere(self, name, cx, cy, cz, r, fromCollide, intoCollide): from panda3d.core import CollisionSphere from panda3d.core import CollisionNode coll = CollisionSphere(cx, cy, cz, r) collNode = CollisionNode(name) collNode.addSolid(coll) collNode.setFromCollideMask(fromCollide) collNode.setIntoCollideMask(intoCollide) collNodePath = self.attachNewNode(collNode) return collNodePath
def attachCollisionSegment(self, name, ax, ay, az, bx, by, bz, fromCollide, intoCollide): from panda3d.core import CollisionSegment from panda3d.core import CollisionNode coll = CollisionSegment(ax, ay, az, bx, by, bz) collNode = CollisionNode(name) collNode.addSolid(coll) collNode.setFromCollideMask(fromCollide) collNode.setIntoCollideMask(intoCollide) collNodePath = self.attachNewNode(collNode) return collNodePath
def attachCollisionRay(self, name, ox, oy, oz, dx, dy, dz, fromCollide, intoCollide): from panda3d.core import CollisionRay from panda3d.core import CollisionNode coll = CollisionRay(ox, oy, oz, dx, dy, dz) collNode = CollisionNode(name) collNode.addSolid(coll) collNode.setFromCollideMask(fromCollide) collNode.setIntoCollideMask(intoCollide) collNodePath = self.attachNewNode(collNode) return collNodePath
def __init__(self, pos, modelName, modelAnims, maxHealth, maxSpeed, colliderName, weaponIntoMask, size): self.root = Common.framework.showBase.render.attachNewNode( PandaNode("obj")) self.colliderName = colliderName self.modelName = modelName if modelName is None: self.actor = NodePath(PandaNode("actor")) elif modelAnims is None: self.actor = Common.framework.showBase.loader.loadModel(modelName) else: self.actor = Actor(modelName, modelAnims) self.actor.reparentTo(self.root) if pos is not None: self.root.setPos(pos) self.maxHealth = maxHealth self.health = maxHealth self.healthRechargeRate = 2.0 self.healthRechargeSuppressionTimer = 0 self.healthRechargeSuppressionDuration = 0.5 self.maxSpeed = maxSpeed self.terminalVelocity = 50 self.flinchCounter = 0 self.velocity = Vec3(0, 0, 0) self.acceleration = 300.0 self.inControl = True self.outOfControlTimer = 0 self.walking = False self.size = size if colliderName is not None: colliderNode = CollisionNode(colliderName) colliderNode.addSolid(CollisionSphere(0, 0, 0, size)) self.colliderNP = self.root.attachNewNode(colliderNode) self.colliderNP.setPythonTag(TAG_OWNER, self) colliderNode.setFromCollideMask(0) colliderNode.setIntoCollideMask(weaponIntoMask) #self.colliderNP.show() else: self.colliderNP = self.root.attachNewNode(PandaNode("stand-in")) self.deathSound = None
def setup_collision_ray(self, offset, bitmask): # Hitter. Do note that not every combination of object works, # there is a table for that in the manual. hitter = CollisionRay(0, 0, 0, 0, 1, 0) hitter_node = CollisionNode('collision_hitter') hitter_node.setFromCollideMask(bitmask) hitter_nodepath = base.render.attach_new_node(hitter_node) hitter_nodepath.node().addSolid(hitter) hitter_nodepath.set_pos(offset, -2, 0) hitter_nodepath.show() return hitter_nodepath
def setup_collision_ray(self, offset, bitmask): # Hitter. Do note that not every combination of object works, # there is a table for that in the manual. hitter = CollisionRay(0, 0, 0, 0, 1, 0) hitter_node = CollisionNode('collision_hitter') hitter_node.setFromCollideMask(bitmask) hitter_nodepath = base.render.attach_new_node(hitter_node) hitter_nodepath.node().addSolid(hitter) hitter_nodepath.set_pos(offset, -2, 0) hitter_nodepath.show() return hitter_nodepath
def getFlyBallBubble(self): if self.__flyBallBubble == None: bubble = CollisionSphere(0, 0, 0, GolfGlobals.GOLF_BALL_RADIUS) node = CollisionNode('flyBallBubble') node.addSolid(bubble) node.setFromCollideMask(ToontownGlobals.PieBitmask | ToontownGlobals.CameraBitmask | ToontownGlobals.FloorBitmask) node.setIntoCollideMask(BitMask32.allOff()) self.__flyBallBubble = NodePath(node) self.flyBallHandler = CollisionHandlerEvent() self.flyBallHandler.addInPattern('flyBallHit-%d' % self.index) return self.__flyBallBubble
def __init__(self, model = "cube_nocol", texture = "lava", pos = (0,0,0), scale = (1,1,1), cubetype = "A"): super(LavaCube, self).__init__(model, texture, pos, scale) cn = CollisionNode('lava') cn.setFromCollideMask(COLLISIONMASKS['lava']) cn.setIntoCollideMask(BitMask32.allOff()) np = self.node.attachNewNode(cn) cn.addSolid(CollisionSphere(0,0,0,1.1)) h = CollisionHandlerEvent() h.addInPattern('%fn-into-%in') h.addOutPattern('%fn-outof-%in') base.cTrav.addCollider(np, h)
def createThrowGag(self, gag): throwGag = CogdoMazePlayer.createThrowGag(self, gag) collSphere = CollisionSphere(0, 0, 0, 0.5) collSphere.setTangible(0) name = Globals.GagCollisionName collNode = CollisionNode(name) collNode.setFromCollideMask(ToontownGlobals.PieBitmask) collNode.addSolid(collSphere) colNp = throwGag.attachNewNode(collNode) base.cTrav.addCollider(colNp, self.gagHandler) return throwGag
def getFlyBallBubble(self): if self.__flyBallBubble == None: bubble = CollisionSphere(0, 0, 0, GolfGlobals.GOLF_BALL_RADIUS) node = CollisionNode('flyBallBubble') node.addSolid(bubble) node.setFromCollideMask(ToontownGlobals.PieBitmask | ToontownGlobals.CameraBitmask | ToontownGlobals.FloorBitmask) node.setIntoCollideMask(BitMask32.allOff()) self.__flyBallBubble = NodePath(node) self.flyBallHandler = CollisionHandlerEvent() self.flyBallHandler.addInPattern('flyBallHit-%d' % self.index) return self.__flyBallBubble
def __init__(self, pos, modelName, modelAnims, maxHealth, maxSpeed, colliderName, height, weaponIntoMask): self.root = render.attachNewNode(PandaNode("obj")) self.colliderName = colliderName self.modelName = modelName if modelName is None: self.actor = NodePath(PandaNode("actor")) elif modelAnims is None: self.actor = loader.loadModel(modelName) else: self.actor = Actor(modelName, modelAnims) self.actor.reparentTo(self.root) if pos is not None: self.root.setPos(pos) self.height = height self.maxHealth = maxHealth self.health = maxHealth self.maxSpeed = maxSpeed self.terminalVelocity = 15 self.flinchCounter = 0 self.velocity = Vec3(0, 0, 0) self.acceleration = 300.0 self.inControl = True self.walking = False self.noZVelocity = True if colliderName is not None: colliderNode = CollisionNode(colliderName) colliderNode.addSolid(CollisionCapsule(0, 0, 0, 0, 0, height, 0.3)) self.weaponCollider = self.root.attachNewNode(colliderNode) self.weaponCollider.setPythonTag(TAG_OWNER, self) colliderNode.setFromCollideMask(0) colliderNode.setIntoCollideMask(weaponIntoMask) #self.weaponCollider.show() else: self.weaponCollider = self.root.attachNewNode( PandaNode("stand-in")) self.deathSound = None self.currentWeapon = None
def createMouseCollisions(self): # Fire the portals firingNode = CollisionNode('mouseRay') firingNP = self.base.camera.attachNewNode(firingNode) firingNode.setFromCollideMask(COLLISIONMASKS['geometry']) firingNode.setIntoCollideMask(BitMask32.allOff()) firingRay = CollisionRay() firingRay.setOrigin(0,0,0) firingRay.setDirection(0,1,0) firingNode.addSolid(firingRay) self.firingHandler = CollisionHandlerQueue() self.base.cTrav.addCollider(firingNP, self.firingHandler)
def setupHeadSphere(self, avatarNodePath): collSphere = CollisionSphere(0, 0, 0, 1) collSphere.setTangible(1) collNode = CollisionNode('Flyer.cHeadCollSphere') collNode.setFromCollideMask(ToontownGlobals.CeilingBitmask) collNode.setIntoCollideMask(BitMask32.allOff()) collNode.addSolid(collSphere) self.cHeadSphereNodePath = avatarNodePath.attachNewNode(collNode) self.cHeadSphereNodePath.setZ(base.localAvatar.getHeight() + 1.0) self.headCollisionEvent = CollisionHandlerEvent() self.headCollisionEvent.addInPattern('%fn-enter-%in') self.headCollisionEvent.addOutPattern('%fn-exit-%in') base.cTrav.addCollider(self.cHeadSphereNodePath, self.headCollisionEvent)
def setupEventSphere(self, bitmask, avatarRadius): self.avatarRadius = avatarRadius cSphere = CollisionSphere(0.0, 0.0, self.avatarRadius + 0.75, self.avatarRadius * 1.04) cSphere.setTangible(0) cSphereNode = CollisionNode('Flyer.cEventSphereNode') cSphereNode.addSolid(cSphere) cSphereNodePath = self.avatarNodePath.attachNewNode(cSphereNode) cSphereNode.setFromCollideMask(bitmask) cSphereNode.setIntoCollideMask(BitMask32.allOff()) self.event = CollisionHandlerEvent() self.event.addInPattern('enter%in') self.event.addOutPattern('exit%in') self.cEventSphereNodePath = cSphereNodePath
def setupFloorEventSphere(self, avatarNodePath, bitmask, avatarRadius): cSphere = CollisionSphere(0.0, 0.0, 0.0, 0.75) cSphereNode = CollisionNode('Flyer.cFloorEventSphere') cSphereNode.addSolid(cSphere) cSphereNodePath = avatarNodePath.attachNewNode(cSphereNode) cSphereNode.setFromCollideMask(bitmask) cSphereNode.setIntoCollideMask(BitMask32.allOff()) self.floorCollisionEvent = CollisionHandlerEvent() self.floorCollisionEvent.addInPattern('%fn-enter-%in') self.floorCollisionEvent.addAgainPattern('%fn-again-%in') self.floorCollisionEvent.addOutPattern('%fn-exit-%in') base.cTrav.addCollider(cSphereNodePath, self.floorCollisionEvent) self.cFloorEventSphereNodePath = cSphereNodePath
def __init__(self, _main): self.main = _main self.name = "" self.points = 0 self.health = 100.0 self.runSpeed = 1.8 self.keyMap = { "left":False, "right":False, "up":False, "down":False } base.camera.setPos(0,0,0) self.model = loader.loadModel("Player") self.model.find('**/+SequenceNode').node().stop() self.model.find('**/+SequenceNode').node().pose(0) base.camera.setP(-90) self.playerHud = Hud() self.playerHud.hide() self.model.hide() # Weapons: size=2, 0=main, 1=offhand self.mountSlot = [] self.activeWeapon = None self.isAutoActive = False self.trigger = False self.lastShot = 0.0 self.fireRate = 0.0 self.playerTraverser = CollisionTraverser() self.playerEH = CollisionHandlerEvent() ## INTO PATTERNS self.playerEH.addInPattern('intoPlayer-%in') #self.playerEH.addInPattern('colIn-%fn') self.playerEH.addInPattern('intoHeal-%in') self.playerEH.addInPattern('intoWeapon-%in') ## OUT PATTERNS self.playerEH.addOutPattern('outOfPlayer-%in') playerCNode = CollisionNode('playerSphere') playerCNode.setFromCollideMask(BitMask32.bit(1)) playerCNode.setIntoCollideMask(BitMask32.bit(1)) self.playerSphere = CollisionSphere(0, 0, 0, 0.6) playerCNode.addSolid(self.playerSphere) self.playerNP = self.model.attachNewNode(playerCNode) self.playerTraverser.addCollider(self.playerNP, self.playerEH) #self.playerNP.show() self.playerPusher = CollisionHandlerPusher() self.playerPusher.addCollider(self.playerNP, self.model) self.playerPushTraverser = CollisionTraverser() self.playerPushTraverser.addCollider(self.playerNP, self.playerPusher)
def setupWallSphere(self, bitmask, avatarRadius): self.avatarRadius = avatarRadius cSphere = CollisionSphere(0.0, 0.0, self.avatarRadius + 0.75, self.avatarRadius) cSphereNode = CollisionNode('Flyer.cWallSphereNode') cSphereNode.addSolid(cSphere) cSphereNodePath = self.avatarNodePath.attachNewNode(cSphereNode) cSphereNode.setFromCollideMask(bitmask) cSphereNode.setIntoCollideMask(BitMask32.allOff()) if config.GetBool('want-fluid-pusher', 0): self.pusher = CollisionHandlerFluidPusher() else: self.pusher = CollisionHandlerPusher() self.pusher.addCollider(cSphereNodePath, self.avatarNodePath) self.cWallSphereNodePath = cSphereNodePath
def __init__(self, model = "models/sphere", texture = "exit", pos = (0,0,0), scale = (1,1,1), cubetype = "A"): super(LevelExit, self).__init__(model, texture, pos, scale) #self.node.setTransparency(TransparencyAttrib.MAlpha) self.node.setTag('noportals', '1') self.node.setTag('isexit', '1') cn = CollisionNode('levelExit') cn.setFromCollideMask(COLLISIONMASKS['exit']) cn.setIntoCollideMask(BitMask32.allOff()) np = self.node.attachNewNode(cn) cn.addSolid(CollisionSphere(0,0,0,1.1)) h = CollisionHandlerEvent() h.addInPattern('%fn-into-%in') h.addOutPattern('%fn-outof-%in') base.cTrav.addCollider(np, h)
class CogdoMazeExit(CogdoGameExit, DirectObject): EnterEventName = 'CogdoMazeDoor_Enter' def __init__(self): CogdoGameExit.__init__(self) self.revealed = False self._players = [] self._initCollisions() def _initCollisions(self): collSphere = CollisionSphere(0, 0, 0, 3.0) collSphere.setTangible(0) self.collNode = CollisionNode(self.getName()) self.collNode.addSolid(collSphere) self.collNP = self.attachNewNode(self.collNode) def destroy(self): self.ignoreAll() CogdoGameExit.destroy(self) def enable(self): self.collNode.setFromCollideMask(ToontownGlobals.WallBitmask) self.accept('enter' + self.getName(), self._handleEnterCollision) def disable(self): self.ignore('enter' + self.getName()) self.collNode.setFromCollideMask(BitMask32(0)) def _handleEnterCollision(self, collEntry): messenger.send(CogdoMazeExit.EnterEventName, [self]) def onstage(self): self.unstash() self.enable() def offstage(self): self.stash() self.disable() def playerEntersDoor(self, player): if player not in self._players: self._players.append(player) self.toonEnters(player.toon) def getPlayerCount(self): return len(self._players) def hasPlayer(self, player): return player in self._players
class PlayerObject(): def __init__(self, render, player): self.username = player.getUsername() self.isMoving = False self.render = render self.keyMap = {"left":0, "right":0, "forward":0, "cam-left":0, "cam-right":0} self.actor = Actor("models/ralph", {"run":"models/ralph-run", "walk":"models/ralph-walk"}) self.actor.reparentTo(render) self.actor.setScale(0.2) self.actor.setPos(player.getX(), player.getY(), player.getZ()) self.actor.setH(player.getH()) self.cTrav = CollisionTraverser() self.GroundRay = CollisionRay() self.GroundRay.setOrigin(0,0,1000) self.GroundRay.setDirection(0,0,-1) self.GroundCol = CollisionNode('actorRay') self.GroundCol.addSolid(self.GroundRay) self.GroundCol.setFromCollideMask(BitMask32.bit(0)) self.GroundCol.setIntoCollideMask(BitMask32.allOff()) self.GroundColNp = self.actor.attachNewNode(self.GroundCol) self.GroundHandler = CollisionHandlerQueue() self.cTrav.addCollider(self.GroundColNp, self.GroundHandler) # def getUsername(self): # return self.username def getActor(self): return self.actor def setPos(self, x, y, z): self.actor.setPos(x, y, z) def setH(self, h): self.actor.setH(h) def move(self, isActorMove): if isActorMove == "True": if self.isMoving is False: self.actor.loop("run") self.isMoving = True else: if self.isMoving: self.actor.stop() self.actor.pose("walk",5) self.isMoving = False
def setupRay(self, bitmask, floorOffset, reach): cRay = CollisionRay(0.0, 0.0, 3.0, 0.0, 0.0, -1.0) cRayNode = CollisionNode('Flyer.cRayNode') cRayNode.addSolid(cRay) self.cRayNodePath = self.avatarNodePath.attachNewNode(cRayNode) cRayNode.setFromCollideMask(bitmask) cRayNode.setIntoCollideMask(BitMask32.allOff()) self.lifter = CollisionHandlerGravity() self.lifter.setLegacyMode(self._legacyLifter) self.lifter.setGravity(self.getGravity(0)) self.lifter.addInPattern('%fn-enter-%in') self.lifter.addAgainPattern('%fn-again-%in') self.lifter.addOutPattern('%fn-exit-%in') self.lifter.setOffset(floorOffset) self.lifter.setReach(reach) self.lifter.addCollider(self.cRayNodePath, self.avatarNodePath)
def setupRay(self): self.shootTraverser = CollisionTraverser() self.shootingQH = CollisionHandlerQueue() #self.shootingEH = CollisionHandlerEvent() #self.shootingEH.addInPattern('into-%in') # Create a collision Node shootNode = CollisionNode('WeaponRay') # set the nodes collision bitmask shootNode.setFromCollideMask(BitMask32.bit(1)) # create a collision segment (ray like) self.shootRay = CollisionSegment() shootNode.addSolid(self.shootRay) #self.pickerNP = self.main.player.model.attachNewNode(pickerNode) self.shootNP = render.attachNewNode(shootNode) #self.shootTraverser.addCollider(self.shootNP, self.shootingEH) self.shootTraverser.addCollider(self.shootNP, self.shootingQH)
def _initCollisions(self): self._camCollRay = CollisionRay() camCollNode = CollisionNode('CameraToonRay') camCollNode.addSolid(self._camCollRay) camCollNode.setFromCollideMask(OTPGlobals.WallBitmask | OTPGlobals.CameraBitmask | ToontownGlobals.FloorEventBitmask | ToontownGlobals.CeilingBitmask) camCollNode.setIntoCollideMask(0) self._camCollNP = self._camera.attachNewNode(camCollNode) self._camCollNP.show() self._collOffset = Vec3(0, 0, 0.5) self._collHandler = CollisionHandlerQueue() self._collTrav = CollisionTraverser() self._collTrav.addCollider(self._camCollNP, self._collHandler) self._betweenCamAndToon = {} self._transNP = NodePath('trans') self._transNP.reparentTo(render) self._transNP.setTransparency(True) self._transNP.setAlphaScale(Globals.Camera.AlphaBetweenToon) self._transNP.setBin('fixed', 10000)
class MouseCollision: def __init__(self, game): self.game = game self.c_trav = CollisionTraverser() self.mouse_groundHandler = CollisionHandlerQueue() self.mouse_ground_ray = CollisionRay() self.mouse_ground_col = CollisionNode('mouseRay') self.mouse_ground_ray.setOrigin(0, 0, 0) self.mouse_ground_ray.setDirection(0, -1, 0) self.mouse_ground_col.addSolid(self.mouse_ground_ray) self.mouse_ground_col.setFromCollideMask(CollideMask.bit(0)) self.mouse_ground_col.setIntoCollideMask(CollideMask.allOff()) self.mouse_ground_col_np = self.game.camera.attachNewNode(self.mouse_ground_col) self.c_trav.addCollider(self.mouse_ground_col_np, self.mouse_groundHandler) self.game.taskMgr.add(self.update, 'updateMouse') def update(self, task): if self.game.mouseWatcherNode.hasMouse(): if self.game.ship.model: mouse_pos = self.game.mouseWatcherNode.getMouse() self.mouse_ground_ray.setFromLens(self.game.camNode, mouse_pos.getX(), mouse_pos.getY()) near_point = render.getRelativePoint(self.game.camera, self.mouse_ground_ray.getOrigin()) near_vec = render.getRelativeVector(self.game.camera, self.mouse_ground_ray.getDirection()) self.game.ship.shipPoint.setPos(self.PointAtY(self.game.ship.model.getY(), near_point, near_vec)) return task.cont def PointAtY(self, y, point, vec): return point + vec * ((y - point.getY()) / vec.getY())
def createPortalCollisions(self): # Enter the portals cn = CollisionNode('bluePortal') cn.setFromCollideMask(COLLISIONMASKS['portals']) cn.setIntoCollideMask(BitMask32.allOff()) np = self.bluePortal.attachNewNode(cn) cn.addSolid(CollisionSphere(0,0,0,2)) h = CollisionHandlerEvent() h.addInPattern('%fn-into-%in') h.addOutPattern('%fn-outof-%in') self.base.cTrav.addCollider(np, h) cn = CollisionNode('orangePortal') cn.setFromCollideMask(COLLISIONMASKS['portals']) cn.setIntoCollideMask(BitMask32.allOff()) np = self.orangePortal.attachNewNode(cn) cn.addSolid(CollisionSphere(0,0,0,2)) h = CollisionHandlerEvent() h.addInPattern('%fn-into-%in') h.addOutPattern('%fn-outof-%in') self.base.cTrav.addCollider(np, h)