예제 #1
0
파일: GameUI.cs 프로젝트: Arekva/winecrash
        private static void CreateInventoryAnchors()
        {
            Vector2D shift;

            // hotbar
            for (int i = 0; i < 9; i++)
            {
                const double baseMinX = 3.0D;
                const double minY     = 0.0D;

                const double baseMaxX = 19.0D;
                const double maxY     = 3 / 22.0D;

                const double divisor    = 182.0D;
                const double incrementX = 20.0D;
                const double incrementY = 0.12325D;

                shift = new Vector2D(0, -0.0025);

                WMath.FlatTo2D(i, 9, out int x, out int y);
                _ItemInventoryAnchors[i] = new Vector2D[2]
                {
                    new Vector2D((baseMinX + incrementX * x) / divisor, minY + incrementY * y) + shift, // min
                    new Vector2D((baseMaxX + incrementX * x) / divisor, maxY + incrementY * y) + shift  // max
                };
            }
            // bag
            for (int i = 9; i < 36; i++)
            {
                const double baseMinX = 3.0D;
                const double minY     = 0.0D;

                const double baseMaxX = 19.0D;
                const double maxY     = 3 / 22.0D;

                const double divisor    = 182.0D;
                const double incrementX = 20.0D;
                const double incrementY = 0.1205D;

                shift = new Vector2D(0.0, 0.0025);

                WMath.FlatTo2D(i, 9, out int x, out int y);
                _ItemInventoryAnchors[i] = new Vector2D[2]
                {
                    new Vector2D((baseMinX + incrementX * x) / divisor, minY + incrementY * y) + shift, // min
                    new Vector2D((baseMaxX + incrementX * x) / divisor, maxY + incrementY * y) + shift  // max
                };
            }
            // armor
            for (int i = 36, y = 0; i < 40; i++, y++)
            {
                shift = new Vector2D(0, 0.865 - y * 0.1205);
                _ItemInventoryAnchors[i] = new Vector2D[2]
                {
                    new Vector2D((3.0 / 182.0), 0.0) + shift,        // min
                    new Vector2D((19.0 / 182.0), 3.0 / 22.0) + shift // max
                };
            }
            // crafting
            for (int i = 40; i < 44; i++)
            {
                int x = i == 41 || i == 43 ? 1 : 0;
                int y = i == 42 || i == 43 ? 1 : 0;

                shift = new Vector2D(0.495 + (20.0 * x / 182.0), 0.8645 - 0.1255 - y * 0.1205);

                _ItemInventoryAnchors[i] = new Vector2D[2]
                {
                    new Vector2D((3.0 / 182.0), 0.0) + shift,        // min
                    new Vector2D((19.0 / 182.0), 3.0 / 22.0) + shift // max
                };
            }

            // crafting result
            shift = new Vector2D(0.825, 0.6725);
            _ItemInventoryAnchors[44] = new Vector2D[2]
            {
                new Vector2D((3.0 / 182.0), 0.0) + shift,        // min
                new Vector2D((19.0 / 182.0), 3.0 / 22.0) + shift // max
            };

            // grabbed
            Vector2D[] @base = ItemSlotBase;
            shift = new Vector2D(-0.0275, -0.0625);
            _ItemInventoryAnchors[45] = new Vector2D[2]
            {
                new Vector2D(0.5) - @base[0] + shift,
                new Vector2D(0.5) + @base[1] + shift
            };
        }
예제 #2
0
파일: World.cs 프로젝트: Arekva/winecrash
        private static ushort[] PaintLandmass(Vector2I chunkCoords, ushort[] indices, out Vector3I[] surfaces)
        {
            ushort airID     = ItemCache.GetIndex("winecrash:air");
            ushort stoneID   = ItemCache.GetIndex("winecrash:stone");
            ushort grassID   = ItemCache.GetIndex("winecrash:grass");
            ushort dirtID    = ItemCache.GetIndex("winecrash:dirt");
            ushort sandID    = ItemCache.GetIndex("winecrash:sand");
            ushort waterID   = ItemCache.GetIndex("winecrash:water");
            ushort bedrockID = ItemCache.GetIndex("winecrash:bedrock");

            //ushort[] indices = new ushort[Chunk.Width * Chunk.Height * Chunk.Depth];

            Vector3F shift = Vector3F.Zero;

            Vector3F basePos = new Vector3F((chunkCoords.X * Chunk.Width) + shift.X, shift.Y, (chunkCoords.Y * Chunk.Depth) + shift.Z);

            ConcurrentBag <Vector3I> allSurfaces = new ConcurrentBag <Vector3I>();

            // for each x and z, for y from top to bottom:
            for (int i = 0; i < Chunk.Width * Chunk.Depth; i++)
            {
                //Parallel.For(0, Chunk.Width /** Chunk.Height*/ * Chunk.Depth, i =>
                //{
                // get the x / z position
                WMath.FlatTo2D(i, Chunk.Width, out int x, out int z);

                int  surfaceHeight = Chunk.Height - 1;
                bool heightFound   = false;
                for (int y = Chunk.Height - 1; y > -1; y--)
                {
                    int idx = WMath.Flatten3D(x, y, z, Chunk.Width, Chunk.Height);


                    // if height already have been found, check back if
                    // there is a surface or not (3D terrain, like grass under arches or so)
                    if (heightFound)
                    {
                        if (indices[idx] == airID) // if air found, reset height
                        {
                            surfaceHeight = y;
                            heightFound   = false;
                        }
                    }
                    else
                    {
                        surfaceHeight = y;
                        if (indices[idx] != airID)
                        {
                            heightFound = true;
                            allSurfaces.Add(new Vector3I(x, y, z));
                        }
                    }

                    // second pass: check the difference between surface and
                    // the current block height.
                    if (heightFound)
                    {
                        int deltaHeight = surfaceHeight - y;

                        bool ocean = surfaceHeight < 64;

                        // surface => grass
                        if (deltaHeight == 0)
                        {
                            indices[idx] = ocean ? sandID : grassID;
                        }
                        // dirt, under the grass
                        else if (deltaHeight < 3)
                        {
                            indices[idx] = ocean ? sandID : dirtID;
                        }
                    }

                    if (y < 64 && indices[idx] == airID)
                    {
                        indices[idx] = waterID;
                    }

                    if (y < 3)
                    {
                        double chance = Winecrash.Random.NextDouble();

                        if (y == 2 && chance < 0.33)
                        {
                            indices[idx] = bedrockID;
                        }
                        else if (y == 1 && chance < 0.66)
                        {
                            indices[idx] = bedrockID;
                        }
                        else if (y == 0)
                        {
                            indices[idx] = bedrockID;
                        }
                    }
                }

                //Vector3F finalPos = new Vector3F((basePos.X + x) * baseLandmassScale, basePos.Y + y,
                //    (basePos.Z + z) * baseLandmassScale) * globalScale;
                //});
            }

            surfaces = allSurfaces.ToArray();

            return(indices);
        }