示例#1
0
class fireSystem(NodePath):

    lifeSpanSeconds = 1
    lifeRemaining = 0

    isAlight = False

    def __init__(self, name, fireType):
        NodePath.__init__(self, "fire" + str(name))
        NodePath.setPythonTag(self, "fireSystem", self)
        self.setScale(1, 1, 1)

        self.fire = ParticleEffect()
        self.fire.loadConfig('fire.ptf')
        try:
            file = open(fireType + ".txt")
            lines = file.readlines()
            newFireColor = LColor()
            colorLine = lines[0].split(",")
            for i in range(4):
                newFireColor[i] = float(colorLine[i])
            self.fire.getParticlesList()[0].getRenderer().setColor(
                newFireColor)
            self.lifeSpanSeconds = float(lines[1])
            file.close()
        except IOError:
            print("Firetype not found")

        self.lifeRemaining = self.lifeSpanSeconds
        fireSphere = CollisionSphere(0, 0, 1.25, 2.5)
        self.collisionNodeName = "fire{}Collision".format(self.id)
        fireCollisionNode = CollisionNode(self.collisionNodeName)
        fireCollisionNode.addSolid(fireSphere)
        self.collision = self.attachNewNode(fireCollisionNode)
        base.cTrav.addCollider(self.collision, base.handler)

        self.fire.start(self, self)
        self.fire.softStop()
        self.burn = taskMgr.add(self.burnTask, "burnTask")

        self.notifier = CollisionHandlerEvent

    def burnTask(self, task):
        if self.isAlight:
            deltaTime = globalClock.getDt()
            self.lifeRemaining -= deltaTime
            if self.lifeRemaining <= 0:
                self.fire.softStop()
                self.isAlight = False
        return task.cont

    def ignite(self):
        self.isAlight = True
        self.lifeRemaining = self.lifeSpanSeconds
        self.fire.softStart()
示例#2
0
def init_player(self, left_btn, right_btn, player_number ,pos=(0,0,0), heading=0):
    color = (configs.COLORS_MAP[player_number][0])

    nodePath = loadObject()
    nodePath.setPos(pos)
    nodePath.setScale(configs.SCALE*0.004)
    nodePath.setColor(color)

    p = ParticleEffect()
    p.loadConfig('textures/flare.ptf')
    p.start(parent = nodePath, renderParent = render)
    p0 = p.getParticlesList()[0]
    p0.emitter.setRadiateOrigin(Point3(0.05*cos(heading* pi/180), 0.0, 0.05*sin(heading* pi/180)))
    p.setPos(0,-1,0)
    # p.setBin("unsorted", 0)
    # p.setDepthTest(False)
    p.setTwoSided(True)

    text= TextNode('text') 
    text.setText(str("%s" % player_number))
    text.setTextColor(color)
    text.setAlign(TextNode.ACenter)
    # text.font = self.font
    text3d = NodePath(text) 
    text3d.setTwoSided(True)
    text3d.setPos(nodePath, -1,-3,-4)
    text3d.reparentTo(render)
    circle = loadObject(tex='circle.png')
    circle.reparentTo(render)
    circle.setPos(nodePath, 0,-2,0)
    text3d.setScale(0.13)
    circle.setScale(0.09)
    text3d.setColorScale(color)
    circle.setColorScale(color)


    new_line, line_vertex, line_node = start_new_line(self, pos[0], pos[2], color)
    line_id = configs.ENTITY_ID
    configs.ENTITIES[configs.ENTITY_ID] = {'CATEGORY':'line', 'GEOM':new_line, 'VERTEX':line_vertex, "NODE": line_node}
    configs.ENTITY_ID += 1
    speed = configs.FORWARD_SPEED
    right_angle = configs.FORCE_RIGHT_ANGLE_TURN
    # print left_btn
    # print right_btn
    self.accept(("%s" % left_btn),     player_controls, [configs.ENTITY_ID, 'TURN_LEFT', 1])
    self.accept(("%s-up" % left_btn),  player_controls, [configs.ENTITY_ID, 'TURN_LEFT', 0])
    self.accept(("%s" % right_btn),     player_controls, [configs.ENTITY_ID, 'TURN_RIGHT', 1])
    self.accept(("%s-up" % right_btn),  player_controls, [configs.ENTITY_ID, 'TURN_RIGHT', 0])

    configs.ENTITIES[configs.ENTITY_ID] = {'CATEGORY':'player','ALIVE':True, 'NODE':nodePath,'PARTICLE_PARENT':p, 'PARTICLE':p0, 
        'HEADING':heading, 'CURRENT_LINE':line_id, 'TICKNESS':configs.SCALE, 'TURN_LEFT':0, 'TURN_RIGHT':0, 'COLOR':color, 
        'PLAYER_ID':text3d, 'CIRCLE_NODE':circle, 'LEFT_ARMED':True, 'RIGHT_ARMED':True, 'PLAYER_NUMBER': player_number, 'SPEED':speed,
        'RIGHT_ANGLE_TURN':right_angle }
    configs.ENTITY_ID += 1
