示例#1
0
 public ActorJob(IEntity jobForEntity, ActorJobType type, ChunkTile tile, IEntity target)
 {
     this.type     = type;
     this.position = new Position(tile.worldX, tile.worldY);
     this.target   = target;
     m_jobOrigin   = jobForEntity;
 }
示例#2
0
 public void AddTileToDrawQueue(ChunkTile tileToAdd)
 {
     if (!m_tileDrawQueue.Contains(tileToAdd))
     {
         m_tileDrawQueue.Add(tileToAdd);
         AddChunkToDrawQueue();
     }
 }
示例#3
0
    public static Vector3 GamePosAtTile(ChunkTile tile)
    {
        Vector3 pos = new Vector3(0, 0, -0.1f);

        pos.x = (tile.worldX - Chunk.WIDTH / 2) + 0.5f;
        pos.y = (tile.worldY - Chunk.HEIGHT / 2) + 0.5f;

        return(pos);
    }
示例#4
0
    public void ChangeArea(ChunkTile startTile, ChunkTile endTile, ChunkTileSerialized newTile)
    {
        int width  = endTile.worldX - startTile.worldX;
        int height = endTile.worldY - startTile.worldY;

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                ChunkTile tile = m_completeMap[startTile.worldX + x, startTile.worldY + y];

                tile.chunk.ChangeBlockAt(tile.x, tile.y, newTile);
            }
        }
    }
示例#5
0
    private void Init()
    {
        grid             = new Node[WorldManager.worldWidth * Chunk.WIDTH, WorldManager.worldHeight *Chunk.HEIGHT];
        ChunkTile[,] map = ManagerInstance.Get <WorldManager>().completeMap;

        for (int x = 0; x < WorldManager.worldWidth * Chunk.WIDTH; x++)
        {
            for (int y = 0; y < WorldManager.worldHeight * Chunk.HEIGHT; y++)
            {
                ChunkTile tile = map[x, y];
                grid[x, y] = new Node(tile.tranversable, tile.worldX, tile.worldY);
            }
        }

        m_path  = new List <Node>();
        m_paths = new List <Path>();
    }
示例#6
0
    public Chunk(int chunkX, int chunkY)
    {
        m_tileDrawQueue = new List <ChunkTile>();

        m_x     = chunkX;
        m_y     = chunkY;
        m_tiles = new ChunkTile[WIDTH, HEIGHT];

        for (int x = 0; x < WIDTH; x++)
        {
            for (int y = 0; y < HEIGHT; y++)
            {
                m_tiles[x, y] = new ChunkTile(x, y, "grass", true, this);
                m_tiles[x, y].ChangeTo(ManagerInstance.Get <DatabaseManager>().dataBase.GetDataFor(m_tiles[x, y].identity));
            }
        }
    }
示例#7
0
    public List <Node> GetPath(ChunkTile startTile, ChunkTile targetTile)
    {
        Node startNode  = grid[startTile.worldX + 1, startTile.worldY + 1];
        Node targetNode = grid[targetTile.worldX, targetTile.worldY];

        for (int i = 0; i < m_paths.Count; i++)
        {
            if (m_paths[i].start.gridX - 1 == startNode.gridX)
            {
                if (m_paths[i].start.gridY - 1 == startNode.gridY)
                {
                    if (m_paths[i].finish.gridX == targetNode.gridX)
                    {
                        if (m_paths[i].finish.gridY == targetNode.gridY)
                        {
                            return(m_paths[i].path);
                        }
                    }
                }
            }
        }


        List <Node>    openSet   = new List <Node>();
        HashSet <Node> closedSet = new HashSet <Node>();

        openSet.Add(startNode);

        while (openSet.Count > 0)
        {
            Node currentNode = openSet[0];
            for (int i = 1; i < openSet.Count; i++)
            {
                if (openSet[i].fCost < currentNode.fCost || openSet[i].fCost == currentNode.fCost && openSet[i].hCost < currentNode.hCost)
                {
                    currentNode = openSet[i];
                }
            }

            openSet.Remove(currentNode);
            closedSet.Add(currentNode);

            if (currentNode == targetNode)
            {
                RetracePath(startNode, targetNode);
                Path path = new Path(m_path);
                if (path.path.Count > 0)
                {
                    m_paths.Add(path);
                }
                return(m_path);
            }

            foreach (Node neighbour in GetNeighbours(currentNode))
            {
                if (!neighbour.walkable || closedSet.Contains(neighbour))
                {
                    continue;
                }

                int newMovementCostToNeighbour = currentNode.gCost + GetDistance(currentNode, neighbour);
                if (newMovementCostToNeighbour < neighbour.gCost || !openSet.Contains(neighbour))
                {
                    neighbour.gCost  = newMovementCostToNeighbour;
                    neighbour.hCost  = GetDistance(neighbour, targetNode);
                    neighbour.parent = currentNode;

                    if (!openSet.Contains(neighbour))
                    {
                        openSet.Add(neighbour);
                    }
                }
            }
        }
        return(m_path);
    }
