Ejemplo n.º 1
0
    def __init__(self, world, pos, hpr):
        super(Flame, self).__init__()

        self.shape = BulletBoxShape(Vec3(0.1,0.05,0.05))
        self.bnode = BulletRigidBodyNode()
        self.bnode.setMass(1.0)
        self.bnode.addShape(self.shape)

        self.np = utilities.app.render.attachNewNode(self.bnode)

        self.world =world 
        self.anim = list()
        self.anim.append(utilities.loadObject("flame1", depth=0))
        self.anim.append(utilities.loadObject("flame2", depth=0))
        self.anim.append(utilities.loadObject("flame3", depth=0))
        world.bw.attachRigidBody(self.bnode)

        self.curspr = 0
        self.obj = self.anim[self.curspr]
        self.obj.show() 
        self.livetime = 0
        self.delta = 0

        self.pos = pos
        self.pos.y = Flame.depth
        #self.pos.z -= 0.2 
        self.hpr = hpr
        self.vel = Point2()
        self.vel.x = cos(world.player.angle)*Flame.speed
        self.vel.y = sin(world.player.angle)*Flame.speed

        tv = Vec3(self.vel.x, 0, self.vel.y)
        # this makes the shot miss the target if the player has any velocity
        tv += world.player.bnode.getLinearVelocity()

        self.bnode.setLinearVelocity(tv)

        tv.normalize()

        # initial position of RB and draw plane
        self.np.setHpr(hpr)
        self.np.setPos(pos+tv/2)

        self.bnode.setAngularFactor(Vec3(0,0,0))
        self.bnode.setLinearFactor(Vec3(1,0,1))
        self.bnode.setGravity(Vec3(0,0,0))

        self.bnode.setCcdMotionThreshold(1e-7)
        self.bnode.setCcdSweptSphereRadius(0.10)

        self.bnode.notifyCollisions(True)
        self.bnode.setIntoCollideMask(BitMask32.bit(1))
        self.bnode.setPythonTag("Entity", self)
        self.noCollideFrames = 4

        for a in self.anim:
            a.hide()
            a.reparentTo(self.np)
            a.setScale(0.25, 1, 0.25)
            a.setPos(0, -0.1,0)
Ejemplo n.º 2
0
    def makeChunk(self, pos):
        # store enemies, bits of terrain and projectiles in entities
        # so we can do some collision detection
        self.bgs.append(utilities.loadObject("stars", depth=100, scaleX=200, scaleY=200.0, pos=Point2(pos.x*worldsize.x,pos.y*worldsize.y)))
        # also need to put these around any other "edge" nodes
        #self.bgs.append(utilities.loadObject("stars", depth=100, scaleX=200, scaleY=200.0, pos=Point2(pos.x*-200,0)))

        for i in range(-10, 10):
            self.entities.append(Rail(self, i * 10, 0))
    
        pt = list()

        for i in range(0, int(worldsize.x)):
            pt.append(list())
            for j in range(0, int(worldsize.y)):
                if self.perlin.noise(i,j) > 0:
                    pt[i].append(1)
                else:
                    pt[i].append(0)  

        pt[0][0] = 0	
        pt[1][0] = 0	
        pt[0][1] = 0	
        pt[1][1] = 0	
        pt[2][2] = 0
        pt[2][1] = 0
        pt[1][2] = 0
        pt[2][2] = 0 

        for i in range(2, int(worldsize.x)):
            for j in range(2, int(worldsize.y)):
                if pt[i][j] == 1:
                    self.entities.append(Wall(self, Point2(i,j)))
Ejemplo n.º 3
0
 def __init__(self, world, player):
     super(Blowtorch, self).__init__(world, player)
     self.obj = utilities.loadObject("blowtorch",
                                     scaleX=1,
                                     scaleY=1,
                                     depth=0.5)
     self.obj.hide()
Ejemplo n.º 4
0
def sample2(prefix, cliptrain, clipvalid):
    namestrain, namesvalid = [], []
    indextrain, indexvalid = [], []
    labelstrain, labelsvalid = [], []
    attrstrain, attrsvalid = [], []

    for i in range(20):
        path = utilities.getPath(prefix + '_' + str(i + 1) + '.cpk')
        obj = utilities.loadObject(path)
        names, index, labels, attrs = obj[0], obj[1], obj[2], obj[3]
        for idx in index:
            j = idx - 1 - i * 500
            if j in cliptrain:
                # print 'train: ', idx, j
                namestrain.append(names[j])
                indextrain.append(index[j])
                labelstrain.append(labels[j])
                attrstrain.append(attrs[j])
            elif j in clipvalid:
                # print 'valid: ', idx, j
                namesvalid.append(names[j])
                indexvalid.append(index[j])
                labelsvalid.append(labels[j])
                attrsvalid.append(attrs[j])
            else:
                pass

    datatrain = [namestrain, indextrain, labelstrain, attrstrain]
    datavalid = [namesvalid, indexvalid, labelsvalid, attrsvalid]
    fntrain = utilities.getPath('train_2000_samples.cpk')
    fnvalid = utilities.getPath('valid_1000_samples.cpk')
    utilities.saveObjects([datatrain, datavalid], [fntrain, fnvalid])
