Example #1
0
        // This provides sub classes a hook to enforce restrictions on the camera's position
        protected override void RestrictPosition(Vector3 previousPosition)
        {
            // Get the range of coordinates allowed in the world
            float maxX = terrain.MaxX;
            float minX = terrain.MinX;

            float maxZ = terrain.MaxZ;
            float minZ = terrain.MinZ;

            float x = Position.X;
            float y = Position.Y;
            float z = Position.Z;

            // Make sure the move won't place the camera outside the world
            if (Position.X < minX || Position.X > maxX)
            {
                x = previousPosition.X;
            }

            if (Position.Z < minZ || Position.Z > maxZ)
            {
                z = previousPosition.Z;
            }

            // Ensure the camera moves along the ground
            float height = terrain.GetHeight(x, z) + POSITION_ABOVE_GROUND;

            y = height;

            Position = new Vector3(x, y, z);
        }
Example #2
0
        private void CheckTerrainCollision(Terrain terrain)
        {
            float minHeightAllowed = terrain.GetHeight(Position.X, Position.Z);

            if (Position.Y < minHeightAllowed)
            {
                Console.WriteLine("Collided with the ground...");
                IsAlive = false;
            }
        }
Example #3
0
        private void UpdatePosition(Camera camera, Terrain terrain)
        {
            // Move in a straight line along the direction the alien is facing
            Position += Direction * movementSpeed;

            // Keep the alien moving on the terrain
            RestrictPositionToTerrainBoundaries(terrain);

            // Ensure the alien still appears on the terrain
            Position.Y = terrain.GetHeight(Position.X, Position.Z) + POSITION_ABOVE_GROUND;
        }
Example #4
0
        private void LoadAliens()
        {
            Model alienModel = Game.Content.Load <Model>(@"Models\alien");

            Random randomNumberGenerator = (Random)Game.Services.GetService(typeof(Random));
            int    alienCount            = randomNumberGenerator.Next(MIN_ALIEN_COUNT, MAX_ALIEN_COUNT);

            aliens = new List <Alien>();
            hud.alienRadarCount = alienCount;

            for (int i = 0; i < alienCount; i++)
            {
                // Place each alien at a random point on the terrain
                Vector3 position = GetUniqueRandomPointInWorld(randomNumberGenerator);
                position.Y = terrain.GetHeight(position.X, position.Z);

                Alien alien = new Alien(alienModel, position, Vector3.UnitZ);
                aliens.Add(alien);

                Console.WriteLine("Alien[" + i + "]: " + alien.Position);
            }
        }
Example #5
0
        private void UpdatePosition(Camera camera, Terrain terrain)
        {
            // Move in a straight line along the direction the alien is facing
            Position += Direction * movementSpeed;

            // Keep the alien moving on the terrain
            RestrictPositionToTerrainBoundaries(terrain);

            // Ensure the alien still appears on the terrain
            Position.Y = terrain.GetHeight(Position.X, Position.Z) + POSITION_ABOVE_GROUND;
        }
 private void CheckTerrainCollision(Terrain terrain)
 {
     float minHeightAllowed = terrain.GetHeight(Position.X, Position.Z);
     if (Position.Y < minHeightAllowed)
     {
         Console.WriteLine("Collided with the ground...");
         IsAlive = false;
     }
 }