示例#1
0
 public ClimateMap(ClimateType cl_type, GraphicTile.TileLandTypes baseLand, bool hasTop = false, GraphicTile.TileLandTypes secondLand = GraphicTile.TileLandTypes.ASH)
 {
     climateType = cl_type;
     hasTopLayer = hasTop;
     baseLandType = baseLand;
     if (hasTopLayer)
     {
         secondLandType = secondLand;
     }
 }
示例#2
0
        private void FillTileGraphic(Tile tileToFill, Tile fillTile)
        {
            GraphicTile destTile = tileToFill as GraphicTile, sourceTile = fillTile as GraphicTile;

            if (destTile.Graphic == sourceTile.Graphic)
            {
                return;
            }

            int graphicToMatch = destTile.Graphic;

            Stack <Tile> tileStack = new Stack <Tile>();

            tileStack.Push(tileToFill);

            while (tileStack.Count != 0)
            {
                GraphicTile currentTile = tileStack.Pop() as GraphicTile;

                if (currentTile.Graphic == graphicToMatch)
                {
                    currentTile.Graphic = sourceTile.Graphic;

                    if (currentTile.X > 0)
                    {
                        tileStack.Push(m_openMap.GetTile(currentTile.X - 1, currentTile.Y, LAYERS.Graphic));
                    }

                    if (currentTile.Y > 0)
                    {
                        tileStack.Push(m_openMap.GetTile(currentTile.X, currentTile.Y - 1, LAYERS.Graphic));
                    }

                    if (currentTile.X < m_openMap.Width - 1)
                    {
                        tileStack.Push(m_openMap.GetTile(currentTile.X + 1, currentTile.Y, LAYERS.Graphic));
                    }

                    if (currentTile.Y < m_openMap.Height - 1)
                    {
                        tileStack.Push(m_openMap.GetTile(currentTile.X, currentTile.Y + 1, LAYERS.Graphic));
                    }
                }
            }
        }
示例#3
0
	void Start() {
		rend = GetComponentsInChildren<Renderer> ();
        
        
        graphicTile = GetComponent<GraphicTile>();
		PickRandomMaterialForNeutral ();
        if (entityPresent)
        {
            currentTileType = entityPresent.entityType;
        }
        else
        {
            currentTileType = 2;
        }
        if (entityPresent == null)
        {
            setTileType(NEUTRAL);
        }
        rend[0].material.color = janitorColor;
        rend[1].material.color = demonColor;
        rend[2].material.color = Color.white;
    }
示例#4
0
        private static Tile GenerateRandomTile(int level, int x, int y)
        {
            Tile t;

            if (level < parameters.DivisionLevels && random.Next(level + 1) == 0)
            {
                //NW; NE; SE; SW
                Tile[] subdivision = new Tile[4];
                int    offset      = parameters.TileSize / (Convert.ToInt32(Math.Pow(2, level)));
                subdivision[0] = GenerateRandomTile(level + 1, x, y);
                subdivision[1] = GenerateRandomTile(level + 1, x + offset, y);
                subdivision[2] = GenerateRandomTile(level + 1, x + offset, y + offset);
                subdivision[3] = GenerateRandomTile(level + 1, x, y + offset);
                t = new ContainerTile(x, y, level, subdivision);
            }
            else
            {
                //int randomType = RANDOM.Next(TILESET.tileCount-1);
                int randomType = 1 + random.Next(13);
                t = new GraphicTile(x, y, level, (TileType)randomType, tileset.GetTile(level - 1, randomType));
            }
            return(t);
        }
示例#5
0
        private void mnuFill_Click(object sender, EventArgs e)
        {
            if (lvTiles.SelectedIndices.Count == 0)
            {
                return;
            }

            bool animMode = tileset.Tiles[lvTiles.SelectedIndices[0]] is AnimatedTile;

            for (int i = 0; i < m_openMap.Height; ++i)
            {
                for (int j = 0; j < m_openMap.Width; ++j)
                {
                    GraphicTile newTile = animMode ? new AnimatedTile(j, i, lvTiles.SelectedIndices[0]) : new GraphicTile(j, i, lvTiles.SelectedIndices[0]);
                    m_openMap.AddTile(j, i, LAYERS.Graphic, newTile);
                }
            }

            m_buffer.AddState(m_openMap);
            UpdateUndoRedo();

            mapViewer1.Refresh();
        }
示例#6
0
        private static Tile GenerateRandomPerlinTile(int level, int x, int y, double[,] noise)
        {
            Tile   t;
            double noiseValue = noise[x / 10, y / 10];

            //DEBUG
            double limit1      = 0.5d;
            double risinglimit = 0.05d;

            //LIL BIT OF RANDOMNESS
            noiseValue += (random.NextDouble() - 0.5) / 5;

            bool isContainer = false;

            if (noiseValue < limit1 - ((level - 1) * (risinglimit)))
            {
                isContainer = true;
            }
            if (level < parameters.DivisionLevels && isContainer)
            {
                //NW; NE; SE; SW
                Tile[] subdivision = new Tile[4];
                int    offset      = parameters.TileSize / (Convert.ToInt32(Math.Pow(2, level)));
                subdivision[0] = GenerateRandomPerlinTile(level + 1, x, y, noise);
                subdivision[1] = GenerateRandomPerlinTile(level + 1, x + offset, y, noise);
                subdivision[2] = GenerateRandomPerlinTile(level + 1, x + offset, y + offset, noise);
                subdivision[3] = GenerateRandomPerlinTile(level + 1, x, y + offset, noise);
                t = new ContainerTile(x, y, level, subdivision);
            }
            else
            {
                //int randomType = RANDOM.Next(TILESET.tileCount-1);
                int randomType = 1 + random.Next(13);
                t = new GraphicTile(x, y, level, (TileType)randomType, tileset.GetTile(level - 1, randomType));
            }
            return(t);
        }
示例#7
0
    // * Tile Data * :
    GraphicTile CheckTileNeighbors(Vector2[] emptyTileArray, Vector2 emptyTilePos, GraphicTile.TileLandTypes myLandType, bool isSecondTex = false)
    {
        bool left = false, right = false, bottom = false, top = false;
        bool leftTop = false, leftBottom = false, rightTop = false, rightBottom = false;

        // Check if a tile exists to my left
        // Vector2 leftTile = new Vector2(emptyTileArray[index].x - 1, emptyTileArray[index].y);
        Vector2 leftTile = new Vector2(emptyTilePos.x - 1, emptyTilePos.y);
        if (CheckIfTileExists(emptyTileArray, leftTile))
        {
            left = true;
        }
        // Check if a tile exists to my right
        Vector2 rightTile = new Vector2(emptyTilePos.x + 1, emptyTilePos.y);

        //Vector2 rightTile = new Vector2(emptyTileArray[index].x + 1, emptyTileArray[index].y);
        if (CheckIfTileExists(emptyTileArray, rightTile))
        {
            right = true;
        }
        // Check if a tile exists on top
        Vector2 topTile = new Vector2(emptyTilePos.x, emptyTilePos.y + 1);
        //Vector2 topTile = new Vector2(emptyTileArray[index].x, emptyTileArray[index].y + 1);

        if (CheckIfTileExists(emptyTileArray, topTile))
        {
            top = true;
        }
        // Check if a tile exists on bottom
        Vector2 bottomTile = new Vector2(emptyTilePos.x, emptyTilePos.y - 1);
        //Vector2 bottomTile = new Vector2(emptyTileArray[index].x, emptyTileArray[index].y - 1);
        if (CheckIfTileExists(emptyTileArray, bottomTile))
        {
            bottom = true;
        }
        // Check if a tile exists on bottom left
        Vector2 bottomLeftTile = new Vector2(emptyTilePos.x - 1, emptyTilePos.y - 1);
        //Vector2 bottomLeftTile = new Vector2(emptyTileArray[index].x - 1, emptyTileArray[index].y - 1);
        if (CheckIfTileExists(emptyTileArray, bottomLeftTile))
        {
            leftBottom = true;
        }
        // Check if a tile exists on top left
        Vector2 topLeftTile = new Vector2(emptyTilePos.x - 1, emptyTilePos.y + 1);
        //Vector2 topLeftTile = new Vector2(emptyTileArray[index].x - 1, emptyTileArray[index].y + 1);
        if (CheckIfTileExists(emptyTileArray, topLeftTile))
        {
            leftTop = true;
        }
        // Check if a tile exists on top right
        Vector2 topRightTile = new Vector2(emptyTilePos.x + 1, emptyTilePos.y + 1);
        //Vector2 topRightTile = new Vector2(emptyTileArray[index].x + 1, emptyTileArray[index].y + 1);
        if (CheckIfTileExists(emptyTileArray, topRightTile))
        {
            rightTop = true;
        }
        // Check if a tile exists on bottom right
        Vector2 bottomRightTile = new Vector2(emptyTilePos.x + 1, emptyTilePos.y - 1);
        //Vector2 bottomRightTile = new Vector2(emptyTileArray[index].x + 1, emptyTileArray[index].y - 1);
        if (CheckIfTileExists(emptyTileArray, bottomRightTile))
        {
            rightBottom = true;
        }

        return GetTilePositionType(left, right, top, bottom, leftTop, leftBottom, rightTop, rightBottom, (int)emptyTilePos.x, (int)emptyTilePos.y, myLandType, isSecondTex);
    }