Ejemplo n.º 5
0
def sample(prefix, nprefix, clip, num=20):
    namesset = []
    indexset = []
    lablesset = []
    attrsset = []

    for i in range(num):
        path1 = utilities.getPath(prefix + '_' + str(i + 1) + '.cpk')
        obj = utilities.loadObject(path1)
        names, index, labels, attrs = obj[0], obj[1], obj[2], obj[3]
        for idx in index:
            j = idx - 1 - i * 500
            if j in clip:
                # print nprefix, idx, j
                namesset.append(names[j])
                indexset.append(index[j])
                lablesset.append(labels[j])
                attrsset.append(attrs[j])
            else:
                pass

    dataset = [namesset, indexset, lablesset, attrsset]
    fn2 = nprefix + '_' + str(len(clip)) + '_' + 'samples.cpk'
    path2 = utilities.getPath(fn2)
    utilities.saveObject(dataset, path2)
Ejemplo n.º 6
0
    def __init__(self, world):
        super(Player, self).__init__()

        self.obj = utilities.loadObject("player", depth=20)

        self.world = world 
        self.health = 100
        self.inventory = dict()

        self.depth = self.obj.getPos().y

        self.location = Point2(0,0)
        self.velocity = Vec3(0)
        self.pt = 0.0

        self.shape = BulletBoxShape(Vec3(0.3, 1.0, 0.49))
        self.bnode = BulletRigidBodyNode('Box')
        self.bnode.setMass(1.0)
        self.bnode.setAngularVelocity(Vec3(0))
        self.bnode.setAngularFactor(Vec3(0))
        self.bnode.addShape(self.shape)
        self.bnode.setLinearDamping(0.95)
        self.bnode.setLinearSleepThreshold(0)

        world.bw.attachRigidBody(self.bnode)
        self.bnode.setPythonTag("Entity", self)
        self.bnode.setIntoCollideMask(BitMask32.bit(0))

        self.node = utilities.app.render.attachNewNode(self.bnode)
        self.node.setPos(self.obj.getPos())

        self.obj.setPos(0,0,0)
        self.obj.setScale(1)
        self.obj.reparentTo(self.node)
        self.node.setPos(self.location.x, self.depth, self.location.y)
Ejemplo n.º 7
0
 def __init__(self, world, player):
     super(LightLaser, self).__init__(world, player)
     self.obj = utilities.loadObject("lightlaser",
                                     scaleX=1,
                                     scaleY=1,
                                     depth=0.5)
     self.obj.hide()
Ejemplo n.º 8
0
    def __init__(self, location, player, cmap, world):
        super(Catcher, self).__init__(location)
        self.player = player
        self.cmap = cmap

        self.obj = utilities.loadObject("robot", depth=20)

        self.world = world 
        self.health = 100

        self.depth = self.obj.getPos().y

        self.location = location 
        self.velocity = Vec3(0)

        self.shape = BulletBoxShape(Vec3(0.5, 1.0, 0.5))
        self.bnode = BulletRigidBodyNode('Box')
        self.bnode.setMass(0.1)
        self.bnode.setAngularVelocity(Vec3(0))
        self.bnode.setAngularFactor(Vec3(0))
        self.bnode.addShape(self.shape)
        self.bnode.setLinearDamping(0.75)
        self.bnode.setLinearSleepThreshold(0)

        world.bw.attachRigidBody(self.bnode)
        self.bnode.setPythonTag("entity", self)
        self.bnode.setIntoCollideMask(BitMask32.bit(0))

        self.node = utilities.app.render.attachNewNode(self.bnode)
        self.node.setPos(self.obj.getPos())

        self.obj.setPos(0,0,0)
        self.obj.setScale(1)
        self.obj.reparentTo(self.node)
        self.node.setPos(self.location.x, self.depth, self.location.y)
