예제 #1
0
    public void LoadColorPaletteSet()
    {
        pixelData = new PixelData();
        List <Texture2D> imageSet = new List <Texture2D>();

        imageSet.Add(backgroundImage);
        imageSet.Add(platformImage);
        imageSet.Add(foregroundImage);
        pixelData.pixelImages = imageSet.ToArray();
        Debug.Log("image counts: " + imageSet.Count);
        for (int i = 0; i < imageSet.Count; i++)
        {
            tiles.tileWrapper.listOfColorTileHolder.Add(new ColorTileHolder());
        }

        Debug.Log("ListCount: " + tiles.tileWrapper.listOfColorTileHolder.Count);
        for (int i = 0; i < imageSet.Count; i++)
        {
            pixelData.pixelImage     = imageSet[i];
            pixelData.pixelColorHash = new HashSet <Color32>();
            pixelData.LoadPixelColors();
            Debug.Log("pixel hash count: " + pixelData.pixelColorHash.Count);
            ColorTile temp = new ColorTile();
            foreach (var pix in pixelData.imageColorList)
            {
                temp.colorHex = ColorUtility.ToHtmlStringRGBA(pix).ToString();
                temp.colorVal = pix;
                //                tiles.tileWrapper.listOfColorTileHolder[i].colorTiles = new List<ColorTile>(pixelData.imageColorList.Count);
                Debug.Log("colorTile set count: " + tiles.tileWrapper.listOfColorTileHolder[i].colorTiles.Capacity);
                tiles.tileWrapper.listOfColorTileHolder[i].colorTiles.Add(temp);
                Debug.Log(tiles.tileWrapper.listOfColorTileHolder[i].colorTiles.Count);
            }
        }
    }
    void OnTriggerEnter2D(Collider2D col)
    {
        string tag = col.gameObject.tag;

        if (tag.Equals("Ground"))
        {
            ResetJump();
            if (Time.time - startTime > 1)
            {
                AudioManager.instance.PlaySound("Land", .5f);
            }
        }
        else if (tag.Equals("Tile"))
        {
            ColorTile tile = col.GetComponent <ColorTile>();
            GameManager.instance.CompleteTile(tile);
        }
        else if (tag.Equals("Pigment"))
        {
            GainPigment(col.GetComponent <Pigment>().PickupColor());
        }
        else if (tag.Equals("Exit"))
        {
            GameManager.instance.CheckVictory();
        }
    }
예제 #3
0
    public void DecompleteTile(ColorTile tile)
    {
        tile.SwitchToBnW();
        currCompletedTiles--;

        UpdateScore();
    }
예제 #4
0
 public MyTile(GameObject tile, Vector2 worldPos, Vector2 gridPos, ColorTile colorTile)
 {
     this.tile      = tile;
     this.worldPos  = worldPos;
     this.gridPos   = gridPos;
     this.colorTile = colorTile;
 }
예제 #5
0
    void CheckVertical(int idx, int limit, ColorTile baseColor, ref int counter, int idxRoot)
    {
        if (idx < 0 || idx >= colorTable.Length)
        {
            return;
        }

        if ((idxRoot / width != idx / width))
        {
            return;
        }

        if (limit <= 0)
        {
            return;
        }

        if (baseColor != colorTable[idx])
        {
            return;
        }

        counter++;
        limit--;
        Debug.Log("Vertical: " + idx + " Color: " + colorTable[idx] + " x: " + idx / width + " y: " + idx % width);
        CheckVertical(idx + 1, limit, baseColor, ref counter, idxRoot);
        CheckVertical(idx - 1, limit, baseColor, ref counter, idxRoot);
    }
예제 #6
0
파일: Tile.cs 프로젝트: R3D87/Match3Game
 public void AddRandomColor()
 {
     colorTileID         = TilesManager.RandomPickColorID();
     rend                = GetComponent <Renderer>();
     rend.enabled        = true;
     rend.sharedMaterial = TilesManager.ColorID[colorTileID];
     //Debug.Log(colorTileID);
 }
예제 #7
0
    public void LoadColorPalette()
    {
        pixelData = new PixelData(platformImage);

        pixelData.LoadPixelColors();
        ColorTile temp = new ColorTile();

        foreach (var pix in pixelData.imageColorList)
        {
            temp.colorHex = ColorUtility.ToHtmlStringRGBA(pix).ToString();
            temp.colorVal = pix;
            colorTiles.Add(temp);
        }
    }
