Ejemplo n.º 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++;
        }
Ejemplo n.º 2
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);
     }
 }
Ejemplo n.º 3
0
        //******************** World methods for the collisions ********************//

        /// <summary>
        /// Checks to see if the passed in ship touched a star
        /// </summary>
        private void CollisionWithAStar(Ship ship, Star star)
        {
            if (WithinARadius(ship.GetLocation(), star.GetLocation(), shipSize + starSize))
            {
                // the passed in ship hit a star so we update the ship's health
                HitAStar(ship);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Spawns a star using the properties of an existing star. Used for respawning existing stars which have been killed (boss mode only.) Spawn location is retained from initial star.
        /// </summary>
        /// <param name="star">star to be respawned</param>
        public void respawnStar(Star star)
        {
            Vector2D newLoc  = new Vector2D(star.GetLocation());
            Star     newStar = new Star(star.GetID(), newLoc, star.GetMass());

            // Set ship's modifiable variables
            newStar.SetHP(BossHealth);

            this.addStar(newStar);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Calculates gravity between a ship and a star.
        /// </summary>
        /// <returns>a Vector2D gravity</returns>
        private Vector2D CalculateForce(Ship ship, Star star)
        {
            // get direction
            Vector2D g = star.GetLocation() - ship.GetLocation();

            g.Normalize();

            // get magnitude
            g *= star.GetSize();

            return(g);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Returns true if ship and star are within collision distance, otherwise false.
        /// </summary>
        /// <param name="ship"></param>
        /// <param name="star"></param>
        /// <returns></returns>
        public bool HasCollidedShipStar(Ship ship, Star star)
        {
            Vector2D shipLoc        = ship.GetLocation();
            Vector2D starLoc        = star.GetLocation();
            Vector2D distanceVector = shipLoc - starLoc;
            double   distanceLength = distanceVector.Length();

            if (distanceLength <= StarSize)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 8
0
        /// <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 StarDrawer(object o, PaintEventArgs e)
        {
            Star   star = o as Star;
            Bitmap starSprite;
            int    x, y;
            Point  p;

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

            if (theWorld.GetMarioMode())
            {
                starSprite = marioStar;
            }
            else
            {
                starSprite = starSprites[star.GetID() % starSprites.Count];
            }

            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            e.Graphics.DrawImage(starSprite, p);
        }
Ejemplo n.º 9
0
        public void TestUpdatingStarLocationInWorldWithNewStar()
        {
            World    testWorld  = new World();
            Vector2D newStarLoc = new Vector2D(50, 50);

            testWorld.SpawnStars(0, 0, 1);
            Star firstFrame = (Star)testWorld.getStars()[0];

            double xStarFirstFrame = firstFrame.GetLocation().GetX();
            double yStarFirstFrame = firstFrame.GetLocation().GetY();

            Star secondFrame = new Star(0, newStarLoc, 1);

            testWorld.addStar(secondFrame);

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

            Star   sameStar         = (Star)testWorld.getStars()[0];
            double xStarSecondFrame = sameStar.GetLocation().GetX();
            double yStarSecondFrame = sameStar.GetLocation().GetY();

            Assert.IsTrue(xStarFirstFrame != xStarSecondFrame);
            Assert.IsTrue(yStarFirstFrame != yStarSecondFrame);
        }
Ejemplo n.º 10
0
        private bool CollidedWith(Projectile proj, Star star)
        {
            Vector2D distance = proj.GetLocation() - star.GetLocation();

            return(distance.Length() < starRadius);
        }
Ejemplo n.º 11
0
        private bool CollidedWith(Star star, Ship ship)
        {
            Vector2D distance = star.GetLocation() - ship.GetLocation();

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