Exemplo n.º 1
0
        public void setCapPos(int x, int y)
        {
            TileState state = boardState[x, y];

            state.captureFully();
            tileManager.drawTileCapture(state);
            capturedPositions.Add(new Vector2Int(x, y));
        }
Exemplo n.º 2
0
        public void initModifiers(Vector2Int winningPos)
        {
            TileState state = boardState[winningPos.x, winningPos.y];

            state.isFinalTile  = true;
            state.modifierTile = tileManager.levelWinningTile;
            endPositions.Add(state);
        }
Exemplo n.º 3
0
 private void addTileStateSafe(List <TileState> listToAdd, int xPos, int yPos)
 {
     if (xPos >= 0 && xPos < boardDimensions.x && yPos >= 0 && yPos < boardDimensions.y)
     {
         TileState tileState = boardState[xPos, yPos];
         if (tileState != null)
         {
             listToAdd.Add(tileState);
         }
     }
 }
Exemplo n.º 4
0
 private void initBoardRectangle(Vector2Int botLeft, Vector2Int topRight)
 {
     boardDimensions = new Vector2Int(topRight.x, topRight.y);
     boardState      = new TileState[boardDimensions.x, boardDimensions.y];
     for (int x = botLeft.x; x < topRight.x; x++)
     {
         for (int y = botLeft.y; y < topRight.y; y++)
         {
             boardState[x, y] = new TileState(tileManager.getRandomTile(), x, y);
         }
     }
 }
Exemplo n.º 5
0
 private void initSquareBoardRandomly(int size)
 {
     Debug.Log("Init square board randomly jack " + size);
     boardDimensions = new Vector2Int(size, size);
     boardState      = new TileState[boardDimensions.x, boardDimensions.y];
     for (int x = 0; x < boardDimensions.x; x++)
     {
         for (int y = 0; y < boardDimensions.y; y++)
         {
             boardState[x, y] = new TileState(tileManager.getRandomTile(), x, y);
         }
     }
 }
Exemplo n.º 6
0
 private void initLineBoardRandomly(int width, int height)
 {
     Debug.Log("Init line board");
     boardDimensions = new Vector2Int(width, height);
     boardState      = new TileState[boardDimensions.x, boardDimensions.y];
     for (int x = 0; x < boardDimensions.x; x++)
     {
         for (int y = 0; y < boardDimensions.y; y++)
         {
             boardState[x, y] = new TileState(tileManager.getRandomTile(), x, y);
         }
     }
 }
Exemplo n.º 7
0
        //Update is called every frame.
        void Update()
        {
            if (levelInit.isInitializing())
            {
                return;
            }

            if (boardState.isLevelClear())
            {
                levelSelector.loadLevelSelect();
            }
            gameCounter++;
            if (gameCounter % 100 == 0)
            {
                //DrawTopColors();
                //Debug.Log(string.Format("gameCounter {0}", gameCounter));
            }
            if (!Input.GetKey("left ctrl") && !Input.GetMouseButton(1))
            {
                lastMousePos = null;
            }
            if (Input.GetKey("left ctrl") || Input.GetMouseButton(1))
            {
                //Debug.Log(string.Format("Co-ords of right click is [X: {0} Y: {1}]", pointClicked.x, pointClicked.y));
                if (lastMousePos.HasValue)
                {
                    Vector2 posDiff = mainCam.ScreenToWorldPoint(lastMousePos.Value) - mainCam.ScreenToWorldPoint(Input.mousePosition);
                    moveMainCam(posDiff);
                    //Debug.Log(string.Format("PosDiff {0} ", posDiff));
                }
                //Debug.Log(string.Format("Co-ords of right click is [X: {0} Y: {1}]", pointClicked.x, pointClicked.y));
                lastMousePos = Input.mousePosition;
            }
            else if (Input.GetMouseButtonDown(0))
            {
                Vector3   pointClicked = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                TileState tileState    = boardState.getTileState(pointClicked);
                if (tileState != null)
                {
                    Color       color         = tileState.getGameTile().getTileColor();
                    TileCapture bestTileMatch = boardState.processBombDrop(pointClicked, acm.getCurColor());
                    bombManager.addBomb(pointClicked, bestTileMatch, acm.getCurColor());
                    //Debug.Log(string.Format("Co-ords of mouse is [X: {0} Y: {1}] {2}", pointClicked.x, pointClicked.y, color.ToString()));
                }
            }
        }