예제 #8
0
    List <Tile> MatchTileCheckNeighbours(int x, int y)
    {
        HashSet <Tile> MatchSet = new HashSet <Tile>();
        //Debug.Log("x: " + x + " y: " + y);
        int       x1, x2, x3, y1, y2, y3;
        ColorTile ColorTarget = boardGame.GetColorTileFormCoord(x, y);

        int[] Template = new int[] { -2, -1, 0 };

        for (int i = 0; i < 3; i++)
        {
            x1 = x + Template[0] + i;
            x2 = x + Template[1] + i;
            x3 = x + Template[2] + i;
            //Debug.Log("x1: " + x1 + " x2: " + x2 + " x3: " + x3);

            if (x1 >= 0 && x2 >= 0 && x3 >= 0 && boardGame.Width > x1 && boardGame.Width > x2 && boardGame.Width > x3)
            {
                if (ColorTarget == boardGame.GetColorTileFormCoord(x1, y) &&
                    ColorTarget == boardGame.GetColorTileFormCoord(x2, y) &&
                    ColorTarget == boardGame.GetColorTileFormCoord(x3, y))
                {
                    MatchSet.Add(boardGame.GetTileFormCoord(x1, y));
                    MatchSet.Add(boardGame.GetTileFormCoord(x2, y));
                    MatchSet.Add(boardGame.GetTileFormCoord(x3, y));
                }
            }

            y1 = y + Template[0] + i;
            y2 = y + Template[1] + i;
            y3 = y + Template[2] + i;
            //Debug.Log("y1: " + y1 + " y2: " + y2 + " y3: " + y3);
            if (y1 >= 0 && y >= 0 && y3 >= 0 && boardGame.Height > y1 && boardGame.Height > y2 && boardGame.Height > y3)
            {
                if (ColorTarget == boardGame.GetColorTileFormCoord(x, y1) &&
                    ColorTarget == boardGame.GetColorTileFormCoord(x, y2) &&
                    ColorTarget == boardGame.GetColorTileFormCoord(x, y3))
                {
                    MatchSet.Add(boardGame.GetTileFormCoord(x, y1));
                    MatchSet.Add(boardGame.GetTileFormCoord(x, y2));
                    MatchSet.Add(boardGame.GetTileFormCoord(x, y3));
                }
            }
        }
        foreach (var item in MatchSet)
        {
            //Debug.Log("item: " + item.PositionX + " " + item.PositionY);
        }
        return(new List <Tile>(MatchSet));
    }
예제 #9
0
    //Uses breadth first search (BFS).
    public void Paint(BruschInfo bruschInfo)
    {
        //Setting up alot of values that will be needed.
        int x      = bruschInfo.xPos;
        int y      = bruschInfo.yPos;
        int height = bruschInfo.grid.Height;
        int width  = bruschInfo.grid.Width;

        MyTile[,] tiles = bruschInfo.grid.Tiles;
        Color currentColor = tiles[x, y].colorTile.CurrentColor;


        Queue <ColorTile> openTiles = new Queue <ColorTile>();
        //Hashset contains method is O(1) so it's great for storing the already visited tiles.
        HashSet <ColorTile> closedTiles = new HashSet <ColorTile>();

        openTiles.Enqueue(tiles[x, y].colorTile);
        //BFS is used. First all nondiagonal neighbours are added to a temporary list.
        //then we check if the tile exists or if it has already been evaluated or if it has the same color as the original tile.
        //If it passes all the conditions its added to the open list. After that the currently evaluated node is added to the closedlist.
        //Lastly we paint all the nodes that is in the closedtiles set
        while (openTiles.Count > 0)
        {
            ColorTile currentTile = openTiles.Dequeue();
            x = (int)currentTile.Tile.gridPos.x;
            y = (int)currentTile.Tile.gridPos.y;
            List <ColorTile> tempList = new List <ColorTile>();
            tempList.Add(currentTile.North);
            tempList.Add(currentTile.East);
            tempList.Add(currentTile.South);
            tempList.Add(currentTile.West);
            foreach (ColorTile c in tempList)
            {
                if (c != null && !closedTiles.Contains(c) && !openTiles.Contains(c) && currentColor == c.CurrentColor)
                {
                    openTiles.Enqueue(c);
                }
            }
            if (!closedTiles.Contains(currentTile))
            {
                closedTiles.Add(currentTile);
            }
        }
        //Hashsets aren't as good for iteration though.
        foreach (ColorTile c in closedTiles)
        {
            c.Paint(bruschInfo.currentColor);
        }
    }
