Download penguin-jumping.a3p
Experiment! Try different ranges of values. Try making amountToFlap a random amount between a little less than amountToJump and a little more. Try to make a natural looking jump.
public void myFirstMethod() {
Double amountToJump = 0.5;
Double amountToFlap = 0.25;
while ( true ) {
amountToJump = RandomUtilities.nextDoubleInRange( 0.1, 0.7 );
amountToFlap = amountToJump/2.0;
doTogether( ()-> {
this.penguin.getLeftWingShoulder().turn( TurnDirection.BACKWARD, amountToFlap );
}, ()-> {
this.penguin.getRightWingShoulder().turn( TurnDirection.BACKWARD, amountToFlap );
}, ()-> {
this.penguin.move( MoveDirection.UP, amountToJump );
} );
doTogether( ()-> {
this.penguin.getLeftWingShoulder().turn( TurnDirection.FORWARD, amountToFlap );
}, ()-> {
this.penguin.getRightWingShoulder().turn( TurnDirection.FORWARD, amountToFlap );
}, ()-> {
this.penguin.move( MoveDirection.DOWN, amountToJump );
} );
}
}
End of lesson, Next lesson: