class Car(box): """Box that can be pushed and have its properties changed, and can update its position""" def __init__(self, mass=1, velocity=vector(), **args): super(Car, self).__init__(**args) self.mass = mass self.velocity = velocity self.momentum = self.mass * self.velocity def changemomentum(self, newmomentum): """Recompute velocity based on new momentum""" self.velocity = newmomentum / self.mass self.momentum = newmomentum def changemass(self, newmass): """Recompute velocity based on new mass using conservation of momentum""" self.mass = newmass self.velocity = self.momentum / self.mass def updateposition(self, deltat): """Update position based on velocity and a deltat""" self.pos = self.pos + (self.velocity * deltat) def applyforce(self, deltat, force=vector()): """Change momentum by applying a force over a period of time""" momentum = self.momentum + (deltat * force) self.updatemomentum(momentum) self.updateposition(deltat)