예제 #10
0
    public void CompleteTile(ColorTile tile)
    {
        if (tile.isColor)
        {
            return;
        }

        lastTiles.Push(tile);
        tile.SwitchToColor();
        currCompletedTiles++;
        UpdateScore();
        if (!isVictory)
        {
            CheckVictoryAvailable();
        }
    }
예제 #11
0
    void FloodFill(int x, int y, ColorTile color, int Limit)
    {
        if (Limit == 0)
        {
            return;
        }


        Limit--;


        FloodFill(x - 1, y, color, Limit);
        FloodFill(x + 1, y, color, Limit);
        FloodFill(x, y - 1, color, Limit);
        FloodFill(x, y + 1, color, Limit);
    }
예제 #12
0
    //Creates all the tiles.
    //Also setups the colortiles
    //This is very slow becuase gameobjects are quite slow and the program will crash if you create to many tiles at once.
    //Want to try to use something other then the tiles in the future and see if that speeds things up.
    void CreateGrid()
    {
        offset = RescaleOffset();
        Vector2 spawnPosition = GetMiddlePos();

        tiles = new MyTile[width, height];
        for (int i = 0; i < height; i++)
        {
            for (int k = 0; k < width; k++)
            {
                Vector3    spawnPos    = new Vector3(spawnPosition.x + (k * offset), spawnPosition.y + (i * offset), 0);
                GameObject temp        = Instantiate(tile, spawnPos, Quaternion.identity, tileHolder);
                ColorTile  colorTile   = temp.GetComponent <ColorTile>();
                MyTile     currentTile = new MyTile(temp, spawnPos, new Vector2(k, i), colorTile);
                tiles[k, i] = currentTile;
                temp.GetComponent <ColorTile>().OnStart(currentTile);
            }
        }
    }
예제 #13
0
    //Finds the 4 nondiagonal neighbours of the tile.
    void SetNeighbours()
    {
        int x = (int)myTile.gridPos.x;
        int y = (int)myTile.gridPos.y;

        if (AllowedPos(x, y + 1, se.MapHeight, se.MapWidth))
        {
            North = se.Grid.Tiles[x, y + 1].colorTile;
        }
        if (AllowedPos(x + 1, y, se.MapHeight, se.MapWidth))
        {
            East = se.Grid.Tiles[x + 1, y].colorTile;
        }
        if (AllowedPos(x, y - 1, se.MapHeight, se.MapWidth))
        {
            South = se.Grid.Tiles[x, y - 1].colorTile;
        }
        if (AllowedPos(x - 1, y, se.MapHeight, se.MapWidth))
        {
            West = se.Grid.Tiles[x - 1, y].colorTile;
        }
    }
예제 #14
0
    void CheckHorizontal(int idx, int limit, ColorTile baseColor, ref int counter)
    {
        if (idx >= colorTable.Length || idx < 0)
        {
            return;
        }

        if (limit <= 0)
        {
            return;
        }

        if (baseColor != colorTable[idx])
        {
            return;
        }

        counter++;

        limit--;
        Debug.Log("Horizontal: " + idx + " Color: " + colorTable[idx] + " x: " + idx / width + " y: " + idx % width);
        CheckHorizontal(idx + width, limit, baseColor, ref counter);
        CheckHorizontal(idx - width, limit, baseColor, ref counter);
    }
    private void ClickHandler()
    {
        if (is_input_palette)
        {
            // turn off output_ref
            if (output_ref != null)
            {
                output_ref.Highlight(false);
                output_ref = null;
            }

            // no input color
            if (input_ref == null)
            {
                ChangeColors.SetColorInputs(color, match);
                input_ref = this;
                Highlight();
                HighlightMatch(match);
            }
            // change input color
            else if (input_ref != this)
            {
                ChangeColors.SetColorInputs(color, match);
                input_ref.Highlight(false);
                input_ref = this;
                Highlight();
                HighlightMatch(match);
            }
            // de-select input color
            else if (input_ref == this)
            {
                ChangeColors.SetColorInputs();
                input_ref.Highlight(false);
                input_ref = null;
            }
        }
        else
        {
            // no colors selected
            if (output_ref == null)
            {
                // set color info so user can inspect output palette
                ChangeColors.SetColorInputs(color);
                output_ref = this;
                Highlight();
            }
            // change output color (with input)
            else if (output_ref != this && input_ref != null)
            {
                // add undo action
                ChangeColors.AddUndo("change match", input_ref.color, input_ref.match);

                // change the match color for the input
                ChangeColors.SetColorInputs(input_ref.color, this.color);
                output_ref.Highlight(false);
                Highlight();
                output_ref      = this;
                input_ref.match = this.color;

                // apply the change
                cc_ref.PickApply();
            }
            // change output color (no input)
            else if (output_ref != this && input_ref == null)
            {
                ChangeColors.SetColorInputs(color);
                output_ref.Highlight(false);
                output_ref = this;
                Highlight();
            }
            // de-select output color (no input)
            else if (input_ref == this && input_ref == null)
            {
                ChangeColors.SetColorInputs();
                input_ref.Highlight(false);
                output_ref.Highlight(false);
                input_ref  = null;
                output_ref = null;
            }
        }
    }
