Exemple #1
0
 /// <summary>
 /// Detects whether or not a ship is hit by a projectile
 /// </summary>
 private void CollisionBetweenAStarAndProjectile(Star star, Projectile projectile)
 {
     if (WithinARadius(star.GetLocation(), projectile.GetLocation(), starSize))
     {
         // the passed in projectile hit a star so we remove it from the world
         projectile.Alive(false);
     }
 }
Exemple #2
0
        /// <summary>
        /// When the projectile is off the screen then remove the projectile
        /// from the world and return true. Else, if it was not removed return
        /// false;
        /// </summary>
        private bool ProjectileOffScreen(Projectile projectile)
        {
            int borderCoordinate = universeSize / 2;

            // check to see if its on the edge of the world
            if (Math.Abs(projectile.GetLocation().GetX()) >= borderCoordinate)
            {
                projectile.Alive(false);
                return(true);
            }

            // check to see if its on the edge of the world
            else if (Math.Abs(projectile.GetLocation().GetY()) >= borderCoordinate)
            {
                projectile.Alive(false);
                return(true);
            }

            return(false);
        }
Exemple #3
0
 /// <summary>
 /// Detects whether or not a ship is hit by a projectile
 /// </summary>
 private void CollisionWithAProjectile(Ship ship, Projectile projectile)
 {
     if (ship.GetID() != projectile.GetOwner() && ship.IsAlive())
     {
         if (WithinARadius(ship.GetLocation(), projectile.GetLocation(), shipSize))
         {
             // the passed in ship was hit by a projectile so we update health and remove
             // the projectile from the world
             HitAProjectile(ship, projectile);
         }
     }
 }
Exemple #4
0
        /// <summary>
        /// Returns true if ship and projectile are within collision distance, otherwise false.
        /// </summary>
        /// <param name="ship"></param>
        /// <param name="proj"></param>
        /// <returns></returns>
        public bool HasCollidedShipProj(Ship ship, Projectile proj)
        {
            Vector2D shipLoc        = ship.GetLocation();
            Vector2D projLoc        = proj.GetLocation();
            Vector2D distanceVector = shipLoc - projLoc;
            double   distanceLength = distanceVector.Length();

            if (distanceLength <= ShipSize && (ship.GetID() != proj.GetOwner()))
            {
                return(true);
            }
            return(false);
        }
Exemple #5
0
        /// <summary>
        /// Returns true if projectile and star are within collision distance, otherwise false.
        /// </summary>
        /// <param name="star"></param>
        /// <param name="proj"></param>
        /// <returns></returns>
        public bool HasCollidedProjStar(Star star, Projectile proj)
        {
            Vector2D starLoc        = star.GetLocation();
            Vector2D projLoc        = proj.GetLocation();
            Vector2D distanceVector = starLoc - projLoc;
            double   distanceLength = distanceVector.Length();

            if (distanceLength <= StarSize)
            {
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// Acts as a drawing delegate for DrawObjectWithTransform
        /// After performing the necessary transformation (translate/rotate)
        /// DrawObjectWithTransform will invoke this method
        /// </summary>
        /// <param name="o">The object to draw</param>
        /// <param name="e">The PaintEventArgs to access the graphics</param>
        private void ProjectileDrawer(object o, PaintEventArgs e)
        {
            Projectile proj = o as Projectile;
            Bitmap     projSprite;
            int        x, y;
            Point      p;

            x = WorldSpaceToImageSpace(this.Size.Width, (int)proj.GetLocation().GetX() - (PROJECTILE_SIZE.Width / 2));
            y = WorldSpaceToImageSpace(this.Size.Width, (int)proj.GetLocation().GetY() - (PROJECTILE_SIZE.Height / 2));
            p = new Point(x, y);

            if (theWorld.GetMarioMode() && proj.GetOwner() == theWorld.GetCurrentPlayer())
            {
                projSprite = marioFireball;
            }
            else
            {
                projSprite = projSprites[proj.GetOwner() % projSprites.Count];
            }

            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            e.Graphics.DrawImage(projSprite, p);
        }
Exemple #7
0
        /// <summary>
        /// Computes the new location for the projectile
        /// </summary>
        public void MotionForProjectiles(Projectile projectile)
        {
            // if the projectile is not alive, don't move it
            if (!projectile.IsAlive())
            {
                return;
            }

            // find the velocity with respect to direction
            Vector2D velocity = projectile.GetDirection() * projectileSpeed;

            // reset the location of the projectile
            projectile.SetLocation(projectile.GetLocation() + velocity);
            if (!ProjectileOffScreen(projectile))
            {
                foreach (Star star in stars.Values)
                {
                    CollisionBetweenAStarAndProjectile(star, projectile);
                }
            }
        }
        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);
        }
Exemple #9
0
        private bool CollidedWith(Projectile proj, Star star)
        {
            Vector2D distance = proj.GetLocation() - star.GetLocation();

            return(distance.Length() < starRadius);
        }
Exemple #10
0
        private bool CollidedWith(Projectile proj, Ship ship)
        {
            Vector2D distance = proj.GetLocation() - ship.GetLocation();

            return(distance.Length() < shipRadius);
        }