class MothershipFactory : ActionRole { @Attribute var delay = 0.0 @Attribute var ships = 3 @Attribute var interval = 10.0 @Attribute var mothershipBirthPeriod = 300 @Attribute var mothershipMaxChildren = 10 @Attribute var mothershipFireFrequency = 100 @Attribute val mothershipVelocity = Vector2( 0, 0 ) @Attribute var mothershipBulletSpeed = 3.0 override fun createAction() : Action { return ( Delay( delay ) thenOnce this:>createMothership then Delay( interval ) ).repeat( ships ) } fun createMothership() { val mothershipA = actor.createChild( "mothership" ) mothershipA.direction.radians = actor.direction.radians val mothership = (mothershipA.role as Mothership) mothership.birthPeriod = mothershipBirthPeriod mothership.maxChildren = mothershipMaxChildren mothership.fireFrequency = mothershipFireFrequency mothership.bulletSpeed = mothershipBulletSpeed // NOTE, we cannot use "=", because then all of the motherships would SHARE the // same velocity, they wouldn't move independantly. mothership.velocity.set( mothershipVelocity ) } }