Ejemplo n.º 9
0
    def __init__(self, location, player, cmap, world):
        super(Catcher, self).__init__(location)
        self.player = player
        self.cmap = cmap

        self.obj = utilities.loadObject("robot", depth=20)

        self.world = world
        self.health = 100

        self.depth = self.obj.getPos().y

        self.location = location
        self.velocity = Vec3(0)

        self.shape = BulletBoxShape(Vec3(0.5, 1.0, 0.5))
        self.bnode = BulletRigidBodyNode('Box')
        self.bnode.setMass(0.1)
        self.bnode.setAngularVelocity(Vec3(0))
        self.bnode.setAngularFactor(Vec3(0))
        self.bnode.addShape(self.shape)
        self.bnode.setLinearDamping(0.75)
        self.bnode.setLinearSleepThreshold(0)

        world.bw.attachRigidBody(self.bnode)
        self.bnode.setPythonTag("entity", self)
        self.bnode.setIntoCollideMask(BitMask32.bit(0))

        self.node = utilities.app.render.attachNewNode(self.bnode)
        self.node.setPos(self.obj.getPos())

        self.obj.setPos(0, 0, 0)
        self.obj.setScale(1)
        self.obj.reparentTo(self.node)
        self.node.setPos(self.location.x, self.depth, self.location.y)
Ejemplo n.º 10
0
    def __init__(self, world):
        super(Player, self).__init__()

        self.obj = utilities.loadObject("tdplayer", depth=20)

        self.world = world
        self.health = 100
        self.inventory = list()

        self.depth = self.obj.getPos().y

        self.location = Point2(10, 0)
        self.velocity = Vec3(0)

        self.shape = BulletBoxShape(Vec3(0.3, 1.0, 0.49))
        self.bnode = BulletRigidBodyNode('Box')
        self.bnode.setMass(0.1)
        self.bnode.setAngularVelocity(Vec3(0))
        self.bnode.setAngularFactor(Vec3(0))
        self.bnode.addShape(self.shape)
        self.bnode.setLinearDamping(0.95)
        self.bnode.setLinearSleepThreshold(0)

        world.bw.attachRigidBody(self.bnode)
        self.bnode.setPythonTag("entity", self)
        self.bnode.setIntoCollideMask(BitMask32.bit(0))

        self.node = utilities.app.render.attachNewNode(self.bnode)
        self.node.setPos(self.obj.getPos())

        self.obj.setPos(0, 0, 0)
        self.obj.setScale(1)
        self.obj.reparentTo(self.node)
        self.node.setPos(self.location.x, self.depth, self.location.y)
Ejemplo n.º 11
0
    def __init__(self, world, pos, tile, edges, shape=BulletBoxShape(Vec3(0.5, 1.0, 0.5))):
        super(Block, self).__init__()

        self.health = 100
        self.world = world
        self.edges = edges
        self.pos = pos
        self.obj = utilities.loadObject(tile, depth=0, pos = self.pos)
        self.shape = shape 
Ejemplo n.º 12
0
 def makeChunk(self, pos, size):
     self.bgs.append(
         utilities.loadObject("stars",
                              depth=100,
                              scaleX=200,
                              scaleY=200.0,
                              pos=Point2(pos.x * worldsize.x,
                                         pos.y * worldsize.y)))
     genFillBox(self, Point2(5, 5), 3, 6, 'metalwalls')
     genBox(self, Point2(10, 5), 2, 2, 'metalwalls')
Ejemplo n.º 13
0
    def __init__(self,
                 world,
                 pos,
                 tile,
                 edges,
                 shape=BulletBoxShape(Vec3(0.5, 1.0, 0.5))):
        super(Block, self).__init__()

        self.health = 100
        self.world = world
        self.edges = edges
        self.pos = pos
        self.obj = utilities.loadObject(tile, depth=0, pos=self.pos)
        self.shape = shape
Ejemplo n.º 14
0
    def __init__(self, world, pos):
        super(Wall, self).__init__()
        self.health = 100

        shape = BulletBoxShape(Vec3(0.5,2.0,0.5))
        self.bnode = BulletRigidBodyNode()
        self.bnode.addShape(shape)
        self.np = utilities.app.render.attachNewNode(self.bnode)
        self.np.setPos(pos.x,20,pos.y)
        world.bw.attachRigidBody(self.bnode)

        self.obj = utilities.loadObject("wall", depth = 0)
        self.obj.reparentTo(self.np)
        self.obj.setScale(1)
Ejemplo n.º 15
0
def smaller(prefix, m, n):
    for i in range(m):
        fn1 = prefix + '_' + str(i + 1) + '.cpk'
        path = utilities.getPath(fn1)
        names, index, labels, attrs = utilities.loadObject(path)
        for j in range(n):
            nms = names[j * 100:(j + 1) * 100]
            idx = index[j * 100:(j + 1) * 100]
            lbs = labels[j * 100:(j + 1) * 100]
            ats = attrs[j * 100:(j + 1) * 100]
            fn2 = prefix + '_' + 's' + '_ ' + str(i * 5 + (j + 1)) + '.cpk'
            path = utilities.getPath(fn2)
            object = [nms, idx, lbs, ats]
            utilities.saveObject(object, path)
