Пример #1
0
 public Tile(int x, int y, int z, e_TileType typeIn, e_tileContents contentsIn)
 {
     xLoc     = x;
     yLoc     = y;
     zLoc     = z;
     type     = typeIn;
     contents = contentsIn;
 }
Пример #2
0
 bool IsTileTypeValid(e_TileType type)
 {
     return((int)type >= (int)e_TileType.FIRSTTILETYPE && (int)type < (int)e_TileType.MAXTILETYPE);
 }
Пример #3
0
    void CreateTile(int x, int y, int z, e_TileType type)
    {
        bool leftOfBoundsX = false;
        bool leftOfBoundsY = false;
        bool leftOfBoundsZ = false;

        if (!IsTileLocValid(x, y, z))
        {
            //need to create new array of a larger size and transfer contents over

            //determine new bounds
            int newX;
            int newY;
            int newZ;

            //expand map outwards
            if (x + 1 > map.xSize)
            {
                newX = x + 1;
            }
            //expand map to the 'left' by shifting all current tiles to the 'right'
            else if (x < 0)
            {
                newX          = map.xSize - x;
                leftOfBoundsX = true;
            }
            //no need to change map size
            else
            {
                newX = map.xSize;
            }
            //expand map outwards
            if (y + 1 > map.ySize)
            {
                newY = y + 1;
            }
            //expand map to the 'left' by shifting all current tiles to the 'right'
            else if (y < 0)
            {
                newY          = map.ySize - y;
                leftOfBoundsY = true;
            }
            //no need to change map size
            else
            {
                newY = map.ySize;
            }
            //expand map outwards
            if (z + 1 > map.zSize)
            {
                newZ = z + 1;
            }
            //expand map to the 'left' by shifting all current tiles to the 'right'
            else if (z < 0)
            {
                newZ          = map.zSize - z;
                leftOfBoundsZ = true;
            }
            //no need to change map size
            else
            {
                newZ = map.zSize;
            }

            Map newMap = new Map(newX, newY, newZ);

            //if for example I have a new tile at 1, -5, 4
            //all tiles copied over will need to be shifted by 5 in the positive direction in the y axis
            //so will make adjustments using ternary operator
            //uuuurrrrghrghr I need to perform the same shifting for the tile objects on the render side also.
            //I only need to code it once though!
            //copy old map array over
            for (int i = 0; i < map.xSize; i++)
            {
                for (int j = 0; j < map.ySize; j++)
                {
                    for (int k = 0; k < map.zSize; k++)
                    {
                        //newMap.mapArray [i,j,k] = map.mapArray [i,j,k];
                        newMap.mapArray [!leftOfBoundsX ? i:i - x, !leftOfBoundsY ? j:j - y, !leftOfBoundsZ ? k:k - z] = map.mapArray [i, j, k];
                    }
                }
            }
            //update view editor components as well
            viewReferenceComponent.UpdateMapArray(map.xSize, map.ySize, map.zSize, newX, newY, newZ,
                                                  leftOfBoundsX, leftOfBoundsY, leftOfBoundsZ, x, y, z);

            map = newMap;
        }

        //add new tile
        //the ternary operators make sure that if a new tile is added to the left it gets put at the start of the array

        int finalX = !leftOfBoundsX ? x : 0;
        int finalY = !leftOfBoundsY ? y : 0;
        int finalZ = !leftOfBoundsZ ? z : 0;

        map.mapArray [finalX, finalY, finalZ] = new Tile(finalX, finalY, finalZ, type, e_tileContents.EMPTY);
        viewReferenceComponent.RenderTile(map.mapArray [finalX, finalY, finalZ], x, y, z);
    }