当前位置: 首页>>代码示例>>Python>>正文


Python ParticleEffect.setHpr方法代码示例

本文整理汇总了Python中direct.particles.ParticleEffect.ParticleEffect.setHpr方法的典型用法代码示例。如果您正苦于以下问题:Python ParticleEffect.setHpr方法的具体用法?Python ParticleEffect.setHpr怎么用?Python ParticleEffect.setHpr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在direct.particles.ParticleEffect.ParticleEffect的用法示例。


在下文中一共展示了ParticleEffect.setHpr方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Vehicle

# 需要导入模块: from direct.particles.ParticleEffect import ParticleEffect [as 别名]
# 或者: from direct.particles.ParticleEffect.ParticleEffect import setHpr [as 别名]
class Vehicle(Actor):

    BACKWARDS = -1
    STOPPED = 0
    FORWARDS = 1

    def __init__(self, modelStr, driveStr, world):
        Actor.__init__(self, modelStr, {"drive": driveStr})
        self.world = world
        self.setScale(0.005)
        self.setH(180)
        self.reparentTo(render)
        self.prevtime = 0
        # some movement stats
        self.accel = 40.0
        self.deccel = -40.0
        self.bkwdsAccel = -10.0
        self.speed = 0.0
        self.maxSpeed = 100.0
        self.maxBkwdsSpeed = -40.0
        self.direction = Vehicle.STOPPED
        self.isTurning = False
        self.turnFactor = 4.0

    def setupBooster(self):
        # Booster Stuff
        self.boosters = ParticleEffect()
        self.boosterStartTime = -1
        self.boosterLight = PointLight("boostlight")
        self.boosterLight.setColor(VBase4(0, 0, 0, 1))
        self.boosterLight.setAttenuation(Point3(0, 0.001, 0.001))
        self.world.boosterLightNP = self.attachNewNode(self.boosterLight)
        self.world.boosterLightNP.setPos(0, 500, 275)
        self.world.boosterLightNP.setHpr(180, 90, 0)
        self.world.boosterLightNP.setScale(200)
        self.world.setWorldLight(self)

    def addKeyMap(self, keyMap):
        self.keyMap = keyMap
        keyMap["boost"] = 0

    def move(self, task):
        elapsed = task.time - self.prevtime

        startpos = self.getPos()  # Initial position
        wasMoving = self.isTurning or (self.direction != Vehicle.STOPPED)

        if self.speed > 0:
            self.direction = Vehicle.FORWARDS
        if self.speed == 0:
            self.direction = Vehicle.STOPPED
        if self.speed < 0:
            self.direction = Vehicle.BACKWARDS

        # Deal with turning
        if self.keyMap["left"]:
            self.setH(self.getH() + elapsed * self.speed * self.turnFactor)
            if self.direction != Vehicle.STOPPED:
                self.isTurning = True
        elif self.keyMap["right"]:
            self.setH(self.getH() - elapsed * self.speed * self.turnFactor)
            if self.direction != Vehicle.STOPPED:
                self.isTurning = True
        else:
            self.isTurning = False

        # Accelerating
        if (self.keyMap["forward"] and not self.keyMap["backwards"]) or self.keyMap["boost"]:
            if self.direction == Vehicle.BACKWARDS:
                newSpeed = self.speed + (self.accel - self.deccel) * elapsed
            else:
                newSpeed = self.speed + self.accel * elapsed
            if newSpeed > self.maxSpeed:
                self.speed = self.maxSpeed
            else:
                self.speed = newSpeed

        # Braking/Reversing
        if self.keyMap["backwards"] and not (self.keyMap["forward"] or self.keyMap["boost"]):
            if self.direction == Vehicle.FORWARDS:
                newSpeed = self.speed + (self.bkwdsAccel + self.deccel) * elapsed
            else:
                newSpeed = self.speed + self.bkwdsAccel * elapsed
            if newSpeed < self.maxBkwdsSpeed:
                self.speed = self.maxBkwdsSpeed
            else:
                self.speed = newSpeed

        # Even if no key is held down, we keep moving!
        if (not self.keyMap["forward"] and not self.keyMap["backwards"] and not self.keyMap["boost"]) or (
            self.keyMap["forward"] and self.keyMap["backwards"] and self.keyMap["boost"]
        ):
            if self.direction == Vehicle.FORWARDS:
                newSpeed = self.speed + self.deccel * elapsed
            else:
                newSpeed = self.speed - self.deccel * elapsed

            if self.direction == Vehicle.FORWARDS:
                if newSpeed < 0:
                    self.speed = 0
