示例#1
0
        public override void CreateProjectile(object source, ElapsedEventArgs args)
        {
            // this.PauseTimersWhileDebugging(source as Timer);

            float spacing        = 2;
            int   verticalOffset = 20;

            for (int row = 0; row < this.widthOfArrow; row++)
            {
                for (int col = 0; col <= row; col++)
                {
                    Vector2    targetPosition = GameState.GetPlayerPosition();
                    Projectile newProjectile  = this.ProjectileToLaunch.Clone() as Projectile;
                    newProjectile.Movement        = this.ProjectileToLaunch.Movement.Clone() as MovementPattern;
                    newProjectile.Movement.Parent = newProjectile;

                    if (row < col / 2.0)
                    {
                        Vector2 velocity = MovementPattern.CalculateVelocity(this.Movement.CurrentPosition, targetPosition, newProjectile.Movement.Speed);

                        velocity.X = (float)((velocity.X * Math.Cos((col - (row / 2.0)) * spacing * (Math.PI / 180))) - (velocity.Y * Math.Sin((col - (row / 2.0)) * spacing * (Math.PI / 180))));
                        velocity.Y = (float)((velocity.X * Math.Sin((col - (row / 2.0)) * spacing * (Math.PI / 180))) + (velocity.Y * Math.Cos((col - (row / 2.0)) * spacing * (Math.PI / 180))));

                        newProjectile.Movement.Velocity = velocity;
                    }
                    else if (row == col / 2.0)
                    {
                        Vector2 velocity = MovementPattern.CalculateVelocity(this.Movement.CurrentPosition, targetPosition, newProjectile.Movement.Speed);

                        newProjectile.Movement.Velocity = velocity;
                    }
                    else if (row > col / 2.0)
                    {
                        Vector2 velocity = MovementPattern.CalculateVelocity(this.Movement.CurrentPosition, targetPosition, newProjectile.Movement.Speed);

                        velocity.X = (float)((velocity.X * Math.Cos((col - (row / 2.0)) * spacing * (Math.PI / 180))) - (velocity.Y * Math.Sin((col - (row / 2.0)) * spacing * (Math.PI / 180))));
                        velocity.Y = (float)((velocity.X * Math.Sin((col - (row / 2.0)) * spacing * (Math.PI / 180))) + (velocity.Y * Math.Cos((col - (row / 2.0)) * spacing * (Math.PI / 180))));

                        newProjectile.Movement.Velocity = velocity;
                    }

                    Vector2 position = this.Movement.CurrentPosition;

                    position.Y -= verticalOffset * row;

                    newProjectile.Movement.CurrentPosition = position;

                    newProjectile.Parent = this.Attacker;
                    GameState.Projectiles.Add(newProjectile);
                }
            }

            this.NumberOfTimesProjectilesHaveLaunched++;
        }
示例#2
0
        protected virtual void Move()
        {
            // For spawning
            if (this.ReachedStart == false && this.Exiting == false)
            {
                if (this.initializedSpawningPosition == false)
                {
                    this.initializedSpawningPosition = true;
                    this.Movement.CurrentPosition    = this.SpawnPosition;
                    this.Movement.CurrentSpeed       = this.Movement.Speed * 2;
                    this.Movement.Velocity           = MovementPattern.CalculateVelocity(this.SpawnPosition, this.Movement.StartPosition, this.Movement.CurrentSpeed);
                }

                if (this.Movement.ExceededPosition(this.SpawnPosition, this.Movement.StartPosition, this.Movement.Velocity))
                {
                    this.ReachedStart = true;
                }
                else
                {
                    this.Movement.CurrentPosition += this.Movement.Velocity;
                }
            }

            // For movement
            else if (this.ReachedStart == true && this.Exiting == false)
            {
                if (this.initializedMovementPosition == false)
                {
                    this.initializedMovementPosition = true;
                    this.Attacks.ForEach(item =>
                    {
                        item.Attacker = this;
                        item.CooldownToAttack.Start();
                        Debug.WriteLineIf(this is Enemy, DateTime.Now + ": " + item.Attacker.GetHashCode() + " is starting the Cooldown to Attack Timer for " + item.GetHashCode());
                    });

                    this.Movement.InitializeMovement();
                }

                if (this.Movement.CompletedMovement == true)
                {
                    this.Exiting = true;
                }
                else
                {
                    this.Movement.Move();
                }
            }

            // For despawning
            else if (this.ReachedStart == true && this.Exiting == true)
            {
                if (this.initializedDespawningPosition == false)
                {
                    this.initializedDespawningPosition = true;

                    // In the case that a despawn position is not provided it goes to the spawn position
                    if (this.DespawnPosition.Equals(default(Vector2)))
                    {
                        this.DespawnPosition = this.SpawnPosition;
                    }

                    this.Movement.CurrentSpeed        = this.Movement.Speed * 2;
                    this.positionWhenDespawningBegins = this.Movement.CurrentPosition;

                    this.Movement.Velocity = MovementPattern.CalculateVelocity(this.Movement.CurrentPosition, this.DespawnPosition, this.Movement.CurrentSpeed);

                    this.Attacks.ForEach(item =>
                    {
                        item.CooldownToAttack.Stop();
                        Debug.WriteLineIf(this is Enemy, DateTime.Now + ": " + item.Attacker.GetHashCode() + " is stoping the Cooldown to Attack Timer for " + item.GetHashCode());
                    });
                }

                if (this.Movement.ExceededPosition(this.positionWhenDespawningBegins, this.DespawnPosition, this.Movement.Velocity))
                {
                    this.isRemoved = true;
                }
                else
                {
                    this.Movement.CurrentPosition += this.Movement.Velocity;
                }
            }
        }