示例#1
0
        public Level(ContentManager contentManager, SoundManager soundManager, GraphicsDevice device, bool editMode) : base()
        {
            mContentManager = contentManager;
            mSoundManager   = soundManager;
            mDevice         = device;
            mEditMode       = editMode;

            var currentDirectoryPath = Directory.GetCurrentDirectory();

            if (!currentDirectoryPath.EndsWith("Content") && !currentDirectoryPath.EndsWith("Content/") &&
                !currentDirectoryPath.EndsWith("Content\\"))
            {
                Directory.SetCurrentDirectory("../../../../Content");
            }

            mModelLoader = new ModelLoader(device);
            mQuadTree    = new QuadTree <Actor>(new Rectangle(-128, -128, 256, 256), 4, 7);
            // Load silverback
            mSilverback           = new Silverback(new Vector3(0.0f), new Vector2(0.0f), mModelLoader.LoadMesh("Mesh/gorilla_idle.fbx"));
            mSilverback.mQuadTree = mQuadTree;

            mHutMesh    = mModelLoader.LoadMesh("Mesh/spawningcabin_scaled 0.015.fbx");
            mHuts       = new List <Hut>();
            Hut.mAmount = 0;

            mGlobalSoundSourceBuffer    = new AudioBuffer("Audio/ForestSoundMono.wav");
            mGlobalSoundSource          = new AudioSource(mGlobalSoundSourceBuffer);
            mGlobalSoundSource.Relative = true;

            mSoundManager.AddSound(mGlobalSoundSource);

            mInitialSilverbackLocation = new Vector3(0.0f);

            if (!mEditMode)
            {
                mSilverback.Actor.mAnimator.SetStandardAnimation("idle");
                mModelLoader.LoadAnimation(mSilverback.Actor.mMesh, "Mesh/gorilla_walking.fbx");
                mModelLoader.LoadAnimation(mSilverback.Actor.mMesh, "Mesh/gorilla_smash.fbx");
                Add(mSilverback);
                mQuadTree.Insert(mSilverback.Actor, mSilverback.Actor.mBoundingRectangle.GetAxisAlignedRectangle(1));

                // Load all the other meshes
                // Load Lumberjack mesh
                mLumberjackMesh = mModelLoader.LoadMesh("Mesh/lumberjack_idle.fbx");
                mModelLoader.LoadAnimation(mLumberjackMesh, "Mesh/lumberjack_walk.fbx");
                mModelLoader.LoadAnimation(mLumberjackMesh, "Mesh/lumberjack_hit.fbx");
                mModelLoader.LoadAnimation(mLumberjackMesh, "Mesh/lumberjack_run.fbx");

                mLumberjacks = new ActorBatch(mLumberjackMesh, true);
                mActorBatches.Add(mLumberjacks);

                // Load DoubleAxeKiller mesh
                mDoubleAxeKillerMesh = mModelLoader.LoadMesh("Mesh/lumberjack_distance_idle.fbx");
                mModelLoader.LoadAnimation(mDoubleAxeKillerMesh, "Mesh/lumberjack_distance_walk.fbx");
                mModelLoader.LoadAnimation(mDoubleAxeKillerMesh, "Mesh/lumberjack_distance_hit.fbx");
                mModelLoader.LoadAnimation(mDoubleAxeKillerMesh, "Mesh/lumberjack_distance_run.fbx");

                mDoubleAxeKillers = new ActorBatch(mDoubleAxeKillerMesh, true);
                mActorBatches.Add(mDoubleAxeKillers);

                // Load Baboon Mesh
                mBaboonMesh = mModelLoader.LoadMesh("Mesh/gibbon_idle.fbx");
                mModelLoader.LoadAnimation(mBaboonMesh, "Mesh/gibbon_walk.fbx");
                mModelLoader.LoadAnimation(mBaboonMesh, "Mesh/gibbon_singing.fbx");

                mBaboonBatch = new ActorBatch(mBaboonMesh, true);
                mActorBatches.Add(mBaboonBatch);

                // Load Capuchin Mesh
                mCapuchinMesh = mModelLoader.LoadMesh("Mesh/kapuziner_idle.fbx");
                mModelLoader.LoadAnimation(mCapuchinMesh, "Mesh/kapuziner_walk.fbx");
                mModelLoader.LoadAnimation(mCapuchinMesh, "Mesh/kapuziner_heal.fbx");

                mCapuchinBatch = new ActorBatch(mCapuchinMesh, true);
                mActorBatches.Add(mCapuchinBatch);

                // Load Chimpanezze Mesh
                mChimpanezzeMesh = mModelLoader.LoadMesh("Mesh/chimp_idle.fbx");
                mModelLoader.LoadAnimation(mChimpanezzeMesh, "Mesh/chimp_walk.fbx");
                mModelLoader.LoadAnimation(mChimpanezzeMesh, "Mesh/chimp_attack.fbx");

                mChimpanezzeBatch = new ActorBatch(mChimpanezzeMesh, true);
                mActorBatches.Add(mChimpanezzeBatch);

                // Load Gibbon Mesh
                mGibbonMesh = mModelLoader.LoadMesh("Mesh/Gibbon_idle.fbx");
                mModelLoader.LoadAnimation(mGibbonMesh, "Mesh/Gibbon_walk.fbx");
                mModelLoader.LoadAnimation(mGibbonMesh, "Mesh/Gibbon_singing.fbx");

                mGibbonBatch = new ActorBatch(mGibbonMesh, true);
                mActorBatches.Add(mGibbonBatch);


                // Load Orang Utan Mesh
                mOrangUtanMesh = mModelLoader.LoadMesh("Mesh/orangutan_idle.fbx");
                mModelLoader.LoadAnimation(mOrangUtanMesh, "Mesh/orangutan_walk.fbx");
                mModelLoader.LoadAnimation(mOrangUtanMesh, "Mesh/orangutan_throw.fbx");

                mOrangutanBatch = new ActorBatch(mOrangUtanMesh, true);
                mActorBatches.Add(mOrangutanBatch);

                mAxeMesh = mModelLoader.LoadMesh("Mesh/axe.fbx");
            }

            mPostProcessing.mBloom.Activated = Options.Bloom;
            mPostProcessing.mBloom.mPasses   = Options.BloomPasses;

            mPostProcessing.mFxaa.Activated = Options.Fxaa;

            mSky.Light.mShadow.mActivated  = Options.Shadows;
            mSky.Light.mShadow.mDistance   = Options.ShadowDistance;
            mSky.Light.mShadow.mNumSamples = Options.ShadowSamples;
            mSky.Light.mShadow.mBias       = Options.ShadowBias;

            Directory.SetCurrentDirectory(currentDirectoryPath);
        }
