コード例 #1
0
 bool IsUnitOnTile(UnitDetails unit, TileDetails tile)
 {
     if (tile != null)
     {
         return(unit.CurrentGridX == tile.GridPos.x && unit.CurrentGridY == tile.GridPos.y);
     }
     return(false);
 }
コード例 #2
0
    protected void AddAdjacent(Node centre)
    {
        if (centre.Cost < unitDetails.MoveRange && !closedTiles.Exists(t => t.Position == centre.Position))
        {
            var newPos = new Vector2(centre.Position.x, centre.Position.y - 1);
            var tile   = MapDetails.GetTileDetails((int)newPos.x, (int)newPos.y);
            if (tile == null)
            {
                tile = new TileDetails(-1000, -1000, false);
            }
            var impassable = (!tile.Passable || MapUtils.FindUnitOnTile((int)newPos.x, (int)newPos.y));
            if (!closedTiles.Exists(t => t.Position == newPos) && !impassable)
            {
                openTiles.Add(new Node(newPos, centre, centre.Cost + 1));
            }

            newPos = new Vector2(centre.Position.x, centre.Position.y + 1);
            tile   = MapDetails.GetTileDetails((int)newPos.x, (int)newPos.y);
            if (tile == null)
            {
                tile = new TileDetails(-1000, -1000, false);
            }
            impassable = (!tile.Passable || MapUtils.FindUnitOnTile((int)newPos.x, (int)newPos.y));
            if (!closedTiles.Exists(t => t.Position == newPos) && !impassable)
            {
                openTiles.Add(new Node(newPos, centre, centre.Cost + 1));
            }

            newPos = new Vector2(centre.Position.x + 1, centre.Position.y);
            tile   = MapDetails.GetTileDetails((int)newPos.x, (int)newPos.y);
            if (tile == null)
            {
                tile = new TileDetails(-1000, -1000, false);
            }
            impassable = (!tile.Passable || MapUtils.FindUnitOnTile((int)newPos.x, (int)newPos.y));
            if (!closedTiles.Exists(t => t.Position == newPos) && !impassable)
            {
                openTiles.Add(new Node(newPos, centre, centre.Cost + 1));
            }

            newPos = new Vector2(centre.Position.x - 1, centre.Position.y);
            tile   = MapDetails.GetTileDetails((int)newPos.x, (int)newPos.y);
            if (tile == null)
            {
                tile = new TileDetails(-1000, -1000, false);
            }
            impassable = (!tile.Passable || MapUtils.FindUnitOnTile((int)newPos.x, (int)newPos.y));
            if (!closedTiles.Exists(t => t.Position == newPos) && !impassable)
            {
                openTiles.Add(new Node(newPos, centre, centre.Cost + 1));
            }
        }
        closedTiles.Add(centre);
        openTiles.Remove(centre);
    }
コード例 #3
0
 public override IEnumerator Tick()
 {
     if (existingMoveTiles.Exists(t => MoveCursor.Instance.transform.position == t.position))
     {
         currentCursorTile = MoveCursor.Instance.CurrentTile;
         if (lastCursorTile != currentCursorTile)
         {
             ClearTiles(existingPathTiles);
             pathToTarget.Clear();
         }
         FindPathToTarget(new Vector2(unitDetails.CurrentGridX, unitDetails.CurrentGridY), new Vector2(MoveCursor.Instance.CurrentGridX, MoveCursor.Instance.CurrentGridY));
     }
     return(base.Tick());
 }
コード例 #4
0
 private void Update()
 {
     if (GameManager.IsPaused)
     {
         return;
     }
     currentTile = MoveCursor.Instance.CurrentTile;
     info        = "";
     if (currentTile != null)
     {
         info = "Name: " + currentTile.TileName;
     }
     InfoText.text = info;
 }
