class TwoClanPlayer : Player { @Attribute var otherClan = Clan.MINY @Attribute var changeSpeed = 2.0 @Attribute var changeDelay = 3.0 var origClan = clan // Must be set in begin! override fun begin() { origClan = clan super.begin() } var isOtherClan = false fun changeClan() { if (isOtherClan == true) { changeClan( origClan ) } else { changeClan( otherClan ) } isOtherClan = ! isOtherClan } fun pips() { actor.event("pips") } /* Change colour from one clan to another. The clan changes at the half way point */ override fun animationAction() : Action { val basic = (Delay( changeDelay ) then ( Colorize( actor.color, changeSpeed, otherClan.color ) and ( Delay( changeSpeed / 2 ) thenOnce this:>changeClan ) ) then Delay( changeDelay ) then ( Colorize( actor.color, changeSpeed, origClan.color ) and ( Delay( changeSpeed / 2 ) thenOnce this:>changeClan ) ) ) // This is the length of the pips sound before the change. val pips = 0.3 // Is there enough time to play the pips? if ( changeDelay + changeSpeed/2 > pips ) { return basic and ( Delay( changeDelay + changeSpeed / 2 - pips ) thenOnce this:>pips then Delay( changeSpeed / 2 + changeDelay + changeSpeed / 2 - pips ) thenOnce this:>pips ) } else { return basic } } fun changeClan( clan : Clan ) { this.clan = clan } }