// Displays the number of additional lives remaining class Life : AbstractRole { var index = 0 var oldShip : Ship = null var animation : Action = null override fun tick() { if (animation != null) { if (animation.act()) { val ship = Ship().apply { bulletSpeed = oldShip.bulletSpeed speedDegrees = oldShip.speedDegrees shieldTicks = oldShip.shieldTicks canMoveShielded = oldShip.canMoveShielded center.set( oldShip.center ) inwards= oldShip.inwards radius = oldShip.radius shielded = true } actor.costume = oldShip.actor.costume actor.role = ship } } } fun rebirth( ship : Ship ) { oldShip = ship val seconds = 2.0 // Flash on and off (this will be repeated, see below) val flash = EventAction(actor, "flashOn") then Delay(0.1) then EventAction(actor, "flashOff") then Delay(0.1) // The amount the ship turns whilest moving into position. // It is nicer looking if it always does and extra spin (360). val turn = Angle.degrees(360) + ship.actor.direction - actor.direction if ( turn.degrees < 180 ) turn.plus( Angle.degrees( 360 ) ) // Return to normal size, move to the correct place, and spin a little bit. val movement = ScaleTo( actor, 1, Vector2(1,1), Eases.easeInQuad ) and MoveTo( actor.position, seconds, ship.actor.position, Eases.easeInOut) and TurnBy( actor.direction, seconds, turn, Eases.easeOut) // Do "flash" 5 times, and then do "movement" // The animation = flash.repeat( 5 ) then EventAction( actor, "shield0") then movement then EventAction( actor, "default") animation.begin() } }