예제 #1
0
        public static void RunGameDebug()
        {
            MainMenu.Hide();

            Input.LockMode      = CursorLockModes.Lock;
            Input.CursorVisible = false;

            new Shader("assets/shaders/cursor/Cursor.vert", "assets/shaders/cursor/Cursor.frag");
            WObject   playerWobj = new WObject("Player");
            RigidBody rb         = playerWobj.AddModule <RigidBody>();

            rb.UseGravity = false;
            BoxCollider bc = playerWobj.AddModule <BoxCollider>();

            bc.Extents = new Vector3D(0.4F, 0.9F, 0.4F);

            playerWobj.AddModule <Player>();

            //FreeCam.FreeCTRL = true;

            Camera.Main.WObject.AddModule <FreeCam>();

            Camera.Main._FarClip = 1000.0F;
            Camera.Main.FOV      = 80.0F;

            playerWobj.Position = Vector3F.Up * 80F;

            Database db = Database.Load("assets/items/items.json");

            db.ParseItems();

            new Shader("assets/shaders/chunk/Chunk.vert", "assets/shaders/chunk/Chunk.frag");
            new Shader("assets/shaders/itemUnlit/ItemUnlit.vert", "assets/shaders/itemUnlit/ItemUnlit.frag");

            Chunk.ChunkTexture = ItemCache.BuildChunkTexture(out int xsize, out int ysize);
            Chunk.TexWidth     = xsize;
            Chunk.TexHeight    = ysize;
            CreateSkybox();

            WObject worldwobj = new WObject("World");

            worldwobj.AddModule <World>();


            new WObject("Debug").AddModule <DebugMenu>();
            new WObject("EscapeMenu").AddModule <EscapeMenu>();

            WObject crosshair = new WObject("Crosshair");

            crosshair.Parent = Engine.GUI.Canvas.Main.WObject;
            Engine.GUI.Image reticule = crosshair.AddModule <Engine.GUI.Image>();
            reticule.Picture   = new Texture("assets/textures/crosshair.png");
            reticule.KeepRatio = true;
            reticule.Material.SourceColorBlending = OpenTK.Graphics.OpenGL4.BlendingFactorSrc.OneMinusDstColor;
            reticule.MinAnchor = new Vector2F(0.48F, 0.48F);
            reticule.MaxAnchor = new Vector2F(0.52F, 0.52F);

            reticule.MaxSize = Vector3F.One * 30.0F;

            WObject itembar = new WObject("Item Bar");

            itembar.Parent = Canvas.Main.WObject;
            Image bar = itembar.AddModule <Image>();

            bar.Picture   = new Texture("assets/textures/itembar.png");
            bar.KeepRatio = true;
            bar.MinAnchor = new Vector2F(0.35F, 0.005F);
            bar.MaxAnchor = new Vector2F(0.65F, 0.08F);
            bar.Color     = new Color256(1.0, 1.0, 1.0, 0.8F);

            Mesh mesh = Mesh.LoadFile("assets/models/BlockCube.obj", MeshFormats.Wavefront);

            for (int i = 0; i < ItemCache.TotalItems; i++)
            {
                Cube item = ItemCache.Get <Cube>(i);

                if (!(item is Cube))
                {
                    continue;
                }

                WObject cube = new WObject("Cube");

                cube.Parent = itembar;
                Model    model = cube.AddModule <Model>();
                Material mat   = new Material(Shader.Find("ItemUnlit"));
                mat.SetData <Vector2>("offset", new Vector2D(0, (double)i / ItemCache.TotalItems));
                mat.SetData <Vector2>("tiling", new Vector2D(1.0, 1.0 / ItemCache.TotalItems));
                mat.SetData <Vector3>("lightDir", new Vector3D(0.8, 1.0, -0.6));
                mat.SetData <Vector4>("ambiant", new Color256(0.0, 0.0, 0.0, 1.0));
                mat.SetData <Vector4>("lightColor", new Color256(2.0, 2.0, 2.0, 1.0));
                mat.SetData <Texture>("albedo", Texture.Find("Cache"));
                mat.SetData <Vector4>("color", Color256.White);

                model.Renderer.Mesh     = mesh;
                model.Renderer.Material = mat;
                model.KeepRatio         = true;

                cube.Scale   *= 1.1F;
                cube.Rotation = new Engine.Quaternion(-21, 45, -20);

                float shift = i * 0.1093F;

                model.MinAnchor = new Vector2F(0.0175F + shift, 0.0F);
                model.MaxAnchor = new Vector2F(0.11F + shift, 1.0F);
            }

            WObject itemcursor = new WObject("Item Cursor");

            itemcursor.Parent = bar.WObject;
            Image itemcurs = itemcursor.AddModule <Image>();

            itemcurs.Picture   = new Texture("assets/textures/barcursor.png");
            itemcurs.Color     = new Color256(0.4, 0.4, 1.0, 1.0F);
            itemcurs.MinAnchor = new Vector2F(0.0F, 0.0F);
            itemcurs.MaxAnchor = new Vector2F(0.125F, 1.0F);
            itemcurs.KeepRatio = true;
        }
