예제 #1
0
class floatTrap():
    traps = list()
    model = 0
    index = 0
    def __init__(self, ppos, world, worldNP):
        self.world = world
        if floatTrap.model==0:
            floatTrap.model = Model("../assets/3d/Actors/beartrap2.egg")
        h = deg2Rad(camera.getH())
        p = deg2Rad(camera.getP())
        dir = (-cos(p)*sin(h), cos(p)*cos(h), sin(p))
        npos = map(lambda i: ppos[i]+dir[i]*25, range(3))
        self.instance = floatTrap.model.createInstance(pos=npos,hpr=(0,0,0))
        self.index = floatTrap.index
        
        pmin = LPoint3()
        pmax = LPoint3()
        self.instance.calcTightBounds(pmin,pmax)
        norm = pmin-pmax
        self.off = (norm[0]*.5,norm[1]*.5,norm[2]*.5)
        r = max(norm)
        shape = BulletSphereShape(.7*r)
        self.sphere = BulletGhostNode('TrapSphere')
        self.sphere.addShape(shape)
        self.sphere.setDeactivationEnabled(False)
        self.np = worldNP.attachNewNode(self.sphere)
        self.np.setPos(LVecBase3(npos[0],npos[1],npos[2]))
        self.np.setCollideMask(BitMask32.allOn())
        world.attachGhost(self.sphere)
        
        #taskMgr.add(self.check,"floatTrap"+str(self.index)+"Check")
        floatTrap.traps.append(self)
        floatTrap.index = floatTrap.index + 1
        #pos = self.instance.getPos()
        #self.np.setPos(pos[0]-self.off[0],pos[1]-self.off[1],pos[2]-self.off[2])
    def kill(self):
        floatTrap.traps.remove(self)
        self.world.removeGhost(self.sphere)
        self.instance.detachNode()
    def check(self,contacts,human,players):
        if len(contacts)>0:
            contactObject = contacts[0].getNode0()
            if contacts[0].getNode0().getName()=="TrapSphere":
                contactObject = contacts[0].getNode1()
            name = contactObject.getName()
            print contactObject
            if name==human.character.getName():
                human.trap1()
                self.kill()
                return
            for i in range(len(players)):
                if name==players[i].character.getName():
                    players[i].trap1()
                    self.kill()
                    return
예제 #2
0
class clawTrap():
    traps = list()
    model = 0
    index = 0
    def __init__(self, world, worldNP):
        self.failed = 1
        self.world = world
        if clawTrap.model==0:
            clawTrap.model = Model("../assets/3d/Actors/claw3.egg")
        h = deg2Rad(camera.getH())
        p = deg2Rad(camera.getP())
        dir = (-cos(p)*sin(h), cos(p)*cos(h), sin(p))
        cpos = camera.getPos()
        vec = map(lambda i: cpos[i]+dir[i]*200, range(3))
        rayHit = world.rayTestClosest(cpos,LPoint3(vec[0],vec[1],vec[2]))
        if not rayHit.hasHit():
            return
        npos = rayHit.getHitPos()
        n = rayHit.getHitNormal()
        print n
        npos = map(lambda i: npos[i]+n[i]*5, range(3))
        self.instance = clawTrap.model.createInstance(pos=npos,hpr=(-90*n.x,180*(n.z==1)+90*(abs(n.x)+n.y),0))
        self.index = clawTrap.index
        
        pmin = LPoint3()
        pmax = LPoint3()
        self.instance.calcTightBounds(pmin,pmax)
        norm = pmin-pmax
        self.off = (norm[0]*.5,norm[1]*.5,norm[2]*.5)
        r = max(norm)
        shape = BulletSphereShape(.7*r)
        self.sphere = BulletGhostNode('TrapSphere')
        self.sphere.addShape(shape)
        self.sphere.setDeactivationEnabled(False)
        self.np = worldNP.attachNewNode(self.sphere)
        self.np.setPos(LVecBase3(npos[0],npos[1],npos[2]))
        self.np.setCollideMask(BitMask32.allOn())
        world.attachGhost(self.sphere)
        
        #taskMgr.add(self.check,"floatTrap"+str(self.index)+"Check")
        clawTrap.traps.append(self)
        clawTrap.index = clawTrap.index + 1
        self.failed = 0
        #pos = self.instance.getPos()
        #self.np.setPos(pos[0]-self.off[0],pos[1]-self.off[1],pos[2]-self.off[2])
    def kill(self):
        clawTrap.traps.remove(self)
        self.world.removeGhost(self.sphere)
        self.instance.detachNode()
    def check(self,contacts,human,players):
        if len(contacts)>0:
            contactObject = contacts[0].getNode0()
            if contacts[0].getNode0().getName()=="TrapSphere":
                contactObject = contacts[0].getNode1()
            name = contactObject.getName()
            print contactObject
            if name==human.character.getName():
                human.trap2()
                self.kill()
                return
            for i in range(len(players)):
                if name==players[i].character.getName():
                    players[i].trap2()
                    self.kill()
                    return
