/// <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;
        }
Beispiel #2
0
        public override void Initialize(Section owner)
        {
            base.Initialize(owner);
            graphics = (ComplexGraphicsObject)ContentPackageManager.GetGraphicsResource("SMBKoopaTroopa");

            graphics.CurrentObjectName = AppendTypeSuffix("walking");

            HealthComponent healthComponent = new HealthComponent(1, 1, new string[] { SpriteDamageTypes.PlayerStomp });
            healthComponent.SpriteKilled += HealthComponent_SpriteKilled;

            SpriteDirection initialDirection = ResolveDirection(this, Direction, Owner);
            facingDirection = (initialDirection == SpriteDirection.Left) ? SMLimitless.Direction.Left : SMLimitless.Direction.Right;
            Components.Add(healthComponent);
            Components.Add(new WalkerComponent(this, initialDirection, WalkingSpeed.Value));
            Components.Add(new DamageComponent());

            ChasePlayerComponent chasePlayer = new ChasePlayerComponent(this, 60);
            chasePlayer.NearestPlayerDirectionUpdated += ChasePlayer_NearestPlayerDirectionUpdated;
            Components.Add(chasePlayer);

            ShelledEnemyComponent shelledEnemy = new ShelledEnemyComponent(this, WalkingSpeed.Value, ShellSpinningSpeed.Value, FramesUntilBeginEmerge.Value, FramesUntilEmerge.Value);
            shelledEnemy.StateChanged += ShelledEnemy_StateChanged;
            Components.Add(shelledEnemy);
            SetBehavior();
        }