コード例 #5
0
ファイル: MoveCursor.cs プロジェクト: jwflannery/tactics
    // Update is called once per frame
    void Update()
    {
        if (GameManager.IsPaused)
        {
            return;
        }

        CheckMouseControl();
        if (IsMouseControlling)
        {
            CurrentGridX = MapUtils.GetMouseGridX();
            CurrentGridY = MapUtils.GetMouseGridY();
            CurrentTile  = MapDetails.GetTileDetails(CurrentGridX, CurrentGridY);
            if (CurrentTile != null)
            {
                transform.position = MapUtils.GetGridWorldPos(MapUtils.GetMouseGridX(), MapUtils.GetMouseGridY());
            }
        }
        else
        {
            if (InputManager.ActiveDevice.DPadLeft.WasPressed)
            {
                CurrentGridX = CurrentGridX - 1;
            }
            if (InputManager.ActiveDevice.DPadRight.WasPressed)
            {
                CurrentGridX = CurrentGridX + 1;
            }
            if (InputManager.ActiveDevice.DPadUp.WasPressed)
            {
                CurrentGridY = CurrentGridY + 1;
            }
            if (InputManager.ActiveDevice.DPadDown.WasPressed)
            {
                CurrentGridY = CurrentGridY - 1;
            }
            transform.position = MapUtils.GetGridWorldPos(CurrentGridX, CurrentGridY);
        }

        CurrentTile = MapDetails.GetTileDetails(CurrentGridX, CurrentGridY);
        if (CurrentTile != null)
        {
            //transform.position = TilemapUtils.GetGridWorldPos(GroundTilemap, TilemapUtils.GetMouseGridX(GroundTilemap, Camera.main), TilemapUtils.GetMouseGridY(GroundTilemap, Camera.main));
        }
        CurrentLocation = transform.position;
    }
コード例 #6
0
ファイル: MapGenerator.cs プロジェクト: thegreatpl/GGJ16
    public override void OnStartServer()
    {
        if (!isServer)
        {
            return;
        }
        int seed = UnityEngine.Random.seed;

        rand = new System.Random(seed);

        //splits all the objects into something I can search with.
        DualStore <TileDetails, GameObject> gameObjects = new DualStore <TileDetails, GameObject>();

        foreach (GameObject obj in TileTypes)
        {
            TileDetails details = obj.GetComponent <TileDetails>();
            gameObjects.Add(details, obj);
        }


        gameObjects = GetTileset(gameObjects);

        Dictionary <TileSetType, TileLevel> tilesByTileSetType = new Dictionary <TileSetType, TileLevel>();

        foreach (TileSetType type in Enum.GetValues(typeof(TileSetType)))
        {
            TileLevel level = new TileLevel(seed);
            DualStore <TileDetails, GameObject> tileSetTiles = GetTileSetType(gameObjects, type);

            foreach (TileType ttype in Enum.GetValues(typeof(TileType)))
            {
                level.AssignTiles(ttype, GetTileTypes(tileSetTiles, ttype));
            }

            tilesByTileSetType.Add(type, level);
        }


        SpawnTiles(tilesByTileSetType);
    }