示例#8
0
    private void Update()
    {
        if (UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

        if (Input.GetMouseButtonUp(1))
        {
            m_mode = "none";
        }

        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, LayerMask.GetMask("Chunk") >> 1))
        {
            Vector3 mouseHit = hit.transform.InverseTransformPoint(hit.point);
            int     x        = (int)Mathf.Floor(Chunk.WIDTH * (mouseHit.x + 0.5f));
            int     y        = (int)Mathf.Floor(Chunk.HEIGHT * (mouseHit.y + 0.5f));

            selector.SetActive(true);
            selector.transform.position = new Vector3((hit.transform.position.x + x) - (8f - m_selectorScale / 2), (hit.transform.position.y + y) - (8f - m_selectorScale / 2), -1);

            Chunk chunk = hit.transform.GetComponent <ChunkObject>().chunkData;

            m_hoveredTile = ManagerInstance.Get <WorldManager>().completeMap[chunk.x * Chunk.WIDTH + x, chunk.y *Chunk.HEIGHT + y];

            if (Input.GetMouseButton(0))
            {
                if (m_mode == "build")
                {
                    if (m_selectorScale == 1)
                    {
                        chunk.ChangeBlockAt(x, y, TileSelectionPanel.i.selectedTile);
                    }
                    else
                    {
                        ChunkTile startTile = ManagerInstance.Get <WorldManager>().completeMap[chunk.x * Chunk.WIDTH + x, chunk.y *Chunk.HEIGHT + y];
                        ChunkTile endTile   = ManagerInstance.Get <WorldManager>().completeMap[(chunk.x * Chunk.WIDTH + x) + (int)m_selectorScale, (chunk.y * Chunk.HEIGHT + y) + (int)m_selectorScale];
                        ManagerInstance.Get <WorldManager>().ChangeArea(startTile, endTile, TileSelectionPanel.i.selectedTile);
                    }
                }
                else if (m_mode == "light")
                {
                    ChunkTile tile = chunk.tiles[x, y];
                    ManagerInstance.Get <FogOfWarManager>().DrawCircle(tile.worldX, tile.worldY, 35, 0f);
                }
                if (m_mode == "neighbor")
                {
                    chunk.tiles[x, y].LogDrawMap(chunk.tiles[x, y].drawMap.borderMap);
                }
            }
        }
        else
        {
            selector.SetActive(false);
        }
        if (m_mode == "spawn")
        {
            if (Input.GetMouseButtonUp(0))
            {
                CommandInput.Spawn(new string[] { "Actor", "try2", "" + m_hoveredTile.worldX, "" + m_hoveredTile.worldY });
            }
        }

        if (Input.GetKeyUp(KeyCode.UpArrow))
        {
            m_selectorScale += 1;
            selector.transform.localScale = new Vector2(m_selectorScale, m_selectorScale);
        }
        if (Input.GetKeyUp(KeyCode.DownArrow))
        {
            if (m_selectorScale > 1)
            {
                m_selectorScale -= 1;
            }

            selector.transform.localScale = new Vector2(m_selectorScale, m_selectorScale);
        }
    }