示例#3
0
文件: dorf.py 项目: anossov/dorfdelf
class Dorf(DirectObject):
    idgen = count()

    def __init__(self, pos, world):
        self.id = next(Dorf.idgen)
        self.world = world
        self.node = loader.loadModel('media/models/dorfPH.egg')
        self.text = core.TextNode('dorf')
        self.text.setText('Dorf {}'.format(self.id))
        self.text.setAlign(core.TextNode.ACenter)
        self.text.setTextColor(1, 1, 0.5, 1)
        self.text.setShadow(0.1, 0.1)
        self.text.setShadowColor(0, 0, 0, 0.8)
        self.textnode = self.node.attachNewNode(self.text)
        self.textnode.setBillboardPointEye()
        self.textnode.setPos(0, 0, 1.1)
        self.textnode.setScale(0.4)
        self.textnode.setDepthWrite(False)
        self.textnode.setDepthTest(False)
        self.textnode.setShaderOff()
        self.x = int(pos.x)
        self.y = int(pos.y)
        self.z = 0
        self.next = None
        self.dir = (1, 0)

        taskMgr.doMethodLater(0.5, self.move, 'Move dorf')

        self.set_z(int(pos.z))
        self.node.setPos(pos.x, pos.y, 0)

        self.particles = ParticleEffect()
        self.particles.loadConfig('media/sparks.ptf')
        self.particles.reparentTo(self.node)

    def set_z(self, z):
        self.z = z
        messenger.send('entity-z-change', [self])

    def move(self, task):
        if self.next:
            self.x, self.y, z = self.next
            self.node.setPos(self.x, self.y, 0)
            if self.z != z:
                self.set_z(z)

        b = self.world.get_block(self.x, self.y, self.z)
        if b.is_ramp:
            self.node.setPos(self.x, self.y, 0.5)
        else:
            self.node.setPos(self.x, self.y, 0.0)

        if b.is_block:
            self.world.set_block(self.x, self.y, self.z, self.world.forms['Void'], 0, False)
            self.particles.setPos(0, 0, 0)
            self.particles.start()
            for p in self.particles.getParticlesList():
                p.induceLabor()
            #taskMgr.doMethodLater(1.0, self.particles.disable, 'stop particling', extraArgs=[])

        self.set_next()
        self.node.lookAt(self.next[0], self.next[1], 0)

        return task.again

    def set_next(self):
        x, y, z = self.x + self.dir[0], self.y + self.dir[1], self.z
        if (x, y, z) not in self.world or random.random() < 0.4:
            ds = [((dx, dy), (self.x + dx, self.y + dy, self.z))
                  for dx, dy in [(1, 0), (0, 1), (0, -1), (-1, 0)]]
            self.dir, np = random.choice([(d, n) for d, n in ds if n in self.world])
            x, y, z = np

        b = self.world.get_block(x, y, z)

        if b.is_void and not b.down.is_block:
            z -= 1

        self.next = (x, y, z)