コード例 #7
0
    // Create board
    // public void CreateBoard(int _row, int _column, Vector2 _startPosition, Vector2 _offset, GameObject _tile, List<name> _names, Dictionary<name, Sprite> _spriteDict, Data _data)
    // {
    //     spriteDict = _spriteDict;
    //     row = _row;
    //     column = _column;
    //     startPosition = _startPosition;
    //     offset = _offset;
    //     tiles = new TileController[row, column];
    //     tile = _tile;
    //     names = _names;
    //     BoardData[] boardData = data.items.levels[0].boards;

    //     // tile = Resources.Load()
    //     for (int y = 0; y < column; y++)
    //     {
    //         for (int x = 0; x < row; x++)
    //         {
    //             GameObject newTile = Instantiate(tile, new Vector3(startPosition.x + (offset.x * x), startPosition.y - (offset.y * y), 0), tile.transform.rotation);
    //             tiles[x, y] = newTile.GetComponent<TileController>();
    //             newTile.name = "[ " + x + " , " + y + " ]";
    //             tiles[x, y].transform.parent = transform;

    //             List<name> listname = new List<name>();
    //             listname.AddRange(names);

    //             if (x > 0)
    //                     listname.Remove(tiles[x - 1, y].name);
    //             if (y > 0)
    //                     listname.Remove(tiles[x, y - 1].name);

    //             name name = listname[UnityEngine.Random.Range(0, listname.Count)];
    //             // Debug.LogFormat("x = {0}, y = {1}, tilesNames count = {2}", x, y , listname.Count);
    //             tiles[x, y].name = name;
    //             newTile.name = name.ToString();
    //             tiles[x, y].SpriteRenderer.sprite = spriteDict[name];
    //         }
    //     }
    // }

    // Create board by level
    // public void CreateBoardByLevelInfo(int _row, int _column, Vector2 _startPosition, Vector2 _offset, GameObject _tile, List<name> _names, Dictionary<name, Sprite> _spriteDict, Dictionary<int, name> intnameDict, int[] intTileArrays, Data _data)
    // {
    //     data = _data;
    //     spriteDict = _spriteDict;
    //     row = _row;
    //     column = _column;
    //     startPosition = _startPosition;
    //     offset = _offset;
    //     tiles = new TileController[row, column];
    //     tile = _tile;
    //     names = _names;
    //     intTileDict = intnameDict;
    //     intTileArray = intTileArrays;

    //     for (int y = 0; y < column; y++)
    //     {
    //         for (int x = 0; x < row; x++)
    //         {
    //             GameObject newTile = Instantiate(tile, new Vector3(startPosition.x + (offset.x * x), startPosition.y - (offset.y * y), 0), tile.transform.rotation);
    //             tiles[x, y] = newTile.GetComponent<TileController>();

    //             // string spriteId = BillboardAsset.Find ( e => e.x == x && e.y == y ).id;
    //             // string spriteName = objects.Find ( e => e.id == spriteId).spriteName;
    //             // SpriteRenderer sprite = Resources.Load<SpriteRenderer>()
    //             // tile[x,y].spriterRedner = sprite;
    //             // tile[x,y].score = object.score;

    //             //newTile.name = "[ " + x + " , " + y + " ]";

    //             // Ba vì có con bò vàng


    //             int soNguyenDaiDienChoTileTrongTuDien = intTileArray[x + y * row];
    //             name name = intTileDict[soNguyenDaiDienChoTileTrongTuDien];

    //             tiles[x, y].name = name;
    //             // Get the sprite through index
    //             tiles[x, y].SpriteRenderer.sprite = Resources.Load<Sprite>("Character/" + (int)name); //spriteDict[name];
    //             newTile.name = soNguyenDaiDienChoTileTrongTuDien.ToString();
    //             //name theTile = intTileDict[]

    //         }
    //     }
    // }

    public void CreateBoardWithIndexAndString(int _row, int _column, Vector2 _startPosition, Vector2 _offset, GameObject _tile, Data _data, TilePointData _tilePointData)
    {
        // spriteDict = _spriteDict;
        row           = _row;
        column        = _column;
        startPosition = _startPosition;
        offset        = _offset;
        tiles         = new TileController[row, column];
        tile          = _tile;
        // names = _names;
        // intTileDict = intnameDict;
        //intTileArray = intTileArrays;
        data          = _data;
        tilePointData = _tilePointData;

        for (int y = 0; y < column; y++)
        {
            for (int x = 0; x < row; x++)
            {
                int posX = data.items.levels[0].boards[x + y * row].x;
                int posY = data.items.levels[0].boards[x + y * row].y;
                // Debug.Log(data.items.levels[0].boards[x * 8 + y].x);

                GameObject newTile = Instantiate(tile, new Vector3(startPosition.x + (offset.x * posX), startPosition.y - (offset.y * posY), 0), tile.transform.rotation);
                tiles[x, y] = newTile.GetComponent <TileController>();
                // int soNguyenDaiDienChoTileTrongTuDien = ;
                string nameLoaded = data.items.levels[0].boards[x + y * row].tileId;
                tiles[x, y].name = nameLoaded;
                TileDetails tileData = tilePointData.items.tileProperties.Find(e => e.id == nameLoaded);
                // Debug.LogFormat("tileData: {0}", tileData.id);
                tiles[x, y].SpriteRenderer.sprite = Resources.Load <Sprite>(tileData.id);
                // Get the sprite through index
                newTile.name = tileData.spriteName;
            }
        }
    }
