/** The gate through which the ship must travel when the level is complete. The gate is initially closed, and will open when all required cargo has been transported through a CargoGate. */ class ExitGate : AbstractRole { @Attribute( isSceneName=true ) var nextScene = "test" var isOpen = false // The bars are initially visible, and then scaled to zero when this gate is opened. var bars : Bars override fun begin() { super.begin() bars = actor.createChild( "bars" ).role as Bars } override fun tick() { } fun open() { isOpen = true actor.event( "open" ) bars.open() } fun transportShip( ship : Ship ) { actor.event( "sending" ) ship.actor.role = ExitGateEntryAnimation( ship.actor, actor, OnShipSent( nextScene ) ) } } class ExitGateEntryAnimation( val shipActor : Actor, val gateActor : Actor, val postAction : Action ) : ActionRole() { override fun createAction() : Action { val distance = gateActor.position - shipActor.position return ( MoveBy( shipActor.position, 0.5, distance, Eases.easeOut ) .then( ScaleTo( shipActor, 1.3, 0.01 ) ) ).and ( TurnBy( shipActor.direction, 1.8, Angle.degrees(720), Eases.easeIn ) ).then( postAction ) } } class OnShipSent( val nextScene : String ) : AbstractAction() { override fun act() : bool { Game.instance.startScene( nextScene ) return true } }