示例#8
0
    GraphicTile CheckTileNeighbors(Vector2[] emptyTileArray, Vector2 emptyTilePos, GraphicTile.TileLandTypes myLandType, GraphicTile[] tiles)
    {
        bool left = false, right = false, bottom = false, top = false;
        bool leftTop = false, leftBottom = false, rightTop = false, rightBottom = false;

        Vector2 leftTile = new Vector2(emptyTilePos.x - 1, emptyTilePos.y);
        int leftTileExists = CheckIfGraphicTileMatches(emptyTileArray, leftTile);
        if (leftTileExists < tiles.Length)
        {
            // It does exist, make sure it's NOT clear
            if (tiles[leftTileExists].MyTilePosType != GraphicTile.TilePositionTypes.CLEAR)
                 left = true;
        }

        // Check if a tile exists to my right
        Vector2 rightTile = new Vector2(emptyTilePos.x + 1, emptyTilePos.y);
        int rightTileExists = CheckIfGraphicTileMatches(emptyTileArray, rightTile);
        if (rightTileExists < tiles.Length)
        {
            if (tiles[rightTileExists].MyTilePosType != GraphicTile.TilePositionTypes.CLEAR)
                right = true;
        }

        // Check if a tile exists on top
        Vector2 topTile = new Vector2(emptyTilePos.x, emptyTilePos.y + 1);
        int topTileExists = CheckIfGraphicTileMatches(emptyTileArray, topTile);
        if (topTileExists < tiles.Length)
        {
            if (tiles[topTileExists].MyTilePosType != GraphicTile.TilePositionTypes.CLEAR)
                top = true;
        }

        // Check if a tile exists on bottom
        Vector2 bottomTile = new Vector2(emptyTilePos.x, emptyTilePos.y - 1);
        int bottomTileExists = CheckIfGraphicTileMatches(emptyTileArray, bottomTile);

        if (bottomTileExists < tiles.Length)
        {
            if (tiles[bottomTileExists].MyTilePosType != GraphicTile.TilePositionTypes.CLEAR)
                bottom = true;
        }

        // Check if a tile exists on bottom left
        Vector2 bottomLeftTile = new Vector2(emptyTilePos.x - 1, emptyTilePos.y - 1);
        int bottomLeftTileExists = CheckIfGraphicTileMatches(emptyTileArray, bottomLeftTile);
        if (bottomLeftTileExists < tiles.Length)
        {
            if (tiles[bottomLeftTileExists].MyTilePosType != GraphicTile.TilePositionTypes.CLEAR)
                leftBottom = true;
        }

        // Check if a tile exists on top left
        Vector2 topLeftTile = new Vector2(emptyTilePos.x - 1, emptyTilePos.y + 1);
        int topLeftTileExists = CheckIfGraphicTileMatches(emptyTileArray, topLeftTile);
        if (topLeftTileExists < tiles.Length)
        {
            if (tiles[topLeftTileExists].MyTilePosType != GraphicTile.TilePositionTypes.CLEAR)
                leftTop = true;
        }

        // Check if a tile exists on top right
        Vector2 topRightTile = new Vector2(emptyTilePos.x + 1, emptyTilePos.y + 1);
        int topRightTileExists = CheckIfGraphicTileMatches(emptyTileArray, topRightTile);
        if (topRightTileExists < tiles.Length)
        {
            if (tiles[topRightTileExists].MyTilePosType != GraphicTile.TilePositionTypes.CLEAR)
                rightTop = true;
        }

        // Check if a tile exists on bottom right
        Vector2 bottomRightTile = new Vector2(emptyTilePos.x + 1, emptyTilePos.y - 1);
        int bottomRightTileExists = CheckIfGraphicTileMatches(emptyTileArray, bottomRightTile);
        if (bottomRightTileExists < tiles.Length)
        {
            if (tiles[bottomRightTileExists].MyTilePosType != GraphicTile.TilePositionTypes.CLEAR)
                rightBottom = true;
        }

        return GetTilePositionType(left, right, top, bottom, leftTop, leftBottom, rightTop, rightBottom, (int)emptyTilePos.x, (int)emptyTilePos.y, myLandType);
    }
示例#9
0
 void InitRegionTiles(int length)
 {
     regionTiles = new GraphicTile[length];
     for (int x = 0; x < regionTiles.Length; x++)
     {
         regionTiles[x] = new GraphicTile();
     }
 }
示例#10
0
    public void DefineTilesAndGenerateSecondTexture(Vector2[] emptyTilesArray, int islandWidth, int islandHeight)
    {
        // Make sure this Mesh object shares the same mesh as Base mesh
        Mesh islandMesh = base_renderer.gameObject.GetComponent<MeshFilter>().mesh;

        second_renderer.gameObject.GetComponent<MeshFilter>().mesh = islandMesh;

        int texWidth = islandWidth * tileResolution;
        int texHeight = islandHeight * tileResolution;
        Texture2D texture2 = new Texture2D(texWidth, texHeight);
        texture2.name = "Top Land Texture";

        //GraphicTile.TileLandTypes landType = GetNewLandType(baseLandType);
        // Split Base land type's tile sheet, based on the already set base land type
        Color[][] tiles = SplitTileSheet(secondaryLandType);
        // Use this array to Set Pixels
        Color[] thisTilePixels;

        secondGraphicTiles = new GraphicTile[islandWidth , islandHeight];

        for (int mapX = 0; mapX < islandWidth; mapX++)
        {
            for (int mapY = 0; mapY < islandHeight; mapY++)
            {
                Vector2 thisPosition = new Vector2(mapX, mapY);
                if (!CheckIfTileExists(emptyTilesArray, thisPosition))
                {
                    // Tile is water, not land, so define tileType as clear
                    // secondGraphicTiles[mapX, mapY] = new GraphicTile(GraphicTile.TilePositionTypes.CLEAR, thisPosition);
                    if (!all_GraphicTiles.ContainsKey(thisPosition))
                    {
                        all_GraphicTiles.Add(thisPosition, new GraphicTile(GraphicTile.TilePositionTypes.CLEAR, thisPosition));

                    }
                    else
                    {
                        if (all_GraphicTiles[thisPosition].MyTilePosType != GraphicTile.TilePositionTypes.CLEAR)
                        {
                            all_GraphicTiles[thisPosition].MyTilePosType = GraphicTile.TilePositionTypes.CLEAR;
                        }
                    }

                    // set pixels to clear
                    thisTilePixels = clearPixels;

                    texture2.SetPixels(mapX * tileResolution, mapY * tileResolution, tileResolution, tileResolution, thisTilePixels);

                }
                else
                {
                    // Tile IS land so define it:

                    // Check Tile's neighbors to define this new tile
                    GraphicTile thisTile = CheckTileNeighbors(emptyTilesArray, thisPosition, secondaryLandType, true);

                    if (!all_GraphicTiles.ContainsKey(thisPosition))
                    {
                        all_GraphicTiles.Add(thisPosition, thisTile);
                    }
                    else
                    {
                        all_GraphicTiles.Remove(thisPosition);

                        all_GraphicTiles.Add(thisPosition, thisTile);

                    }

                    thisTilePixels = tiles[FindIndex(thisTile.MyTilePosType, thisTile.MyTileEdgeType, secondaryLandType)];

                    texture2.SetPixels(mapX * tileResolution, mapY * tileResolution, tileResolution, tileResolution, thisTilePixels);

                }
            }

            texture2.filterMode = FilterMode.Bilinear;
            texture2.wrapMode = TextureWrapMode.Clamp;

            // Apply texture
            texture2.Apply();

            // Give the mesh collider the same mesh
            second_renderer.gameObject.GetComponent<MeshCollider>().sharedMesh = islandMesh;

            Texture2 = texture2;

            ApplyTextures();
        }
    }