#.........这里部分代码省略.........
开发者ID:Splime,项目名称:ProjectThree,代码行数:103,代码来源:vehicle.py

示例2: Enemy

# 需要导入模块: from direct.particles.ParticleEffect import ParticleEffect [as 别名]
# 或者: from direct.particles.ParticleEffect.ParticleEffect import setHpr [as 别名]
class Enemy():
    def __init__(self, pos, index, app, manager, level, style):
        self.position = pos
        self.app = app
        self.np = app.render.attachNewNode("enemy%d" % index)

        if style == 1:
            self.np.setColorScale(1.0, 1.0, 1.0, 1.0)
            self.movespeed = 2.5
            self.max_movespeed = 30
        else:
            self.movespeed = 0.5
            self.max_movespeed = 25

        if style == 2:
            self.activate_delay = 0.01
            self.np.setColorScale(0.6, 1.0, 1.0, 1.0)
        else:
            self.activate_delay = 0.1

        if style == 3:
            self.hp = 50 * level
            self.np.setColorScale(0.0, 1.0, 0.5, 1.0)
        else:
            self.hp = 100 * level

        if style == 4:
            self.damage = 20
            self.np.setColorScale(1.0, 1.0, 0.0, 1.0)
        else:
            self.damage = 10

        self.dead = 0.0
        self.level = level
        self.style = style
        self.particle_clean = False

        # this allows us to detach the instance nodepath
        # on death, but keep one with no model to attach particle effects
        self.dnp = app.render.attachNewNode("enemy_top%d" % index)

        self.np.setPos(self.position)

        self.np.setHpr(uniform(1,360),0,0)
        self.np.setScale(level)

        colsize = 3.0
        self.cn = self.np.attachNewNode(CollisionNode('enemy_cn_%d' % index))
        self.cs0 = CollisionSphere(0.0, colsize/2,0.0,colsize)
        self.cs1 = CollisionSphere(0.0, -colsize/2,0.0,colsize)
        self.cs2 = CollisionSphere(0.0, -colsize/3*4,0.0,colsize/2)
        self.cn.node().addSolid(self.cs0)
        self.cn.node().addSolid(self.cs1)
        self.cn.node().addSolid(self.cs2)
        #self.cn.show() # debug

        self.cqueue = CollisionHandlerQueue()
        app.cTrav.addCollider(self.cn, self.cqueue)

        self.cn.node().setIntoCollideMask(BitMask32(0x01))
        self.cn.node().setFromCollideMask(BitMask32(0x10))

        self.last_activated = 0.0

        manager.add_instance(self)


        # name, nodepath, mass, move_force, max_force
        self.ai_char = AICharacter('enemy_ai_%d' % index, self.np, 100, self.movespeed, self.max_movespeed)
        app.ai_world.addAiChar(self.ai_char)
        self.ai_b = self.ai_char.getAiBehaviors()
        self.ai_b.pursue(app.player.np)

        self.load_particle_config()
    
    def update(self, time):

        a = 0
        # Handle collsions
        for i in range(self.cqueue.getNumEntries()):
           collided_name = self.cqueue.getEntry(i).getIntoNodePath().getName()
           #handle bullets
           if collided_name[0] == 'b': 
               bullet = self.app.bullet_manager.get_bullet(collided_name)
               bullet.apply_effect(self)
               self.app.bullet_manager.remove_bullet(collided_name)

        if self.cqueue.getNumEntries() != 0:
            self.np.setColorScale(1.0, self.hp / 100.0, self.hp / 100.0, 1.0)
       
        """
        desired = self.app.player.position - self.np.getPos()
        angle = degrees(atan2(desired.y, desired.x))
        
        hpr = self.np.getHpr()
        if hpr.x > 360:
            hpr.x = hpr.x - 360
        if hpr.x < -360:
            hpr.x = hpr.x + 360

#.........这里部分代码省略.........
开发者ID:michaeltchapman,项目名称:alem,代码行数:103,代码来源:enemy.py

示例3: Vehicle

# 需要导入模块: from direct.particles.ParticleEffect import ParticleEffect [as 别名]
# 或者: from direct.particles.ParticleEffect.ParticleEffect import setHpr [as 别名]

#.........这里部分代码省略.........
        #print "Old speed = %i, New speed = %i"%(self.speedClass, newSpeed)
        if newSpeed != self.speedClass:
            self.speedClass = newSpeed
            if self.speedClass == Vehicle.LOW:
                self.mediumSound.stop()
                self.highSound.stop()
                self.medhighSound.stop()
                self.lowSound.play()
            elif self.speedClass == Vehicle.MEDIUM:
                self.lowSound.stop()
                self.highSound.stop()
                self.medhighSound.stop()
                self.mediumSound.play()
            elif self.speedClass == Vehicle.MEDHIGH:
                self.lowSound.stop()
                self.highSound.stop()
                self.mediumSound.stop()
                self.medhighSound.play()
            else:
                self.mediumSound.stop()
                self.lowSound.stop()
                self.medhighSound.stop()
                self.highSound.play()
    
    def setupBooster(self):
        #Booster Stuff
        self.boosters = ParticleEffect()
        self.boosterStartTime = -1
        self.boosterLight = PointLight('boostlight')
        self.boosterLight.setColor(VBase4(0,0,0,1))
        self.boosterLight.setAttenuation(Point3(0,0.001,0.001))
        self.world.boosterLightNP = self.attachNewNode(self.boosterLight)
        self.world.boosterLightNP.setPos(0, 20, 2)
        self.world.boosterLightNP.setHpr(180, 90, 0)
        #self.world.setWorldLight(self)
    
    def addKeyMap(self, keyMap):
        self.keyMap = keyMap
        keyMap["boost"] = 0
        
    def rampInterval(self, t, start, end):
        self.setP(((end[0] - start[0]) * (t / 100)) + start[0])
        self.setR(((end[1] - start[1]) * (t / 100)) + start[1])
        
    #Move: Deals with the frame-by-frame stuff
    def move(self, task):
        elapsed = task.time - self.prevtime
        startpos = self.getPos() #Initial position
        wasMoving = self.isTurning or (self.direction != Vehicle.STOPPED)
        
        if self.speed > 0:
            self.direction = Vehicle.FORWARDS
        if self.speed == 0:
            self.direction = Vehicle.STOPPED
        if self.speed < 0:
            self.direction = Vehicle.BACKWARDS
        
        #Deal with turning
        if self.keyMap["left"]:
            self.setH(self.getH() + elapsed * self.speed * self.turnFactor)
            if self.direction != Vehicle.STOPPED:
                self.isTurning = True
        elif self.keyMap["right"]:
            self.setH(self.getH() - elapsed * self.speed * self.turnFactor)
            if self.direction != Vehicle.STOPPED:
                self.isTurning = True
开发者ID:Splime,项目名称:ProjectThree,代码行数:70,代码来源:vehicle.py

示例4: Lvl03

# 需要导入模块: from direct.particles.ParticleEffect import ParticleEffect [as 别名]
# 或者: from direct.particles.ParticleEffect.ParticleEffect import setHpr [as 别名]

#.........这里部分代码省略.........
        self.playerModel2.setScale(.6)
        self.playerModel2.setH(0)
        
        # ** Position player at center of the field with it lying directly above the field. ** #
        
        self.playerModel2.setPos(196,0,2.0)

    def reset(self):
	self.an1.getPhysicsObject().setVelocity(Vec3(0,0,0))
	self.an2.getPhysicsObject().setVelocity(Vec3(0,0,0))
	self.an1.getPhysicsObject().setPosition(Point3(0,0,11.76))
	self.an2.getPhysicsObject().setPosition(Point3(196,0,22.0))
	
	self.playerModel.setH(90)
	self.playerModel.detachNode()
	self.playerModel.setPos(0,0,1.76)
	self.anp.setFluidPos(Point3(0,0,1.76))
	self.playerModel.reparentTo(self.anp)
	
	self.playerModel2.setH(0)
	self.playerModel2.detachNode()
	self.playerModel2.setPos(196,0,22.0)
	self.anp2.setFluidPos(Point3(196,0,22.0))
	self.playerModel2.reparentTo(self.anp2)

    def setupLighting(self):
        ambientLight = AmbientLight('ambientLight')
        ambientLight.setColor(Vec4(0.55,0.55,0.55,1.0))
        ambientLightNP = render.attachNewNode(ambientLight)
        render.setLight(ambientLightNP)
        dirLight = DirectionalLight('dirLight')
        dirLight.setColor(Vec4(0.6,0.6,0.6,1))
        dirLightNP = render.attachNewNode(dirLight)
        dirLightNP.setHpr(Vec3(0.0,-26.0,0.0))
        render.setLight(dirLightNP)
        
    def setupIntervals(self):
        self.charWalk1l = self.playerModel.actorInterval("walk")
        self.charWalk1l.loop( )
        self.charWalk1l.pause( )
        
        self.charWalk1r = self.playerModel.actorInterval("walk")
        self.charWalk1r.loop( )
        self.charWalk1r.pause( )
        
        self.charWalk2l = self.playerModel2.actorInterval("walk2")
        self.charWalk2l.loop( )
        self.charWalk2l.pause( )
        
        self.charWalk2r = self.playerModel2.actorInterval("walk2")
        self.charWalk2r.loop( )
        self.charWalk2r.pause( )
        
        self.jump1 = self.playerModel.actorInterval("jump")
        self.jump1.loop()
        self.jump1.pause()
        
        self.jump2 = self.playerModel2.actorInterval("jump2")
        self.jump2.loop()
        self.jump2.pause()
        
        self.climb1 = self.playerModel.actorInterval("climb")
        self.climb1.loop()
        self.climb1.pause()
        
        self.climb2 = self.playerModel2.actorInterval("climb2")
开发者ID:CarlosPlusPlus,项目名称:rpi-undergrad,代码行数:70,代码来源:LVL03.py

示例5: World

# 需要导入模块: from direct.particles.ParticleEffect import ParticleEffect [as 别名]
# 或者: from direct.particles.ParticleEffect.ParticleEffect import setHpr [as 别名]

#.........这里部分代码省略.........
        if self.cameraIndex == len(self.cameraPositions):
            self.cameraIndex = 0
        self.cameraMove=LerpPosHprInterval(camera,
                                            .7, 
                                            self.cameraPositions[self.cameraIndex][0], 
                                            self.cameraPositions[self.cameraIndex][1],
                                            camera.getPos(), 
                                            camera.getHpr())
        self.cameraMove.start()
     
    def loadModels(self):
        """loads models into the world"""
        #eat no longer exists? Phooey
        
        self.flameLights = []
        shadowcam = Spotlight('shadowlight')
        shadowcam.setColor(VBase4(0,0,0,1))
        lens = PerspectiveLens()
        shadowcam.setLens(lens)
        shadowcam.setAttenuation(Point3(0, 0.001, 0.001))
        shadowNP = self.player.attachNewNode(shadowcam)
        shadowNP.setPos(0, -1400, 450)
        shadowNP.lookAt(self.player)
        shadowNP.setScale(200)
        shadowNP.node().setShadowCaster(True)
        self.flameLights.append((shadowcam, shadowNP))
        
        for i in range(2):
            slight = PointLight('plight')
            slight.setColor(VBase4(0, 0, 0, 1))
            slight.setAttenuation(Point3(0, 0.001, 0.001))
            slnp = self.player.attachNewNode(slight)
            slnp.setPos(0, -750 - (950 * i), 450)
            slnp.setHpr(180, 0, 0)
            slnp.setScale(200)
            self.flameLights.append((slight, slnp))
        
        self.player.setupBooster()
        
        #self.env = loader.loadModel("models/environment")
        #self.env.reparentTo(render)
        #self.env.setScale(.25)
        #self.env.setPos(-8, 42, 0)
        self.env = loader.loadModel("models/terrain2")      
        self.env.reparentTo(render)
        self.env.setPos(0,0,0)
        
        self.setWorldLight(self.env)
        
        #load targets
        self.targets = []
        for i in range (10):
            target = loader.loadModel("smiley")
            target.setScale(.5)
            target.setPos(random.uniform(-20, 20), random.uniform(-15, 15), 2)
            target.reparentTo(self.targetRoot)
            self.targets.append(target)
            self.setWorldLight(target)
        
    def setupLights(self):
        #ambient light
        self.ambientLight = AmbientLight("ambientLight")
        #four values, RGBA (alpha is largely irrelevent), value range is 0:1
        self.ambientLight.setColor((.10, .10, .10, 1))
        self.ambientLightNP = render.attachNewNode(self.ambientLight)
        #the nodepath that calls setLight is what gets illuminated by the light
开发者ID:Splime,项目名称:ProjectThree,代码行数:70,代码来源:tutorial8.py

示例6: World

# 需要导入模块: from direct.particles.ParticleEffect import ParticleEffect [as 别名]
# 或者: from direct.particles.ParticleEffect.ParticleEffect import setHpr [as 别名]
class World(DirectObject):
    def __init__(self):
        self.winprops=WindowProperties()
        self.winprops.setCursorFilename(Filename.binaryFilename("question-icon.ico"))
        
        base.win.setClearColorActive(True)
        base.win.setClearColor(VBase4(0, 0, 0, 1))
        
        base.win.requestProperties(self.winprops) 
        self.enemyLights = []
        self.cameraPositions = [((0, 95, 75), (180, -27, 0)),((0, 55, 25), (180, -15, 0)),((0, -55, 25), (0, -15, 0))]
        self.cameraIndex = 0
        base.disableMouse()
        base.enableParticles()
        self.setupLights()
        self.setupPicking()
        #Prepare the vehicular manslaughter!
        self.boosterLightNP = None
        self.flameLights = None
        self.player = Vehicle("ralph_models/vampire_car", "ralph_models/vampire_car", self, "player")

        self.finalGas = None

        self.livesFrame = DirectFrame(frameColor=(0, 0, 0, 0), parent = base.a2dTopLeft)

        self.livesSprites = list()
        for i in range(0,self.player.health):
            sprite = OnscreenImage(image = 'images/healthicon.png', parent = self.livesFrame, scale = 0.08, pos = (0.2*i+0.1,0,-0.1))
            sprite.setTransparency(TransparencyAttrib.MAlpha)
            self.livesSprites.append(sprite)

        self.progressFrame = DirectFrame(frameColor=(0, 0, 0, 0), parent = base.a2dpTopRight)
        gasIcon = OnscreenImage(image = 'images/gas_icon.png', parent = self.progressFrame, scale = 0.04, pos = (-1,0,-0.05))
        # gasIcon.reparentTo(aspect2d)
        gasIcon.setTransparency(TransparencyAttrib.MAlpha)
                    
        # gasBar = OnscreenImage(image = 'images/gas_bar.png', parent = self.progressFrame, scale = 0.4)#, pos = (-0.9,0,-0.05))
        self.gasMax = DirectFrame(frameColor=(.133, .149, .149, 1),frameSize=(-1, 1, -1, 1), parent = self.progressFrame, scale = (0.432,1,0.055625), pos = (-.5,0,-0.04))
        self.gasLevel = DirectFrame(frameColor=(.433, .149, .149, 1),frameSize=(-1, -1, -1, 1), parent = self.progressFrame, scale = (0.432,1,0.055625), pos = (-.5,0,-0.04))
        gasBar = OnscreenImage(image = 'images/gas_bar_border.png', scale = (1,1,.9), pos = (-.0005,0,-0.04))
        gasBar.reparentTo(self.gasLevel)
        gasBar.setTransparency(TransparencyAttrib.MAlpha)

        timeBar = OnscreenImage(image = 'images/time_bar.png', parent = self.progressFrame, scale = (0.44,1,0.0525), pos = (-.47,0,-0.15))
        self.timePointer = OnscreenImage(image = 'images/time_bar_marker.png', parent = timeBar, scale = (0.05, 0, .2222), pos = (-.83,0,-0.15))
        # self.timePointer = OnscreenImage(image = 'images/time_bar_marker.png', parent = self.timeBar, scale = (0.44,1,0.0525), pos = (-.47,0,-0.2))
        timeBar.setTransparency(TransparencyAttrib.MAlpha)


        taskMgr.add(self.updateGasBar, "Update gas")

        self.loadModels()
        self.player.setPos(0,0,0)
        self.setupIntervals()
        camera.reparentTo(self.player)
        camera.setPos(self.cameraPositions[0][0][0],self.cameraPositions[0][0][1],self.cameraPositions[0][0][2])
        camera.setHpr(self.cameraPositions[0][1][0],self.cameraPositions[0][1][1],self.cameraPositions[0][1][2])
        self.setupCollisions()
        render.setShaderAuto() #you probably want to use this
        self.keyMap = {"left":0, "right":0, "forward":0, "backwards":0}
        taskMgr.add(self.player.move, "moveTask")
        
        #Give the vehicle direct access to the keyMap
        self.player.addKeyMap(self.keyMap)
        
        #Player Death
        taskMgr.add(self.deathChecker, "deathTask")
        
        #Sounds!
        self.loadSounds()
        self.currIcon = ""
        self.prevtime = 0
        self.isMoving = False
        self.accept("escape", sys.exit)
        
        self.accept("arrow_up", self.setKey, ["forward", 1])
        self.accept("w", self.setKey, ["forward", 1])
        self.accept("arrow_right", self.setKey, ["right", 1])
        self.accept("d", self.setKey, ["right", 1])
        self.accept("arrow_left", self.setKey, ["left", 1])
        self.accept("a", self.setKey, ["left", 1])
        self.accept("arrow_down", self.setKey, ["backwards", 1])
        self.accept("s", self.setKey, ["backwards", 1])
        
        self.accept("arrow_up-up", self.setKey, ["forward", 0])
        self.accept("w-up", self.setKey, ["forward", 0])
        self.accept("arrow_right-up", self.setKey, ["right", 0])
        self.accept("d-up", self.setKey, ["right", 0])
        self.accept("arrow_left-up", self.setKey, ["left", 0])
        self.accept("a-up", self.setKey, ["left", 0])
        self.accept("arrow_down-up", self.setKey, ["backwards", 0])
        self.accept("s-up", self.setKey, ["backwards", 0])
        
        self.accept("mouse1", self.startShoot)
        self.accept("mouse1-up", self.stopShoot)
        self.accept("mouse3", self.startDrain )
        self.accept("mouse3-up" , self.stopDrain)
        
        self.accept("tab", self.shiftCamera)   
        self.accept("space", self.player.startBoosters)
#.........这里部分代码省略.........
开发者ID:Splime,项目名称:ProjectThree,代码行数:103,代码来源:world.py


注:本文中的direct.particles.ParticleEffect.ParticleEffect.setHpr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。