Exemplo 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)
Exemplo 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)
Exemplo 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)
Exemplo 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 )
Exemplo n.º 5
0
 def testScaleTuple(self):
   self.failUnlessEqual( scaleTuple( (1, -4), 3 ), (3, -12) )
Exemplo n.º 6
0
 def testScaleTuple(self):
     self.failUnlessEqual(scaleTuple((1, -4), 3), (3, -12))