示例#11
0
        private void btnRemoveTile_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count == 0 && listView2.SelectedItems.Count == 0)
            {
                return;
            }

            ListView selectedListView = tabControl1.SelectedIndex == 0 ? listView1 : listView2;

            // Make sure we don't mess up the map
            if (Map != null)
            {
                int count = Map.Layers[(int)LAYERS.Graphic].Values.Where(i => (i as GraphicTile).Graphic == selectedListView.SelectedIndices[0]).Count(i => true);

                if (count > 0)
                {
                    if (MessageBox.Show("This will erase some tiles from the current map. Continue?", "", MessageBoxButtons.YesNo) == DialogResult.No)
                    {
                        return;
                    }
                }

                // Remove the removed tile from the map
                foreach (Tile tile in Map.Layers[(int)LAYERS.Graphic].Values)
                {
                    GraphicTile gTile = tile as GraphicTile;

                    if (gTile.Graphic == selectedListView.SelectedIndices[0])
                    {
                        gTile.Graphic = 0;
                    }
                }
            }

            // Remove the tile from everything
            Tiles.Tiles.RemoveAt(selectedListView.SelectedIndices[0]);
            Tiles.Images.Images.RemoveAt(selectedListView.SelectedIndices[0]);
            m_sourceImages.RemoveAt(selectedListView.SelectedIndices[0]);

            // Make sure graphic tiles are still pointing to the right things
            for (int i = selectedListView.SelectedIndices[0]; i < Tiles.Tiles.Count; i++)
            {
                if (Tiles.Tiles[i] is GraphicTile)
                {
                    GraphicTile gt = Tiles.Tiles[i] as GraphicTile;
                    gt.Graphic--;
                }
            }

            // Set up selected index
            int tmp = selectedListView.SelectedIndices[0];

            listView1.RefreshContents(Tiles, TileType.Graphic);
            listView2.RefreshContents(Tiles, TileType.Special);
            selectedListView.SelectedIndices.Clear();
            if (tmp > selectedListView.Items.Count - 1)
            {
                selectedListView.SelectedIndices.Add(selectedListView.Items.Count - 1);
            }
            else
            {
                selectedListView.SelectedIndices.Add(tmp);
            }

            Tiles.FileUpToDate = false;
        }
示例#12
0
    Color[][] SplitTileSheet(GraphicTile.TileLandTypes landType)
    {
        TileSheet tileSheet;
        if (landType == GraphicTile.TileLandTypes.ASH)
        {
            tileSheet = ashTileSheet;
        }
        else
        {
            tileSheet = sandMudTileSheet;
        }

        Color[][] tiles = new Color[tileSheet.tilesPerRow * tileSheet.numberOfRows][];

        for (int y = 0; y < tileSheet.numberOfRows; y++)
        {
            for (int x = 0; x < tileSheet.tilesPerRow; x++)
            {
                tiles[y * tileSheet.tilesPerRow + x] = tileSheet.tileSheetTexture.GetPixels(x * tileResolution, y * tileResolution, tileResolution, tileResolution);

            }
        }

        return tiles;
    }
示例#13
0
    GraphicTile.TileEdgeTypes GetMyTileTypeFromNeighbors(GraphicTile.TileEdgeTypes neighbor1Type, GraphicTile.TileEdgeTypes neighbor2Type, bool isCorner = false)
    {
        GraphicTile.TileEdgeTypes myTileType = GraphicTile.TileEdgeTypes.UNDEFINED;

        switch (neighbor1Type)
        {
            case GraphicTile.TileEdgeTypes.SHORE:
                if (neighbor2Type == GraphicTile.TileEdgeTypes.SHORE)
                {
                    myTileType = GraphicTile.TileEdgeTypes.SHORE;
                }
                else if (neighbor2Type == GraphicTile.TileEdgeTypes.CLIFF && !isCorner)
                {
                    myTileType = GraphicTile.TileEdgeTypes.SHORE_CLIFF;
                }
                else if (neighbor2Type == GraphicTile.TileEdgeTypes.SHORE_CLIFF)
                {
                    myTileType = GraphicTile.TileEdgeTypes.SHORE;
                }
                else if (neighbor2Type == GraphicTile.TileEdgeTypes.CLIFF_SHORE && !isCorner)
                {
                    myTileType = GraphicTile.TileEdgeTypes.SHORE_CLIFF;
                }
                else if (neighbor2Type == GraphicTile.TileEdgeTypes.UNDEFINED && !isCorner)
                {
                    myTileType = GraphicTile.TileEdgeTypes.SHORE_CLIFF;
                }
                else
                {
                    myTileType = GraphicTile.TileEdgeTypes.SHORE;
                }

                break;
            case GraphicTile.TileEdgeTypes.CLIFF:
                if (neighbor2Type == GraphicTile.TileEdgeTypes.SHORE || neighbor2Type == GraphicTile.TileEdgeTypes.SHORE_CLIFF && !isCorner)
                {
                    myTileType = GraphicTile.TileEdgeTypes.CLIFF_SHORE;
                }
                else if (neighbor2Type == GraphicTile.TileEdgeTypes.CLIFF || neighbor2Type == GraphicTile.TileEdgeTypes.CLIFF_SHORE)
                {
                    myTileType = GraphicTile.TileEdgeTypes.CLIFF;
                }
                else if (neighbor2Type == GraphicTile.TileEdgeTypes.UNDEFINED && !isCorner)
                {
                    myTileType = GraphicTile.TileEdgeTypes.CLIFF_SHORE;
                }
                else
                {
                    myTileType = GraphicTile.TileEdgeTypes.CLIFF;
                }

                break;
            case GraphicTile.TileEdgeTypes.SHORE_CLIFF:
                if (neighbor2Type == GraphicTile.TileEdgeTypes.SHORE || neighbor2Type == GraphicTile.TileEdgeTypes.SHORE_CLIFF && !isCorner)
                {
                    myTileType = GraphicTile.TileEdgeTypes.CLIFF_SHORE;
                }
                else if (neighbor2Type == GraphicTile.TileEdgeTypes.CLIFF || neighbor2Type == GraphicTile.TileEdgeTypes.CLIFF_SHORE)
                {
                    myTileType = GraphicTile.TileEdgeTypes.CLIFF;
                }
                else
                {
                    myTileType = GraphicTile.TileEdgeTypes.CLIFF;
                }

                break;
            case GraphicTile.TileEdgeTypes.CLIFF_SHORE:
                if (neighbor2Type == GraphicTile.TileEdgeTypes.SHORE || neighbor2Type == GraphicTile.TileEdgeTypes.SHORE_CLIFF)
                {
                    myTileType = GraphicTile.TileEdgeTypes.SHORE;
                }
                else if (neighbor2Type == GraphicTile.TileEdgeTypes.CLIFF || neighbor2Type == GraphicTile.TileEdgeTypes.CLIFF_SHORE && !isCorner)
                {
                    myTileType = GraphicTile.TileEdgeTypes.SHORE_CLIFF;
                }
                else
                {
                    myTileType = GraphicTile.TileEdgeTypes.SHORE;
                }

                break;
            case GraphicTile.TileEdgeTypes.UNDEFINED:
                if (neighbor2Type == GraphicTile.TileEdgeTypes.SHORE || neighbor2Type == GraphicTile.TileEdgeTypes.SHORE_CLIFF || neighbor2Type == GraphicTile.TileEdgeTypes.UNDEFINED)
                {
                    myTileType = GraphicTile.TileEdgeTypes.SHORE;
                }
                else if (neighbor2Type == GraphicTile.TileEdgeTypes.CLIFF || neighbor2Type == GraphicTile.TileEdgeTypes.CLIFF_SHORE && !isCorner)
                {
                    myTileType = GraphicTile.TileEdgeTypes.SHORE_CLIFF;
                }
                else
                {
                    myTileType = GraphicTile.TileEdgeTypes.SHORE;
                }
                break;

            default:
                myTileType = GraphicTile.TileEdgeTypes.SHORE;
                break;
        }

        return myTileType;
    }