示例#4
0
class Dorf(DirectObject):
    idgen = count()

    def __init__(self, pos, world):
        self.id = next(Dorf.idgen)
        self.world = world
        self.node = loader.loadModel('media/models/dorfPH.egg')
        self.text = core.TextNode('dorf')
        self.text.setText('Dorf {}'.format(self.id))
        self.text.setAlign(core.TextNode.ACenter)
        self.text.setTextColor(1, 1, 0.5, 1)
        self.text.setShadow(0.1, 0.1)
        self.text.setShadowColor(0, 0, 0, 0.8)
        self.textnode = self.node.attachNewNode(self.text)
        self.textnode.setBillboardPointEye()
        self.textnode.setPos(0, 0, 1.1)
        self.textnode.setScale(0.4)
        self.textnode.setDepthWrite(False)
        self.textnode.setDepthTest(False)
        self.textnode.setShaderOff()
        self.x = int(pos.x)
        self.y = int(pos.y)
        self.z = 0
        self.next = None
        self.dir = (1, 0)

        taskMgr.doMethodLater(0.5, self.move, 'Move dorf')

        self.set_z(int(pos.z))
        self.node.setPos(pos.x, pos.y, 0)

        self.particles = ParticleEffect()
        self.particles.loadConfig('media/sparks.ptf')
        self.particles.reparentTo(self.node)

    def set_z(self, z):
        self.z = z
        messenger.send('entity-z-change', [self])

    def move(self, task):
        if self.next:
            self.x, self.y, z = self.next
            self.node.setPos(self.x, self.y, 0)
            if self.z != z:
                self.set_z(z)

        b = self.world.get_block(self.x, self.y, self.z)
        if b.is_ramp:
            self.node.setPos(self.x, self.y, 0.5)
        else:
            self.node.setPos(self.x, self.y, 0.0)

        if b.is_block:
            self.world.set_block(self.x, self.y, self.z,
                                 self.world.forms['Void'], 0, False)
            self.particles.setPos(0, 0, 0)
            self.particles.start()
            for p in self.particles.getParticlesList():
                p.induceLabor()
            #taskMgr.doMethodLater(1.0, self.particles.disable, 'stop particling', extraArgs=[])

        self.set_next()
        self.node.lookAt(self.next[0], self.next[1], 0)

        return task.again

    def set_next(self):
        x, y, z = self.x + self.dir[0], self.y + self.dir[1], self.z
        if (x, y, z) not in self.world or random.random() < 0.4:
            ds = [((dx, dy), (self.x + dx, self.y + dy, self.z))
                  for dx, dy in [(1, 0), (0, 1), (0, -1), (-1, 0)]]
            self.dir, np = random.choice([(d, n) for d, n in ds
                                          if n in self.world])
            x, y, z = np

        b = self.world.get_block(x, y, z)

        if b.is_void and not b.down.is_block:
            z -= 1

        self.next = (x, y, z)
