public void act1Scene1Action ( ) {
Number maxCnt = 0 ; |
|
print( act1Scene1Action ); |
// Each of the penguins will be wandering aimlessly. |
// Since all three penguins will be doing the same thing, |
// it would be better to put this behavior in a separate |
// method. However, that would require passing parameters |
// which we haven't studied yet, so I will write this as |
// in-line code. |
doTogether { |
|
// Cause papa to wander aimlessly |
doInOrder { |
|
// Insert random delay to avoid penguins walking in lockstep |
wait( ( Random.nextDouble() minimum = 0 maximum = 0.5 ) ); |
// Use a random value for the number of iterations |
maxCnt .set( value , ( Random.nextDouble() minimum = 3 maximum = 10 ) ); |
for (int index=0; index< maxCnt times ; index++) { |
|
if ( ( Random.nextBoolean() ) ) { |
|
papa .turn( LEFT , 0.2 revolutions ); |
papa.walking ( x = 0.25 ); |
} else { |
|
papa .turn( RIGHT , 0.3 revolutions ); |
papa.walking ( x = 0.75 ); |
} |
} |
} |
// Cause mama to wander aimlessly |
doInOrder { |
|
wait( ( Random.nextDouble() minimum = 0 maximum = 0.5 ) ); |
maxCnt .set( value , ( Random.nextDouble() minimum = 3 maximum = 10 ) ); |
for (int index=0; index< maxCnt times ; index++) { |
|
if ( ( Random.nextBoolean() ) ) { |
|
mama .turn( RIGHT , 0.4 revolutions ); |
mama.walking ( x = 0.5 ); |
} else { |
|
mama .turn( LEFT , 0.2 revolutions ); |
mama.walking ( x = 0.2 ); |
} |
} |
} |
// Cause baby to wander aimlessly |
doInOrder { |
|
wait( ( Random.nextDouble() minimum = 0 maximum = 0.5 ) ); |
maxCnt .set( value , ( Random.nextDouble() minimum = 3 maximum = 10 ) ); |
for (int index=0; index< maxCnt times ; index++) { |
|
if ( ( Random.nextBoolean() ) ) { |
|
baby .turn( LEFT , .2 revolutions ); |
baby.walking ( x = 0.6 ); |
} else { |
|
baby .turn( RIGHT , .3 revolutions ); |
baby.walking ( x = 0.2 ); |
} |
} |
} |
} |
// Play sound and make the hole appear |
hole .playSound( world.thud2 (0:00.444) ); |
hole .set( opacity , 1 (100%) ); duration = 0 seconds |
doTogether { |
|
// All eyes turn to face the hole |
papa .turnToFace( hole ); |
mama .turnToFace( hole ); |
baby .turnToFace( hole ); |
} |
} |