Esempio n. 1
0
 def ship(self):
     an = ActorNode()
     an.getPhysicsObject().setMass(100)
     self.fighter = self.render.attachNewNode(an)
     self.physicsMgr.attachPhysicalNode(an)
     self.anpo = an.getPhysicsObject()
     fn = ForceNode("force-node-fighter")
     self.fighter.attachNewNode(fn)
     self.pft = LinearVectorForce(Vec3(0, +1, 0) * 500)  # forward thrust
     self.prt = LinearVectorForce(Vec3(0, -1, 0) * 500)  # reverse thrust
     self.pft.setMassDependent(1)
     self.prt.setMassDependent(1)
     self.pft.setActive(False)
     self.prt.setActive(False)
     fn.addForce(self.pft)
     fn.addForce(self.prt)
     an.getPhysical(0).addLinearForce(self.pft)
     an.getPhysical(0).addLinearForce(self.prt)
     self.camera.reparentTo(self.fighter)
     from_obj = self.fighter.attachNewNode(CollisionNode('fighter'))
     from_obj.node().setFromCollideMask(BitMask32(0x1))
     from_obj.setCollideMask(BitMask32(0x1))
     from_obj.node().addSolid(CollisionSphere(0, 0, 0, 1))
     # from_obj.show()
     self.pusher.addCollider(from_obj, self.fighter)
     self.cTrav.addCollider(from_obj, self.pusher)
Esempio n. 2
0
class Zombie:
    def __init__(self,zombie,app,i=0):
        self.app = app
        self.zombie = zombie
        self.zombie.setPythonTag('health',10+30*self.app.level)
        self.zombie.setTag('zombie','1')
        self.zombie.setPythonTag('dead',False)
        self.zombie.setScale(0.5,0.5,0.5)
        self.zombie.setX(-40)
        self.zombie.setY(-i*10)
        self.zombie.setZ(20)
        self.zombie.loop("walk")
        self.zombie.reparentTo(self.app.render)
        #Collision detection
        self.create_collider()
        
    def addPhy(self):
        self.zombieAN = ActorNode("ZombieActor")
        self.zombieActorPhysicsP = self.app.phy.attachNewNode(self.zombieAN)
        
        self.app.physicsMgr.attachPhysicalNode(self.zombieAN)
        self.zombie.reparentTo(self.zombieActorPhysicsP)
        self.zombieAN.getPhysicsObject().setMass(150)
    def create_collider(self):
        self.addPhy()
        
        #walker this has been commented because two collision detectors per panda were decreasing the fps
        #self.collision_sphere = CollisionSphere(0,0,2,2)
        #self.cnodePath = self.zombie.attachNewNode(CollisionNode('zombieWalker'))
        #self.cnodePath.node().addSolid(self.collision_sphere)
        #self.cnodePath.show()
        
        #body
        #self.zombie_body = CollisionSphere(0,0,10,4)
        self.zombie_body = CollisionSphere(0,0,7,7)
        self.zombie_body_NP = self.zombie.attachNewNode(CollisionNode('zombieBody'))
        self.zombie_body_NP.node().addSolid(self.zombie_body)
        #self.zombie_body_NP.show()
        
        #self.app.pusher.addCollider(self.cnodePath,self.zombieActorPhysicsP)
        self.app.pusher.addCollider(self.zombie_body_NP,self.zombieActorPhysicsP)
        #self.app.cTrav.addCollider(self.cnodePath,self.app.pusher)
        self.app.cTrav.addCollider(self.zombie_body_NP,self.app.pusher)
        
    
    def meelee(self):
        point = self.app.pandaActor.getRelativePoint(self.zombie,Point3(0,0,0))
        dist = point.getX()**2 + point.getY()**2 + point.getZ()**2
        if dist < 300:
            self.app.kicked.play()
            self.zombieAN.getPhysicsObject().setVelocity(self.app.render.getRelativeVector(self.app.pandaActor,Vec3(0,-30,0)))
            self.zombie.setPythonTag('health',self.zombie.getPythonTag('health')-10)
            if self.zombie.getPythonTag('health') <= 0 and self.zombie.getPythonTag('dead') <> True:
                self.zombie.setPythonTag('dead',True)
                self.app.panda_kill_count += 1
                self.app.zombie_die.play()