コード例 #8
0
    //void ResetColorAndFillBoard(List<TileController> tilesList, int value)
    //{
    //    if (value == 0)
    //    {
    //        foreach (var tile in tilesList)
    //        {
    //            tile.gameObject.SetActive(false);
    //            tile.SpriteRenderer.color = new Color (1, 1, 1, 1);
    //            OnScoreChanged();
    //        }
    //        firstTile = null;
    //        secondTile = null;
    //        boardControllerObject.OnBoardFilled(startPosition, offset, coroutineMap);
    //    }
    //}

    public IEnumerator AllTilesFadeOut(List <TileController> tiles)
    {
        for (int i = 10; i > 0; i--)
        {
            foreach (var tile in tiles)
            {
                tile.GetComponent <SpriteRenderer>().color = new Color(1, 1, 1, i * .1f);
            }
            yield return(new WaitForSeconds(.05f));
        }
        foreach (var tile in tiles)
        {
            tile.gameObject.SetActive(false);
            tile.SpriteRenderer.color = new Color(1, 1, 1, 1);
            string s    = tile.SpriteRenderer.sprite.name;
            int    temp = 0;

            TileDetails tileData = tilePointData.items.tileProperties.Find(x => x.id == s);
            temp = tileData.score;

            // for (int i = 0; i < tilePointData.items.tileProperties.Count; i++)
            // {
            //     if (s == tilePointData.items.tileProperties[i].id)
            //     {
            //         temp = tilePointData.items.tileProperties[i].score;
            //         break;
            //     }
            // }

            // Debug.LogFormat("string = {0}, int = {1}", s, temp);
            if (temp != 0)
            {
                OnScoreChanged(temp);
            }
        }
        firstTile  = null;
        secondTile = null;

        if (score >= scoreTarget)
        {
            if (level < 9)
            {
                Debug.LogFormat("LevelComplete");
                GenerateNewLevelBoard(level);
            }
            else
            {
                Debug.LogFormat("Victory");
            }
        }
        else
        {
            if (counter > 0)
            {
                boardControllerObject.OnBoardFilled(startPosition, offset, coroutineMap);
            }
            else
            if (score < scoreTarget)
            {
                gameOverUI.SetActive(true);
            }
        }
    }
コード例 #9
0
    // Fill board
    public void OnBoardFilled(Vector2 startPosition, Vector2 offsetPosition, Dictionary <TileController, Coroutine> coroutineMap)
    {
        for (int y = 0; y < column; y++)
        {
            for (int x = 0; x < row; x++)
            {
                if (tiles[x, y].SpriteRenderer.color != new Color(1, 1, 1, 1))
                {
                    tiles[x, y].SpriteRenderer.color = new Color(1, 1, 1, 1);
                }
            }
        }

        for (int x = 0; x < row; x++)
        {
            //Debug.LogFormat("Execute GetNewUpperTiles2");
            List <TileController> listTotal = new List <TileController>();
            List <TileController> nullList  = new List <TileController>();

            int nullCount = 0;
            for (int y = column - 1; y >= 0; y--)
            {
                if (tiles[x, y].gameObject.activeSelf)
                {
                    if (nullCount == 0)
                    {
                        continue;
                    }
                    else
                    {
                        listTotal.Add(tiles[x, y]);
                    }
                }
                else
                {
                    nullList.Add(tiles[x, y]);
                    nullCount++;
                }
            }
            for (int i = 0; i < nullList.Count; i++)
            {
                //nullList[i].SpriteRenderer.sprite = listSprite[Random.Range(0, listSprite.Count)];
                nullList[i].transform.position = new Vector2(nullList[i].transform.position.x, startPosition.y + (i + 1) * offsetPosition.y);

                // nullList[i].name = names[UnityEngine.Random.Range(0, names.Count)];

                // nullList[i].SpriteRenderer.sprite = spriteDict[nullList[i].name];

                string nameString = tilePointData.items.tileProperties[UnityEngine.Random.Range(0, tilePointData.items.tileProperties.Count)].id;
                // nullList[i].name = (name)Enum.Parse(typeof(name), nameString);
                TileDetails tileData = tilePointData.items.tileProperties.Find(e => e.id == nameString);
                nullList[i].name = tileData.spriteName;
                nullList[i].SpriteRenderer.sprite = (Resources.Load <Sprite>(nameString));
            }
            listTotal.AddRange(nullList);

            for (int i = 0; i < listTotal.Count; i++)
            {
                tiles[x, i] = listTotal[listTotal.Count - 1 - i];
                // tiles[x, i].name = "New [ " + x + ", " + i + " ]";
            }

            for (int i = 0; i < listTotal.Count; i++)
            {
                if (coroutineMap.ContainsKey(tiles[x, i]))
                {
                    StopCoroutine(coroutineMap[tiles[x, i]]);
                    coroutineMap.Remove(tiles[x, i]);
                }
                coroutineMap[tiles[x, i]] = StartCoroutine(MoveTilesDown(tiles[x, i], x, i, startPosition, offsetPosition, tiles));
            }
        }
    }