예제 #3
0
class Projectile():
    projectiles = list()
    model = 0
    index = 0
    def __init__(self, ppos, h, p, parent, parentVel, world, worldNP):
        self.world=world
        if Projectile.model==0:
            Projectile.model = Model("../assets/3d/Actors/ball_proj2.egg")
        h = deg2Rad(camera.getH())
        p = deg2Rad(camera.getP())
        dir = (-cos(p)*sin(h), cos(p)*cos(h), sin(p))
        ppos = map(lambda i: ppos[i]+dir[i]*20, range(3))
        self.instance = Projectile.model.createInstance(pos=ppos,hpr=(h,p,0),scale=3)
        
        self.dhpr = [random.random(),random.random(),random.random()]
        
        pmin = LPoint3()
        pmax = LPoint3()
        self.instance.calcTightBounds(pmin,pmax)
        norm = pmin-pmax
        self.off = (norm[0]*.5,norm[1]*.5,norm[2]*.5)
        r = max(norm)
        
        pos = ppos
        
        shape = BulletSphereShape(.5*r)
        self.sphere = BulletGhostNode('ProjectileSphere')
        self.sphere.addShape(shape)
        self.sphere.setDeactivationEnabled(False)
        self.np = worldNP.attachNewNode(self.sphere)
        self.np.setPos(LVecBase3f(ppos[0],ppos[1],ppos[2]))
        self.np.setCollideMask(BitMask32.allOn())
        world.attachGhost(self.sphere)
        
        dir = (-cos(p)*sin(h), cos(p)*cos(h), sin(p))
        self.vel = parentVel
        self.vel = map(lambda i: dir[i]*100, range(3))
        self.index = Projectile.index
        self.parent = parent
        Projectile.index = Projectile.index + 1
        taskMgr.add(self.move,"Proj"+str(Projectile.index)+"MoveTask")
        self.prevTime = 0
        self.lifeTime = 0
        Projectile.projectiles.append(self)
        self.TIMEDLIFE = 120
        self.dead = 0
    def kill(self):
        self.instance.removeNode()
        self.parent.projectiles.remove(self)
        self.world.removeGhost(self.sphere)
        Projectile.projectiles.remove(self)
        self.dead = 1
    def check(self,contacts,human,players):
        if len(contacts)==0:
            return
        contactObject = contacts[0].getNode0()
        if contacts[0].getNode0().getName()=="ProjectileSphere":
            contactObject = contacts[0].getNode1()
        name = contactObject.getName()
        #print name
        if name==human.character.getName():
            human.impact(self.vel)
            self.kill()
            return
        for i in range(len(players)):
            if name==players[i].character.getName():
                players[i].impact(self.vel)
                self.kill()
                return
        return
        
    def move(self,task):
        if self.dead==1:
            return
        dt = task.time-self.prevTime
        #If the projectile exceeds its maximum lifetime or burns out on the arena bounds -
        self.lifeTime += dt
        if(self.lifeTime >= self.TIMEDLIFE):
            #kill projectile
            self.instance.removeNode()
            self.parent.projectiles.remove(self)
            self.world.removeGhost(self.sphere)
            Projectile.projectiles.remove(self)
            return
            #print "Projectile removed"
        if(self.lifeTime < self.TIMEDLIFE):
            #get the position
            pos = self.instance.getPos()
            #get the displacement
            dis = (self.vel[0]*dt,self.vel[1]*dt,self.vel[2]*dt)
            #set the new position
            self.np.setPos(pos[0]+dis[0],pos[1]+dis[1],pos[2]+dis[2])
            self.instance.setPos(pos[0]+dis[0],pos[1]+dis[1],pos[2]+dis[2])
            
            hpr = self.instance.getHpr()
            hpr = map(lambda i: hpr[i]+dt*100*self.dhpr[i], range(3))
            self.instance.setHpr(hpr[0],hpr[1],hpr[2])
            return task.cont