Esempio n. 3
0
 def __init__(self, base, name, speed, scale, color, mask, relA, xyz, relB, lookat, life):
     an = ActorNode()
     self.anp = base.render.attachNewNode(an)
     base.physicsMgr.attachPhysicalNode(an)
     self.anpo = an.getPhysicsObject()
     fn = ForceNode("force-missile")
     self.anp.attachNewNode(fn)
     bft = LinearVectorForce(Vec3(0, 1, 0)*speed)
     fn.addForce(bft)
     an.getPhysical(0).addLinearForce(bft)
     missile = base.loader.loadModel("./mdl/missile.egg")
     missile.setColor(color)
     missile.setScale(scale)
     missile.reparentTo(self.anp)
     missile.setTag(name, '1')
     missile_from_obj = missile.attachNewNode(CollisionNode(name))
     missile_from_obj.node().addSolid(CollisionSphere(0, 0, 0, 1))
     missile_from_obj.node().setFromCollideMask(mask)
     missile_from_obj.setCollideMask(mask)
     base.pusher.addCollider(missile_from_obj, self.anp)
     base.cTrav.addCollider(missile_from_obj, base.pusher)
     self.anp.setPos(relA, xyz)
     self.anp.lookAt(relB, lookat)
     # light the missile
     mlight = DirectionalLight('mlight')
     mlight.setColor(VBase4(1., 1., 1., 1))
     mlnp = base.render.attachNewNode(mlight)
     mlnp.setHpr(self.anp.getHpr())
     self.anp.setLightOff()
     self.anp.setLight(mlnp)
     # remove the missile
     base.taskMgr.doMethodLater(life, self.remove_missile, 'task-remove-missile', extraArgs=[self.anp], appendTask=True)
Esempio n. 4
0
    def createBarrel(self):

        barrelNode = NodePath("PhysicalBarrel")
        barrelNode.reparentTo(self.scene)
        barrelNode.setPos(self.scene, 0,0,0)
        physicsBarrel = ActorNode("physics_barrel")
        physicsBarrel.getPhysicsObject().setMass(0.01) #in what units? (69 kindda 3 lbs)
        barrel = barrelNode.attachNewNode(physicsBarrel)
        base.physicsMgr.attachPhysicalNode(physicsBarrel)

        barrel.setPos(barrelNode, 0,0,0)

        visual_barrel = self.scene.attachNewNode("BarrelCopy")
        originalBarrel = self.scene.find("barrel")
        originalBarrel.instanceTo(visual_barrel)
        visual_barrel.reparentTo(barrel)
        visual_barrel.setPos(self.scene, -6.5,0,-24.5 )

        dataNode = barrelNode.attachNewNode(AuxData("Sequence",None))
        seq = self.createBarrelGraphicSequence(visual_barrel, physicsBarrel, dataNode)
        dataNode.node().getPythonTag("subclass").sequence = seq

        #sphere =  CollisionSphere(6.6,0,4.78, 0.5)
        sphere =  CollisionSphere(6.6,0,24.7, 0.5)
        cnodePath = visual_barrel.attachNewNode(CollisionNode('barrelCollider'))
        cnodePath.node().addSolid(sphere)
        cnodePath.node().setFromCollideMask(0xD) # crash with default and mario body and walls
        cnodePath.node().setIntoCollideMask(0xD) # crash with default and mario body and walls
        self.showCollision(cnodePath)
        #cnodePath.show()
        self.physicsCollisionPusher.addCollider(cnodePath,barrel)
        base.cTrav.addCollider(cnodePath, self.physicsCollisionPusher)

        barrelForceNode = ForceNode('barrelForce')
        barrel.attachNewNode(barrelForceNode)
        barrelForce = LinearVectorForce(-7,0,0, 1, False)
        # barrelForce.setMassDependent(0)
        barrelForceNode.addForce(barrelForce)
        physicsBarrel.getPhysical(0).addLinearForce(barrelForce)
        # starting barrel point :D
        barrelNode.setPos(self.scene,6.5,0,4.5)
