Beispiel #1
0
 def applyGravity(self, ship, deltaTime):
     distance = tupleDistance(ship.getPos(),
                              vec3ToTuple(self.planet.getPos()))
     if distance > Game.GRAVITY_DISTANCE: return
     gravity = Game.GRAVITY / distance
     gravityVector = tupleNormalize(
         tupleSegment(ship.getPos(), vec3ToTuple(self.planet.getPos())))
     gravityVector = scaleTuple(gravityVector, gravity * deltaTime)
     ship.applyForce(gravityVector)
Beispiel #2
0
 def applyGravity(self, ship, deltaTime):
   distance = tupleDistance(
     ship.getPos(),
     vec3ToTuple( self.planet.getPos() )
   )
   if distance > Game.GRAVITY_DISTANCE: return
   gravity = Game.GRAVITY/distance
   gravityVector = tupleNormalize(
     tupleSegment(
       ship.getPos(),
       vec3ToTuple( self.planet.getPos() )
     )
   )
   gravityVector = scaleTuple( gravityVector, gravity * deltaTime)
   ship.applyForce( gravityVector )
Beispiel #3
0
    def updateCamera(self):
        ships = self.getShips()
        shipOne = ships[0]
        shipOnePos = shipOne.getPos()
        shipTwo = ships[1]
        shipTwoPos = shipTwo.getPos()

        # Calculate the distance between the ships
        distance = tupleDistance(shipOnePos, shipTwoPos)
        cameraDistance = distance * Game.CAMERA_DISTANCE_COEFFICIENT
        if cameraDistance > Game.CAMERA_DISTANCE_MAX:
            cameraDistance = Game.CAMERA_DISTANCE_MAX
        if cameraDistance < Game.CAMERA_DISTANCE_MIN:
            cameraDistance = Game.CAMERA_DISTANCE_MIN
        # Calculate the middle point in space between the ship's positions
        middle = tupleMiddle(shipOnePos, shipTwoPos)
        cameraPos = self.getCameraPos()
        self.lastCameraPos = cameraPos
        newCameraPos = (middle[0], middle[1], cameraDistance)
        self.setCameraPos(newCameraPos)
        self.updateStars(newCameraPos)
Beispiel #4
0
  def updateCamera(self):
    ships = self.getShips()
    shipOne = ships[0]
    shipOnePos = shipOne.getPos()
    shipTwo = ships[1]
    shipTwoPos = shipTwo.getPos()

    # Calculate the distance between the ships
    distance = tupleDistance(shipOnePos, shipTwoPos)
    cameraDistance = distance * Game.CAMERA_DISTANCE_COEFFICIENT
    if cameraDistance > Game.CAMERA_DISTANCE_MAX:
      cameraDistance = Game.CAMERA_DISTANCE_MAX
    if cameraDistance < Game.CAMERA_DISTANCE_MIN:
      cameraDistance = Game.CAMERA_DISTANCE_MIN
    # Calculate the middle point in space between the ship's positions
    middle = tupleMiddle(shipOnePos, shipTwoPos)
    cameraPos = self.getCameraPos()
    self.lastCameraPos = cameraPos
    newCameraPos = (middle[0], middle[1], cameraDistance)
    self.setCameraPos(newCameraPos)
    self.updateStars(newCameraPos)
Beispiel #5
0
 def testTupleDistance(self):
   tuple1 = (1, 2)
   tuple2 = (4, 6)
   distance = ( ( tuple2[0] - tuple1[0] )**2 + ( tuple2[1] - tuple1[1] )**2 )**(1/2.)
   self.failUnlessEqual( tupleDistance( tuple1, tuple2 ), distance )
Beispiel #6
0
 def testTupleDistance(self):
     tuple1 = (1, 2)
     tuple2 = (4, 6)
     distance = ((tuple2[0] - tuple1[0])**2 +
                 (tuple2[1] - tuple1[1])**2)**(1 / 2.)
     self.failUnlessEqual(tupleDistance(tuple1, tuple2), distance)