示例#14
0
        private void UpdateMapViewer_MouseMove(object sender, MouseEventArgs e)
        {
            if (!m_fileOpen)
            {
                return;
            }
            lock (lockObject)
            {
                //update logic below
                int x, y;
                int zf = (int)(mapViewer1.TileSize * mapViewer1.ZoomFactor);

                x = e.X - (e.X % zf) + ((int)mapViewer1.Offset.X % zf);
                y = e.Y - (e.Y % zf) + ((int)mapViewer1.Offset.Y % zf);

                if (x < mapViewer1.Offset.X)
                {
                    x = (int)mapViewer1.Offset.X;
                }
                else if (x > mapViewer1.Area.Width + mapViewer1.Offset.X - zf)
                {
                    x = mapViewer1.Area.Width + (int)mapViewer1.Offset.X - zf;
                }

                if (y < mapViewer1.Offset.Y)
                {
                    y = (int)mapViewer1.Offset.Y;
                }
                else if (y > mapViewer1.Area.Height + mapViewer1.Offset.Y - zf)
                {
                    y = mapViewer1.Area.Height + (int)mapViewer1.Offset.Y - zf;
                }

                mapViewer1.SelectorPosition = new Vector2((float)x, (float)y);
                x = (int)(x - mapViewer1.Offset.X) / zf;
                y = (int)(y - mapViewer1.Offset.Y) / zf;

                if (shiftKeyPressed && prevShift && e.Button == MouseButtons.Left)
                {
                    if (dragdir == DragState.NoDrag)
                    {
                        if (y == orig_y && x != orig_x)
                        {
                            dragdir = DragState.Horizontal;                             //horizontal
                        }
                        else if (x == orig_x && y != orig_y)
                        {
                            dragdir = DragState.Vertical;                             //vertical
                        }
                    }

                    switch (dragdir)
                    {
                    //force coordinates to be what the originals were
                    case DragState.Horizontal: y = orig_y; break;

                    case DragState.Vertical: x = orig_x; break;
                    }
                }

                tsLblSelX.Text = x.ToString();
                tsLblSelY.Text = y.ToString();

                switch (currentState)
                {
                case PlaceState.SINGLEFILL:
                    if (e.Button == System.Windows.Forms.MouseButtons.Left)
                    {
                        Tile toAdd;
                        switch (tabs.SelectedIndex)
                        {
                        case (int)LAYERS.Graphic:
                            if (lvTiles.SelectedIndices.Count == 0)
                            {
                                break;
                            }

                            //if (tileset.Tiles[lvTiles.SelectedIndices[0]] is AnimatedTile)
                            //{
                            //	int index = tileset.CorrectedTileIndex(lvTiles.SelectedIndices[0], TileType.Animated);
                            //	toAdd = new AnimatedTile(x, y, index);
                            //}
                            //else
                            //{
                            toAdd = new GraphicTile(x, y);
                            (toAdd as GraphicTile).Graphic = tileset.CorrectedTileIndex <GraphicTile>(lvTiles.SelectedIndices[0]);
                            //}
                            m_openMap.AddTile(x, y, LAYERS.Graphic, toAdd);
                            break;

                        case (int)LAYERS.Special:
                            float density = 0.0f;
                            if (!CreateSpecialTile(out toAdd) ||
                                ((toAdd as SpecialTile).Type == SpecialTileSpec.WALL && !float.TryParse(txtDensity.Text, out density)))
                            {
                                break;
                            }

                            (toAdd as SpecialTile).Type = (SpecialTileSpec)cmbSpecialType.SelectedIndex;

                            if ((toAdd as SpecialTile).Type == SpecialTileSpec.WALL)
                            {
                                (toAdd as SpecialTile).Density = density;
                            }

                            (toAdd as SpecialTile).Graphic = tileset.CorrectedTileIndex <SpecialTile>(lvTiles2.SelectedIndices[0]);

                            m_openMap.AddTile(toAdd.X, toAdd.Y, LAYERS.Special, toAdd);
                            break;

                        case (int)LAYERS.NPC:
                            //first check if there is an NPC spawn. if there is, open up a dialog to edit it
                            //  otherwise, create a new spawn
                            int ID; uint speed = 0;
                            if (!int.TryParse(txtNPCId.Text, out ID) || (chkNPCMoves.Checked && !uint.TryParse(txtNPCMoveSpeed.Text, out speed)))
                            {
                                MessageBox.Show("Please enter valid NPC id (integer)");
                                break;
                            }
                            if (chkNPCMoves.Checked)
                            {
                                toAdd = new NPCTile(x, y, ID, speed);
                            }
                            else
                            {
                                toAdd = new NPCTile(x, y, ID);
                            }
                            m_openMap.AddTile(x, y, LAYERS.NPC, toAdd);
                            break;

                        case (int)LAYERS.Interactive:                                         //using this as item layer for now
                            //first check if there is an Item spawn. if there is, open up a dialog to edit it
                            //  otherwise, create a new spawn
                            break;
                        }
                    }
                    break;

                case PlaceState.MULTIFILL:
                    if (e.Button == System.Windows.Forms.MouseButtons.Left)
                    {                             //the previous mouse state recorded the left button clicked
                        if (tabs.SelectedIndex == (int)LAYERS.Special)
                        {
                            Tile based = m_openMap.GetTile(x, y, LAYERS.Special), spec;
                            if (based != null)
                            {
                                break;
                            }
                            if (!CreateSpecialTile(out spec))
                            {
                                break;
                            }

                            FillTileSpecial(based, spec);
                        }
                        else if (tabs.SelectedIndex == (int)LAYERS.Graphic)
                        {
                            Tile toAdd, current = m_openMap.GetTile(x, y, LAYERS.Graphic);

                            if (lvTiles.SelectedItems.Count == 0)
                            {
                                return;
                            }

                            if (tileset.Tiles[tileset.CorrectedTileIndex <AnimatedTile>(lvTiles.SelectedIndices[0])] is AnimatedTile)
                            {
                                int index = tileset.CorrectedTileIndex <AnimatedTile>(lvTiles.SelectedIndices[0]);
                                toAdd = new AnimatedTile(x, y, index);
                            }
                            else
                            {
                                toAdd = new GraphicTile(x, y);
                                (toAdd as GraphicTile).Graphic = tileset.CorrectedTileIndex <GraphicTile>(lvTiles.SelectedIndices[0]);
                            }

                            FillTileGraphic(current, toAdd);
                        }

                        m_buffer.AddState(m_openMap);
                        UpdateUndoRedo();
                    }
                    break;

                case PlaceState.ERASER:
                    if (e.Button == MouseButtons.Left)
                    {
                        m_openMap.EraseTile(int.Parse(tsLblSelX.Text), int.Parse(tsLblSelY.Text), (LAYERS)tabs.SelectedIndex);
                    }
                    else if (prevMousePressed && e.Button != MouseButtons.Left)
                    {
                        m_buffer.AddState(m_openMap);
                        UpdateUndoRedo();
                    }
                    break;

                case PlaceState.PAN:
                    if (e.Button == System.Windows.Forms.MouseButtons.Left)
                    {
                        using (MemoryStream mem = new MemoryStream(Properties.Resources.hand_closed))
                        {
                            mapViewer1.Cursor = new Cursor(mem);
                        }
                        if (!prevMousePressed)
                        {
                            originalLocation.X   = e.X;
                            originalLocation.Y   = e.Y;
                            originalAdjustment.X = mapViewer1.Offset.X;
                            originalAdjustment.Y = mapViewer1.Offset.Y;
                        }
                        else
                        {
                            mapViewer1.Offset = new Vector2(originalAdjustment.X + (e.X - originalLocation.X), originalAdjustment.Y + (e.Y - originalLocation.Y));
                        }
                    }
                    else
                    {
                        using (MemoryStream mem = new MemoryStream(Properties.Resources.hand_cur))
                        {
                            mapViewer1.Cursor = new Cursor(mem);
                        }
                    }
                    break;
                }

                prevMousePressed = (e.Button == System.Windows.Forms.MouseButtons.Left);
                if (shiftKeyPressed && !prevShift && prevMousePressed)
                {
                    dragdir   = DragState.NoDrag;
                    prevShift = true;
                    orig_x    = x;
                    orig_y    = y;
                }

                mapViewer1.State    = currentState;
                mapViewer1.ShowGrid = mnuGrid.Checked;
                tsLblNumTiles.Text  = "";
                foreach (SortedList <string, Tile> sublist in m_openMap.Layers)
                {                 //show the number of tiles in each layer in the appropriate TS label
                    tsLblNumTiles.Text += sublist.Count.ToString();
                    if (sublist != m_openMap.Layers.Last())
                    {
                        tsLblNumTiles.Text += " / ";
                    }
                }

                mapViewer1.Refresh();                 //force the control to redraw after updating
            }
        }