Esempio n. 5
0
    def createBarrel(self):

        barrelNode = NodePath("PhysicalBarrel")
        barrelNode.reparentTo(self.scene)

        physicsBarrel = ActorNode("physics_barrel")
        physicsBarrel.getPhysicsObject().setMass(
            0.01)  #in what units? (69 kindda 3 lbs)
        barrel = barrelNode.attachNewNode(physicsBarrel)
        base.physicsMgr.attachPhysicalNode(physicsBarrel)

        barrel.setPos(0, 0, 2)

        visual_barrel = self.scene.attachNewNode("BarrelCopy")
        originalBarrel = self.scene.find("barrel")
        originalBarrel.instanceTo(visual_barrel)
        visual_barrel.reparentTo(barrel)

        sphere = CollisionSphere(6.6, 0, 4.78, 0.5)
        cnodePath = visual_barrel.attachNewNode(
            CollisionNode('barrelCollider'))
        cnodePath.node().addSolid(sphere)
        cnodePath.node().setFromCollideMask(
            0xD)  # crash with default and mario body and walls
        cnodePath.node().setIntoCollideMask(
            0xD)  # crash with default and mario body and walls
        cnodePath.show()
        self.physicsCollisionPusher.addCollider(cnodePath, barrel)
        base.cTrav.addCollider(cnodePath, self.physicsCollisionPusher)

        barrelForceNode = ForceNode('barrelForce')
        barrel.attachNewNode(barrelForceNode)
        barrelForce = LinearVectorForce(-7, 0, 0, 1, False)
        # barrelForce.setMassDependent(0)
        barrelForceNode.addForce(barrelForce)
        physicsBarrel.getPhysical(0).addLinearForce(barrelForce)
 def setupPhysics(self, name):
     an = ActorNode('%s-%s' % (name, self.doId))
     anp = NodePath(an)
     if not self.isEmpty():
         self.reparentTo(anp)
     NodePath.assign(self, anp)
     self.physicsObject = an.getPhysicsObject()
     self.setTag('object', str(self.doId))
     self.collisionNodePath.reparentTo(self)
     self.handler = PhysicsCollisionHandler()
     self.handler.addCollider(self.collisionNodePath, self)
     self.collideName = self.uniqueName('collide')
     self.handler.addInPattern(self.collideName + '-%in')
     self.handler.addAgainPattern(self.collideName + '-%in')
     self.watchDriftName = self.uniqueName('watchDrift')
Esempio n. 7
0
 def __init__(self, base, name, speed, scale, color, mask, relA, xyz, relB,
              lookat, life):
     an = ActorNode()
     self.anp = base.render.attachNewNode(an)
     base.physicsMgr.attachPhysicalNode(an)
     self.anpo = an.getPhysicsObject()
     fn = ForceNode("force-missile")
     self.anp.attachNewNode(fn)
     bft = LinearVectorForce(Vec3(0, 1, 0) * speed)
     fn.addForce(bft)
     an.getPhysical(0).addLinearForce(bft)
     missile = base.loader.loadModel("./mdl/missile.egg")
     missile.setColor(color)
     missile.setScale(scale)
     missile.reparentTo(self.anp)
     missile.setTag(name, '1')
     missile_from_obj = missile.attachNewNode(CollisionNode(name))
     missile_from_obj.node().addSolid(CollisionSphere(0, 0, 0, 1))
     missile_from_obj.node().setFromCollideMask(mask)
     missile_from_obj.setCollideMask(mask)
     base.pusher.addCollider(missile_from_obj, self.anp)
     base.cTrav.addCollider(missile_from_obj, base.pusher)
     self.anp.setPos(relA, xyz)
     self.anp.lookAt(relB, lookat)
     # light the missile
     mlight = DirectionalLight('mlight')
     mlight.setColor(VBase4(1., 1., 1., 1))
     mlnp = base.render.attachNewNode(mlight)
     mlnp.setHpr(self.anp.getHpr())
     self.anp.setLightOff()
     self.anp.setLight(mlnp)
     # remove the missile
     base.taskMgr.doMethodLater(life,
                                self.remove_missile,
                                'task-remove-missile',
                                extraArgs=[self.anp],
                                appendTask=True)
