Example #1
0
        void InitializeScene()
        {
            ResetScene();

            Entities.Add("Sky", new Sky());
            MainLight = new Sunlight();
            MainTerrain = new TerrainVoxel();
            /*
            MainTerrain = new TerrainHeightmap("Textures/level1_hm.png", 0, 100.0f);
            float width = (MainTerrain as TerrainHeightmap).GetWidth();
            float height = (MainTerrain as TerrainHeightmap).MaximumHeight;
            MainTerrain.Transformation.SetScale(new Vector3(1, height / width, 1) * width);
            */

            MainPlayer = new Camera();

            Entities.Add("MainCamera", MainPlayer);
            Entities.Add("Terrain", MainTerrain);
            Entities.Add("Light", MainLight);
            Entities.Add("Plane", new Model("Plane"));
            Entities.Add("AmbientLight", new Light(LightType.Ambient, new Vector3(0.15f, 0.35f, 0.55f), Vector3.Zero, false));
            Entities.Add("TestTree", new Model("Palm02"));
            Entities["TestTree"].Transformation.SetPosition(Vector3.Forward * 10.0f);
            Entities.Add("TestTree2", new Model("JungleOverhang"));
            Entities["TestTree2"].Transformation.SetPosition(Vector3.Forward * 10.0f + Vector3.Right * 7.6f);

            //AddEntity("Grass", new GrassPlacement());
            AddEntity("Forest", new ForestManager());
            //CreateForest();

            //Entities.Add("Grass", new ShapePlacement());

            /*
            Model testGeom = new Model("test_level");
            testGeom.Transformation.SetPosition(Vector3.Up*20.0f);
            Entities.Add("scene_geom1", testGeom);

            Model testGeom2 = new Model("cgWarehouse002story");
            testGeom2.Transformation.SetPosition(Vector3.Up * 21.0f);
            Entities.Add("scene_geom2", testGeom2);
            */
            AnimatedModel model = new AnimatedModel("Allosaurus");

            model.Transformation.SetPosition(Vector3.Forward*10+Vector3.Up*68);
            model.Model.GetAnimationLayer().SetActiveAnimation("AllosaurusIdle", true);//.SetAnimationLayer("AllosaurusIdle", 1.0f);
            model.Model.SetCustomMatrix(Matrix.CreateScale(0.09f)*Matrix.CreateRotationX(-MathHelper.PiOver2));
            //model.UpdateAnimation();
            Entities.Add("TestCharacter", model);

            AnimatedModel model2 = new AnimatedModel("AlphaRaptor");

            model2.Transformation.SetPosition(Vector3.Forward * -5 + Vector3.Up * 62);
            model2.Model.GetAnimationLayer().SetActiveAnimation("AlphaRaptorIdle", true);//.SetAnimationLayer("AlphaRaptorIdle", 1.0f);
            model2.Model.SetCustomMatrix(Matrix.CreateScale(0.12f) * Matrix.CreateRotationX(-MathHelper.PiOver2));
            //model.UpdateAnimation();
            Entities.Add("TestCharacter2", model2);

            Raptor raptor = new Raptor(ResourceManager.Inst.GetDinosaurDatablock("Coelophysis"));
            Entities.Add("Raptor", raptor);

            Chest weaponCrate = new Chest("Weapon Box", "WeaponBox");
            weaponCrate.Transformation.SetPosition(Vector3.Up * 30.0f);
            Entities.Add("weaponCrate", weaponCrate);
            CreateTeams();

            //Entities.Add("Light2", new Light(LightType.Directional, new Vector3(0.2797f, 0.344f, 0.43f), Vector3.Up, false));

            Initialize();
        }
Example #2
0
 void SpawnDinosaurs()
 {
     double difficulty = 0.15 * Math.Pow(scene.MainPlayer.GetHealthPercent(), 0.25);
     double nightTerm = 0.35 * Math.Min(0.0, Math.Max(1.0, -scene.MainLight.Transformation.GetPosition().Y));
     double spawnProbability = difficulty + nightTerm + 0.6 * RandomHelper.RandomGen.NextDouble();
     int spawnCount = Math.Max(1, (int)spawnProbability * MAX_ENEMIES);
     Vector3 playerPosition = scene.MainPlayer.Transformation.GetPosition();
     Vector3 fwd = scene.MainPlayer.GetForwardVector();
     Vector3 right = scene.MainPlayer.GetRightVector();
     Vector3 minVector = playerPosition - right - fwd*100 - Vector3.Up*50;
     Vector3 maxVector = playerPosition + right - fwd*15 + Vector3.Up*50;
     BoundingBox spawnRegion = new BoundingBox(Vector3.Min(minVector, maxVector), Vector3.Max(minVector, maxVector));
     List<TriangleGraph> availableTriangles = null;
     scene.MainTerrain.GetTrianglesInRegion(RandomHelper.RandomGen, out availableTriangles, spawnRegion);
     if (availableTriangles.Count > 0)
     {
         for (int i = 0; i < spawnCount; i++)
         {
             int randDinoIndex = RandomHelper.RandomGen.Next(dinoDatablocks.Length);
             if (dinoDatablocks[randDinoIndex].Name == "Allosaurus")
             {
                 if (RandomHelper.RandomGen.NextDouble() < 0.75)
                 {
                     int oldIndex = randDinoIndex;
                     while(randDinoIndex == oldIndex)
                         randDinoIndex = RandomHelper.RandomGen.Next(dinoDatablocks.Length);
                 }
             }
             Raptor raptor = new Raptor(dinoDatablocks[randDinoIndex]);
             Vector3 spawnPos = availableTriangles[RandomHelper.RandomGen.Next(availableTriangles.Count)].Centroid + Vector3.Up * 3.0f;
             raptor.SetSpawnPosition(spawnPos);
             scene.AddEntity("Raptor", raptor);
             activeDinosaurs.Add(raptor);
         }
     }
 }