示例#5
0
    def setVehicle(self, model):
        '''
        Choose what vehicle the player has chosen. This method initializes all data of this vehicle
        '''
        self.cleanResources()

        self._notify.debug("Set new vehicle: %s" % model)

        # Load the attributes of the vehicle
        attributes = model.find("**/Attributes")
        if attributes.isEmpty():
            self._notify.warning("No Attribute-Node found")
        for tag in self._tags:
            value = attributes.getNetTag(tag[0])
            if value:
                self._notify.debug("%s: %s" % (tag[0], value))
                # translate the value if its a string
                if type(tag[2](value)) == str:
                    tag[1](_(tag[2](value)))
                else:
                    tag[1](tag[2](value))
            else:
                self._notify.warning("No value defined for tag: %s" % (tag[0]))

        self._weight = 10  # for testing purposes

        blowout = model.find("**/Blowout")
        if not blowout.isEmpty():
            self._notify.debug("Loading Blowout-Particles")
            for node in blowout.getChildren():
                particle = ParticleEffect()
                self._blowout.append(particle)
                particle.loadConfig('./data/particles/blowout_test.ptf')

                try:  # try to read out the particle scale
                    scale = float(node.getTag("scale"))
                except Exception:  # default is 0.5
                    scale = .5

                renderer = particle.getParticlesList()[0].getRenderer()
                renderer.setInitialXScale(scale)
                renderer.setInitialYScale(scale)

                particle.setLightOff()
                particle.start(node)
                particle.softStop()
        else:
            self._notify.warning("No Blowout-Node found")

        if self._model is not None:
            heading = self._model.getH()
            self._model.removeNode()
        else:
            heading = 160

        # display the attributes
        text = model.getParent().find("AttributeNode")
        if not text.isEmpty():
            node = text.find("name")
            if not node.isEmpty():
                node = node.node()
                node.setText(self._name)
                node.update()
                text.show()

            node = text.find("description")
            if not node.isEmpty():
                node = node.node()
                node.setText(self._name)
                node.update()
                text.show()

        self._model = model
        self._model.setPos(0, 0, 2)
        self._model.setHpr(heading, 0, 0)

        #        #Test
        #        plightCenter = NodePath( 'plightCenter' )
        #        plightCenter.reparentTo( render )
        #        self.interval = plightCenter.hprInterval(12, Vec3(360, 0, 0))
        #        self.interval.loop()
        #
        #        plight = PointLight('plight')
        #        plight.setColor(VBase4(0.8, 0.8, 0.8, 1))
        #        plight.setAttenuation(Vec3(1,0,0))
        #        plnp = plightCenter.attachNewNode(plight)
        #        plnp.setPos(5, 5, 10)
        #        render.setLight(plnp)
        #
        #        alight = AmbientLight('alight')
        #        alight.setColor(VBase4(0,0,0, 1))
        #        alnp = render.attachNewNode(alight)
        #        render.setLight(alnp)

        #        GlowTextur
        #        self.glowSize=10
        #        self.filters = CommonFilters(base.win, self._model)
        #        self.filters.setBloom(blend=(0,self.glowSize,0,0) ,desat=1, intensity=1, size='medium')
        #        tex = loader.loadTexture( 'data/textures/glowmap.png' )
        #        ts = TextureStage('ts')
        #        ts.setMode(TextureStage.MGlow)
        #        self._model.setTexture(ts, tex)

        # Initialize the physics-simulation for the vehicle
        self._physics_model = OdeBody(self._ode_world)
        self._physics_model.setPosition(self._model.getPos(render))
        self._physics_model.setQuaternion(self._model.getQuat(render))

        # Initialize the mass of the vehicle
        physics_mass = OdeMass()
        physics_mass.setBoxTotal(self._weight, 1, 1, 1)
        self._physics_model.setMass(physics_mass)

        # Initialize the collision-model of the vehicle
        # for use with blender models
        # try:
        # col_model = loader.loadModel("data/models/vehicles/%s.collision" %(self._model.getName()))
        # self.collision_model = OdeTriMeshGeom(self._ode_space, OdeTriMeshData(col_model, True))
        # self._notify.info("Loading collision-file: %s" %("data/models/vehicles/%s.collision" %(self._model.getName())))
        # for fast collisions
        # except:
        # self._notify.warning("Could not load collision-file. Using standard collision-box")
        # self.collision_model = OdeTriMeshGeom(self._ode_space, OdeTriMeshData(model, False))
        # self._collision_model = OdeBoxGeom(self._ode_space, 3,3,2)
        self._collision_model = OdeBoxGeom(self._ode_space, 3, 3, 2)
        self._collision_model.setBody(self._physics_model)
        self._collision_model.setCollideBits(7)
        self._collision_model.setCategoryBits(2)

        # Add collision-rays for the floating effect
        self._ray = CollisionRay(Vec3(5, 0, 0),
                                 Vec3(0, 0, -1),
                                 self._ode_space,
                                 parent=self._collision_model,
                                 collide_bits=0,
                                 length=20.0)
        # This one is used for the floating effect but also for slipstream
        self._frontray = CollisionRay(Vec3(0, 0, 0),
                                      Vec3(1, 0, 0),
                                      self._ode_space,
                                      parent=self._collision_model,
                                      collide_bits=0,
                                      length=15.0)
        # Overwrite variables for testing purposes
        self._grip_strength = 0.9
        self._track_grip = 0.2
        self._boost_strength = 1400
        self._control_strength = 2.5

        # Loading finished
        self._model_loading = False
