Yes, that's exactly how it should be done.
Now that the structure is correct, the only significant issues I see are smaller things like:
- The
&& totalMovementSet == false
explicitly prevents the player from changing totalMovement until the current "movement" is completed; are you sure you want to do that?
- The vector operations in your code can be significantly simplified in a few places:
totalMovementSet = true;
totalMovement = sf::Mouse::getPosition(window) - darthVader.getPosition();
mousePoint = sf::Mouse::getPosition(window);
and
sf::Vector2f distFromMouse = darthVader.getPosition() - mousePoint;
if (abs(distFromMouse.x) < 10 && abs(distFromMouse.y) < 10) { // I think this is what your if() means
- Technically, in this snippet you're declaring an sf::Event object and then never using it, but I assume you'll want to write at least a line of code to handle the Close event later, so it's not exactly a problem.