示例#9
0
        private static void InitializeTile(LD44Game game, Level level, int x, int y, ChunkTile tileType)
        {
            Tile tile = level.GetTile(x, y);

            switch (tileType)
            {
            case ChunkTile.Rock: {
                tile.FrontSprite.Texture = "rock";
                tile.TileType            = TileType.Solid;
                break;
            }

            case ChunkTile.Leaf: {
                tile.FrontSprite.Texture = "leaf";
                tile.TileType            = TileType.Solid;
                break;
            }

            case ChunkTile.Marble: {
                tile.FrontSprite.Texture = "marble";
                tile.TileType            = TileType.Solid;
                break;
            }

            case ChunkTile.Roof: {
                tile.FrontSprite.Texture = "roof";
                tile.TileType            = TileType.Solid;
                break;
            }

            case ChunkTile.HouseWall: {
                tile.FrontSprite.Texture = "house_wall";
                tile.TileType            = TileType.Solid;
                break;
            }

            case ChunkTile.HouseWindow: {
                tile.FrontSprite.Texture = "house_window";
                tile.TileType            = TileType.Solid;
                break;
            }

            case ChunkTile.RockWall: {
                tile.BackSprite.Texture = "rock_wall";
                break;
            }

            case ChunkTile.Sapling: {
                tile.BackSprite.Texture = "sapling";
                break;
            }

            case ChunkTile.Bat: {
                var bat = new BatMob {
                    Animation = new AnimationState <Sprite>(game.SpriteAnimations["bat_flying"], 0.5f)
                    {
                        IsLooping = true
                    }
                };
                bat.Body.Position = new Vector2(x, y) + new Vector2(0.5f);
                level.Mobs.Add(bat);
                break;
            }

            case ChunkTile.Player: {
                level.Entrance = new Vector2(x + 0.5f, y + 0.5f);
                break;
            }

            case ChunkTile.Door: {
                tile.BackSprite.Texture = "rock_wall";

                var door = new Interactable {
                    Position = new Vector2(x, y) + new Vector2(0.5f),
                    Region   = new RectangleF(0f, 0f, 1f, 1f),

                    InteractableType = InteractableType.Door,

                    Destination = game.TunnelTemplate
                };
                door.Sprite.Texture = "door";
                door.Sprite.Origin  = new Vector2(0.5f);
                level.Interactables.Add(door);
                break;
            }

            case ChunkTile.Greeter: {
                var talker = new Interactable {
                    Position = new Vector2(x, y) + new Vector2(0.5f),
                    Region   = new RectangleF(0f, 0f, 1f, 1f),

                    InteractableType = InteractableType.Message,

                    Message = "Hohohohoho, you dare enter the domain of Volgax uninvited? You fool!"
                };
                talker.Animation = new AnimationState <Sprite>(game.SpriteAnimations["trader_idle"], 0.5f)
                {
                    IsLooping = true
                };
                talker.Sprite.Texture = "trader";
                talker.Sprite.Origin  = new Vector2(0.5f);
                level.Interactables.Add(talker);
                break;
            }

            case ChunkTile.Spikes: {
                var spikes = new SpikesMob();
                spikes.Body.Ghost    = true;
                spikes.Body.Position = new Vector2(x, y + 6f / 16f) + new Vector2(0.5f);
                level.Mobs.Add(spikes);
                break;
            }

            case ChunkTile.Spot: {
                level.Spots.Add(new Point(x, y));
                break;
            }

            case ChunkTile.Monkey: {
                var monkey = new MonkeyMob(_random)
                {
                    Animation = new AnimationState <Sprite>(game.SpriteAnimations["monkey_idle"], 0.5f)
                    {
                        IsLooping = true
                    }
                };
                monkey.Body.Position = new Vector2(x, y) + new Vector2(0.5f);
                level.Mobs.Add(monkey);
                break;
            }

            case ChunkTile.EliteBat: {
                var bat = new EliteBatMob {
                    Animation = new AnimationState <Sprite>(game.SpriteAnimations["elite_bat_flying"], 0.5f)
                    {
                        IsLooping = true
                    }
                };
                bat.Body.Position = new Vector2(x, y) + new Vector2(0.5f);
                level.Mobs.Add(bat);
                break;
            }

            case ChunkTile.Gem: {
                var gem = new GemMob {
                    Animation = new AnimationState <Sprite>(game.SpriteAnimations["gem_idle"], 3f)
                    {
                        IsLooping = true
                    }
                };
                gem.Body.Position = new Vector2(x, y) + new Vector2(0.5f);
                level.Mobs.Add(gem);
                break;
            }

            case ChunkTile.Angel: {
                var angel = new Interactable {
                    Position = new Vector2(x, y) + new Vector2(0.5f),
                    Region   = new RectangleF(0f, 0f, 1f, 1f),

                    InteractableType = InteractableType.Blessing,

                    Message = "Please, accept my blessing."
                };
                angel.Animation = new AnimationState <Sprite>(game.SpriteAnimations["angel_idle"], 10f)
                {
                    IsLooping = true
                };
                angel.Sprite.Texture = "angel";
                angel.Sprite.Origin  = new Vector2(0.5f, 0.75f);
                level.Interactables.Add(angel);
                break;
            }

            case ChunkTile.Waterfall: {
                tile.FrontSprite.Texture = "waterfall";
                tile.FrontAnimation      = new AnimationState <Sprite>(game.SpriteAnimations["waterfall"], 0.1f)
                {
                    IsLooping = true
                };
                break;
            }

            case ChunkTile.Villager: {
                var villager = new VillagerMob {
                    Animation = new AnimationState <Sprite>(game.SpriteAnimations["villager_idle"], 0.5f)
                    {
                        IsLooping = true
                    }
                };
                villager.Body.Position = new Vector2(x, y) + new Vector2(0.5f);
                level.Mobs.Add(villager);
                break;
            }

            case ChunkTile.Entrance: {
                level.Entrances.Add(new Point(x, y));
                break;
            }

            case ChunkTile.Exit: {
                level.Exits.Add(new Point(x, y));
                break;
            }

            case ChunkTile.Valgox: {
                var valgox = new Interactable {
                    Position = new Vector2(x, y) + new Vector2(0.5f),
                    Region   = new RectangleF(0f, 0f, 1f, 1f),

                    InteractableType = InteractableType.Valgox,

                    Message = "Oi, you! Get off my tower right now or I'll smite you!"
                };
                valgox.Animation = new AnimationState <Sprite>(game.SpriteAnimations["valgox_idle"], 0.5f)
                {
                    IsLooping = true
                };
                valgox.Sprite.Texture = "valgox";
                valgox.Sprite.Origin  = new Vector2(0.5f, 0.85f);
                level.Interactables.Add(valgox);
                break;
            }

            case ChunkTile.Curse: {
                var curse = new CurseMob();
                curse.Body.Position = new Vector2(x, y) + new Vector2(0.5f);
                level.Mobs.Add(curse);
                break;
            }
            }
        }
    private Color[] TileTexture(int x, int y)
    {
        ChunkTile tile = ManagerInstance.Get <WorldManager>().completeMap[x, y];

        if (x >= 0 && x < WorldManager.worldWidth * Chunk.WIDTH && y >= 0 && y < WorldManager.worldHeight * Chunk.HEIGHT)
        {
            //check for cached version
            for (int i = 0; i < m_textureCache.Count; i++)
            {
                if (m_textureCache[i].tileIdentity == tile.identity)
                {
                    bool foundCached = true;
                    for (int bX = 0; bX < 3; bX++)
                    {
                        for (int bY = 0; bY < 3; bY++)
                        {
                            if (m_textureCache[i].borderMap[bX, bY].border != tile.drawMap.borderMap[bX, bY].border)
                            {
                                foundCached = false;
                            }
                            if (m_textureCache[i].borderMap[bX, bY].type != tile.drawMap.borderMap[bX, bY].type)
                            {
                                foundCached = false;
                            }
                        }
                    }
                    if (foundCached)
                    {
                        return(m_textureCache[i].texture);
                    }
                }
            }


            Color[] pix = new Color[TILE_RESOLUTION * TILE_RESOLUTION];

            for (int i = 0; i < pix.Length; i++)
            {
                pix[i] = ManagerInstance.Get <DatabaseManager>().dataBase.GetDefaultTexture(tile.identity)[i] * Random.Range(1.05f, 1.2f);
            }

            if (x - 1 >= 0)
            {
                if (tile.drawMap.borderMap[0, 1].border)
                {
                    //draw shadowMap
                    if (tile.drawMap.borderMap[0, 1].type == BorderType.Shadow)
                    {
                        for (int i = 0; i < pix.Length; i++)
                        {
                            if (i % TILE_RESOLUTION == 0)
                            {
                                pix[i] *= Random.Range(0.35f, 0.45f);
                            }
                            if ((i - 1) % TILE_RESOLUTION == 0)
                            {
                                pix[i] *= Random.Range(0.45f, 0.55f);
                            }
                            if ((i - 2) % TILE_RESOLUTION == 0)
                            {
                                pix[i] *= Random.Range(0.55f, 0.65f);
                            }
                            if ((i - 3) % TILE_RESOLUTION == 0)
                            {
                                pix[i] *= Random.Range(0.65f, 0.75f);
                            }
                            if ((i - 4) % TILE_RESOLUTION == 0)
                            {
                                pix[i] *= Random.Range(0.75f, 0.85f);
                            }
                        }
                    }
                    else if (tile.drawMap.borderMap[0, 1].type == BorderType.Merge)
                    {
                        Color[] neightborTex = ManagerInstance.Get <DatabaseManager>().dataBase.GetGraphicsFor(ManagerInstance.Get <WorldManager>().completeMap[x - 1, y].identity).texture;

                        for (int i = 0; i < pix.Length; i++)
                        {
                            Gradient gradient = new Gradient();

                            GradientColorKey[] gck = new GradientColorKey[2];
                            gck[0].color = pix[i];
                            gck[0].time  = 0.0f;
                            gck[1].color = neightborTex[i];
                            gck[1].time  = 1.0f;

                            // Populate the alpha  keys at relative time 0 and 1  (0 and 100%)
                            GradientAlphaKey[] gak = new GradientAlphaKey[2];
                            gak[0].alpha = 1.0f;
                            gak[0].time  = 0.0f;
                            gak[1].alpha = 1f;
                            gak[1].time  = 1.0f;

                            gradient.SetKeys(gck, gak);

                            if (i % TILE_RESOLUTION == 0)
                            {
                                pix[i] = gradient.Evaluate(0.8f);
                            }
                            if ((i - 1) % TILE_RESOLUTION == 0)
                            {
                                pix[i] = gradient.Evaluate(0.775f);
                            }
                            if ((i - 2) % TILE_RESOLUTION == 0)
                            {
                                pix[i] = gradient.Evaluate(0.65f);
                            }
                            if ((i - 3) % TILE_RESOLUTION == 0)
                            {
                                pix[i] = gradient.Evaluate(0.525f);
                            }
                            if ((i - 4) % TILE_RESOLUTION == 0)
                            {
                                pix[i] = gradient.Evaluate(0.4f);
                            }
                            if ((i - 5) % TILE_RESOLUTION == 0)
                            {
                                pix[i] = gradient.Evaluate(0.375f);
                            }
                            if ((i - 6) % TILE_RESOLUTION == 0)
                            {
                                pix[i] = gradient.Evaluate(0.25f);
                            }
                            if ((i - 7) % TILE_RESOLUTION == 0)
                            {
                                pix[i] = gradient.Evaluate(0.125f);
                            }
                            if ((i - 8) % TILE_RESOLUTION == 0)
                            {
                                pix[i] = gradient.Evaluate(0f);
                            }
                        }
                    }
                }
            }
            if (y + 1 < WorldManager.worldHeight * Chunk.HEIGHT)
            {
                if (tile.drawMap.borderMap[1, 2].border)
                {
                    if (tile.drawMap.borderMap[1, 2].type == BorderType.Shadow)
                    {
                        for (int i = 0; i < pix.Length; i++)
                        {
                            if (i > pix.Length - (TILE_RESOLUTION + 1))
                            {
                                pix[i] *= Random.Range(0.35f, 0.45f);
                            }
                            if (i > pix.Length - (TILE_RESOLUTION + 1) * 2 && i < pix.Length - (TILE_RESOLUTION + 1))
                            {
                                pix[i] *= Random.Range(0.45f, 0.55f);
                            }
                            if (i > pix.Length - (TILE_RESOLUTION + 1) * 3 && i < pix.Length - (TILE_RESOLUTION + 1) * 2)
                            {
                                pix[i] *= Random.Range(0.55f, 0.65f);
                            }
                            if (i > pix.Length - (TILE_RESOLUTION + 1) * 4 && i < pix.Length - (TILE_RESOLUTION + 1) * 3)
                            {
                                pix[i] *= Random.Range(0.65f, 0.75f);
                            }
                            if (i > pix.Length - (TILE_RESOLUTION + 1) * 5 && i < pix.Length - (TILE_RESOLUTION + 1) * 4)
                            {
                                pix[i] *= Random.Range(0.75f, 0.85f);
                            }
                        }
                    }
                    else if (tile.drawMap.borderMap[1, 2].type == BorderType.Merge)
                    {
                        Color[] neightborTex = ManagerInstance.Get <DatabaseManager>().dataBase.GetGraphicsFor(ManagerInstance.Get <WorldManager>().completeMap[x, y + 1].identity).texture;

                        for (int i = 0; i < pix.Length; i++)
                        {
                            Gradient gradient = new Gradient();

                            GradientColorKey[] gck = new GradientColorKey[2];
                            gck[0].color = pix[i];
                            gck[0].time  = 0.0f;
                            gck[1].color = neightborTex[i];
                            gck[1].time  = 1.0f;

                            // Populate the alpha  keys at relative time 0 and 1  (0 and 100%)
                            GradientAlphaKey[] gak = new GradientAlphaKey[2];
                            gak[0].alpha = 1.0f;
                            gak[0].time  = 0.0f;
                            gak[1].alpha = 1f;
                            gak[1].time  = 1.0f;

                            gradient.SetKeys(gck, gak);

                            if (i > pix.Length - (TILE_RESOLUTION + 1))
                            {
                                pix[i] = gradient.Evaluate(0.8f);
                            }
                            if (i > pix.Length - (TILE_RESOLUTION + 1) * 2 && i < pix.Length - (TILE_RESOLUTION + 1))
                            {
                                pix[i] = gradient.Evaluate(0.775f);
                            }
                            if (i > pix.Length - (TILE_RESOLUTION + 1) * 3 && i < pix.Length - (TILE_RESOLUTION + 1) * 2)
                            {
                                pix[i] = gradient.Evaluate(0.65f);
                            }
                            if (i > pix.Length - (TILE_RESOLUTION + 1) * 4 && i < pix.Length - (TILE_RESOLUTION + 1) * 3)
                            {
                                pix[i] = gradient.Evaluate(0.525f);
                            }
                            if (i > pix.Length - (TILE_RESOLUTION + 1) * 5 && i < pix.Length - (TILE_RESOLUTION + 1) * 4)
                            {
                                pix[i] = gradient.Evaluate(0.4f);
                            }
                            if (i > pix.Length - (TILE_RESOLUTION + 1) * 6 && i < pix.Length - (TILE_RESOLUTION + 1) * 5)
                            {
                                pix[i] = gradient.Evaluate(0.375f);
                            }
                            if (i > pix.Length - (TILE_RESOLUTION + 1) * 7 && i < pix.Length - (TILE_RESOLUTION + 1) * 6)
                            {
                                pix[i] = gradient.Evaluate(0.25f);
                            }
                            if (i > pix.Length - (TILE_RESOLUTION + 1) * 8 && i < pix.Length - (TILE_RESOLUTION + 1) * 7)
                            {
                                pix[i] = gradient.Evaluate(0.125f);
                            }
                            if (i > pix.Length - (TILE_RESOLUTION + 1) * 9 && i < pix.Length - (TILE_RESOLUTION + 1) * 8)
                            {
                                pix[i] = gradient.Evaluate(0f);
                            }
                        }
                    }
                }
            }
            if (x + 1 < WorldManager.worldWidth * Chunk.WIDTH)
            {
                if (tile.drawMap.borderMap[2, 1].border)
                {
                    if (tile.drawMap.borderMap[2, 1].type == BorderType.Shadow)
                    {
                        for (int i = 0; i < pix.Length; i++)
                        {
                            if ((i + 1) % TILE_RESOLUTION == 0)
                            {
                                pix[i] *= Random.Range(0.35f, 0.45f);
                            }
                            if ((i + 2) % TILE_RESOLUTION == 0)
                            {
                                pix[i] *= Random.Range(0.45f, 0.55f);
                            }
                            if ((i + 3) % TILE_RESOLUTION == 0)
                            {
                                pix[i] *= Random.Range(0.55f, 0.65f);
                            }
                            if ((i + 4) % TILE_RESOLUTION == 0)
                            {
                                pix[i] *= Random.Range(0.65f, 0.75f);
                            }
                            if ((i + 5) % TILE_RESOLUTION == 0)
                            {
                                pix[i] *= Random.Range(0.75f, 0.85f);
                            }
                        }
                    }
                    else if (tile.drawMap.borderMap[2, 1].type == BorderType.Merge)
                    {
                        Color[] neightborTex = ManagerInstance.Get <DatabaseManager>().dataBase.GetGraphicsFor(ManagerInstance.Get <WorldManager>().completeMap[x + 1, y].identity).texture;

                        for (int i = 0; i < pix.Length; i++)
                        {
                            Gradient gradient = new Gradient();

                            GradientColorKey[] gck = new GradientColorKey[2];
                            gck[0].color = pix[i];
                            gck[0].time  = 0.0f;
                            gck[1].color = neightborTex[i];
                            gck[1].time  = 1.0f;

                            // Populate the alpha  keys at relative time 0 and 1  (0 and 100%)
                            GradientAlphaKey[] gak = new GradientAlphaKey[2];
                            gak[0].alpha = 1.0f;
                            gak[0].time  = 0.0f;
                            gak[1].alpha = 1f;
                            gak[1].time  = 1.0f;

                            gradient.SetKeys(gck, gak);

                            if ((i + 1) % TILE_RESOLUTION == 0)
                            {
                                pix[i] = gradient.Evaluate(0.8f);
                            }
                            if ((i + 2) % TILE_RESOLUTION == 0)
                            {
                                pix[i] = gradient.Evaluate(0.775f);
                            }
                            if ((i + 3) % TILE_RESOLUTION == 0)
                            {
                                pix[i] = gradient.Evaluate(0.65f);
                            }
                            if ((i + 4) % TILE_RESOLUTION == 0)
                            {
                                pix[i] = gradient.Evaluate(0.525f);
                            }
                            if ((i + 5) % TILE_RESOLUTION == 0)
                            {
                                pix[i] = gradient.Evaluate(0.4f);
                            }
                            if ((i + 6) % TILE_RESOLUTION == 0)
                            {
                                pix[i] = gradient.Evaluate(0.375f);
                            }
                            if ((i + 7) % TILE_RESOLUTION == 0)
                            {
                                pix[i] = gradient.Evaluate(0.25f);
                            }
                            if ((i + 8) % TILE_RESOLUTION == 0)
                            {
                                pix[i] = gradient.Evaluate(0.125f);
                            }
                            if ((i + 9) % TILE_RESOLUTION == 0)
                            {
                                pix[i] = gradient.Evaluate(0f);
                            }
                        }
                    }
                }
            }
            if (y - 1 >= 0)
            {
                if (tile.drawMap.borderMap[1, 0].border)
                {
                    if (tile.drawMap.borderMap[1, 0].type == BorderType.Shadow)
                    {
                        for (int i = 0; i < pix.Length; i++)
                        {
                            //TODO Fix 1 pixelline shade
                            if (i < TILE_RESOLUTION)
                            {
                                pix[i] *= Random.Range(0.35f, 0.45f);
                            }
                            if (i < TILE_RESOLUTION * 2 && i > TILE_RESOLUTION)
                            {
                                pix[i] *= Random.Range(0.45f, 0.55f);
                            }
                            if (i < TILE_RESOLUTION * 3 && i > TILE_RESOLUTION * 2)
                            {
                                pix[i] *= Random.Range(0.55f, 0.65f);
                            }
                            if (i < TILE_RESOLUTION * 4 && i > TILE_RESOLUTION * 3)
                            {
                                pix[i] *= Random.Range(0.65f, 0.75f);
                            }
                            if (i < TILE_RESOLUTION * 5 && i > TILE_RESOLUTION * 4)
                            {
                                pix[i] *= Random.Range(0.75f, 0.85f);
                            }
                        }
                    }
                    else if (tile.drawMap.borderMap[1, 0].type == BorderType.Merge)
                    {
                        Color[] neightborTex = ManagerInstance.Get <DatabaseManager>().dataBase.GetGraphicsFor(ManagerInstance.Get <WorldManager>().completeMap[x, y - 1].identity).texture;

                        for (int i = 0; i < pix.Length; i++)
                        {
                            Gradient gradient = new Gradient();

                            GradientColorKey[] gck = new GradientColorKey[2];
                            gck[0].color = pix[i];
                            gck[0].time  = 0.0f;
                            gck[1].color = neightborTex[i];
                            gck[1].time  = 1.0f;

                            // Populate the alpha  keys at relative time 0 and 1  (0 and 100%)
                            GradientAlphaKey[] gak = new GradientAlphaKey[2];
                            gak[0].alpha = 1.0f;
                            gak[0].time  = 0.0f;
                            gak[1].alpha = 1f;
                            gak[1].time  = 1.0f;

                            gradient.SetKeys(gck, gak);

                            if (i < TILE_RESOLUTION)
                            {
                                pix[i] = gradient.Evaluate(0.8f);
                            }
                            if (i < TILE_RESOLUTION * 2 && i > TILE_RESOLUTION)
                            {
                                pix[i] = gradient.Evaluate(0.775f);
                            }
                            if (i < TILE_RESOLUTION * 3 && i > TILE_RESOLUTION * 2)
                            {
                                pix[i] = gradient.Evaluate(0.65f);
                            }
                            if (i < TILE_RESOLUTION * 4 && i > TILE_RESOLUTION * 3)
                            {
                                pix[i] = gradient.Evaluate(0.525f);
                            }
                            if (i < TILE_RESOLUTION * 5 && i > TILE_RESOLUTION * 4)
                            {
                                pix[i] = gradient.Evaluate(0.4f);
                            }
                            if (i < TILE_RESOLUTION * 6 && i > TILE_RESOLUTION * 5)
                            {
                                pix[i] = gradient.Evaluate(0.375f);
                            }
                            if (i < TILE_RESOLUTION * 7 && i > TILE_RESOLUTION * 6)
                            {
                                pix[i] = gradient.Evaluate(0.25f);
                            }
                            if (i < TILE_RESOLUTION * 8 && i > TILE_RESOLUTION * 7)
                            {
                                pix[i] = gradient.Evaluate(0.125f);
                            }
                            if (i < TILE_RESOLUTION * 9 && i > TILE_RESOLUTION * 8)
                            {
                                pix[i] = gradient.Evaluate(0f);
                            }
                        }
                    }
                }
            }

            tile.drawMap.Redraw();

            //cache the new texture
            ChunkTileCachedTexture textureCache = new ChunkTileCachedTexture(tile.identity, tile.drawMap.borderMap, pix);
            m_textureCache.Add(textureCache);

            return(pix);
        }
        return(DebugTexture(tile.identity));
    }
示例#11
0
    public void SetLightAt(ChunkTile tile, float range)
    {
        Light light = (GameObject.Instantiate(m_lightPrefab, WorldManager.GamePosAtTile(tile), Quaternion.identity) as GameObject).GetComponent <Light>();

        light.range = range;
    }