def __init__(self): camera_hpr = base.camera.getHpr() self.name = "missle" self.core = loader.loadModel("./Models/sphere.egg") self.ttl = 2 # Time to live in seconds self.core.setPos(base.camera, (0, 0, 0)) self.core.setHpr(camera_hpr) self.core.setScale(600, 600, 600) self.glow = loader.loadModel("./Models/sphere.egg") self.core.setTransparency(TransparencyAttrib.MAlpha) self.glow.setScale(2, 2, 2) self.glow.reparentTo(self.core) self.core.setColor(colors.get("white")) self.glow.setColor(colors.get("white-transparent")) self.glow.setPos(0, 0, 0) #relative to parent self.core.setLightOff( ) # remove all other lights from missle so it is a bright white missle_total.append(self) #Create the light so the missle glows plight = PointLight('plight') plight.setColor(colors.get("white")) plight.setAttenuation(LVector3(0, 0.00008, 0)) plight.setMaxDistance(1000) self.plnp = self.core.attachNewNode(plight) #point light node point render.setLight(self.plnp) # Create hitsphere cNode = CollisionNode(self.name) cNode.addSolid(CollisionSphere(0, 0, 0, 1)) self.c_np = self.core.attachNewNode(cNode) # Create and run the missle animation end_location = Location(self.core).obj.getPos() start_location = base.camera.getPos() dt = globalClock.getDt() start_location[0] += spaceship_speed_x * dt start_location[1] += spaceship_speed_y * dt start_location[2] += spaceship_speed_z * dt self.asteroid_lerp = LerpPosInterval( self.core, # Object being manipulated. The missle in this case. 500, # How long it will take the missle to go from point a to b in seconds end_location, # future location at end of lerp start_location, # The start position of the missle fluid=1) # Allow for colisions during the lerp self.asteroid_lerp.start() del end_location self.core.reparentTo(render)
def __init__(self, position, value): #Invisiible point so that both spheres have the same parent self.name = "pointball" self.center = NodePath(PandaNode("Pointball center")) self.ttl = 15 #Time to live in seconds self.ttl_max = 15 self.max_size = 9000 self.attraction_distance = 900000 self.center.setPos(position) self.center.setTag("value", str(value)) # Create 1st sphere self.one = loader.loadModel("./Models/sphere.egg") self.one.setColor(colors.get("blue-transparent")) self.one.setScale(self.max_size, self.max_size, self.max_size) self.one.setLightOff() self.one.reparentTo(self.center) #Create 2nd sphere self.two = loader.loadModel("./Models/sphere.egg") self.two.setColor(colors.get("lightblue-transparent")) self.two.setScale(self.max_size, self.max_size, self.max_size) self.two.setLightOff() self.two.reparentTo(self.center) #Create the light so the missle glows plight = PointLight('plight') plight.setColor(colors.get("blue")) plight.setAttenuation(LVector3(0, 0.000008, 0)) plight.setMaxDistance(100) self.plnp = self.center.attachNewNode(plight) #point light node point render.setLight(self.plnp) # Create Collision hitsphere cNode = CollisionNode(self.name) cNode.addSolid(CollisionSphere(0, 0, 0, self.max_size * 20)) self.c_np = self.center.attach_new_node(cNode) #Render to scene self.center.reparentTo(render)