Esempio n. 1
0
        /// <summary>
        /// Rotates a ship left for the given shipID.
        /// </summary>
        public void RotateShipLeft(int shipID)
        {
            Ship     ship   = theShips[shipID];
            Vector2D newDir = ship.GetOrientation();

            newDir.Rotate(-turningRate);
            ship.SetOrientation(newDir);
        }
Esempio n. 2
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();
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Calculates the instant acceleration from stars and engine thrusts.
        /// </summary>
        /// <param name="ship"></param>
        /// <returns></returns>
        private Vector2D CalculateInstantAcceleration(Ship ship)
        {
            Vector2D totalAcc = new Vector2D(0, 0);

            // add gravity from each star
            foreach (Star star in theStars.Values)
            {
                totalAcc += CalculateForce(ship, star);
            }

            // if thrust add enginestrength
            if (ship.IsThrusting())
            {
                totalAcc += (ship.GetOrientation() * engineStrength);
            }

            // return accumulated vector
            return(totalAcc);
        }
Esempio n. 4
0
        public void TestUpdatingShipLocationInWorldWithNewShip()
        {
            World testWorld = new World();

            testWorld.SpawnShip(1, "testName");
            Ship firstFrame = (Ship)testWorld.getPlayers()[1];

            double xShipFirstFrame = firstFrame.GetLocation().GetX();
            double yShipFirstFrame = firstFrame.GetLocation().GetY();

            Ship secondFrame = new Ship(1, firstFrame.GetLocation() + firstFrame.GetLocation(), firstFrame.GetOrientation(), false, "testName", 5, 0);

            testWorld.addShip(secondFrame);

            Assert.IsTrue(testWorld.getPlayers().Count == 1);

            Ship   sameShip         = (Ship)testWorld.getPlayers()[1];
            double xShipSecondFrame = sameShip.GetLocation().GetX();
            double yShipSecondFrame = sameShip.GetLocation().GetY();

            Assert.IsTrue(xShipFirstFrame != xShipSecondFrame);
            Assert.IsTrue(yShipFirstFrame != yShipSecondFrame);
        }