예제 #16
0
    //Creates a bruschinfo objext that stores all info needed to paint a tile.
    public void OnMousePress(ColorTile colorTile)
    {
        BruschInfo bruschInfo = new BruschInfo((int)colorTile.Tile.gridPos.x, (int)colorTile.Tile.gridPos.y, grid, CurrentColor);

        currentBrusch.Paint(bruschInfo);
    }
예제 #17
0
    private void PopulatePalettes()
    {
        // copy original state in case user hits cancel
        orig_input_palette.AddRange(ImageUtilities.input_palette);
        orig_output_palette.AddRange(ImageUtilities.output_palette);

        // ensure we have a valid input palette
        if (ImageUtilities.input_palette.Count == 0)
        {
            return;
        }

        ColorPlus[] input_palette = new ColorPlus[ImageUtilities.input_palette.Count];
        ColorPlus[] output_palette;

        if (ImageUtilities.sort_saved_palette)
        {
            ImageUtilities.StepSort(ImageUtilities.input_palette).CopyTo(input_palette);
        }
        else
        {
            ImageUtilities.input_palette.CopyTo(input_palette);
        }

        // figure out if an output palette has been defined or not (use input as default)
        if (ImageUtilities.output_palette.Count == 0)
        {
            output_palette = new ColorPlus[input_palette.Length];
            input_palette.CopyTo(output_palette, 0);
        }
        else
        {
            output_palette = new ColorPlus[ImageUtilities.output_palette.Count];
            if (ImageUtilities.sort_saved_palette)
            {
                ImageUtilities.StepSort(ImageUtilities.output_palette).CopyTo(output_palette);
            }
            else
            {
                ImageUtilities.output_palette.CopyTo(output_palette);
            }
        }

        // tell all the tiles they are input colors
        GameObject[] temp_objs  = new GameObject[input_palette.Length];
        ColorTile[]  temp_tiles = new ColorTile[input_palette.Length];
        int          index      = 0;

        for (int i = 0; i != input_palette.Length; i++)
        {
            // don't list transparent colors
            if (input_palette[i].alpha < ImageUtilities.transparent_threshhold)
            {
                continue;
            }

            // new color tile
            temp_objs[index]      = Instantiate(prefab, input_viewport.transform) as GameObject;
            temp_objs[index].name = "input_color_" + index.ToString();

            // set color tile color
            temp_tiles[index] = temp_objs[index].GetComponent(typeof(ColorTile)) as ColorTile;
            temp_tiles[index].Setup(true, input_palette[i].color32, input_palette[i].match, ref temp_objs[index]);

            index++;
        }

        GameObject[] temp1 = new GameObject[index];
        Array.Copy(temp_objs, temp1, index);
        input_colors.AddRange(temp1);

        ColorTile[] temp2 = new ColorTile[index];
        Array.Copy(temp_tiles, temp2, index);
        input_tiles.AddRange(temp2);

        temp_objs  = new GameObject[output_palette.Length];
        temp_tiles = new ColorTile[output_palette.Length];
        index      = 0;

        for (int i = 0; i != output_palette.Length; i++)
        {
            // don't list transparent colors
            if (output_palette[i].alpha < ImageUtilities.transparent_threshhold)
            {
                continue;
            }

            // new color tile
            temp_objs[index]      = Instantiate(prefab, output_viewport.transform) as GameObject;
            temp_objs[index].name = "output_color_" + index.ToString();

            // set color tile color
            temp_tiles[index] = temp_objs[index].GetComponent(typeof(ColorTile)) as ColorTile;
            temp_tiles[index].Setup(false, output_palette[i].color32, output_palette[i].match, ref temp_objs[index]);

            index++;
        }

        temp1 = new GameObject[index];
        Array.Copy(temp_objs, temp1, index);
        output_colors.AddRange(temp1);

        temp2 = new ColorTile[index];
        Array.Copy(temp_tiles, temp2, index);
        output_tiles.AddRange(temp2);
    }
