Example #1
0
        /// <summary>
        /// Creates a projectile with the same location and orientation of the ship which fired it, and adds it to the world. Then tells the ship that is projectile has been fired.
        /// </summary>
        /// <param name="currentShip">ship which fired this projectile</param>
        public void SpawnProjectile(Ship currentShip)
        {
            if (currentShip.ReadyToFire())
            {
                // Need to adjust spawn location Y-axis
                Vector2D projLocation = new Vector2D(currentShip.GetLocation().GetX(), currentShip.GetLocation().GetY());
                Vector2D projDir      = new Vector2D(currentShip.GetOrientation());
                Vector2D projVeloc    = new Vector2D(currentShip.GetOrientation().GetX() * ProjVelocity, currentShip.GetOrientation().GetY() * ProjVelocity);

                Projectile newProj = new Projectile(projIDs, projLocation, projDir, true, currentShip.GetID());   // May want to shift projectile
                newProj.SetVelocity(projVeloc);
                this.addProjectile(newProj);
                projIDs++;

                lock (shipDictionary)
                {
                    this.shipDictionary[currentShip.GetID()].FireProjectile();
                }
            }
        }