示例#15
0
    int GetAshSheetIndex(GraphicTile.TilePositionTypes myPosType, GraphicTile.TileEdgeTypes myEdgeType)
    {
        int tileIndex = 0;

        switch (myEdgeType)
        {
            case GraphicTile.TileEdgeTypes.CLIFF:

                // Select a cliff of this edgetype
                if (myPosType == GraphicTile.TilePositionTypes.BOTTOM)
                {
                    tileIndex = pseudoRandom.Next(90, 100);
                }
                if (myPosType == GraphicTile.TilePositionTypes.TOP)
                {
                    tileIndex = pseudoRandom.Next(145, 150);
                }
                if (myPosType == GraphicTile.TilePositionTypes.LEFT)
                {
                    tileIndex = pseudoRandom.Next(80, 90);
                }
                if (myPosType == GraphicTile.TilePositionTypes.RIGHT)
                {
                    tileIndex = pseudoRandom.Next(70, 80);
                }
                if (myPosType == GraphicTile.TilePositionTypes.BOTTOM_LEFT_CORNER)
                {
                    // Pick between large corner or small corner
                    int pick = pseudoRandom.Next(0, 3);
                    if (pick <= 1)
                    {
                        tileIndex = pseudoRandom.Next(161, 165);
                    }
                    else
                    {
                        tileIndex = pseudoRandom.Next(65, 70);
                    }
                }
                if (myPosType == GraphicTile.TilePositionTypes.BOTTOM_RIGHT_CORNER)
                {
                    // Pick between large corner or small corner
                    int pick = pseudoRandom.Next(0, 3);
                    if (pick <= 1)
                    {
                        tileIndex = pseudoRandom.Next(165, 170);
                    }
                    else
                    {
                        tileIndex = pseudoRandom.Next(60, 65);
                    }
                }
                if (myPosType == GraphicTile.TilePositionTypes.TOP_LEFT_CORNER)
                {
                    tileIndex = pseudoRandom.Next(180, 185);
                }
                if (myPosType == GraphicTile.TilePositionTypes.TOP_RIGHT_CORNER)
                {
                    tileIndex = pseudoRandom.Next(185, 190);
                }
                if (myPosType == GraphicTile.TilePositionTypes.LEFT_BOTTOM_DIAG)
                {
                    tileIndex = pseudoRandom.Next(150, 155);
                }
                if (myPosType == GraphicTile.TilePositionTypes.RIGHT_BOTTOM_DIAG)
                {
                    tileIndex = pseudoRandom.Next(155, 160);
                }
                if (myPosType == GraphicTile.TilePositionTypes.LEFT_TOP_DIAG)
                {
                    tileIndex = pseudoRandom.Next(170, 175);
                }
                if (myPosType == GraphicTile.TilePositionTypes.RIGHT_TOP_DIAG)
                {
                    tileIndex = pseudoRandom.Next(175, 180);
                }

                break;
            case GraphicTile.TileEdgeTypes.CLIFF_SHORE:
                // Select a cliff shore of this edgetype
                if (myPosType == GraphicTile.TilePositionTypes.BOTTOM)
                {
                    tileIndex = pseudoRandom.Next(130, 135);
                }
                if (myPosType == GraphicTile.TilePositionTypes.TOP)
                {
                    tileIndex = pseudoRandom.Next(190, 195);
                }
                if (myPosType == GraphicTile.TilePositionTypes.LEFT)
                {
                    tileIndex = pseudoRandom.Next(15, 20);
                }
                if (myPosType == GraphicTile.TilePositionTypes.RIGHT)
                {
                    tileIndex = pseudoRandom.Next(25, 30);
                }
                // USING CLIFF CORNERS AND DIAGONALS HERE
                if (myPosType == GraphicTile.TilePositionTypes.BOTTOM_LEFT_CORNER)
                {
                    // Pick between large corner or small corner
                    int pick = pseudoRandom.Next(0, 3);
                    if (pick <= 1)
                    {
                        tileIndex = pseudoRandom.Next(161, 165);
                    }
                    else
                    {
                        tileIndex = pseudoRandom.Next(65, 70);
                    }
                }
                if (myPosType == GraphicTile.TilePositionTypes.BOTTOM_RIGHT_CORNER)
                {
                    // Pick between large corner or small corner
                    int pick = pseudoRandom.Next(0, 3);
                    if (pick <= 1)
                    {
                        tileIndex = pseudoRandom.Next(165, 170);
                    }
                    else
                    {
                        tileIndex = pseudoRandom.Next(60, 65);
                    }
                }
                if (myPosType == GraphicTile.TilePositionTypes.TOP_LEFT_CORNER)
                {
                    tileIndex = pseudoRandom.Next(180, 185);
                }
                if (myPosType == GraphicTile.TilePositionTypes.TOP_RIGHT_CORNER)
                {
                    tileIndex = pseudoRandom.Next(185, 190);
                }
                if (myPosType == GraphicTile.TilePositionTypes.LEFT_BOTTOM_DIAG)
                {
                    tileIndex = pseudoRandom.Next(150, 155);
                }
                if (myPosType == GraphicTile.TilePositionTypes.RIGHT_BOTTOM_DIAG)
                {
                    tileIndex = pseudoRandom.Next(155, 160);
                }
                if (myPosType == GraphicTile.TilePositionTypes.LEFT_TOP_DIAG)
                {
                    tileIndex = pseudoRandom.Next(170, 175);
                }
                if (myPosType == GraphicTile.TilePositionTypes.RIGHT_TOP_DIAG)
                {
                    tileIndex = pseudoRandom.Next(175, 180);
                }
                break;
            case GraphicTile.TileEdgeTypes.SHORE_CLIFF:
                // select a shore cliff of this edge type
                if (myPosType == GraphicTile.TilePositionTypes.BOTTOM)
                {
                    tileIndex = pseudoRandom.Next(135, 140);
                }
                if (myPosType == GraphicTile.TilePositionTypes.TOP)
                {
                    tileIndex = pseudoRandom.Next(195, 200);
                }
                if (myPosType == GraphicTile.TilePositionTypes.LEFT)
                {
                    tileIndex = pseudoRandom.Next(10, 15);
                }
                if (myPosType == GraphicTile.TilePositionTypes.RIGHT)
                {
                    tileIndex = pseudoRandom.Next(20, 25);
                }
                // USING SHORE CORNERS AND DIAGONALS HERE (WHERE AVAILABLE)
                if (myPosType == GraphicTile.TilePositionTypes.BOTTOM_LEFT_CORNER)
                {
                    tileIndex = pseudoRandom.Next(125, 130);
                }
                if (myPosType == GraphicTile.TilePositionTypes.BOTTOM_RIGHT_CORNER)
                {
                    tileIndex = pseudoRandom.Next(120, 125);
                }
                if (myPosType == GraphicTile.TilePositionTypes.TOP_LEFT_CORNER)
                {
                    tileIndex = pseudoRandom.Next(30, 35);
                }
                if (myPosType == GraphicTile.TilePositionTypes.TOP_RIGHT_CORNER)
                {
                    tileIndex = pseudoRandom.Next(35, 40);
                }
                if (myPosType == GraphicTile.TilePositionTypes.LEFT_BOTTOM_DIAG)
                {
                    tileIndex = pseudoRandom.Next(50, 55);
                }
                if (myPosType == GraphicTile.TilePositionTypes.RIGHT_BOTTOM_DIAG)
                {
                    tileIndex = pseudoRandom.Next(55, 60);
                }
                if (myPosType == GraphicTile.TilePositionTypes.LEFT_TOP_DIAG)
                {
                    tileIndex = pseudoRandom.Next(40, 45);
                }
                if (myPosType == GraphicTile.TilePositionTypes.RIGHT_TOP_DIAG)
                {
                    tileIndex = pseudoRandom.Next(45, 50);
                }
                break;

            case GraphicTile.TileEdgeTypes.SHORE:
                // select a shore cliff of this edge type
                if (myPosType == GraphicTile.TilePositionTypes.BOTTOM)
                {
                    tileIndex = pseudoRandom.Next(110, 120);
                }
                if (myPosType == GraphicTile.TilePositionTypes.TOP)
                {
                    tileIndex = pseudoRandom.Next(140, 150);
                }
                if (myPosType == GraphicTile.TilePositionTypes.LEFT)
                {
                    tileIndex = pseudoRandom.Next(105, 110);
                }
                if (myPosType == GraphicTile.TilePositionTypes.RIGHT)
                {
                    tileIndex = pseudoRandom.Next(100, 105);
                }

                // USING SHORE CORNERS AND DIAGONALS HERE (WHERE AVAILABLE)
                if (myPosType == GraphicTile.TilePositionTypes.BOTTOM_LEFT_CORNER)
                {
                    tileIndex = pseudoRandom.Next(125, 130);
                }
                if (myPosType == GraphicTile.TilePositionTypes.BOTTOM_RIGHT_CORNER)
                {
                    tileIndex = pseudoRandom.Next(120, 125);
                }
                if (myPosType == GraphicTile.TilePositionTypes.TOP_LEFT_CORNER)
                {
                    tileIndex = pseudoRandom.Next(30, 35);
                }
                if (myPosType == GraphicTile.TilePositionTypes.TOP_RIGHT_CORNER)
                {
                    tileIndex = pseudoRandom.Next(35, 40);
                }
                if (myPosType == GraphicTile.TilePositionTypes.LEFT_BOTTOM_DIAG)
                {
                    tileIndex = pseudoRandom.Next(50, 55);
                }
                if (myPosType == GraphicTile.TilePositionTypes.RIGHT_BOTTOM_DIAG)
                {
                    tileIndex = pseudoRandom.Next(55, 60);
                }
                if (myPosType == GraphicTile.TilePositionTypes.LEFT_TOP_DIAG)
                {
                    tileIndex = pseudoRandom.Next(40, 45);
                }
                if (myPosType == GraphicTile.TilePositionTypes.RIGHT_TOP_DIAG)
                {
                    tileIndex = pseudoRandom.Next(45, 50);
                }
                break;

            default:
                // Select a center tile
                int select = pseudoRandom.Next(0, 11);
                if (select > 8)
                {
                    tileIndex = pseudoRandom.Next(0, 10);
                }
                else
                {
                    tileIndex = 160;
                }

                break;

        }

        return tileIndex;
    }
 public SpriteData(SpriteData Other)
 {
     Mode = Other.Mode;
     Tile = new GraphicTile(Other.Tile);
 }
示例#17
0
    int FindIndex(GraphicTile.TilePositionTypes myPosType, GraphicTile.TileEdgeTypes myEdgeType, GraphicTile.TileLandTypes myLandType)
    {
        int tileIndex = 0;

        if (myLandType == GraphicTile.TileLandTypes.ASH)
        {
            // Get the index using the Ash Tile Sheet
            tileIndex = GetAshSheetIndex(myPosType, myEdgeType);
        }
        else
        {
            // Get the index using the Mud Tile Sheet
            tileIndex = GetIndexFromSandOrMudSheet(myPosType, myLandType);

        }

        return tileIndex;
    }