예제 #18
0
    List <Tile> MatchTileCheckAll()
    {
        List <Tile> HotizontalTileMatch = new List <Tile>();
        List <Tile> VerticalTileMatch   = new List <Tile>();
        List <Tile> TileMatch           = new List <Tile>();

        for (int x = 0; x < boardGame.Width; x++)
        {
            for (int y = 0; y < boardGame.Height; y++)
            {
                int horizontalCounter = 0;
                int verticalCounter   = 0;
                //Debug.Log("Color: " + boardGame.GetTileFormCoord(x, y).colorTileID + " x: " + x + " y: " + y);


                for (int k = 1; k <= 2; k++)
                {
                    int xNeighbour = x + k;


                    if (xNeighbour >= boardGame.Width)
                    {
                        break;
                    }
                    //Debug.Log("Color: " + boardGame.GetTileFormCoord(xNeighbour, y).colorTileID + " xNeighbour:" + xNeighbour + " y: " + y);
                    ColorTile targetColor = boardGame.GetColorTileFormCoord(x, y);

                    ColorTile neighbourHorizontalColor = boardGame.GetColorTileFormCoord(xNeighbour, y);


                    if (neighbourHorizontalColor == targetColor)
                    {
                        horizontalCounter++;
                    }
                }

                for (int k = 1; k <= 2; k++)
                {
                    int yNeighbour = y + k;
                    if (yNeighbour >= boardGame.Height)
                    {
                        break;
                    }
                    //Debug.Log("Color: " + boardGame.GetTileFormCoord(x, yNeighbour).colorTileID + "x: " + x + " yNeighbour: " + yNeighbour);
                    ColorTile targetColor = boardGame.GetColorTileFormCoord(x, y);


                    ColorTile neighbourVerticalColor = boardGame.GetColorTileFormCoord(x, yNeighbour);

                    if (neighbourVerticalColor == targetColor)
                    {
                        verticalCounter++;
                    }
                }
                //Debug.Log("-------------------------------------");
                if (verticalCounter == 2)
                {
                    if (!VerticalTileMatch.Contains(boardGame.GetTileFormCoord(x, y)))
                    {
                        VerticalTileMatch.Add(boardGame.GetTileFormCoord(x, y));
                        VerticalTileMatch.Add(boardGame.GetTileFormCoord(x, y + 1));
                        VerticalTileMatch.Add(boardGame.GetTileFormCoord(x, y + 2));
                    }
                }
                if (horizontalCounter == 2)
                {
                    if (!HotizontalTileMatch.Contains(boardGame.GetTileFormCoord(x, y)))
                    {
                        HotizontalTileMatch.Add(boardGame.GetTileFormCoord(x, y));
                        HotizontalTileMatch.Add(boardGame.GetTileFormCoord(x + 1, y));
                        HotizontalTileMatch.Add(boardGame.GetTileFormCoord(x + 2, y));
                    }
                }
            }
        }



        //Debug.Log("List of Matched items:\n\n");
        foreach (var item in HotizontalTileMatch)
        {
            //Debug.Log("Color Tile: " + item.colorTileID + " x: " + item.PositionX + " y: " + item.PositionY);
            TileMatch.Add(item);
        }
        foreach (var item in VerticalTileMatch)
        {
            //Debug.Log("Color Tile: " + item.colorTileID + " x: " + item.PositionX + " y: " + item.PositionY);
            if (!TileMatch.Contains(item))
            {
                TileMatch.Add(item);
            }
        }

        return(TileMatch);
    }