Ejemplo n.º 1
0
        public static double GetEscapeVelocity(Coordinate coord, IMassive body)
        {
            // V(esc) = 2 * G * M / r
            double dist = VecCart(coord).Length;

            return(dist == 0 ? 0 : body.Mass / dist);
        }
Ejemplo n.º 2
0
            public void ApplyGravity(IMassive massive)
            {
                Vector distVec         = VecCart(massive.Vel.Origin, this.Vel.Origin);
                double distanceSquared = Math.Pow(distVec.Length, 2);
                double force           = distanceSquared == 0 ? 0 : massive.Mass / distanceSquared;
                Vector forceVec        = VecCirc(distVec.ForwardAngle, force, this.Vel.Origin);

                this.Accel = AddVectors(this.Accel, forceVec);
            }
Ejemplo n.º 3
0
    void OnTriggerStay2D(Collider2D collision)
    {
        IMassive massComponent = collision.GetComponent <IMassive>();

        // The colliding object will begin falling if the point on the bottom of the object's collider is contained inside of the collider on this pit
        if (massComponent != null && !massComponent.isFalling() && m_Collider2D.bounds.Contains(collision.bounds.center - new Vector3(0, collision.bounds.size.y / 2, collision.bounds.center.z)))
        {
            if (collision.CompareTag("Player"))
            {
                massComponent.Fall(fallingRate);
                UI_Manager.WinGame();
            }
        }
    }
Ejemplo n.º 4
0
    void OnTriggerStay2D(Collider2D collision)
    {
        IMassive massComponent = collision.GetComponent <IMassive>();

        // The colliding object will begin falling if the point on the bottom of the object's collider is contained inside of the collider on this pit
        if (massComponent != null && !massComponent.isFalling() && m_Collider2D.bounds.Contains(collision.bounds.center - new Vector3(0, collision.bounds.size.y / 2, collision.bounds.center.z)))
        {
            if (collision.CompareTag("Block"))
            {
                massComponent.Fall(fallingRate);
                Destroy(gameObject);
            }
            else
            {
                massComponent.Fall(fallingRate);
                audioPlayer.PlaySFX(fallsfx);
            }
        }
    }
Ejemplo n.º 5
0
        public void SetNewWave()
        {
            XmlNode asteroidConfig = (from XmlNode node in this.Level.ChildNodes
                                      where node.Name == "Asteroid"
                                      select node).First();

            int number = 0, altitude = 0, parent = 0;

            Int32.TryParse(asteroidConfig.Attributes["number"].Value, out number);
            Int32.TryParse(asteroidConfig.Attributes["altitude"].Value, out altitude);
            Int32.TryParse(asteroidConfig.Attributes["parent"].Value, out parent);
            Random rand = new Random();

            for (int i = 0; i < number; i++)
            {
                double   forwardAngle = i * 2 * Math.PI / number - Math.PI / 2;
                IMassive parentBody   = parent == 0 ? this.Barycenter : this.Planets[parent - 1];
                Vector   distVec      = VecCirc(i * 2 * Math.PI / number, altitude, parentBody.Vel.Origin);
                this.Asteroids.Add(new Asteroid(rand, VecCirc(forwardAngle, Physics.GetOrbitalVelocity(distVec.Head, parentBody), distVec.Head), 50, .5, "#808080", (rand.NextDouble() - .5) / 200));
            }
        }
Ejemplo n.º 6
0
        public void SetShip()
        {
            XmlNode shipConfig = (from XmlNode node in this.Level.ChildNodes
                                  where node.Name == "Ship"
                                  select node).First();

            if (this.Ships.Count == 0)
            {
                this.Ships.Add(new Ship(VecCirc()));
            }

            int altitude = 0, parent = 0;

            Int32.TryParse(shipConfig.Attributes["altitude"].Value, out altitude);
            Int32.TryParse(shipConfig.Attributes["parent"].Value, out parent);

            IMassive parentBody = parent == 0 ? this.Barycenter : this.Planets[parent - 1];
            Vector   distVec    = VecCirc(Math.PI, altitude, parentBody.Vel.Origin);

            this.Ships[0].Vel          = VecCirc(Math.PI / 2, Physics.GetOrbitalVelocity(distVec.Head, parentBody), distVec.Head);
            this.Ships[0].DeltaRot     = 0;
            this.Ships[0].ForwardAngle = 0;
        }
Ejemplo n.º 7
0
        public static double GetOrbitalVelocity(Coordinate coord, IMassive body)
        {
            double dist = VecCart(coord, body.Vel.Origin).Length;

            return(dist == 0 ? 0 : Math.Sqrt(body.Mass / dist) / 4);
        }
Ejemplo n.º 8
0
        private static void CheckAsteroidEscaped(IEnumerable <Asteroid> asteroids, DestroyAsteroids destroyAsteroids, IMassive barycenter)
        {
            List <Asteroid> doomedAsteroids = new List <Asteroid>();

            foreach (Asteroid asteroid in asteroids)
            {
                if ((Math.Abs(asteroid.Vel.Origin.X) > 300 || Math.Abs(asteroid.Vel.Origin.Y) > 300) && Physics.GetEscapeVelocity(asteroid.Vel.Origin, barycenter) <= asteroid.Vel.Length)
                {
                    doomedAsteroids.Add(asteroid);
                }
            }
            destroyAsteroids(doomedAsteroids, false);
        }
Ejemplo n.º 9
0
        private static void CheckShotEscaped(IEnumerable <Shot> shots, DestroyShots destroyShots, IMassive barycenter)
        {
            List <Shot> doomedShots = new List <Shot>();

            foreach (Shot shot in shots)
            {
                if ((Math.Abs(shot.Vel.Origin.X) > 300 || Math.Abs(shot.Vel.Origin.Y) > 300) && Physics.GetEscapeVelocity(shot.Vel.Origin, barycenter) <= shot.Vel.Length)
                {
                    doomedShots.Add(shot);
                }
            }
            destroyShots(doomedShots);
        }
Ejemplo n.º 10
0
 public static void HandleCollisions(IEnumerable <Shot> shots, IEnumerable <Asteroid> asteroids, IEnumerable <Planet> planets, IEnumerable <Ship> ships, IMassive barycenter, DestroyShots destroyShots, DestroyShips destroyShips, DestroyAsteroids destroyAsteroids, int maxShots, int maxAsteroids)
 {
     CheckShotEscaped(shots, destroyShots, barycenter);
     CheckAsteroidEscaped(asteroids, destroyAsteroids, barycenter);
     CheckShipEscaped(ships, destroyShips);
     CheckShotAsteroidCollision(shots, asteroids, destroyShots, destroyAsteroids);
     CheckShotShipCollision(shots, ships, destroyShots, destroyShips);
     CheckShotPlanetCollision(shots, planets, destroyShots);
     CheckAsteroidShipCollision(asteroids, ships, destroyAsteroids, destroyShips);
     CheckAsteroidPlanetCollision(asteroids, planets, destroyAsteroids);
     CheckShipPlanetCollision(ships, planets, destroyShips);
     CheckMaxShots(shots, maxShots);
     CheckMaxAsteroids(asteroids, maxAsteroids);
 }