Esempio n. 8
0
class Bullet(DirectObject):
    def __init__(self, playerID, color=LPoint3f(0,0,0)):
        self.color = color
        self.playerID = playerID

        self.bulletNP = NodePath("Bullet-%d" % id(self))
        self.bulletAN = ActorNode("bullet-physics-%d" % id(self))
        # set the mass of the ball to 3.3g = average weight of a paintball
        self.bulletAN.getPhysicsObject().setMass(0.033)
        self.bulletANP = self.bulletNP.attachNewNode(self.bulletAN)
        base.physicsMgr.attachPhysicalNode(self.bulletAN)
        self.bullet = loader.loadModel("Bullet")
        self.bullet.setScale(2)
        self.bullet.setColorScale(
            self.color.getX(),
            self.color.getY(),
            self.color.getZ(),
            1.0)
        self.bullet.reparentTo(self.bulletANP)

        # setup the collision detection
        # 17.3 mm (0.0173) = size of a .68cal paintball
        self.bulletColName = "bulletCollision-%02d" % id(self)
        self.bulletSphere = CollisionSphere(0, 0, 0, 0.0173*2)
        self.bulletCollision = self.bulletANP.attachNewNode(CollisionNode(self.bulletColName))
        self.bulletCollision.node().addSolid(self.bulletSphere)
        #self.bulletCollision.show()
        base.physicpusher.addCollider(self.bulletCollision, self.bulletANP)
        base.cTrav.addCollider(self.bulletCollision, base.physicpusher)

    def shoot(self, pos, shootVec=None):
        if shootVec != None:
            v = shootVec
            v *= 214.0
        else:
            # Get from/to points from mouse click
            pMouse = base.mouseWatcherNode.getMouse()
            pFrom = Point3()
            pTo = Point3()
            base.camLens.extrude(pMouse, pFrom, pTo)

            pFrom = render.getRelativePoint(base.cam, pFrom)
            pTo = render.getRelativePoint(base.cam, pTo)

            # Calculate initial velocity
            v = pTo - pFrom
            v.normalize()
            v *= 214.0

        self.bulletNP.setPos(pos)
        self.bulletNP.reparentTo(render)
        self.bulletFN = ForceNode("Bullet-force-%d" % id(self))
        self.bulletFNP = self.bulletNP.attachNewNode(self.bulletFN)
        # speed of a paintball when he leafes the muzzle: 214 fps
        self.lvf = LinearVectorForce(v)
        self.lvf.setMassDependent(1)
        self.bulletFN.addForce(self.lvf)
        self.bulletAN.getPhysical(0).addLinearForce(self.lvf)

        self.accept("bulletCollision-%d-hit" % id(self), self.bulletHit)
        taskMgr.doMethodLater(
            2,
            self.doRemove,
            'doRemove-%d' % id(self),
            appendTask=True)

    def doRemove(self, task):
        if self is None: return task.done
        self.ignoreAll()
        self.bulletNP.removeNode()
        self.bulletAN.getPhysical(0).removeLinearForce(self.lvf)
        return task.done

    def bulletHit(self, entry):
        hitName = entry.getIntoNode().getName()
        if str(self.playerID) not in hitName and \
            self.bulletColName not in hitName:
            base.messenger.send("Bulet-hit-%s" % hitName, [entry, self.color])
            self.bulletNP.removeNode()
            self.bulletAN.getPhysical(0).removeLinearForce(self.lvf)
