class Player : TaggedActionRole { @Attribute var clan = Clan.MEENY var started = false fun followAction() : Action = FollowMouse(actor, false) override fun begin() { super.begin() actor.name = "player" actor.color.set( clan.color ) } /** The action at the beginning of the scene (before the game starts) */ override fun createAction() : Action { return followAction().forever() and ( Fade( actor.color, 1, 0.25 ) then Fade( actor.color, 1, 0.75 ) ).forever() and animationAction().forever() } /** ElasticPlayer and TwoClanPlayer override this. */ fun animationAction() : Action = Delay(0) fun realStart() { actor.event( "go" ) actor.color.opaque() replaceAction( createRealAction() ) } /** The animation after you press enter (to begin the game). */ fun createRealAction() : Action { started = true return followAction() and animationAction().forever() } override fun tick() { super.tick() if (started) { if ( TagManager.instance.findOverlapping( this, clan ) != null ) { die() } } } /** Explode into pieces. */ fun die() { val countdown = findActorByName( "countdown" ).role as Countdown countdown.stop() DodgeEm.instance.finishedScene( countdown.score, countdown.requiredSeconds ) Play.instance.playerDied() actor.event("explode") started = false // Prevent dying again! createFragments() actor.hide() replaceAction( Delay( 0.4 ) thenOnce this:>showRestartMenu then Kill( actor ) ) } fun createFragments() { createFragmentActions(actor, this:>fragmentAction ) } fun fragmentAction( fragment : Actor, offset : Vector2 ) : Action { val secs = Rand.between( 2, 5 ) fragment.color.set( actor.color ) return MoveBy(fragment.position, secs, offset * Rand.between(1.0,10.0)) and TurnBy(fragment.direction, secs, Angle.degrees(Rand.between( -200, 200 ))) and Fade(fragment.color, secs, 0f, Eases.easeInQuad) then Kill(fragment) } fun showRestartMenu() { mergeScene( "restartContinueMenu" ) } }