コード例 #1
0
    def createCircularObstacle(self, pos, obstacleIndex):
        """Create one physics obstacle. Returns a nodePath"""
        self.notify.debug("create obstacleindex %s" % (obstacleIndex))

        geom = OdeSphereGeom(self.space, IceGameGlobals.TireRadius)
        geom.setCollideBits(self.allTiresMask)  # we only collide against tires
        geom.setCategoryBits(self.obstacleMask)
        self.space.setCollideId(geom, self.obstacleCollideId)

        #tireModel = loader.loadModel('phase_3/models/misc/sphere')
        tireModel = loader.loadModel(
            "phase_4/models/minigames/ice_game_tirestack")

        # assuming it has a radius of 1
        tireHeight = 1
        #tireModel.setScale(IceGameGlobals.TireRadius, IceGameGlobals.TireRadius,  IceGameGlobals.TireRadius)
        #tireModel.setZ( 0 - IceGameGlobals.TireRadius + (tireHeight /2.0))
        #tireModel.setZ(IceGameGlobals.TireRadius)
        tireModel.setPos(pos)
        #tireModel.setColor(0.5,0.5,0.5)
        tireModel.reparentTo(render)
        geom.setPosition(tireModel.getPos())

        # the real assets are set at Z zero
        tireModel.setZ(0)
        return tireModel
コード例 #2
0
    def loadPlanet(self):
        self.planet = loader.loadModel('planet.bam')
        self.planet.setPos(tupleToVec3(Game.PLANET_POSITION))
        self.planet.setScale(20)
        self.planet.reparentTo(render)

        self.planetCollGeom = OdeSphereGeom(20)
コード例 #3
0
 def createBallGeom(self, modelNode, ballBody, space):
     ballGeom = OdeSphereGeom(space, 1)
     ballGeom.setCollideBits(BitMask32(0x2))
     ballGeom.setCategoryBits(BitMask32(0x1))
     ballGeom.setBody(ballBody)
     space.setSurfaceType(ballGeom, SurfaceType.BALL)
     return ballGeom
コード例 #4
0
 def createCircularObstacle(self, pos, obstacleIndex):
     self.notify.debug('create obstacleindex %s' % obstacleIndex)
     geom = OdeSphereGeom(self.space, IceGameGlobals.TireRadius)
     geom.setCollideBits(self.allTiresMask)
     geom.setCategoryBits(self.obstacleMask)
     self.space.setCollideId(geom, self.obstacleCollideId)
     tireModel = loader.loadModel('phase_4/models/minigames/ice_game_tirestack')
     tireHeight = 1
     tireModel.setPos(pos)
     tireModel.reparentTo(render)
     geom.setPosition(tireModel.getPos())
     tireModel.setZ(0)
     return tireModel
コード例 #5
0
    def createTire(self, tireIndex):
        if tireIndex < 0 or tireIndex >= len(self.tireMasks):
            self.notify.error('invalid tireIndex %s' % tireIndex)

        self.notify.debug('create tireindex %s' % tireIndex)
        zOffset = 0
        body = OdeBody(self.world)
        mass = OdeMass()
        mass.setSphere(self.tireDensity, IceGameGlobals.TireRadius)
        body.setMass(mass)
        body.setPosition(IceGameGlobals.StartingPositions[tireIndex][0],
                         IceGameGlobals.StartingPositions[tireIndex][1],
                         IceGameGlobals.StartingPositions[tireIndex][2])
        body.setAutoDisableDefaults()
        geom = OdeSphereGeom(self.space, IceGameGlobals.TireRadius)
        self.space.setSurfaceType(geom, self.tireSurfaceType)
        self.space.setCollideId(geom, self.tireCollideIds[tireIndex])
        self.massList.append(mass)
        self.geomList.append(geom)
        geom.setCollideBits(self.allTiresMask | self.wallMask | self.floorMask
                            | self.obstacleMask)
        geom.setCategoryBits(self.tireMasks[tireIndex])
        geom.setBody(body)
        if self.notify.getDebug():
            self.notify.debug('tire geom id')
            geom.write()
            self.notify.debug(' -')

        if self.canRender:
            testTire = render.attachNewNode('tire holder %d' % tireIndex)
            smileyModel = NodePath()
            if not smileyModel.isEmpty():
                smileyModel.setScale(IceGameGlobals.TireRadius)
                smileyModel.reparentTo(testTire)
                smileyModel.setAlphaScale(0.5)
                smileyModel.setTransparency(1)

            testTire.setPos(IceGameGlobals.StartingPositions[tireIndex])
            tireModel = loader.loadModel(
                'phase_4/models/minigames/ice_game_tire')
            tireHeight = 1
            tireModel.setZ(-(IceGameGlobals.TireRadius) + 0.01)
            tireModel.reparentTo(testTire)
            self.odePandaRelationList.append((testTire, body))
        else:
            testTire = None
            self.bodyList.append((None, body))
        return (testTire, body, geom)
