public override void Initialize()
        {
            textureEditor = new TextureEditor("TextureEditorTest", textureEditorInterface);
            textureEditorInterface.TextureEditor = textureEditor;

            levelEditor.Visible = true;
            textureEditorInterface.Visible = true;
            assetsWindow.Visible = true;

            mList.Add(TileManager.Get());

            mSpriteBatch = GameFiles.SpriteBatch;
            mGraphicDevice = GameFiles.GraphicsDevice;

            mEditorWorkAreaRenderTexture2D = new RenderTarget2D(mGraphicDevice, 728, 561);

            GameFiles.EditorWorkAreaRenderTexture2D = mEditorWorkAreaRenderTexture2D;

            gizmo = new GizmoComponent();

            mTerrain = new Terrain[4];

            for (int loop = 0; loop < mTerrain.Length; loop += 2)
            {
                mTerrain[loop] = new Terrain();
                mTerrain[loop].WorldPosition = new Vector3(2048 * (-loop / 2), 0, -2048);

                mTerrain[loop + 1] = new Terrain();
                mTerrain[loop + 1].WorldPosition = new Vector3(2048 * (-loop / 2), 0, 0);
            }

            for (int loop = 0; loop < mTerrain.Length; loop++)
            {
                mTerrain[loop].Update();
            }

            mSelectionBox = GameFiles.LoadTexture2D("Selection");
            mRectangle = new Rectangle(0, 0, mSelectionBox.Width, mSelectionBox.Height);

            levelEditor.mRectangle = mRectangle;
        }
Пример #2
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;
            }
        }