コード例 #1
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="ShelledEnemyComponent"
        ///   /> sprite.
        /// </summary>
        /// <param name="owner">The sprite that owns this component.</param>
        /// <param name="walkingVelocity">
        ///   The horizontal velocity at which the owner will walk.
        /// </param>
        /// <param name="shellSpinningVelocity">
        ///   The horizontal velocity at which the owner will spin.
        /// </param>
        /// <param name="framesFromShellToEmerging">
        ///   The number of frames between entering the Shell state and entering
        ///   the Emerging state.
        /// </param>
        /// <param name="framesFromEmergingToWalking">
        ///   The number of frames between entering the Emerging state and
        ///   entering the Walking state.
        /// </param>
        public ShelledEnemyComponent(Sprite owner, float walkingVelocity, float shellSpinningVelocity, int framesFromShellToEmerging, int framesFromEmergingToWalking)
        {
            WalkerComponent walker = owner.GetComponent<WalkerComponent>();
            DamageComponent damage = owner.GetComponent<DamageComponent>();
            ChasePlayerComponent chasePlayer = owner.GetComponent<ChasePlayerComponent>();

            if (walker == null || damage == null || chasePlayer == null)
            {
                throw new ArgumentException("This component requires its owner to have WalkerComponent, DamageComponent, and ChasePlayerComponent instances before constructing this ShelledEnemyComponent.");
            }

            IsActive = true;
            Owner = owner;
            spriteWalker = walker;
            spriteDamage = damage;
            spriteChasePlayer = chasePlayer;

            behavior = ShelledEnemyBehavior.DontTurnOnCliffs;
            state = ShelledEnemyState.Walking;

            this.walkingVelocity = walkingVelocity;
            this.shellSpinningVelocity = shellSpinningVelocity;
            this.framesFromShellToEmerging = framesFromShellToEmerging;
            this.framesFromEmergingToWalking = framesFromEmergingToWalking;

            spriteWalker.CurrentVelocity = walkingVelocity;
        }
コード例 #2
0
 private void HandleSpriteCollisionWhileShell(Sprite sprite, Vector2 resolutionDistance)
 {
     if (sprite.IsPlayer)
     {
         // If the player's center is to the right (or equal to) our
         // center, go left Otherwise, go right
         spriteWalker.Direction = (sprite.Hitbox.Center.X >= Owner.Hitbox.X) ? Direction.Left : Direction.Right;
         State = ShelledEnemyState.ShellSpinning;
         ActionScheduler.Instance.CancelScheduledAction(emergeAction);
         emergeAction = null;
     }
 }
コード例 #3
0
 private void GoToShell()
 {
     State = ShelledEnemyState.Shell;
     spriteChasePlayer.IsActive = false;
     emergeAction = ActionScheduler.Instance.ScheduleAction(() =>
     {
         State = ShelledEnemyState.Emerging;
         emergeAction = ActionScheduler.Instance.ScheduleActionOnNextFrame(() =>
         {
             State = ShelledEnemyState.Walking;
             spriteChasePlayer.IsActive = (Behavior == ShelledEnemyBehavior.ChasePlayer);
         }, framesFromEmergingToWalking);
     }, framesFromShellToEmerging);
 }