コード例 #6
0
 def __init__(
         self,
         name=NAME_DEFAULT,
         pos=POS_DEFAULT,
         heading=HEADING_DEFAULT,
         vel=VEL_DEFAULT,
         acc=ACC_DEFAULT  # player controlled acceleration. Can be 0.0 - 1.0
 ):
     """@param name string"""
     self.name = name
     self.pos = pos
     self.vel = vel
     self.acc = acc
     self.heading = heading
     self.rotateLeft = False
     self.rotateRight = False
     self.visualNode = self.createVisualNode(self.pos)
     self.bullets = []
     self.collisionHandler = colHandler
     self.collisions = []
     self.collisionSphere = OdeSphereGeom(4)
     self.collisionSphere.setCategoryBits(BitMask32(0xffffffff))
     self.collisionSphere.setCollideBits(BitMask32(0xffffffff))
     self.collisionSphere.setPosition(pos[0], pos[1], 0)
     self.forces = []
     self.mass = 1.0
     self.health = Ship.HEALTH
     self.isAlive = True
     self.shootingSound = loader.loadSfx('anti_tank_gun_single_shot.mp3')
     self.destroySound = loader.loadSfx('large_explosion.mp3')
     self.bulletHitSound = loader.loadSfx(
         'explosion_loud_internal_explosion_very_reverberant.mp3')
     self.collisionSound = loader.loadSfx('car_door_close.mp3')
     self.bulletParent = NodePath("Bullet Parent")
     self.bulletParent.reparentTo(render)
     self.bulletAmbientLight = AmbientLight('Bullet Light')
     self.bulletAmbientLight.setColor(Vec4(.0, .1, .2, .0))
     lightnode = render.attachNewNode(self.bulletAmbientLight)
     self.bulletParent.setLight(lightnode)
コード例 #7
0
    def shoot(self):
        # TODO: add proper unit tests!
        angle = self.heading * math.pi / 180.0
        headingX = math.cos(angle)
        headingY = math.sin(angle)
        offset = Vec3(headingX, headingY, 0) * Ship.BULLET_OFFSET
        shipPos = self.getPos()
        bulletPos = (offset[0] + shipPos[0], offset[1] + shipPos[1], offset[2])

        bulletVisual = loader.loadModel("bullet.bam")
        bulletVisual.setPos(tupleToVec3(bulletPos))
        bulletVisual.setHpr(tupleToVec3((self.heading + 90, 180)))
        bulletVisual.setScale(1.5)
        bulletVisual.reparentTo(self.bulletParent)

        # Create physics for bullet
        collisionSphere = OdeSphereGeom(1.5)
        collisionSphere.setCategoryBits(BitMask32(0xffffffff))
        collisionSphere.setCollideBits(BitMask32(0xffffffff))
        collisionSphere.setPosition(bulletPos[0], bulletPos[1], bulletPos[2])

        shipVel = self.getVel()

        bullet = {
            'vel': (headingX * Ship.BULLET_SPEED +
                    shipVel[0] / Ship.BULLET_SHIP_SPEED_CORRELATION,
                    headingY * Ship.BULLET_SPEED +
                    shipVel[1] / Ship.BULLET_SHIP_SPEED_CORRELATION),
            'visual':
            bulletVisual,
            'physical':
            collisionSphere,
            'isAlive':
            True,
            'timeToLive':
            Ship.BULLET_MAX_LIFE_TIME
        }
        self.bullets.append(bullet)
        self.shootingSound.play()
コード例 #8
0
    def __init__(self,
                 world,
                 parent,
                 color,
                 pos,
                 dir,
                 radius,
                 density,
                 posParent=None):
        GameObject.__init__(self, world)

        self.node = parent.attachNewNode("")
        if posParent == None:
            self.node.setPos(*pos)
        else:
            self.node.setPos(posParent, *pos)
        self.node.setColor(*color)
        self.node.setScale(radius)
        self.node.lookAt(self.node, *dir)
        self.parent = parent

        self.color = color
        self.scale = radius

        self.model = loader.loadModel("models/smiley.egg")
        self.model.reparentTo(self.node)

        self.mass = OdeMass()
        self.mass.setSphere(density, radius)
        self.body = OdeBody(world.world)
        self.body.setMass(self.mass)
        self.body.setPosition(self.node.getPos())
        self.body.setQuaternion(self.node.getQuat())
        self.body.setData(self)
        self.geom = OdeSphereGeom(world.space, radius)
        self.geom.setBody(self.body)
        world.space.setSurfaceType(self.geom, world.surfaces["sphere"])