Esempio n. 9
0
class MyApp(ShowBase):
    def center_mouse(self):
        self.win.movePointer(0,self.win.getXSize()/2,self.win.getYSize()/2)
    def __init__(self):
        #Game variables
        self.health = 100
        self.panda_kill_count = 0
        self.level = 0
        
        #Implementation variables
        #self.color = [Vec4((204.0/255), (255.0/255), (204/255), 0.1),Vec4((0/255), (255.0/255), (255.0/255), 0.1),Vec4((255.0/255), (51.0/255), (255.0/255), 0.1),Vec4((153.0/255), (255.0/255), (153.0/255), 0.1),Vec4((255.0/255), (178.0/255), (102.0/255), 0.1),Vec4((229.0/255), (204.0/255), (255.0/255), 0.1)]
        self.color = [Vec4(0.4,0.4,0.4,0.1)]
        self.mirror=False
        self.paused=False
        self.displayed=False
        self.game_started=False
        self.randomthings_ = randomthings.RandomThings(self)
        self.shifted_cam=False
        self.is_firstP=False
        self.old_anim2 = None
        self.old_anim=None
        self.timeout=False
        (self.r,self.f,self.b,self.l)=(0,0,0,0)
        self.inside_level=False
        self.move_anim_queue=[]
        self.anim_queue=[]
        self.prev_time=0.0
        self.bullets = []
        self.rightspeed=0
        self.forwardspeed=0
        ShowBase.__init__(self)
        self.makeDefaultPipe()
        bb=self.pipe.getDisplayHeight()
        aa=self.pipe.getDisplayWidth()
        
        self.openDefaultWindow(size=(aa, bb))
        import layer2d
        self.layer2d = layer2d
        self.layer2d.update_info('Loading...')
        self.keyreader= ReadKeys(self,layer2d)
        
        #Sounds
        self.gunshot = self.loader.loadSfx("sounds/gunshot_se.ogg")
        self.gunshot.setLoop(False)
        
        self.music = self.loader.loadSfx("sounds/music.ogg")
        self.music.setLoop(True)
        
        
        self.zombie_die = self.loader.loadSfx('sounds/zombie_die.ogg')
        self.zombie_die.setLoop(False)
        
        self.kicked = self.loader.loadSfx('sounds/kicked.ogg')
        self.kicked.setLoop(False)
        
        self.hurt_sound = self.loader.loadSfx('sounds/hurt.ogg')
        self.hurt_sound.setLoop(False)
        
        self.dead_sound = self.loader.loadSfx('sounds/dead.ogg')
        self.dead_sound.setLoop(False)
        
        self.intro_sound = self.loader.loadSfx('sounds/intro.ogg')
        self.intro_sound.setLoop(False)
        self.intro_sound.play()
        
        
        self.enableParticles()
        self.center_mouse()
        #self.disableMouse()
        self.prev_pos = None
        if base.mouseWatcherNode.hasMouse():
            x=base.mouseWatcherNode.getMouseX()
            y=base.mouseWatcherNode.getMouseY()
            self.prev_pos = (x,y)
        #Hide cursor
        props = WindowProperties()
        props.setCursorHidden(True) 
        self.win.requestProperties(props)
        
        
        self.environ = self.loader.loadModel('models/ourworld')
        self.environ.setPos(0,0,0)
        self.environ.reparentTo(self.render)
        
        
        self.pandaActor = Actor("models/hero_anim", {'kick':'models/hero_anim-kick','unready_to_shoot':'models/hero_anim-unready_to_shoot','jump':'models/hero_anim-jump',"shooting":"models/hero_anim-shooting","ready_to_shoot":"models/hero_anim-ready_to_shoot","ready_to_walk":"models/hero_anim-ready_to_run","ready_to_run":"models/hero_anim-ready_to_run","walk4":"models/hero_anim-walk1", "breathe": "models/hero_anim-breathe", "run": "models/hero_anim-walk"})
        self.pandaActor.setPlayRate(3,'ready_to_shoot')
        self.pandaActor.setPlayRate(-1.0,"ready_to_walk")
        self.pandaActor.setPlayRate(1.5,'run')
        self.pandaActor.setPlayRate(1.5,'ready_to_run')
        self.pandaActor.reparentTo(self.render)
        self.pandaActor.setPos(self.environ,0,0,100)
        self.pandaActor.loop("breathe")
        
        self.phy = NodePath("PhysicsNode")
        self.phy.reparentTo(self.render)
        
        self.pandaAN = ActorNode("PandaActor")
        self.pandaActorPhysicsP = self.phy.attachNewNode(self.pandaAN)
        
        self.physicsMgr.attachPhysicalNode(self.pandaAN)
        self.pandaActor.reparentTo(self.pandaActorPhysicsP)
        
        
        #set mass of panda
        self.pandaAN.getPhysicsObject().setMass(100)
        
        #apply gravity
        self.gravityFN=ForceNode('world-forces')
        self.gravityFNP=self.environ.attachNewNode(self.gravityFN)
        self.gravityForce=LinearVectorForce(0,0,-30.81) #gravity acceleration
        self.gravityFN.addForce(self.gravityForce)
        self.physicsMgr.addLinearForce(self.gravityForce)
        
        
        #camera stuff
        self.camera.reparentTo(self.pandaActor)
        self.camera.lookAt(self.pandaActor)
        self.taskMgr.add(self.spinCameraTask, "zombieTask_SpinCameraTask")
        self.taskMgr.doMethodLater(0.01,self.movePandaTask,"zombieTask_movePandaTask")
        
        
        #Collision Handling
        self.cTrav = CollisionTraverser()
        self.collisionHandler = CollisionHandlerEvent()
        
        #Add collider for terrain
        self.groundCollider = self.environ.find("**/terrain")
        
        #Add walker for panda
        self.collision_sphere = CollisionSphere(0,0,1,1)
        self.collNode = CollisionNode('pandaWalker')
        self.cnodePath = self.pandaActor.attachNewNode(self.collNode)
        self.cnodePath.node().addSolid(self.collision_sphere)
        
        #AddZombieDetector for panda
        self.zombie_sphere = CollisionSphere(0,0,3,1)
        self.zomb_detector_node = CollisionNode('zombieDetector')
        self.zomb_detector_NP = self.pandaActor.attachNewNode(self.zomb_detector_node)
        self.zomb_detector_NP.node().addSolid(self.zombie_sphere)
        #self.zomb_detector_NP.show()
        
        #Add pusher against gravity
        self.pusher = PhysicsCollisionHandler()
        self.pusher.addCollider(self.cnodePath, self.pandaActorPhysicsP)
        self.pusher.addCollider(self.zomb_detector_NP,self.pandaActorPhysicsP)
        self.cTrav.addCollider(self.cnodePath,self.pusher)
        self.cTrav.addCollider(self.zomb_detector_NP,self.pusher)
        
        self.pusher.addInPattern('%fn-into-%in')
        self.pusher.addAgainPattern('%fn-again-%in')
        
        #Add collision handler patterns
        self.collisionHandler.addInPattern('%fn-into-%in')
        self.collisionHandler.addAgainPattern('%fn-again-%in')
        
        self.abientLight = AmbientLight("ambientLight")
        self.abientLight.setColor(Vec4(0.1, 0.1, 0.1, 1))
        self.directionalLight = DirectionalLight("directionalLight")
        self.directionalLight.setDirection(Vec3(-5, -5, -5))
        self.directionalLight.setColor(Vec4((229.0/255), (204.0/255), (255.0/255), 0.7))
        self.directionalLight.setSpecularColor(Vec4(0.4, 0.4, 0.4, 0.1))
        self.directionalLight.setShadowCaster(True,512,512)
        self.render.setLight(self.render.attachNewNode(self.abientLight))
        self.render.setLight(self.render.attachNewNode(self.directionalLight))
        self.render.setShaderAuto()
        
        #create zombie land
        self.zombieland = zombie.Zombies(self)
        self.taskMgr.doMethodLater(0.01,self.zombieland.moveZombie, "zombieTask_ZombieMover")
        layer2d.incBar(self.health)
        self.taskMgr.add(self.game_monitor,"zombieTask_gameMonitor")
        self.taskMgr.doMethodLater(2.7,self.music_play, "zombieTask_music")
        
        #Add random useless things:
        self.randomthings_.add_random_things()
    def music_play(self,task):
        self.music.play()
        return Task.done
    #def get_color(self):
     #   return self.color[min(len(self.color)-1,self.level)]
    
    #GameMonitor
    def game_monitor(self,task):
        if self.paused:
            return Task.cont
        #Update Score
        self.layer2d.update_score(self.panda_kill_count)
        #Check for health of actor
        if self.health <= 0:
            self.dead_sound.play()
            self.pandaActor.detachNode()
            print "LOL u ded"
            self.info = """Game Over..
    Score: """ + str(self.panda_kill_count) + """
    Press alt+f4 to quit the game.
    
    """
            self.layer2d.update_info(self.info)
            self.taskMgr.removeTasksMatching('zombieTask_*')
        
        if self.game_started<>True:
            if not self.displayed:
                self.display_information()
            self.pandaActor.setPos(self.pandaActorPhysicsP.getRelativePoint(self.render,Point3(10,10,100)))
            return Task.cont
        
        #Check if user is inside some level. if yes, pass.
        if self.inside_level or self.timeout:
            return Task.cont
        self.inside_level = True
        #self.health=100
        self.timeout=True
        print ".."
        #The next lines will be executed only when the user is in between two levels (or at the beginning of the game)
        #Display information based on game level
        self.display_information()
        print "HUEHUEHUEHUE"    
        #Schedule wave of zombies
        self.taskMgr.doMethodLater(10,self.addWave, "zombieTask_ZombieAdder")
        
        return Task.cont
        
            
    
    def addWave(self,task):
        ##add a wave of 5 zombies, depending on the level.
        ##speed of zombie increases with each level
        ##durability of zombie increases with each level.
        ##Wave ends when all zombies die.
        self.directionalLight.setSpecularColor(Vec4(0.4, 0.4, 0.4, 0.1))
        self.layer2d.update_info("level"+str(self.level))
        self.timeout=False
        self.zombieland.add(5)
        return Task.done
        
    
    #information displayer
    def display_information(self):
        #display information based on levels.
        print self.game_started
        self.displayed=True
        if self.game_started==False:
            info = """
    Welcome to PandaLand. Once upon a time, there used to be these cute

    little creatures called Pandas. They were lazy, funny, and

    adorable. But that is what we humans thought. Pandas are

    actually an evil alien race that spread from planet to planet,

    spreading destruction and terror everywhere. They ruled earth

    several billion years ago. But our super ancestors (Dinosaurs)

    fought agaisnt them with great valour and selflessness; and managed

    to save planet Earth from doom. But the pandas went into hiding

    (and became cute); until few days back! Now they seek to kill all.

    You, the Joker, are our only hope,since Batman has retired.

    Go Kill Pandas.For Mother Earth!
    
    

    """
            self.layer2d.information['bg'] = (0,0,0,0.8)
        else:
            self.layer2d.update_info('')
            if self.level==0:
                info="""
    Your game will start in a few seconds.
    This is the first level. Pandas will spawn
    and follow you. Shoot to kill.

    Test out your controls while
    they are still cute and harmless :)
    
    Jump: Space
    Shoot: LeftClick
    Kick: RightClick
    Walk: A/W/S/D
    
    For more information, press P.

"""
                
                self.layer2d.information['bg'] = (0,0,0,0.6)
            elif self.level==1:
                info="""
    Level 0 Completed!
    Starting Level 1.
    
    Pandas have turned evil
    and stronger. They will try
    to eat you up.

    To run:
    Press Shift + A/S/W/D

"""
            elif self.level==2:
                info="""
    Level 1 Completed!
    Starting Level 2.
    
    Pandas are even stronger now.
    They will get stronger by
    each level.

    Your automatic shooting speed has
    also improved due to experience
    gained.

"""
            elif self.level==3:
                info="""
    Level 2 Completed!
    Starting Level 3.
    
    Pandas also move faster
    by each level. They really
    want to eat you.

    But don't worry, you also 
    run faster as the levels
    proceed.
    
"""
            else:
                info = """
    Level """ + str(self.level-1) + """ Completed!
    Starting """ + str(self.level) + """ .
    
    Well done!
    Keep fighting, our fate lies
    in your hands.
    
"""
        self.layer2d.update_info(info)
    #self.create_bullet()
    def create_bullet(self):
        self.bullet = self.loader.loadModel('models/gun/bullet')
        self.gunshot.play()
        self.bulletAN = ActorNode("BulletNode")
        self.bulletActorPhysicsP = self.phy.attachNewNode(self.bulletAN)
        
        self.physicsMgr.attachPhysicalNode(self.bulletAN)
        self.bullet.reparentTo(self.bulletActorPhysicsP)
        self.bulletAN.getPhysicsObject().setMass(1)
        self.bullet.setPos(self.pandaActor,0,-3,3.5)
        self.bullet.setScale(0.1,0.1,0.1)
        self.bullet.setHpr(self.pandaActor,0,90,0)
        self.bullet.setP(self.camera.getP()+90)
        self.bullet_sphere = CollisionSphere(0,0,0,0.2)
        self.bullet_collNode = CollisionNode('bullet')
        self.bullet_cnodePath = self.bullet.attachNewNode(self.bullet_collNode)
        self.bullet_cnodePath.node().addSolid(self.bullet_sphere)
        
        #self.pusher.addCollider(self.bullet_cnodePath,self.bulletActorPhysicsP)
        self.cTrav.addCollider(self.bullet_cnodePath,self.collisionHandler)
        
        #self.bullet_cnodePath.show()
        self.bullets += [self.bullet]
    def bulletKiller(self,task):
        if self.paused:
            return Task.cont
        self.bullets[0].remove_node()
        self.bullets = self.bullets[1:]
        return Task.done
    
    
    def bulletThrower(self,task):
        if self.paused:
            return Task.cont
        #make bullet move
        if self.pandaActor.getCurrentAnim()<>'shooting' and self.pandaActor.getCurrentAnim()<>'ready_to_shoot':
            self.pandaActor.play('shooting')
        print "loL"
        self.create_bullet()
        
        self.bulletAN.getPhysicsObject().setVelocity(self.render.getRelativeVector(self.camera,Vec3(0,200,0)))
        
        self.taskMgr.doMethodLater(max(0.05,0.1*(5-self.level)),self.bulletThrower, "zombieTask_bulletThrower")
        self.taskMgr.doMethodLater(0.5,self.bulletKiller, "zombieTask_bulletKiller")
        
        self.prev=True
        
        if self.old_anim2==None:
            self.old_anim2='breathe'
        if self.old_anim2 not in ['run','walk4']:
            self.old_anim2='breathe'
        self.anim_queue = [(self.pandaActor,True,'unready_to_shoot'),(self.pandaActor,False,self.old_anim2)]
        return Task.done
        
    def movePandaTask(self,task):
        
        if self.paused:
            return Task.cont
        tempos = self.pandaActor.getPos()
        speed = 0.1
        if self.run_:
            speed+=0.3*self.level
        self.rightspeed = -(self.r-self.l)*speed
        self.forwardspeed = -(self.f-self.b)*speed
        if (self.r-self.l)<>0 and (self.f-self.b)<>0:
            #print self.forwardspeed
            #print self.rightspeed
            #sys.exit(0)
            self.rightspeed *= 0.7
            self.forwardspeed *= 0.7
        self.pandaActor.setPos(self.pandaActor,self.rightspeed, self.forwardspeed,0)
        return Task.again
    def spinCameraTask(self, task):
        if self.paused:
           
            return Task.cont
        if self.render.getRelativePoint(self.pandaActorPhysicsP,self.pandaActor.getPos())[2] < -10:
            self.pandaAN.getPhysicsObject().setVelocity(0,0,30)
            #self.pandaActor.setPos(self.pandaActorPhysicsP.getRelativePoint(self.render,Point3(10,10,100)))
        self.prev_time=task.time
        
            
            
        #play queued animations:
        for x in self.move_anim_queue+self.anim_queue:
            if x[0].getCurrentAnim()==None:
                if x[1]:
                    x[0].play(x[2])
                else:
                    x[0].loop(x[2])
                if x in self.move_anim_queue:
                    self.move_anim_queue.remove(x)
                elif x in self.anim_queue:
                    self.anim_queue.remove(x)
                    
        
        #Do other stuff
        if self.mouseWatcherNode.hasMouse():
            x=base.mouseWatcherNode.getMouseX()
            y=base.mouseWatcherNode.getMouseY()
            if self.prev_pos==None:
                self.prev_pos = (x,y)
            xx = self.prev_pos[0] - x
            yy = self.prev_pos[1] + y
            self.prev_pos = (xx,yy)
            
            self.pandaActor.setHpr(self.pandaActor,-20*(pi/2.0)*x,0,0)
            
            #self.camera.setHpr(self.pandaActor, 20*(pi/2.0)*x, 20*(pi/2.0)*yy, 0)
            if self.is_firstP:
                self.camera.lookAt(self.pandaActor)
                self.camera.setPos(self.pandaActor,0,0,4)
                self.camera.setHpr(self.camera,180,0,0)
                
            else:
                self.camera.setPos(self.pandaActor,0,8,5)
                self.camera.lookAt(self.pandaActor)
                if self.mirror:
                    self.camera.setY(-self.camera.getY())
                    self.camera.lookAt(self.pandaActor)
            self.camera.setHpr(self.camera,0,20*(pi/2.0)*yy,0)
        self.center_mouse()
        
        #zombie collisions
        return Task.cont
    
    #User Actions:
    def meelee(self):
        #Make actor stomp here. or something
        #Load animation
        self.zombieland.meelee()
        self.anim_queue += [(self.pandaActor,True,self.pandaActor.getCurrentAnim())]
        self.pandaActor.play('kick')
        #pass
    def ranged_start(self):
        #put animation here
        self.old_anim = self.pandaActor.getCurrentAnim()
        if self.old_anim not in  ['shooting','unready_to_shoot','ready_to_shoot'] :
            self.old_anim2 = self.old_anim
        if self.old_anim not in ['ready_to_shoot','shooting','unready_to_shoot']:
            self.pandaActor.play('ready_to_shoot')
        
        self.taskMgr.add(self.bulletThrower, "zombieTask_bulletThrower")
    def ranged_stop(self,task=None):
        if self.paused:
            return Task.cont
        #stop animation here
        if self.pandaActor.getCurrentAnim()<>'shooting' and task==None:
            self.pandaActor.play('shooting')
            self.taskMgr.remove("zombieTask_bulletThrower")
            self.taskMgr.doMethodLater(0.5,self.ranged_stop,'zombieTask_rangedStop')
            return Task.done
        self.taskMgr.remove("zombieTask_bulletThrower")
        return Task.done