示例#1
0
 private void addBlockToGameScene(int x, int y, int spriteIndex)
 {
     if (spriteIndex == -2)
     {
         // DEAD
         UnityEngine.Object.Destroy(GameObject.Find(x + "," + y));
         UtilsClass.CreateWorldSprite(x + "," + y, sprites[sprites.Length - 1], GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * .5f, new Vector3(1, 1, 1), 0, Color.white);
         return;
     }
     if (x >= 0 && y >= 0 && x < width && y < height)
     {
         if (spriteIndex >= 0)
         {
             UnityEngine.Object.Destroy(GameObject.Find(x + "," + y));
             UtilsClass.CreateWorldSprite(x + "," + y, sprites[spriteIndex], GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * .5f, new Vector3(1, 1, 1), 0, Color.white);
         }
         else
         {
             UnityEngine.Object.Destroy(GameObject.Find(x + "," + y));
         }
     }
     if (hasBomb(x, y))
     {
         UnityEngine.Object.Destroy(GameObject.Find(x + "," + y));
         UtilsClass.CreateWorldSprite(x + "," + y, sprites[0], GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * .5f, new Vector3(1, 1, 1), 0, Color.white);
     }
 }
示例#2
0
    //Constructor for Grid
    public Pattern(int width, int height, float cellSize, Vector3 originPosition, Sprite sprite, Color color)
    {
        this.width          = width;
        this.height         = height;
        this.cellSize       = cellSize;
        this.originPosition = originPosition;
        this.sprite         = sprite;
        this.color          = color;

        gridArray      = new int[width, height];
        flagGridArray  = new int[width, height];
        debugTextArray = new TextMesh[width, height];
        SpriteArray    = new GameObject[width, height];
        for (int x = 0; x < gridArray.GetLength(0); x++)
        {
            for (int y = 0; y < gridArray.GetLength(1); y++)
            {
                randomNumber = Random.Range(1, 9);
                countNumber[randomNumber] += 1;
                gridArray[x, y]            = randomNumber;

                debugTextArray[x, y] = UtilsClass.CreateWorldText(randomNumber.ToString(), null, GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * .5f, 20, Color.white, TextAnchor.MiddleCenter);

                Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x, y + 1), Color.white, 100f);
                Debug.DrawLine(GetWorldPosition(x, y), GetWorldPosition(x + 1, y), Color.white, 100f);
                SpriteArray[x, y] = UtilsClass.CreateWorldSprite(gridArray[x, y].ToString(), sprite, GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * .5f, new Vector3(20f, 20f), 0, Color.red);
            }
        }

        Debug.DrawLine(GetWorldPosition(0, height), GetWorldPosition(width, height), Color.white, 100f);
        Debug.DrawLine(GetWorldPosition(width, 0), GetWorldPosition(width, height), Color.white, 100f);
    }
    public MapTileGridObject(Grid <MapTileGridObject> grid, int x, int y, Transform parent)
    {
        this.x     = x;
        this.y     = y;
        this.grid  = grid;
        TypeOfCell = Type.Empty;
        tile       = UtilsClass.CreateWorldSprite(parent, ToString(), MinesWeeperGameHandler.spritesArray[MinesWeeperGameHandler.COVERED_INDEX], grid.GetWorldPosition(x, y) + new Vector3(grid.CellSize, grid.CellSize) * .5f, Vector3.one, 1, Color.white);
        tile.GetComponent <SpriteRenderer>().sprite = MinesWeeperGameHandler.spritesArray[MinesWeeperGameHandler.COVERED_INDEX];
        float newScale = grid.CellSize / 0.65f;

        tile.transform.localScale = new Vector3(newScale, newScale);
    }
示例#4
0
    public void SetValue(Vector3 worldPosition, Sprite sprite)
    {
        int x, y;

        GetXY(worldPosition, out x, out y);
        if (x >= 0 && y >= 0 && x < width && y < height)
        {
            flagGridArray[x, y]       = 1;
            debugTextArray[x, y].text = " ";
            switch (currentNumber)
            {
            case 1: numberColor = Color.cyan;
                break;

            case 2: numberColor = Color.yellow;
                break;

            case 3:
                numberColor = Color.blue;
                break;

            case 4:
                numberColor = Color.white;
                break;

            case 5:
                numberColor = Color.grey;
                break;

            case 6:
                numberColor = Color.green;
                break;

            case 7:
                numberColor = Color.white;
                break;

            case 8:
                numberColor = Color.magenta;
                break;
            }
            SpriteArray[x, y]           = UtilsClass.CreateWorldSprite(gridArray[x, y].ToString(), sprite, GetWorldPosition(x, y) + new Vector3(cellSize, cellSize) * .5f, new Vector3(20f, 20f), 0, numberColor);
            countNumber[currentNumber] -= 1;
            if (countNumber[currentNumber] == 0)
            {
                currentNumber += 1;
            }
        }
    }
示例#5
0
 //enables movement and shows player possible tiles they can move to.
 public void EnableMovement()
 {
     if (isSelected)
     {
         if (canMove == false)
         {
             originalPos = transform.position;
             UtilsClass.CreateWorldSprite(
                 "MovementArea",
                 movementAreaTile,                                                                     //sprite
                 new Vector3(transform.position.x, transform.position.y - 0.5f, transform.position.z), // pos
                 new Vector3((moveSpeed + 0.5f) * 2, ((moveSpeed) * 2) + 1, 0),                        // scale
                 1,                                                                                    //order
                 new Color(0, 0, 139, 0.3f)                                                            // color
                 );
             canMove = true;
         }
         //UtilsClass.CreateWorldSprite(string name, Sprite sprite, Vector3 position, Vector3 localPosition, Vector3 localScale, int sortingOrder, Color color)
     }
 }