Ejemplo n.º 16
0
    def initialise(self):
        self.inventory["LightLaser"] = LightLaser(self.world, self)
        self.inventory["Blowtorch"] = Blowtorch(self.world, self)
        self.inventory["Grenade"] = Grenade(self.world, self)

        for i in self.inventory:
            self.inventory[i].initialise()

        self.currentItem = self.inventory["Blowtorch"]
        self.currentItem.equip()

        self.armNode = self.obj.attachNewNode("arm")
        self.armNode.setPos(0.20,0,0.08)
        self.arm = utilities.loadObject("arm", scaleX = 0.5,scaleY = 0.5, depth = -0.2)
        self.arm.reparentTo(self.armNode)
Ejemplo n.º 17
0
 def makeChunk(self, pos, size):
     self.bgs.append(utilities.loadObject("stars", depth=100, scaleX=200, scaleY=200.0, pos=Point2(pos.x*worldsize.x,pos.y*worldsize.y)))
     genFillBox(self, Point2(5,5), 3, 6, 'metalwalls')
     genBox(self, Point2(10,5), 2, 2, 'metalwalls')
Ejemplo n.º 18
0
 def __init__(self, world, player):
     super(Grenade, self).__init__(world, player)
     self.obj = utilities.loadObject("grenade", scaleX=1, scaleY=1)
     self.obj.hide()
Ejemplo n.º 19
0
 def __init__(self, world, posX, posY):
     super(Rail, self).__init__()
     self.obj = utilities.loadObject("rail", depth=20, scaleX=10.0, scaleY=1.0, pos=Point2(posX,posY))
Ejemplo n.º 20
0
 def __init__(self, world, player):
     super(Blowtorch, self).__init__(world, player)
     self.obj = utilities.loadObject("blowtorch", scaleX = 1, scaleY = 1, depth = -0.2)
     self.obj.hide()
Ejemplo n.º 21
0
 def __init__(self, world, player):
     super(LightLaser, self).__init__(world, player)
     self.obj = utilities.loadObject("lightlaser", scaleX = 1, scaleY = 2)
     self.obj.hide()
Ejemplo n.º 22
0
 def __init__(self, world, player):
     super(Grenade, self).__init__(world, player)
     self.obj = utilities.loadObject("grenade", scaleX = 1, scaleY = 2)
     self.obj.hide()
Ejemplo n.º 23
0
    def __init__(self, world, pos, hpr):
        super(Flame, self).__init__()

        self.shape = BulletBoxShape(Vec3(0.1, 0.05, 0.05))
        self.bnode = BulletRigidBodyNode()
        self.bnode.setMass(0.00001)
        self.bnode.addShape(self.shape)

        self.np = utilities.app.render.attachNewNode(self.bnode)

        self.remove = False

        self.world = world
        self.anim = list()
        self.anim.append(utilities.loadObject("flame1", depth=0))
        self.anim.append(utilities.loadObject("flame2", depth=0))
        self.anim.append(utilities.loadObject("flame3", depth=0))
        world.bw.attachRigidBody(self.bnode)

        self.curspr = 0
        self.livetime = 0
        self.delta = 0

        self.pos = pos
        self.pos.y = Flame.depth
        self.hpr = hpr
        self.vel = Point2()
        self.vel.x = cos(world.player.angle) * Flame.speed
        self.vel.y = sin(world.player.angle) * Flame.speed

        tv = Vec3(self.vel.x, 0, self.vel.y)
        # this makes the shot miss the target if the player has any velocity
        tv += world.player.bnode.getLinearVelocity()

        self.bnode.setLinearVelocity(tv)

        tv.normalize()

        # initial position of RB and draw plane
        self.np.setHpr(hpr)
        self.np.setPos(pos + tv / 2)

        self.bnode.setAngularFactor(Vec3(0, 0, 0))
        self.bnode.setLinearFactor(Vec3(1, 0, 1))
        self.bnode.setGravity(Vec3(0, 0, 0))

        #self.bnode.setCcdMotionThreshold(1e-7)
        #self.bnode.setCcdSweptSphereRadius(0.50)

        self.bnode.notifyCollisions(True)
        self.bnode.setIntoCollideMask(BitMask32.bit(1))
        self.bnode.setPythonTag("Entity", self)
        self.noCollideFrames = 4

        for a in self.anim:
            a.hide()
            a.reparentTo(self.np)
            a.setScale(0.25, 1, 0.25)
            a.setPos(0, -0.1, 0)

        self.obj = self.anim[self.curspr]
        self.obj.show()

        self.bnode.setPythonTag("entity", self)