class Mothership : AlienShip { @Attribute var birthPeriod = 300 @Attribute var maxChildren = 10 override fun createAnimation() : Action { return Delay( 0.2 ) then EventAction( actor, "frame1" ) then Delay( 0.2 ) then EventAction( actor, "frame2" ) then Delay( 0.2 ) then EventAction( actor, "default" ) } override fun tick() { super.tick() if (maxChildren > 0 && Rand.oneIn( birthPeriod )) { maxChildren -- actor.event( "birth" ) val shipA = actor.createChild( "child" ) val alienShip = shipA.role as AlienShip // Make the child come out from the bottom of the mothership shipA.direction.radians = actor.direction.radians shipA.moveForwards( radius * 0.3 ) // The child moves directly away from the mother, but also adding the // mothers velocity. alienShip.velocity.setMinus( shipA.position, actor.position ) alienShip.velocity *= 0.3 alienShip.velocity += velocity // Make the child very small at first, and begin an action to scale it up shipA.scaleXY = actor.scaleXY * 0.1 alienShip.scaleAction = ScaleTo( shipA, 1, actor.scaleXY, Eases.easeOut ) alienShip.scaleAction.begin() } } override fun hit() { DrunkInvaders.instance.shake(0.5) super.hit() } }