示例#1
0
        /// <summary>
        /// this method checks if the ship is going out of the universe.
        /// </summary>
        /// <param name="s"></param>
        private static void shipsPosition(Ship s)
        {
            //if ships x is greater than universize by 2.
            if (s.getShipLoc().GetX() > (UniverseSize / 2))
            {
                //set ship to the opposite location.
                s.setShipLoc(new Vector2D((-UniverseSize / 2), (s.getShipLoc().GetY())));
            }

            //if ships y os greter than universesize by two
            if (s.getShipLoc().GetY() > (UniverseSize / 2))
            {
                //set ship to the opposite location.
                s.setShipLoc(new Vector2D((s.getShipLoc().GetX()), (-(UniverseSize / 2))));
            }
            //if ships x is less than universize by 2.
            if (s.getShipLoc().GetX() < -(UniverseSize / 2))
            {
                //set ship to the opposite location.
                s.setShipLoc(new Vector2D(((UniverseSize / 2)), s.getShipLoc().GetY()));
            }
            //if ships y os less than universesize by two
            if (s.getShipLoc().GetY() < -(UniverseSize / 2))
            {
                //set ship to the opposite location.
                s.setShipLoc(new Vector2D((s.getShipLoc().GetX()), (UniverseSize / 2)));
            }
        }
示例#2
0
        /// <summary>
        /// This method is used to move ship/
        /// </summary>
        /// <param name="s"></param>
        private static void moveShip(Ship s)
        {
            //calls the method shipFuntion from world class.
            s.shipFunctions();
            //sets gravity to 0,0.
            Vector2D g = new Vector2D(0, 0);

            //calculate g.
            g = star.getStarLoc() - s.getShipLoc();
            g.Normalize();
            //gets the mass of the star from xml file.
            g = g * star.getStarMass();

            Vector2D a = new Vector2D(0, 0);

            //the ship is thrusting.
            if (s.getShipThrust())
            {
                Vector2D t = new Vector2D(s.getShipDir());
                //calculate the thrust and apply to gravity.
                t = t * 0.08;
                a = g + t;
            }
            else
            {
                //else acceleration is equal to gravity.
                a = g;
            }
            //set thr ships velocity and location.
            s.setShipVelocity(s.getShipVelocity() + a);
            s.setShipLoc(s.getShipLoc() + s.getShipVelocity());
        }