コード例 #9
0
    def createTire(self, tireIndex):
        """Create one physics tire. Returns a (nodePath, OdeBody, OdeGeom) tuple"""
        if (tireIndex < 0) or (tireIndex >= len(self.tireMasks)):
            self.notify.error('invalid tireIndex %s' % tireIndex)
        self.notify.debug("create tireindex %s" % (tireIndex))
        zOffset = 0
        # for now the tires are spheres
        body = OdeBody(self.world)
        mass = OdeMass()
        mass.setSphere(self.tireDensity, IceGameGlobals.TireRadius)
        body.setMass(mass)
        body.setPosition(IceGameGlobals.StartingPositions[tireIndex][0],
                         IceGameGlobals.StartingPositions[tireIndex][1],
                         IceGameGlobals.StartingPositions[tireIndex][2])
        #body.setAutoDisableFlag(1)
        #body.setAutoDisableLinearThreshold(1.01 * MetersToFeet)
        # skipping AutoDisableAngularThreshold as that is radians per second
        #body.setAutoDisableAngularThreshold(0.1)
        body.setAutoDisableDefaults()

        geom = OdeSphereGeom(self.space, IceGameGlobals.TireRadius)
        self.space.setSurfaceType(geom, self.tireSurfaceType)
        self.space.setCollideId(geom, self.tireCollideIds[tireIndex])

        self.massList.append(mass)
        self.geomList.append(geom)

        # a tire collides against other tires, the wall and the floor
        geom.setCollideBits(self.allTiresMask | self.wallMask | self.floorMask
                            | self.obstacleMask)
        geom.setCategoryBits(self.tireMasks[tireIndex])
        geom.setBody(body)

        if self.notify.getDebug():
            self.notify.debug('tire geom id')
            geom.write()
            self.notify.debug(' -')

        if self.canRender:
            testTire = render.attachNewNode("tire holder %d" % tireIndex)
            smileyModel = NodePath(
            )  # loader.loadModel('models/misc/smiley') # smiley!
            if not smileyModel.isEmpty():
                smileyModel.setScale(IceGameGlobals.TireRadius)
                smileyModel.reparentTo(testTire)
                smileyModel.setAlphaScale(0.5)
                smileyModel.setTransparency(1)
            testTire.setPos(IceGameGlobals.StartingPositions[tireIndex])
            #debugAxis = loader.loadModel('models/misc/xyzAxis')
            if 0:  #not debugAxis.isEmpty():
                debugAxis.reparentTo(testTire)
                debugAxis.setScale(IceGameGlobals.TireRadius / 10.0)
                debugAxis2 = loader.loadModel('models/misc/xyzAxis')
                debugAxis2.reparentTo(testTire)
                debugAxis2.setScale(-IceGameGlobals.TireRadius / 10.0)
            # lets create a black tire
            #tireModel = loader.loadModel('phase_3/models/misc/sphere')
            tireModel = loader.loadModel(
                "phase_4/models/minigames/ice_game_tire")
            # assuming it has a radius of 1
            tireHeight = 1
            #tireModel.setScale(IceGameGlobals.TireRadius, IceGameGlobals.TireRadius, 1)
            #tireModel.setZ( 0 - IceGameGlobals.TireRadius + (tireHeight /2.0))
            #tireModel.setColor(0,0,0)
            tireModel.setZ(-IceGameGlobals.TireRadius + 0.01)
            tireModel.reparentTo(testTire)
            #tireModel.setAlphaScale(0.5)
            #tireModel.setTransparency(1)

            self.odePandaRelationList.append((testTire, body))
        else:
            testTire = None
            self.bodyList.append((None, body))
        return testTire, body, geom
コード例 #10
0
ファイル: ode.py プロジェクト: gurgelff/Bast
# This 'balls' list contains tuples of nodepaths with their ode geoms
for i in range(15):
  # Setup the geometry
  ballNP = ball.copyTo(render)
  ballNP.setPos(randint(-7, 7), randint(-7, 7), 10 + random() * 5.0)
  ballNP.setColor(random(), random(), random(), 1)
  ballNP.setHpr(randint(-45, 45), randint(-45, 45), randint(-45, 45))
  # Create the body and set the mass
  ballBody = OdeBody(world)
  M = OdeMass()
  M.setSphere(50, 1)
  ballBody.setMass(M)
  ballBody.setPosition(ballNP.getPos(render))
  ballBody.setQuaternion(ballNP.getQuat(render))
  # Create a ballGeom
  ballGeom = OdeSphereGeom(space, 1)
  ballGeom.setCollideBits(BitMask32(0x00000001))
  ballGeom.setCategoryBits(BitMask32(0x00000001))
  ballGeom.setBody(ballBody)
  # Create the sound
  ballSound = loader.loadSfx("audio/sfx/GUI_rollover.wav")
  balls.append((ballNP, ballGeom, ballSound))

# Add a plane to collide with
cm = CardMaker("ground")
cm.setFrame(-20, 20, -20, 20)
cm.setUvRange((0, 1), (1, 0))
ground = render.attachNewNode(cm.generate())
ground.setPos(0, 0, 0); ground.lookAt(0, 0, -1)
groundGeom = OdePlaneGeom(space, (0, 0, 1, 0))
groundGeom.setCollideBits(BitMask32(0x00000001))