示例#18
0
    GraphicTile DefineRegionTile(GraphicTile.TileLandTypes myLandType, Vector2[] positions,Vector2 position, GraphicTile[] tiles)
    {
        // Make them all clear tiles at first
        //GraphicTile definedTile = new GraphicTile();

          //  return CheckTileNeighbors(positions, position, myLandType, tiles);

        // First we need to know if this is the First region tile to be defined
        if (position == positions[0])
        {
            // First tile is ALWAYS the bottom left corner. But we still need to find out its Edge Type.
            // Define the tile as a Bottom Left Corner:
            // top && right && not left && not bottom
            return GetTilePositionType(false, true, true, false, false, false, false, false, (int)position.x, (int)position.y, myLandType);
        }
        else if (position == positions[positions.Length - 1])
        {
            // If this is the LAST tile it will ALWAYS be a top right corner
            // !_top && !_right && _left && _bottom && !_topRight
            return GetTilePositionType(_left: true,_right: false, _top: false, _bottom: true,_topLeft: false, _bottLeft: false, _topRight: false,_bottRight: false, posX: (int)position.x, posY: (int)position.y, myLandType: myLandType);

        }
        else
        {
            return CheckTileNeighbors(positions, position, myLandType, tiles);
        }

        //return definedTile;

        /*
        int decideIfClear = Random.Range(0, 6);
        if (decideIfClear == 0)
        {
           definedTile = new GraphicTile(GraphicTile.TilePositionTypes.CLEAR, position);
        }
        else
        {

            // Initialize this new Graphic Tile
            definedTile = CheckTileNeighbors(positions, position, myLandType, tiles);

            // THIS NOW considers clear tiles to be Non-existant and will create edges accordingly

        }
        */

        //return definedTile;
    }
示例#19
0
	public void setInitialEntity(Entity entity) {
        removeEntity();
        entity.transform.parent = this.transform.parent;
        entity.transform.position = transform.position;
		this.entityPresent = entity;
		entity.setCurrentTile (this);
        if (entity.GetType() != typeof(Obstacle))
        {
            int type = (entity.getIsPlayer() ? 0 : 1);
            graphicTile = GetComponent<GraphicTile>();
            graphicTile.setAnim();
            setTileType(type);
        }
    }
示例#20
0
    GraphicTile.TileEdgeTypes DefineEdgeType(GraphicTile.TileEdgeTypes neighborOne, GraphicTile.TileEdgeTypes neighborTwo, bool isCorner = false)
    {
        GraphicTile.TileEdgeTypes myTileEdgeType = GraphicTile.TileEdgeTypes.UNDEFINED;

        if (neighborOne != GraphicTile.TileEdgeTypes.UNDEFINED || neighborTwo != GraphicTile.TileEdgeTypes.UNDEFINED)
        {
            // Both are DEFINED, so select based on the first and second neighbor
            myTileEdgeType = GetMyTileTypeFromNeighbors(neighborOne, neighborTwo, isCorner);

        }
        else
        {

            myTileEdgeType = DefineTypeFromUndefinedNeighbors(isCorner);

        }

        return myTileEdgeType;
    }
示例#21
0
    GraphicTile.TileLandTypes GetNewLandType(GraphicTile.TileLandTypes currLandType)
    {
        //make it so there's a low chance of it selecting the same as the Base land type
        int randomLandType = Random.Range(0, 20);

        if (randomLandType <= 1)
        {
            return baseLandType;

        }
        else
        {

            if (baseLandType == GraphicTile.TileLandTypes.ASH)
            {
                int random = Random.Range(0, 2);
                if (random == 0)
                {
                    return GraphicTile.TileLandTypes.MUD;
                }
                else
                {
                    return GraphicTile.TileLandTypes.SAND;
                }

            }
            else if (baseLandType == GraphicTile.TileLandTypes.MUD)
            {
                int random = Random.Range(0, 2);
                if (random == 0)
                {
                    return GraphicTile.TileLandTypes.ASH;
                }
                else
                {
                    return GraphicTile.TileLandTypes.SAND;
                }
            }
            else
            {
                int random = Random.Range(0, 2);
                if (random == 0)
                {
                    return GraphicTile.TileLandTypes.ASH;
                }
                else
                {
                    return GraphicTile.TileLandTypes.MUD;
                }
            }

        }

         //   return thisLandType;
    }
 public SpriteData(ColorSettings Settings)
 {
     Tile             = new GraphicTile(24, 21, GraphicTileMode.COMMODORE_HIRES, Settings);
     Tile.CustomColor = 1;
 }