示例#2
0
        public void LoadContent(GraphicsDeviceManager deviceManager,
                                ContentManager contentManager,
                                int windowWidth,
                                int windowHeight)
        {
            var currentDirectoryPath = Directory.GetCurrentDirectory();

            Directory.SetCurrentDirectory("../../../../Content");

            var graphicsDevice = deviceManager.GraphicsDevice;

            // Create a new content manager so we can unload all its content later
            mContentManager = new ContentManager(contentManager.ServiceProvider, contentManager.RootDirectory);


            mSpriteBatch = new SpriteBatch(graphicsDevice);

            var font        = mContentManager.Load <SpriteFont>("Font");
            var modelLoader = new ModelLoader(graphicsDevice);

            var texture2D = UIv2.Menu.CreateTexture2D(graphicsDevice,
                                                      50,
                                                      30,
                                                      pixel => Color.Black);

            mMenu = new UIv2.Menu(graphicsDevice, 0, 0, 100, 4);
            mMenu.NonSolid();
            mLabel = new UIv2.Components.Label(graphicsDevice, 0, 0, 25, 100, "", font, Color.Orange);
            mLabel.AddTo(mMenu);

            var backButton = new UIv2.Components.Button(graphicsDevice, 90, 0, 10, 100, texture2D, "Back", font, Color.White);

            backButton.AddTo(mMenu);

            backButton.AddListener(MouseButtons.Left, InputState.Pressed, () =>
            {
                ScreenManager.Remove(this);
                IsVisible = false;
            });

            mRenderTarget = new RenderTarget(graphicsDevice,
                                             Options.ResolutionWidth,
                                             Options.ResolutionHeight,
                                             1);
            mMasterRenderer = new MasterRenderer(graphicsDevice, mContentManager)
            {
                DebugMode = false
            };

            mCamera = new Camera(farPlane: Options.ViewingDistance,
                                 nearPlane: 0.5f,
                                 thirdPerson: true,
                                 location: new Vector3(0.0f, 0.0f, -110.0f));
            mCameraHandler = new CameraHandler(mCamera, 4.0f, 2.0f, .3f);

            mScene = new Scene();

            var staticObjectsRectangles = new List <CollisionRectangle>();

            mScene.mQuadTree = new QuadTree <Actor>(new Rectangle(-128, -128, 256, 256), 4, 10);

            mScene.mTerrain = new Terrain(mContentManager,
                                          graphicsDevice,
                                          "Terrain/level1 heightmap.png",
                                          "Terrain/techdemoTexture.png");
            mScene.Add(mScene.mTerrain);

            var obstacleMesh = modelLoader.LoadMesh("Mesh/beerbottle2.obj");

            var random = new Random();

            for (var i = 0; i < ObstacleCount; i++)
            {
                var x = (2.0f * (float)random.NextDouble() - 1.0f) * ObstacleRadius;
                var z = (2.0f * (float)random.NextDouble() - 1.0f) * ObstacleRadius;

                var vector = new Vector3(x, 0.0f, z) + new Vector3(20.0f, 0.0f, -100.0f);

                vector.Y = mScene.mTerrain.GetHeight(vector);

                var actor = new Actor(obstacleMesh)
                {
                    ModelMatrix = Matrix.CreateTranslation(vector)
                };

                mScene.Add(actor);
                mScene.mQuadTree.Insert(actor, actor.mBoundingRectangle.GetAxisAlignedRectangle(1));
                staticObjectsRectangles.Add(actor.mBoundingRectangle);
            }

            mScene.mVisibilityGraph = new Pathfinding.VisibilityGraph(staticObjectsRectangles, new Rectangle(-128, -128, 256, 256), 0.0f, false);

            var hutMesh = modelLoader.LoadMesh("Mesh/spawningcabin_scaled 0.015.fbx");

            var lumberjackMesh = modelLoader.LoadMesh("Mesh/lumberjack_minimal_noanimation.obj");

            var doubleAxeKillerMesh = modelLoader.LoadMesh("Mesh/lumberjack_distance_idle.fbx");

            modelLoader.LoadAnimation(doubleAxeKillerMesh, "Mesh/lumberjack_distance_walk.fbx");
            modelLoader.LoadAnimation(doubleAxeKillerMesh, "Mesh/lumberjack_distance_hit.fbx");
            modelLoader.LoadAnimation(doubleAxeKillerMesh, "Mesh/lumberjack_distance_run.fbx");

            var axeMesh = modelLoader.LoadMesh("Mesh/axe.fbx");

            var silverbackMesh = modelLoader.LoadMesh("Mesh/gorilla_idle.fbx");

            modelLoader.LoadAnimation(silverbackMesh, "Mesh/gorilla_walking.fbx");
            modelLoader.LoadAnimation(silverbackMesh, "Mesh/gorilla_smash.fbx");

            var capuchinMesh = modelLoader.LoadMesh("Mesh/kapuziner_idle.fbx");

            modelLoader.LoadAnimation(capuchinMesh, "Mesh/kapuziner_walk.fbx");
            modelLoader.LoadAnimation(capuchinMesh, "Mesh/kapuziner_heal.fbx");

            mSilverback = new Silverback(new Vector3(0.0f, 0.0f, -110.0f), new Vector2(0.0f), silverbackMesh);
            mScene.Add(mSilverback);

            var otherSilverback = new Silverback(new Vector3(0.0f, 0.0f, -110.0f), new Vector2(0.0f), silverbackMesh);

            mSubApe = new Capuchin(capuchinMesh, mScene.mTerrain, otherSilverback, mScene, ref random);
            mScene.Add(mSubApe);

            var hut = new Hut(hutMesh, lumberjackMesh, doubleAxeKillerMesh, axeMesh, mSilverback, mScene, 1000, 100.0f, 110.0f, true);

            mScene.Add(hut);

            mScene.mPostProcessing.mBloom.Activated = false;
            mScene.mPostProcessing.mFxaa.Activated  = false;
            mScene.mSky.Light.mShadow.mActivated    = false;

            mCamera.UpdatePerspective();

            Directory.SetCurrentDirectory(currentDirectoryPath);
        }
