Game Development Reference
In-Depth Information
We defined a couple of input mappings earlier. Now, we can all implement the functional-
ity for them in the onAction method by performing the following steps:
1. If the left mouse button is clicked, we should call checkSelection . If the re-
turned value is not null, we should set selectedSegment to that value, as fol-
lows:
if (name.equals(LEFT_CLICK) && !isPressed) {
RigidBodyControl newSelection = checkSelection();
if (newSelection != null) {
selectedSegment = newSelection;
}
}
2. If the right mouse button is clicked, we should also call checkSelection . If
the returned value is not null and it's not selectedSegment , we call cre-
ateJoint with selectedSegment and the value of checkSelection to
create a link between selectedSegment and the segment returned from the
method, as shown in the following code snippet:
else if (name.equals(RIGHT_CLICK) && !isPressed) {
RigidBodyControl hitSegment = checkSelection();
if (hitSegment != null && hitSegment !=
selectedSegment) {
createJoint(selectedSegment, hitSegment);
}
3. Otherwise, if we didn't hit anything, we call createSegment with the position
of the mouse cursor to create a new segment at that location as follows:
createSegment(cam.getWorldCoordinates(inputManager.getCursorPosition(),
10f));
4. If the Space bar has been pressed, all we need to do is set the speed of bul-
letAppState to 1 to start the physics.
Search WWH ::




Custom Search