示例#1
0
        IEnumerator MoveToEnemy(GameObject target)
        {
            var         time            = 0f;
            var         targetComponent = target.GetComponent <Enemy>();
            Coordinates step;

            do
            {
                var start = Spawn.pCache.p;
                var goal  = targetComponent.p;
                var path  = AstarAlgorithm.GetPath(start, goal, empty, seek: false);
                if (Stop(path[0]))
                {
                    var obstacles = ObstacleSetter.GetObstacles(start, target: target);
                    path = AstarAlgorithm.GetPath(start, goal, obstacles, seek: false);
                    if (Stop(path[0]))
                    {
                        break;
                    }
                }
                step = path.Pop();

                StartCoroutine(Steping(Spawn.player, Spawn.pCache.p, step));
                _Synchronize(Spawn.player, Spawn.pCache, Spawn.pCache.p, step);
                Updater.update = true;
                _Wait();
                time = CalculateTime();
                StartCoroutine(ActEnemies());
                yield return(new WaitForSecondsRealtime(time));
            } while (!Reach(step, target));
            playerTurn = true;
        }
示例#2
0
        void Update()
        {
            if (update)
            {
                var p = Spawn.pCache.p;
                if (Dungeon.map[p.X, p.Y] == (int)Tile.hPath)
                {
                    Dungeon.map[p.X, p.Y] = (int)Tile.path;
                    if (Dungeon.map[p.X + 1, p.Y] == (int)Tile.hPath)
                    {
                        Dungeon.map[p.X + 1, p.Y] = (int)Tile.path;
                    }
                    if (Dungeon.map[p.X - 1, p.Y] == (int)Tile.hPath)
                    {
                        Dungeon.map[p.X - 1, p.Y] = (int)Tile.path;
                    }
                    if (Dungeon.map[p.X, p.Y + 1] == (int)Tile.hPath)
                    {
                        Dungeon.map[p.X, p.Y + 1] = (int)Tile.path;
                    }
                    if (Dungeon.map[p.X, p.Y - 1] == (int)Tile.hPath)
                    {
                        Dungeon.map[p.X, p.Y - 1] = (int)Tile.path;
                    }
                }
                var sight = ObstacleSetter.Sight(p);
                Dungeon._UpdateSight(sight);
                Dungeon._Illuminate();

                if (Spawn.items.ContainsKey(p))
                {
                    string[] itemName = Spawn.items[p][0].name.Split('/');
                    UI.dropWindowSprite.color = (Spawn.items[p].Count == 1) ? skeleton : Color.red;
                    UI.dropImageSprite.sprite = MasterData.itemSprites[int.Parse(itemName[0])][int.Parse(itemName[1])];
                    UI.dropImageSprite.color  = Color.white;
                }
                else
                {
                    UI.dropWindowSprite.color = skeleton;
                    var clear = new Color(1.0f, 1.0f, 1.0f, 0);
                    UI.dropImageSprite.color = clear;
                }

                update = false;
            }
        }
示例#3
0
        IEnumerator Walk(Coordinates start, Coordinates goal)
        {
            var obstacles = ObstacleSetter.GetObstacles(start, target: null);
            var path      = AstarAlgorithm.GetPath(start, goal, obstacles, seek: false);
            var time      = 0f;

            for (int n = 0; n < path.Count; n++)
            {
                //移動中止のチェック
                if (n > 0 && Stop(path[n]))
                {
                    break;
                }

                StartCoroutine(Steping(Spawn.player, Spawn.pCache.p, path[n]));
                _Synchronize(Spawn.player, Spawn.pCache, Spawn.pCache.p, path[n]);
                Updater.update = true;
                _Wait();
                time = CalculateTime();
                StartCoroutine(ActEnemies());
                yield return(new WaitForSecondsRealtime(time));
            }
            playerTurn = true;
        }