示例#3
0
        /// <summary>
        /// Load a file, read relevant infos from it and build level
        /// </summary>
        public void Load(string filename)
        {
            /* File is build up like this line by line(for now)
             * 1. Light information x,y,z
             * 1. Heightmap path
             * 2. Heightmap texture path
             * 3. M Mesh1 (including relative path to mesh? and other relevant informations)
             * 4. A Actor1 using Mesh1 is represented by following information: x,z,rotation,(scale?)
             * 5. A Actor2 using Mesh1 is represented by following information: x,z,rotation,(scale?)
             * 6. ......
             * n. Mesh2 (including relative path to mesh? and other relevant informations)
             * k. EOF (end of file, stream reader stops reading)
             */
            var currentDirectoryPath = Directory.GetCurrentDirectory();

            if (currentDirectoryPath.EndsWith("Content") || currentDirectoryPath.EndsWith("Content/") ||
                currentDirectoryPath.EndsWith("Content\\"))
            {
                Directory.SetCurrentDirectory("..\\bin\\Windows\\x86\\Debug\\");
            }
            mLevelFilename = filename;
            try
            {
                using (var sr = new StreamReader(filename))
                {
                    var directoryPath = Path.GetDirectoryName(filename);

                    Directory.SetCurrentDirectory(directoryPath);

                    // Load/build terrain
                    mTerrain = new Terrain(mContentManager, mDevice, sr.ReadLine(), sr.ReadLine());
                    mTerrain.mGrass.mActivated = Options.GraphicsQuality > 0 ? true : false;
                    var mCollisionRectangles = new List <CollisionRectangle>();

                    string line;

                    Mesh mesh = null;
                    // Load the rest (objects and actors and light)
                    while ((line = sr.ReadLine()) != null)
                    {
                        var lineSub = line.Substring(2);

                        if (line.StartsWith("M "))
                        {
                            // Read the path to the mesh
                            mesh      = mModelLoader.LoadMesh(lineSub);
                            mesh.Path = lineSub;
                        }
                        else if (line.StartsWith("A "))
                        {
                            var strings       = lineSub.Split(' ');
                            var actorLocation = strings[0].Split(',');
                            var actorRotation = strings[1].Split(',');
                            var actorOffset   = strings[2];

                            var x = StringToFloat(actorLocation[0]);
                            var z = StringToFloat(actorLocation[1]);

                            var qX = StringToFloat(actorRotation[0]);
                            var qY = StringToFloat(actorRotation[1]);
                            var qZ = StringToFloat(actorRotation[2]);
                            var qW = StringToFloat(actorRotation[3]);

                            var offset = StringToFloat(actorOffset);

                            var vector = new Vector3(x, 0.0f, z);
                            vector.Y = mTerrain.GetHeight(vector) - offset;

                            var quaternion = new Quaternion(qX, qY, qZ, qW);

                            var matrix = Matrix.CreateFromQuaternion(quaternion) * Matrix.CreateTranslation(vector);
                            var actor  = new Actor(mesh)
                            {
                                ModelMatrix = matrix
                            };

                            // We dont want to allow actors which hover above the ground to be in the collision caluc
                            if (-offset < mesh.mMeshData.mBoundingSphere.Radius && actor.mBoundingRectangle.mCollidable)
                            {
                                mQuadTree.Insert(actor, actor.mBoundingRectangle.GetAxisAlignedRectangle(1));
                                mCollisionRectangles.Add(actor.mBoundingRectangle);
                            }

                            Add(actor);
                        }
                        else if (line.StartsWith("L "))
                        {
                            var strings = lineSub.Split(' ');

                            var time         = strings[0];
                            var lightColor   = strings[1].Split(',');
                            var lightAmbient = strings[2];

                            var light = mSky.Light;

                            mSky.mTime = StringToFloat(time);

                            light.mColor.X = StringToFloat(lightColor[0]);
                            light.mColor.Y = StringToFloat(lightColor[1]);
                            light.mColor.Z = StringToFloat(lightColor[2]);

                            light.mAmbient = StringToFloat(lightAmbient);
                        }
                        else if (line.StartsWith("B "))
                        {
                            var strings = lineSub.Split(' ');

                            var threshold = strings[0];
                            var power     = strings[1];
                            var intensity = strings[2];

                            mPostProcessing.mBloom.mThreshold = StringToFloat(threshold);
                            mPostProcessing.mBloom.mPower     = StringToFloat(power);
                            mPostProcessing.mBloom.mIntensity = StringToFloat(intensity);
                        }
                        else if (line.StartsWith("F "))
                        {
                            var strings = lineSub.Split(' ');

                            var lumaThreshold    = strings[0];
                            var lumaThresholdMin = strings[1];

                            mPostProcessing.mFxaa.mLumaThreshold    = StringToFloat(lumaThreshold);
                            mPostProcessing.mFxaa.mLumaThresholdMin = StringToFloat(lumaThresholdMin);
                        }
                        else if (line.StartsWith("T "))
                        {
                            mLevelTitle = lineSub;
                        }
                        else if (line.StartsWith("S "))
                        {
                            var story = lineSub.Replace('|', '\n');
                            mLevelStory = story;
                        }
                        else if (line.StartsWith("H "))
                        {
                            var strings     = lineSub.Split(' ');
                            var hutLocation = strings[0].Split(',');
                            var hutRotation = strings[1].Split(',');
                            var hutHp       = strings[2];

                            var x = StringToFloat(hutLocation[0]);
                            var z = StringToFloat(hutLocation[1]);

                            var qX = StringToFloat(hutRotation[0]);
                            var qY = StringToFloat(hutRotation[1]);
                            var qZ = StringToFloat(hutRotation[2]);
                            var qW = StringToFloat(hutRotation[3]);

                            var hp = Convert.ToInt32(hutHp);

                            var vector = new Vector3(x, 0.0f, z);
                            vector.Y = mTerrain.GetHeight(vector);

                            var quaternion = new Quaternion(qX, qY, qZ, qW);

                            var matrix = Matrix.CreateFromQuaternion(quaternion) * Matrix.CreateTranslation(vector);

                            var hut = new Hut(mHutMesh, mLumberjackMesh, mDoubleAxeKillerMesh, mAxeMesh, mSilverback, this, hp, 15.0f, 30.0f, false);
                            hut.Actor.ModelMatrix = matrix;

                            mHuts.Add(hut);
                            if (!mEditMode)
                            {
                                mQuadTree.Insert(hut.Actor, hut.Actor.mBoundingRectangle.GetAxisAlignedRectangle(1));
                                Add(hut);
                            }
                            else
                            {
                                hut.Actor.IActor = null;
                                Add(hut.Actor);
                            }

                            mCollisionRectangles.Add(hut.Actor.mBoundingRectangle);
                        }
                        else if (line.StartsWith("W "))
                        {
                            var strings = lineSub.Split(' ');

                            var fogColor    = strings[0].Split(',');
                            var fogDistance = strings[1];

                            mFog.mColor.X = StringToFloat(fogColor[0]);
                            mFog.mColor.Y = StringToFloat(fogColor[1]);
                            mFog.mColor.Z = StringToFloat(fogColor[2]);

                            mFog.mDistance = StringToFloat(fogDistance);
                        }
                        else if (line.StartsWith("N "))
                        {
                            mNextLevelFilename = lineSub;
                        }
                        else if (line.StartsWith("P "))
                        {
                            if (mSpawnablePrimatesCount == -1)
                            {
                                mSpawnablePrimatesCount = Convert.ToInt32(lineSub);
                            }
                        }
                        else if (line.StartsWith("I "))
                        {
                            var strings = lineSub.Split(',');

                            var x = StringToFloat(strings[0]);
                            var z = StringToFloat(strings[1]);

                            var location = new Vector3(x, 0.0f, z);
                            location.Y = mTerrain.GetHeight(location);

                            mInitialSilverbackLocation = location;

                            mSilverback.Actor.ModelMatrix = Matrix.CreateTranslation(location);
                        }
                    }

                    sr.Close();

                    Add(mTerrain);
                    mVisibilityGraph = new Pathfinding.VisibilityGraph(mCollisionRectangles, new Rectangle(-128, -128, 256, 256), 1.0f, false);

                    Directory.SetCurrentDirectory(currentDirectoryPath);
                }
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine("This file could not be read:");
                Console.WriteLine(e.Message);
                throw;
            }
        }