class RotatingPlayer : Player{ @Attribute var rotationPeriod = 4.0 /** * Number of seconds after which the direction of rotation can be changed. */ @Attribute var allowFlipAfter = 1.0 var rot = 360.0 var reverseI : Input override fun begin() { super.begin() reverseI = Resources.instance.inputs.find( "reverse" ) } override fun animationAction() : Action { // Do half a turn, without allowing the direction to change. return TurnBy( actor.direction, rotationPeriod, Angle.degrees(rot) ).forever() and ( Delay( allowFlipAfter ) then this:>checkFlip ) } fun checkFlip() : bool { if (reverseI.isPressed() && Game.instance.director is Play) { rot = -rot replaceAction( createRealAction() ) } return false } }