Beispiel #1
0
        /// <summary>
        /// Creates a projectile with the same location as the star which fired it, and adds it to the world. Orientation must be provided as stars do not have an orientation.
        /// </summary>
        /// <param name="currentStar">star which fired this projectile</param>
        /// <param name="dir">orientation of the projectile</param>
        public void SpawnProjectile(Star currentStar, Vector2D dir)
        {
            // Need to adjust spawn location Y-axis
            Vector2D projLocation = new Vector2D(currentStar.GetLocation().GetX(), currentStar.GetLocation().GetY());
            Vector2D projDir      = new Vector2D(dir);
            Vector2D projVeloc    = new Vector2D(dir.GetX() * ProjVelocity / 3, dir.GetY() * ProjVelocity / 3);

            Projectile newProj = new Projectile(projIDs, projLocation, projDir, true, int.MaxValue); // hard coding this, bad design but... yeah...

            newProj.SetVelocity(projVeloc);
            this.addProjectile(newProj);
            projIDs++;
        }
Beispiel #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();
                }
            }
        }
Beispiel #3
0
        public void TestProjectileVelocity()
        {
            World testWorld = new World();

            testWorld.SpawnShip(1, "testname");
            Ship testShip = (Ship)testWorld.getPlayers()[1];

            Assert.IsTrue(testWorld.getProjs().Count == 0);

            testWorld.SpawnProjectile(testShip);


            Projectile testProj = ((Dictionary <int, Projectile>)testWorld.getProjs())[0];

            double xProj = testProj.GetLocation().GetX();
            double yProj = testProj.GetLocation().GetY();

            double xShip = testShip.GetLocation().GetX();
            double yShip = testShip.GetLocation().GetY();


            Assert.IsTrue(xProj == xShip);
            Assert.IsTrue(yProj == yShip);

            testWorld.updateProjectiles();

            xProj = testProj.GetLocation().GetX();
            yProj = testProj.GetLocation().GetY();

            Assert.IsTrue(xProj == xShip);
            Assert.IsTrue(yProj == yShip);

            testProj.SetVelocity(new Vector2D(1, 2));
            testWorld.updateProjectiles();

            xProj = testProj.GetLocation().GetX();
            yProj = testProj.GetLocation().GetY();

            Assert.IsTrue(xProj == xShip + 1);
            Assert.IsTrue(yProj == yShip + 2);
        }