예제 #2
0
        private static ushort[] LoadFromSave(string path)
        {
            JsonSerializer serializer = new JsonSerializer();

            using (StreamReader sr = File.OpenText(path))
                using (JsonTextReader jtr = new JsonTextReader(sr))
                {
                    JSONChunk dc = (JSONChunk)serializer.Deserialize(jtr, typeof(JSONChunk));

                    ushort[] blocks     = new ushort[Chunk.Width * Chunk.Height * Chunk.Depth];
                    int      chunkindex = 0;

                    for (int z = 0; z < Chunk.Depth; z++)
                    {
                        for (int y = 0; y < Chunk.Height; y++)
                        {
                            for (int x = 0; x < Chunk.Width; x++)
                            {
                                blocks[x + Chunk.Width * y + Chunk.Width * Chunk.Height * z] = ItemCache.GetIndex(dc.Palette[dc.Data[chunkindex++]]);
                            }
                        }
                    }

                    return(blocks);
                }
        }
예제 #3
0
        public static ushort[] CreateTerrain(int chunkx, int chunky, bool save = false, bool erase = false)
        {
            ushort[] blocks = new ushort[Chunk.Width * Chunk.Height * Chunk.Depth];

            string id;
            ushort cacheindex = 0;
            Dictionary <string, ushort> idscache = new Dictionary <string, ushort>();

            for (int z = 0; z < Chunk.Depth; z++)
            {
                for (int y = 0; y < Chunk.Height; y++)
                {
                    for (int x = 0; x < Chunk.Width; x++)
                    {
                        id = "winecrash:air";

                        const float scale         = 0.025F;
                        const float contScale     = 0.001F;
                        const float mountainScale = 0.005F;
                        const float shiftX        = 0; //Début des farlands : 16000000 | Grosses Farlands : 200000000
                        const float shiftZ        = 0; //todo: auré tu fais chier avec tes commentaires.

                        const float caveScale = 0.1F;
                        const float thresold  = 0.3F;


                        float xsample = (chunkx * Chunk.Width + shiftX + x);
                        float ysample = (chunky * Chunk.Depth + shiftZ + z);

                        float  continentValue    = continents.GetValue(xsample * contScale, ysample * contScale);
                        double continentalHeight = WMath.Remap(WMath.Clamp(Math.Exp(continentValue), 0.0, 65.0), -1.0D, 1.0D, 55.0D, 63.0D);

                        float  landValue  = details.GetValue(xsample * scale, ysample * scale);
                        double landHeight = WMath.Remap(landValue, -1.0D, 1.0D, 0.0D, 30.0D);

                        float mountainValue = (float)WMath.Remap(mountainMult.GetValue(xsample * mountainScale, ysample * mountainScale), -1.0, 1.0, 0.0, 1.0);
                        mountainValue = (float)WMath.Clamp(Math.Pow(mountainValue, 4.0), 0.0, 1.0);

                        double final = continentalHeight + (landHeight * mountainValue);

                        int height = (int)final;

                        bool waterlevel = height < 64;


                        if (y == height)
                        {
                            if (waterlevel)
                            {
                                id = "winecrash:sand"; //sand
                            }
                            else
                            {
                                id = "winecrash:grass"; //grass
                            }
                        }
                        else if (y < height)
                        {
                            if (y > height - 3)
                            {
                                if (waterlevel)
                                {
                                    id = "winecrash:sand"; //sand
                                }
                                else
                                {
                                    id = "winecrash:dirt"; //dirt
                                }
                            }
                            else
                            {
                                id = "winecrash:stone";
                            }
                        }

                        /*if(isCave)
                         * {
                         *  id = "winecrash:air";
                         * }*/

                        if (y == 2)
                        {
                            if (World.WorldRandom.NextDouble() < 0.33D)
                            {
                                id = "winecrash:bedrock";
                            }
                        }
                        else if (y == 1)
                        {
                            if (World.WorldRandom.NextDouble() < 0.66D)
                            {
                                id = "winecrash:bedrock";
                            }
                        }
                        else if (y == 0)
                        {
                            id = "winecrash:bedrock";
                        }

                        if (!idscache.TryGetValue(id, out cacheindex))
                        {
                            cacheindex = ItemCache.GetIndex(id);
                            idscache.Add(id, cacheindex);
                        }
                        //Server.Log(id);
                        blocks[x + Chunk.Width * y + Chunk.Width * Chunk.Height * z] = cacheindex;//new Block(id);
                    }
                }
            }

            if (save)
            {
                string fileName = "save/" + $"c{chunkx}_{chunky}.json";

                if (erase)
                {
                    File.WriteAllText(fileName, ToJSON(blocks));
                }

                else if (!File.Exists(fileName))
                {
                    File.WriteAllText(fileName, ToJSON(blocks));
                }
            }

            return(blocks);
        }
예제 #4
0
 protected override void WorldTick(Chunk chunk, Vector3I position)
 {
     chunk.Edit(position.X, position.Y, position.Z, ItemCache.Get <Block>("winecrash:log"));
 }