Esempio n. 1
0
def colHandler(ship, contact):
    pos = ship.getPos()

    elasticity = 2.5
    #mass1 = ship.getMass()
    #mass2 = collider.getMass()
    vel1 = ship.getVel()
    normal = tupleNormalize(tupleSegment(pos, contact))
    force = (scaleTuple(normal,
                        -elasticity * (1 / 2.) * dotProduct(vel1, normal)))

    ship.applyForce(force)
    ship.setPos(addTuples(ship.getPos(), scaleTuple(normal, -.1)))
    ship.getCollisions().remove(contact)
Esempio n. 2
0
 def limitVelocity(self):
     shipVel = self.getVel()
     newVelScalar = tupleLength(shipVel)
     if newVelScalar > Ship.SPEED_MAX:
         newVelScale = Ship.SPEED_MAX / newVelScalar
         newVel = scaleTuple(shipVel, newVelScale)
         self.setVel(newVel)
Esempio n. 3
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)
Esempio n. 4
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 )
Esempio n. 5
0
 def testScaleTuple(self):
   self.failUnlessEqual( scaleTuple( (1, -4), 3 ), (3, -12) )
Esempio n. 6
0
 def testScaleTuple(self):
     self.failUnlessEqual(scaleTuple((1, -4), 3), (3, -12))