Exemplo n.º 8
0
        public void drawTileCapture(TileState state) // int x, int y, float capPct)
        {
            float numTiles  = partialCapTiles.Length;
            float pctSlices = 1f / numTiles;
            float capPct    = state.getCapPercent();
            int   x         = state.getTilePosition().x;
            int   y         = state.getTilePosition().y;

            if (capPct >= 1f)
            {
                capturedGrid.SetTile(new Vector3Int(x, y, 0), fullCapTile);
            }
            else
            {
                int tileNum = Mathf.FloorToInt(capPct / pctSlices);
                capturedGrid.SetTile(new Vector3Int(x, y, 0), partialCapTiles[tileNum]);
            }
        }
Exemplo n.º 9
0
 public void paintBoardState()
 {
     Debug.Log("Painting board state");
     // paint background tilemap
     for (int x = 0; x < boardDimensions.x; x++)
     {
         for (int y = 0; y < boardDimensions.y; y++)
         {
             TileState tileState = boardState[x, y];
             if (tileState != null)
             {
                 Tile tile = tileState.getGameTile().getTile();
                 tileManager.setBackgroundTile(tile, x, y);
                 if (tileState.modifierTile != null)
                 {
                     tileManager.setModifierTile(tileState.modifierTile, x, y);
                 }
             }
         }
     }
 }
Exemplo n.º 10
0
        public void createBomb(Vector3 initialPos, TileCapture tileCapture, Color color, TileManager tileManager)
        {
            this.initialPos  = initialPos;
            this.endTile     = tileCapture.tileState;
            this.startColor  = color;
            this.bombDamage  = tileCapture.capAmount;
            this.tileManager = tileManager;

            if (endTile != null)
            {
                this.endPos  = endTile.getTileMiddle();
                endDirection = new Vector2(endPos.Value.x - initialPos.x, endPos.Value.y - initialPos.y);
            }
            else
            {
                startColor.a = BAD_TILE_ALPHA;
            }

            setLr(backgroundRenderer, new Color(90, 90, 90, BAD_TILE_ALPHA), 9, .25f);
            setLr(colorRenderer, startColor, 10, .2f);

            colorRenderer.transform.position      = initialPos;
            backgroundRenderer.transform.position = initialPos;
        }
Exemplo n.º 11
0
        public TileCapture processBombDrop(Vector3 pos, Color color)
        {
            float     highestDamageValue = 0;
            TileState bestMatch          = null;

            int numCandidates            = 0;
            List <TileState> nearbyTiles = getNearbyTiles(pos);

            foreach (var state in nearbyTiles)
            {
                // if state is capped, or there's no captured tile adjacent
                bool hasCapAdj = hasCapAdjacent(state.getTilePosition());
                if (state.isCapped() || !hasCapAdj)
                {
                    continue;
                }
                numCandidates++;
                Vector2 tileMiddle    = state.getTileMiddle();
                Color   tileColor     = state.getGameTile().getTileColor();
                float   distanceScore = getDistanceScore(pos, tileMiddle);
                float   colorScore    = getColorScore(color, tileColor);


                //TODO: make this better
                float curDamageValue = (distanceScore + colorScore) / 2f;

                Debug.Log(string.Format("Candidate lowest dist [{0}] colorMatch [{1}] ", distanceScore, colorScore));
                if (curDamageValue > highestDamageValue && curDamageValue > MIN_DAMAGE_THRESHOLD)
                {
                    highestDamageValue = curDamageValue;
                    bestMatch          = state;
                }
            }
            //Debug.Log(string.Format("Best dmg val {0}, NumCandidates {1}/{2}", highestDamageValue, numCandidates, nearbyTiles.Count));
            return(new TileCapture(bestMatch, highestDamageValue));
        }
Exemplo n.º 12
0
 public TileCapture(TileState tileState, float capAmount)
 {
     this.tileState = tileState;
     this.capAmount = capAmount;
 }