示例#6
0
def init_player(self,
                left_btn,
                right_btn,
                player_number,
                pos=(0, 0, 0),
                heading=0):
    color = (configs.COLORS_MAP[player_number][0])

    nodePath = loadObject()
    nodePath.setPos(pos)
    nodePath.setScale(configs.SCALE * 0.004)
    nodePath.setColor(color)

    p = ParticleEffect()
    p.loadConfig('textures/flare.ptf')
    p.start(parent=nodePath, renderParent=render)
    p0 = p.getParticlesList()[0]
    p0.emitter.setRadiateOrigin(
        Point3(0.05 * cos(heading * pi / 180), 0.0,
               0.05 * sin(heading * pi / 180)))
    p.setPos(0, -1, 0)
    # p.setBin("unsorted", 0)
    # p.setDepthTest(False)
    p.setTwoSided(True)

    text = TextNode('text')
    text.setText(str("%s" % player_number))
    text.setTextColor(color)
    text.setAlign(TextNode.ACenter)
    # text.font = self.font
    text3d = NodePath(text)
    text3d.setTwoSided(True)
    text3d.setPos(nodePath, -1, -3, -4)
    text3d.reparentTo(render)
    circle = loadObject(tex='circle.png')
    circle.reparentTo(render)
    circle.setPos(nodePath, 0, -2, 0)
    text3d.setScale(0.13)
    circle.setScale(0.09)
    text3d.setColorScale(color)
    circle.setColorScale(color)

    new_line, line_vertex, line_node = start_new_line(self, pos[0], pos[2],
                                                      color)
    line_id = configs.ENTITY_ID
    configs.ENTITIES[configs.ENTITY_ID] = {
        'CATEGORY': 'line',
        'GEOM': new_line,
        'VERTEX': line_vertex,
        "NODE": line_node
    }
    configs.ENTITY_ID += 1
    speed = configs.FORWARD_SPEED
    right_angle = configs.FORCE_RIGHT_ANGLE_TURN
    # print left_btn
    # print right_btn
    self.accept(("%s" % left_btn), player_controls,
                [configs.ENTITY_ID, 'TURN_LEFT', 1])
    self.accept(("%s-up" % left_btn), player_controls,
                [configs.ENTITY_ID, 'TURN_LEFT', 0])
    self.accept(("%s" % right_btn), player_controls,
                [configs.ENTITY_ID, 'TURN_RIGHT', 1])
    self.accept(("%s-up" % right_btn), player_controls,
                [configs.ENTITY_ID, 'TURN_RIGHT', 0])

    configs.ENTITIES[configs.ENTITY_ID] = {
        'CATEGORY': 'player',
        'ALIVE': True,
        'NODE': nodePath,
        'PARTICLE_PARENT': p,
        'PARTICLE': p0,
        'HEADING': heading,
        'CURRENT_LINE': line_id,
        'TICKNESS': configs.SCALE,
        'TURN_LEFT': 0,
        'TURN_RIGHT': 0,
        'COLOR': color,
        'PLAYER_ID': text3d,
        'CIRCLE_NODE': circle,
        'LEFT_ARMED': True,
        'RIGHT_ARMED': True,
        'PLAYER_NUMBER': player_number,
        'SPEED': speed,
        'RIGHT_ANGLE_TURN': right_angle
    }
    configs.ENTITY_ID += 1