示例#23
0
    GraphicTile GetTilePositionType(bool _left, bool _right, bool _top, bool _bottom, bool _topLeft = false, bool _bottLeft = false, bool _topRight = false, bool _bottRight = false, int posX = 0, int posY = 0, GraphicTile.TileLandTypes myLandType = GraphicTile.TileLandTypes.ASH, bool isSecondTexture = false)
    {
        // Positions to check
        int right = posX + 1;
        int left = posX - 1;
        int top = posY + 1;
        int bottom = posY - 1;

        GraphicTile.TileEdgeTypes myTileEdgeType;
        GraphicTile.TileEdgeTypes neighborTop = (myLandType == GraphicTile.TileLandTypes.ASH) ? GetNeighborEdgeTypes(posX, top, isSecondTexture) : GraphicTile.TileEdgeTypes.SHORE;
        GraphicTile.TileEdgeTypes neighborRight = (myLandType == GraphicTile.TileLandTypes.ASH) ? GetNeighborEdgeTypes(right, posY, isSecondTexture) : GraphicTile.TileEdgeTypes.SHORE;
        GraphicTile.TileEdgeTypes neighborLeft = (myLandType == GraphicTile.TileLandTypes.ASH) ? GetNeighborEdgeTypes(left, posY, isSecondTexture) : GraphicTile.TileEdgeTypes.SHORE;
        GraphicTile.TileEdgeTypes neighborBottom = (myLandType == GraphicTile.TileLandTypes.ASH) ? GetNeighborEdgeTypes(posX, bottom, isSecondTexture) : GraphicTile.TileEdgeTypes.SHORE;

        // Tile to return
        GraphicTile newTile = new GraphicTile();

        // Check diagonal tiles first:
        if (_top && _right && _left && _bottom && !_bottLeft)
        {
            // Left bottom diagonal
            if (myLandType == GraphicTile.TileLandTypes.ASH)
            {
                // Neighbor 1 = left, Neighbor 2 = bottom
                myTileEdgeType = DefineEdgeType(neighborLeft, neighborBottom);

                // Define the tile to return
                newTile = new GraphicTile(GraphicTile.TilePositionTypes.LEFT_BOTTOM_DIAG, myTileEdgeType, GraphicTile.TileLandTypes.ASH, new Vector2(posX, posY));
            }
            else
            {
                // Tiles that are NOT edge are all SHORE types
                newTile = new GraphicTile(GraphicTile.TilePositionTypes.LEFT_BOTTOM_DIAG, GraphicTile.TileEdgeTypes.SHORE, myLandType, new Vector2(posX, posY));
            }

        }
        else if (_top && _left && _bottom && _right && !_bottRight)
        {
            // Right bottom diagonal
            if (myLandType == GraphicTile.TileLandTypes.ASH)
            {
                // Neighbor 1 = bottom, Neighbor 2 = right
                myTileEdgeType = DefineEdgeType(neighborBottom, neighborRight);

                newTile = new GraphicTile(GraphicTile.TilePositionTypes.RIGHT_BOTTOM_DIAG, myTileEdgeType, GraphicTile.TileLandTypes.ASH, new Vector2(posX, posY));
            }
            else
            {
                newTile = new GraphicTile(GraphicTile.TilePositionTypes.RIGHT_BOTTOM_DIAG, GraphicTile.TileEdgeTypes.SHORE, myLandType, new Vector2(posX, posY));
            }

        }
        else if (_top && _left && _bottom && _right && !_topRight)
        {
            // Right top diagonal
            if (myLandType == GraphicTile.TileLandTypes.ASH)
            {
                // Neighbor 1 = bottom, Neighbor 2 = right
                myTileEdgeType = DefineEdgeType(neighborTop, neighborRight);

                newTile = new GraphicTile(GraphicTile.TilePositionTypes.RIGHT_TOP_DIAG, myTileEdgeType, GraphicTile.TileLandTypes.ASH, new Vector2(posX, posY));
            }
            else
            {
                newTile = new GraphicTile(GraphicTile.TilePositionTypes.RIGHT_TOP_DIAG, GraphicTile.TileEdgeTypes.SHORE, myLandType, new Vector2(posX, posY));
            }

        }
        else if (_top && _left && _bottom && _right && !_topLeft)
        {
            // Left top diagonal
            if (myLandType == GraphicTile.TileLandTypes.ASH)
            {
                // Neighbor 1 = bottom, Neighbor 2 = right
                myTileEdgeType = DefineEdgeType(neighborLeft, neighborTop);

                newTile = new GraphicTile(GraphicTile.TilePositionTypes.LEFT_TOP_DIAG, myTileEdgeType, GraphicTile.TileLandTypes.ASH, new Vector2(posX, posY));
            }
            else
            {
                newTile = new GraphicTile(GraphicTile.TilePositionTypes.LEFT_TOP_DIAG, GraphicTile.TileEdgeTypes.SHORE, myLandType, new Vector2(posX, posY));
            }

        }
        else if (_top && _right && !_left && !_bottom)
        {
            // bottom left corner
            if (myLandType == GraphicTile.TileLandTypes.ASH)
            {

                // Neighbor 1 = top, Neighbor 2 = right
                myTileEdgeType = DefineEdgeType(neighborTop, neighborRight, isCorner: true);

                newTile = new GraphicTile(GraphicTile.TilePositionTypes.BOTTOM_LEFT_CORNER, myTileEdgeType, GraphicTile.TileLandTypes.ASH, new Vector2(posX, posY));
            }
            else
            {
                newTile = new GraphicTile(GraphicTile.TilePositionTypes.BOTTOM_LEFT_CORNER, GraphicTile.TileEdgeTypes.SHORE, myLandType, new Vector2(posX, posY));
            }

        }
        else if (_top && _left && _right && !_bottom)
        {
            // Bottom
            if (myLandType == GraphicTile.TileLandTypes.ASH)
            {

                // Neighbor 1 = left, Neighbor 2 = right
                myTileEdgeType = DefineEdgeType(neighborLeft, neighborRight);

                newTile = new GraphicTile(GraphicTile.TilePositionTypes.BOTTOM, myTileEdgeType, GraphicTile.TileLandTypes.ASH, new Vector2(posX, posY));
            }
            else
            {
                newTile = new GraphicTile(GraphicTile.TilePositionTypes.BOTTOM, GraphicTile.TileEdgeTypes.SHORE, myLandType, new Vector2(posX, posY));
            }

        }
        else if (_top && _left && !_right && !_bottom)
        {
            // Bottom right corner
            if (myLandType == GraphicTile.TileLandTypes.ASH)
            {
                // Neighbor 1 = left, Neighbor 2 = top
                myTileEdgeType = DefineEdgeType(neighborLeft, neighborTop, isCorner: true);

                newTile = new GraphicTile(GraphicTile.TilePositionTypes.BOTTOM_RIGHT_CORNER, myTileEdgeType, GraphicTile.TileLandTypes.ASH, new Vector2(posX, posY));
            }
            else
            {
                newTile = new GraphicTile(GraphicTile.TilePositionTypes.BOTTOM_RIGHT_CORNER, GraphicTile.TileEdgeTypes.SHORE, myLandType, new Vector2(posX, posY));
            }

        }
        else if (_top && _left && _bottom && !_right)
        {
            // Right
            if (myLandType == GraphicTile.TileLandTypes.ASH)
            {

                // Neighbor 1 = bottom, Neighbor 2 = top
                myTileEdgeType = DefineEdgeType(neighborBottom, neighborTop);

                newTile = new GraphicTile(GraphicTile.TilePositionTypes.RIGHT, myTileEdgeType, GraphicTile.TileLandTypes.ASH, new Vector2(posX, posY));
            }
            else
            {
                newTile = new GraphicTile(GraphicTile.TilePositionTypes.RIGHT, GraphicTile.TileEdgeTypes.SHORE, myLandType, new Vector2(posX, posY));
            }

        }
        else if (_top && _right && _bottom && !_left)
        {
            // left
            if (myLandType == GraphicTile.TileLandTypes.ASH)
            {// Neighbor 1 = bottom, Neighbor 2 = top
                myTileEdgeType = DefineEdgeType(neighborBottom, neighborTop);

                newTile = new GraphicTile(GraphicTile.TilePositionTypes.LEFT, myTileEdgeType, GraphicTile.TileLandTypes.ASH, new Vector2(posX, posY));
            }
            else
            {
                newTile = new GraphicTile(GraphicTile.TilePositionTypes.LEFT, GraphicTile.TileEdgeTypes.SHORE, myLandType, new Vector2(posX, posY));
            }

        }
        else if (!_top && _right && _left && _bottom)
        {
            // top shore
            if (myLandType == GraphicTile.TileLandTypes.ASH)
            {
                // Neighbor 1 = left, Neighbor 2 = right
                myTileEdgeType = DefineEdgeType(neighborLeft, neighborRight);
                //myTileType = GetMyTileTypeFromNeighbors(neighborLeft, neighborRight);

                newTile = new GraphicTile(GraphicTile.TilePositionTypes.TOP, myTileEdgeType, GraphicTile.TileLandTypes.ASH, new Vector2(posX, posY));
            }
            else
            {
                newTile = new GraphicTile(GraphicTile.TilePositionTypes.TOP, GraphicTile.TileEdgeTypes.SHORE, myLandType, new Vector2(posX, posY));
            }

        }
        else if (!_top && !_right && _left && _bottom && !_topRight)
        {
            // top right corner
            if (myLandType == GraphicTile.TileLandTypes.ASH)
            {

                // Neighbor 1 = left, Neighbor 2 = bottom
                myTileEdgeType = DefineEdgeType(neighborLeft, neighborBottom, isCorner: true);

                newTile = new GraphicTile(GraphicTile.TilePositionTypes.TOP_RIGHT_CORNER, myTileEdgeType, GraphicTile.TileLandTypes.ASH, new Vector2(posX, posY));
            }
            else
            {
                newTile = new GraphicTile(GraphicTile.TilePositionTypes.TOP_RIGHT_CORNER, GraphicTile.TileEdgeTypes.SHORE, myLandType, new Vector2(posX, posY));
            }

        }

        else if (!_top && _right && !_left && _bottom && !_topLeft)
        {
            // top left corner
            if (myLandType == GraphicTile.TileLandTypes.ASH)
            {

                // Neighbor 1 = bottom, Neighbor 2 = right
                myTileEdgeType = DefineEdgeType(neighborBottom, neighborRight, isCorner: true);

                newTile = new GraphicTile(GraphicTile.TilePositionTypes.TOP_LEFT_CORNER, myTileEdgeType, GraphicTile.TileLandTypes.ASH, new Vector2(posX, posY));
            }
            else
            {
                newTile = new GraphicTile(GraphicTile.TilePositionTypes.TOP_LEFT_CORNER, GraphicTile.TileEdgeTypes.SHORE, myLandType, new Vector2(posX, posY));
            }
        }
        //else if (_top && !_left && !)
        else
        {
            if (myLandType == GraphicTile.TileLandTypes.ASH)
            {
                // if top , left , right , !bottom place a bottom left corner
                if (_top &&  !_left && !_right && !_bottom)
                {
                    myTileEdgeType = DefineTypeFromUndefinedNeighbors(false);
                    newTile = new GraphicTile(GraphicTile.TilePositionTypes.BOTTOM, myTileEdgeType, GraphicTile.TileLandTypes.ASH, new Vector2(posX, posY));
                }
                // else if !top, left, right, bottom place a top left corner
                else if (!_top && !_left && !_right && _bottom)
                {
                    myTileEdgeType = DefineTypeFromUndefinedNeighbors(true);
                    newTile = new GraphicTile(GraphicTile.TilePositionTypes.TOP_LEFT_CORNER, myTileEdgeType, GraphicTile.TileLandTypes.ASH, new Vector2(posX, posY));
                }
                else if (_top && !_left && !_right && !_bottom && _topLeft)
                {
                    myTileEdgeType = DefineTypeFromUndefinedNeighbors(true);
                    newTile = new GraphicTile(GraphicTile.TilePositionTypes.BOTTOM_LEFT_CORNER, myTileEdgeType, GraphicTile.TileLandTypes.ASH, new Vector2(posX, posY));
                }

                else if (!_top && !_left && !_right && _bottom && _bottRight)
                {
                    myTileEdgeType = DefineTypeFromUndefinedNeighbors(true);
                    newTile = new GraphicTile(GraphicTile.TilePositionTypes.TOP_RIGHT_CORNER, myTileEdgeType, GraphicTile.TileLandTypes.ASH, new Vector2(posX, posY));

                }
                else if (!_top && _left && !_right && !_bottom && _bottLeft)
                {
                    myTileEdgeType = DefineTypeFromUndefinedNeighbors(true);
                    newTile = new GraphicTile(GraphicTile.TilePositionTypes.BOTTOM_RIGHT_CORNER, myTileEdgeType, GraphicTile.TileLandTypes.ASH, new Vector2(posX, posY));
                }
                else if (!_top && !_left && _right && !_bottom && _bottRight)
                {
                    myTileEdgeType = DefineTypeFromUndefinedNeighbors(true);
                    newTile = new GraphicTile(GraphicTile.TilePositionTypes.TOP_LEFT_CORNER, myTileEdgeType, GraphicTile.TileLandTypes.ASH, new Vector2(posX, posY));
                }
                else if (!_top && !_left && _right && _bottom)
                {
                    myTileEdgeType = DefineTypeFromUndefinedNeighbors(true);
                    newTile = new GraphicTile(GraphicTile.TilePositionTypes.LEFT_TOP_DIAG, myTileEdgeType, GraphicTile.TileLandTypes.ASH, new Vector2(posX, posY));
                }
                // else it's a center
                else
                {
                    newTile = new GraphicTile(GraphicTile.TilePositionTypes.CENTER, GraphicTile.TileEdgeTypes.CENTER, GraphicTile.TileLandTypes.ASH, new Vector2(posX, posY));
                }
            }
            else
            {
                // if top , left , right , !bottom place a bottom left corner
                if (_top && _left && _right && !_bottom)
                {
                    myTileEdgeType = DefineEdgeType(neighborLeft, neighborRight, isCorner: true);
                    newTile = new GraphicTile(GraphicTile.TilePositionTypes.BOTTOM_LEFT_CORNER, myTileEdgeType, myLandType, new Vector2(posX, posY));
                }
                // else if !top, left, right, bottom place a top left corner
                else if (!_top && _left && _right && _bottom)
                {
                    myTileEdgeType = DefineEdgeType(neighborLeft, neighborRight, isCorner: true);
                    newTile = new GraphicTile(GraphicTile.TilePositionTypes.TOP_LEFT_CORNER, myTileEdgeType, myLandType, new Vector2(posX, posY));
                }
                else if(_top && !_left && !_right && !_bottom && _topLeft)
                {
                    newTile = new GraphicTile(GraphicTile.TilePositionTypes.BOTTOM_LEFT_CORNER, GraphicTile.TileEdgeTypes.SHORE, myLandType, new Vector2(posX, posY));
                }
                else if (!_top && !_left && !_right && _bottom && _bottRight)
                {
                    newTile = new GraphicTile(GraphicTile.TilePositionTypes.TOP_RIGHT_CORNER, GraphicTile.TileEdgeTypes.SHORE, myLandType, new Vector2(posX, posY));

                }
                else if (!_top && _left && !_right && !_bottom && _bottLeft)
                {
                    newTile = new GraphicTile(GraphicTile.TilePositionTypes.BOTTOM_RIGHT_CORNER, GraphicTile.TileEdgeTypes.SHORE, myLandType, new Vector2(posX, posY));
                }
                else if (!_top && !_left && _right && !_bottom && _bottRight)
                {
                    newTile = new GraphicTile(GraphicTile.TilePositionTypes.TOP_LEFT_CORNER, GraphicTile.TileEdgeTypes.SHORE, myLandType, new Vector2(posX, posY));
                }
                else if (!_top && !_left && _right && _bottom && _bottLeft)
                {
                    newTile = new GraphicTile(GraphicTile.TilePositionTypes.LEFT_TOP_DIAG, GraphicTile.TileEdgeTypes.SHORE, myLandType, new Vector2(posX, posY));
                }
                // else it's a center
                else
                {
                    newTile = new GraphicTile(GraphicTile.TilePositionTypes.CENTER, GraphicTile.TileEdgeTypes.CENTER, myLandType, new Vector2(posX, posY));
                }
            }
        }

        return newTile;
    }
