Ejemplo n.º 1
0
    public SightInfo[,] GetPoliceSight()
    {
        if (policeSightRule == null)
        {
            policeSightRule =
                new SightRay(0, 0, new SightRay[]
            {
                new SightRay(1, 0, new SightRay[]
                {
                    new SightRay(0, -1, new SightRay[]
                    {
                        new SightRay(1, 0)
                    }),
                    new SightRay(1, 0, new SightRay[]
                    {
                        new SightRay(1, 0)
                    }),
                    new SightRay(0, 1, new SightRay[]
                    {
                        new SightRay(1, 0)
                    })
                })
            });
        }
        SightInfo[,] sightInfos = new SightInfo[mapSizeX, mapSizeY];
        for (int x = 0; x < mapSizeX; x++)
        {
            for (int y = 0; y < mapSizeY; y++)
            {
                sightInfos[x, y] = new SightInfo();
            }
        }

        for (int i = 0; i < polices.Length; i++)
        {
            Vector2Int policePos = new Vector2Int((int)polices[i].mapPos.x, (int)polices[i].mapPos.y);
            int        sin       = (int)Mathf.Sin((int)polices[i].angle * Mathf.Deg2Rad);
            int        cos       = (int)Mathf.Cos((int)polices[i].angle * Mathf.Deg2Rad);

            PoliceSightDFS(sightInfos, policePos, sin, cos, policeSightRule);
        }

        return(sightInfos);
    }
Ejemplo n.º 2
0
    private void PoliceSightDFS(SightInfo[,] infos, Vector2Int pos, int sin, int cos, SightRay ray)
    {
        Vector2Int nextPos = new Vector2Int(cos * ray.ray.x - sin * ray.ray.y + pos.x, sin * ray.ray.x + cos * ray.ray.y + pos.y);

        if (nextPos.x >= 0 && nextPos.x < mapSizeX &&
            nextPos.y >= 0 && nextPos.y < mapSizeY &&
            map[nextPos.x, nextPos.y] != TileType.Exit && map[nextPos.x, nextPos.y] != TileType.Wall)
        {
            int enemy = 0, treasure = 0;
            foreach (ThiefInfo thief in thieves)
            {
                if (thief != null && (int)thief.mapPos.x == nextPos.x && (int)thief.mapPos.y == nextPos.y)
                {
                    enemy++;
                    foreach (int value in thief.treasures)
                    {
                        treasure += value;
                    }
                }
            }
            if (treasures.TryGetValue(new Vector2(nextPos.x, nextPos.y), out TreasureInfo o))
            {
                treasure += o.value;
            }
            infos[nextPos.x, nextPos.y] = new SightInfo(true, enemy, treasure);

            foreach (SightRay child in ray.next)
            {
                PoliceSightDFS(infos, nextPos, sin, cos, child);
            }
        }
    }