Lunar resultant

The golf example demonstrates deceleration and momentum. It’s too easy to copy the code and call it a day, so I try to implement “morsel concepts” in different contexts. In this case, it was the moon and an astronaut. gif

moon

I couldn’t track the dx and dy being thrown around, even with the Vec2D encapsulation, so I initialized a zeroed Vec2D object called resultantVector. During each update(), resultantVector would apply both vectors to itself before modifying the y-pos.

public void update(Rectangle bounds) {
  resultantVector.addVec(gravityVector);  // dx = 0, dy = 0.4f

  if (thrusterActivated) 
    resultantVector.subVec(thrustVector); // dx = 0, dy = 1.0f

  addPos(resultantVector);  // the one place where y += dy

  // collision detection and reset resultantVector
  if (...) {
    y = just_above_the_ground;
    resultantVector.setVec(0, 0); // avoid accumulating
  }
}