示例#24
0
    int GetIndexFromSandOrMudSheet(GraphicTile.TilePositionTypes myPosType, GraphicTile.TileLandTypes myLandType)
    {
        int tileIndex = 0;

        switch (myPosType)
        {
            case GraphicTile.TilePositionTypes.BOTTOM:
                if (myLandType == GraphicTile.TileLandTypes.SAND)
                {
                    return Random.Range(61, 70);

                }else if (myLandType == GraphicTile.TileLandTypes.MUD)
                {
                    return Random.Range(131, 140);
                }
                break;
             case GraphicTile.TilePositionTypes.TOP:
                if (myLandType == GraphicTile.TileLandTypes.SAND)
                {
                    return Random.Range(0, 9);
                }
                else if (myLandType == GraphicTile.TileLandTypes.MUD)
                {
                    return Random.Range(91, 95);
                }
                break;

            case GraphicTile.TilePositionTypes.LEFT:
                if (myLandType == GraphicTile.TileLandTypes.SAND)
                {
                    return Random.Range(40, 45);
                }
                else if (myLandType == GraphicTile.TileLandTypes.MUD)
                {
                    return Random.Range(100, 105);
                }
                break;

            case GraphicTile.TilePositionTypes.RIGHT:
                if (myLandType == GraphicTile.TileLandTypes.SAND)
                {
                    return Random.Range(45, 50);
                }
                else if (myLandType == GraphicTile.TileLandTypes.MUD)
                {
                    return Random.Range(105, 110);
                }
                break;

            case GraphicTile.TilePositionTypes.BOTTOM_LEFT_CORNER:

                if (myLandType == GraphicTile.TileLandTypes.SAND)
                {
                    return Random.Range(30, 35);
                }
                else if (myLandType == GraphicTile.TileLandTypes.MUD)
                {
                    return Random.Range(120, 125);
                }
                break;

            case GraphicTile.TilePositionTypes.BOTTOM_RIGHT_CORNER:
                if (myLandType == GraphicTile.TileLandTypes.SAND)
                {
                    return Random.Range(35,40);
                }
                else if (myLandType == GraphicTile.TileLandTypes.MUD)
                {
                    return Random.Range(125, 130);
                }
                break;

            case GraphicTile.TilePositionTypes.TOP_LEFT_CORNER:
                if (myLandType == GraphicTile.TileLandTypes.SAND)
                {
                    return Random.Range(20 , 25);
                }
                else if (myLandType == GraphicTile.TileLandTypes.MUD)
                {
                    return Random.Range(110, 115);
                }
                break;

            case GraphicTile.TilePositionTypes.TOP_RIGHT_CORNER:
                if (myLandType == GraphicTile.TileLandTypes.SAND)
                {
                    return Random.Range(25, 30);
                }
                else if (myLandType == GraphicTile.TileLandTypes.MUD)
                {
                    return Random.Range(115, 120);
                }
                break;

            case GraphicTile.TilePositionTypes.LEFT_BOTTOM_DIAG:
                if (myLandType == GraphicTile.TileLandTypes.SAND)
                {
                    return Random.Range(50, 55);
                }
                else if (myLandType == GraphicTile.TileLandTypes.MUD)
                {
                    return Random.Range(80, 85);
                }
                break;

            case GraphicTile.TilePositionTypes.RIGHT_BOTTOM_DIAG:
                if (myLandType == GraphicTile.TileLandTypes.SAND)
                {
                    return Random.Range(55, 60);
                }
                else if (myLandType == GraphicTile.TileLandTypes.MUD)
                {
                    return Random.Range(85, 90);
                }
                break;
            case GraphicTile.TilePositionTypes.LEFT_TOP_DIAG:
                if (myLandType == GraphicTile.TileLandTypes.SAND)
                {
                    return Random.Range(10, 15);
                }
                else if (myLandType == GraphicTile.TileLandTypes.MUD)
                {
                    return Random.Range(80, 85);
                }
                break;
            case GraphicTile.TilePositionTypes.RIGHT_TOP_DIAG:
                if (myLandType == GraphicTile.TileLandTypes.SAND)
                {
                    return Random.Range(15, 20);
                }
                else if (myLandType == GraphicTile.TileLandTypes.MUD)
                {
                    return Random.Range(95, 100);
                }
                break;

            default:
                // Center tile
                if (myLandType == GraphicTile.TileLandTypes.SAND)
                {
                    return 60;
                }
                else if (myLandType == GraphicTile.TileLandTypes.MUD)
                {
                    return 130;
                }
                break;

        }

        return tileIndex;
    }
示例#25
0
        // This is one of the ugliest functions I've ever written
        private void ApplyChange(int source, int dest)
        {
            if (source == dest)
            {
                return;
            }

            Tiles.FileUpToDate = false;

            // Update integer value for graphic of tiles
            Tile destTile = Tiles.Tiles[dest];

            if (destTile is GraphicTile)
            {
                (destTile as GraphicTile).Graphic = source;
            }
            Tile sourceTile = Tiles.Tiles[source];

            if (sourceTile is GraphicTile)
            {
                (sourceTile as GraphicTile).Graphic = dest;
            }

            // Swap images in imagelist and source images
            var tmp = Tiles.Images.Images[source];

            Tiles.Images.Images[source] = Tiles.Images.Images[dest];
            Tiles.Images.Images[dest]   = tmp;
            var tmp2 = Tiles.Tiles[source];

            Tiles.Tiles[source] = Tiles.Tiles[dest];
            Tiles.Tiles[dest]   = tmp2;
            var tmp3 = m_sourceImages[source];

            m_sourceImages[source] = m_sourceImages[dest];
            m_sourceImages[dest]   = tmp3;

            listView1.RefreshContents(Tiles, TileType.Graphic);
            listView1.SelectedIndices.Clear();
            if (listView1.Items.Count > 0)
            {
                listView1.SelectedIndices.Add(0);
            }

            listView2.RefreshContents(Tiles, TileType.Special);
            listView2.SelectedIndices.Clear();
            if (listView2.Items.Count > 0)
            {
                listView2.SelectedIndices.Add(0);
            }

            if (Map != null)
            {
                ((Action)(() =>
                {
                    foreach (Tile tile in Map.Layers[(int)LAYERS.Graphic].Values)
                    {
                        if (tile is GraphicTile)
                        {
                            GraphicTile gTile = tile as GraphicTile;

                            if (gTile.Graphic == source)
                            {
                                gTile.Graphic = dest;
                            }
                            else if (gTile.Graphic == dest)
                            {
                                gTile.Graphic = source;
                            }
                        }
                    }
                })).BeginInvoke(null, null);
            }
        }