/** Some of the [Rain] scenes let you shrink the doll for a short period, so that if you get into a tight spot, you can still survive. See input 'rainShrink', which is currently the space bar. You can only shrink a limited number of times, given by [available]. When there are no more shrinks left, a sound is played, and the text disappears. */ class RainShrinks : ActionRole { @Attribute( about="The number of times in the game that you can shrink the doll" ) var available = 3 var trigger : Input // A local reference to the Doll which will be shrunk. var doll : Doll override fun activated() { trigger = findInput( "rainShrink" ) doll = (Game.instance.director as Rain).doll updateText() } override fun tick() { super.tick() if ( isFinished() && trigger.isPressed()) { available -- updateText() // The shrinkage is animated in 5 steps. replaceAction( (doll:>scale.curry( Vector2(0.9,0.9) ) onceThen Delay(0.1) ).repeat(5) then Delay( 3 ) then (doll:>scale.curry( Vector2(1/0.9,1/0.9) ) onceThen Delay(0.1) ).repeat(5) thenOnce this:>animationComplete ) } } fun updateText() { actor.textAppearance.text = "Space to Shrink ($available)" } fun animationComplete() { if (available == 0) { actor.event( "die" ) // Play a sound. actor.die() } } }