Example #1
0
        protected virtual void SpreadTo(int x, int y)
        {
            if (increments - 1 <= 0)
            {
                return;
            }
            Tile         t       = Terrain.TileAt(x, y);
            FluidAttribs attribs = t.tileattribs as FluidAttribs;

            if (t.enumId == TileID.Air)
            {
                Tile f = fluid();
                ((FluidAttribs)(f.tileattribs)).increments = 1;
                increments--;
                Terrain.SetTile(x, y, f);
            }
            else if (attribs != null && attribs.GetType().Equals(fluid().tileattribs.GetType()))
            {
                if (attribs.increments < increments)
                {
                    attribs.increments++;
                    FluidManager.Instance.UpdateAround(x, y);
                    increments--;
                }
            }
        }
Example #2
0
        public static void SetTile(int x, int y, Tile tile, bool overwrite = false)
        {
            if (x < 0 || x >= Tiles.GetLength(0) || y < 0 || y >= Tiles.GetLength(1))
            {
                return;
            }
            if (!overwrite && Tiles[x, y].enumId != TileID.Air)
            {
                return;
            }

            Tiles[x, y] = tile;

            LogicAttribs logic = tile.tileattribs as LogicAttribs;

            if (logic != null)
            {
                LogicManager.Instance.AddUpdate(x, y, logic);
            }

            LightAttribs light = tile.tileattribs as LightAttribs;

            if (light != null)
            {
                Lighting.AddLight(x, y, light.intensity);
            }

            FluidAttribs fluid = tile.tileattribs as FluidAttribs;

            if (fluid != null)
            {
                FluidManager.Instance.AddUpdate(x, y, fluid);
            }
            FluidManager.Instance.UpdateAround(x, y);

            if (generating)
            {
                return;
            }

            if (y > Heights[x])
            {
                Heights[x] = y;
            }
            Lighting.QueueUpdate(x, y);
        }
Example #3
0
        protected override void FallFluid(int x, int y)
        {
            Tile         t       = Terrain.TileAt(x, y - 1);
            FluidAttribs attribs = t.tileattribs as FluidAttribs;

            if (!t.tileattribs.GetType().Equals(fluid().tileattribs.GetType()))
            {
                return;
            }

            attribs.increments += increments;
            if (attribs.increments <= attribs.maxIncrements)
            {
                Terrain.BreakTile(x, y);
            }
            else
            {
                increments         = attribs.increments - attribs.maxIncrements;
                attribs.increments = attribs.maxIncrements;
            }
            FluidManager.Instance.AddUpdate(x, y - 1, attribs);
        }
Example #4
0
        public static void CalculateMesh(out Vector2[] vertices, out int[] elements, out Vector2[] uvs)
        {
            int startX, endX, startY, endY;

            Range(out startX, out endX, out startY, out endY);
            List <Vector2> verticesList = new List <Vector2>((endX - startX) * (endY - startY));
            List <Vector2> uvList       = new List <Vector2>((endX - startX) * (endY - startY));

            for (int i = startX; i <= endX; i++)
            {
                for (int j = startY; j <= endY; j++)
                {
                    if (Tiles[i, j].enumId != TileID.Air)
                    {
                        TileID t = Tiles[i, j].enumId;

                        float x = ((float)((int)t % TerrainTextureSize)) / TerrainTextureSize;
                        float y = ((float)((int)t / TerrainTextureSize)) / TerrainTextureSize;
                        float s = 1f / TerrainTextureSize;
                        //half pixel correction
                        float h = 1f / (TerrainTextureSize * TerrainTextureSize * 2);

                        // float height = 1;
                        //TODO
                        //something like
                        float        height   = 1;
                        FluidAttribs fattribs = Tiles[i, j].tileattribs as FluidAttribs;
                        if (fattribs != null)
                        {
                            height = fattribs.GetHeight();
                        }

                        //top left, bottom left, bottom right, top right
                        verticesList.AddRange(new Vector2[] {
                            new Vector2(i, j + height),
                            new Vector2(i, j),
                            new Vector2(i + 1, j),
                            new Vector2(i + 1, j + height)
                        });

                        switch (Tiles[i, j].tileattribs.rotation)
                        {
                        case Direction.Up:
                            //top left, bottom left, bottom right, top right
                            uvList.AddRange(new Vector2[] {
                                new Vector2(x + h, y + s - h),
                                new Vector2(x + h, y + h),
                                new Vector2(x + s - h, y + h),
                                new Vector2(x + s - h, y + s - h)
                            });
                            break;

                        case Direction.Right:
                            uvList.AddRange(new Vector2[] {
                                new Vector2(x + h, y + h),
                                new Vector2(x + s - h, y + h),
                                new Vector2(x + s - h, y + s - h),
                                new Vector2(x + h, y + s - h)
                            });
                            break;

                        case Direction.Down:
                            uvList.AddRange(new Vector2[] {
                                new Vector2(x + s - h, y + h),
                                new Vector2(x + s - h, y + s - h),
                                new Vector2(x + h, y + s - h),
                                new Vector2(x + h, y + h),
                            });
                            break;

                        case Direction.Left:
                            uvList.AddRange(new Vector2[] {
                                new Vector2(x + s - h, y + s - h),
                                new Vector2(x + h, y + s - h),
                                new Vector2(x + h, y + h),
                                new Vector2(x + s - h, y + h)
                            });
                            break;
                        }
                    }
                }
            }
            vertices = verticesList.ToArray();
            uvs      = uvList.ToArray();

            elements = new int[verticesList.Count / 4 * 6];
            for (int i = 0; i < verticesList.Count / 4; i++)
            {
                elements[6 * i]     = 4 * i;
                elements[6 * i + 1] = 4 * i + 1;
                elements[6 * i + 2] = 4 * i + 2;
                elements[6 * i + 3] = 4 * i + 2;
                elements[6 * i + 4] = 4 * i + 3;
                elements[6 * i + 5] = 4 * i + 0;
            }
        }