Exemplo n.º 1
0
    private void PlaceTile(string id, Vector3Int location)
    {
        if (tiles[id].Contains(location))
        {
            return;
        }
        Dictionary <string, Tile> loadedTiles;

        if (paletteTypes[id] == PaletteType.Semisolid)
        {
            loadedTiles = loadedTilesSemisolid;
        }
        if (paletteTypes[id] == PaletteType.Danger)
        {
            loadedTiles = loadedTilesOutline;
        }
        else
        {
            loadedTiles = loadedTilesFull;
        }
        tiles[id].Add(location);
        tilemaps[id].SetTile(location, loadedTiles[TilePicker.GetTile(tiles[id], totalBounds, tileVariations, tileUpdateRadiuses, location, id, tileNames)]);
        playCam.GetComponent <PlayCameraController>().UpdateBounds(CalculateBounds());
        UpdateSurroundingTiles(location, id);
    }
Exemplo n.º 2
0
        private void LinearFloodFill(ref int x, ref int y, ref TilePicker tp, ref Tile originTile)
        {
            int bitmapWidth  = _world.Header.WorldBounds.W;
            int bitmapHeight = _world.Header.WorldBounds.H;

            //FIND LEFT EDGE OF COLOR AREA
            int lFillLoc  = x; //the location to check/fill on the left
            int tileIndex = (bitmapWidth * y) + x;

            while (true)
            {
                if (HistMan.SaveHistory)
                {
                    HistMan.AddTileToBuffer(lFillLoc, y, ref _world.Tiles[x, y]);
                }
                _world.SetTileXY(ref lFillLoc, ref y, ref tp, ref _selection);
                tilesChecked[tileIndex] = true;

                lFillLoc--;
                tileIndex--;
                if (lFillLoc <= 0 || tilesChecked[tileIndex] || !CheckTileMatch(ref originTile, ref _world.Tiles[lFillLoc, y], ref tp) || !_selection.IsValid(new PointInt32(lFillLoc, y)))
                {
                    break;                               //exit loop if we're at edge of bitmap or color area
                }
            }
            lFillLoc++;
            if (lFillLoc < minX)
            {
                minX = lFillLoc;
            }
            //FIND RIGHT EDGE OF COLOR AREA
            int rFillLoc = x; //the location to check/fill on the left

            tileIndex = (bitmapWidth * y) + x;
            while (true)
            {
                if (HistMan.SaveHistory)
                {
                    HistMan.AddTileToBuffer(rFillLoc, y, ref _world.Tiles[x, y]);
                }
                _world.SetTileXY(ref rFillLoc, ref y, ref tp, ref _selection);
                tilesChecked[tileIndex] = true;

                rFillLoc++;
                tileIndex++;
                if (rFillLoc >= bitmapWidth || tilesChecked[tileIndex] || !CheckTileMatch(ref originTile, ref _world.Tiles[rFillLoc, y], ref tp) || !_selection.IsValid(new PointInt32(rFillLoc, y)))
                {
                    break;                               //exit loop if we're at edge of bitmap or color area
                }
            }
            rFillLoc--;
            if (rFillLoc > maxX)
            {
                maxX = rFillLoc;
            }

            FloodFillRange r = new FloodFillRange(lFillLoc, rFillLoc, y);

            ranges.Enqueue(ref r);
        }
Exemplo n.º 3
0
    public override void Execute()
    {
        parentMenu.gameObject.SetActive(false);
        Debug.Log("Move! - " + combatant);

        BattleOrder order = new BattleOrder();

        order.Action          = "move";
        order.SourceCombatant = combatant;

        MapManager map = GameObject.FindGameObjectWithTag("Map").GetComponent <MapManager>();
        //List<Tile> tiles = map.GetTilesInRange(combatant.Tile, combatant.Stats.Movement, false);
        List <Tile> tiles = map.GetTilesInRangeThreadsafe(combatant.Tile.TileData, combatant.Stats.Movement).ConvertAll(t => t.Tile);

        tiles = TileUtility.FilterOutOccupiedTiles(tiles);

        // TODO also maybe cache tilepicker results

        GameObject objToSpawn = new GameObject("Tile Picker - Move");

        objToSpawn.AddComponent <TilePicker>();
        TilePicker tilePicker = objToSpawn.GetComponent <TilePicker>();

        tilePicker.SetTileParamsMove(combatant);
        //tilePicker.SetTiles(tiles);
        tilePicker.battleStateTracker.previous = this.parentMenu.battleStateTracker;
        tilePicker.SetBattleOrder(order);

        parentMenu.CleanUp();
    }
Exemplo n.º 4
0
    public override void Execute()
    {
        parentMenu.gameObject.SetActive(false);
        Debug.Log("attack! - " + combatant);

        BattleOrder order = new BattleOrder();

        order.Action          = "attack";
        order.SourceCombatant = combatant;

        MapManager map = GameObject.FindGameObjectWithTag("Map").GetComponent <MapManager>();
        //List<Tile> tiles = map.GetTilesInRange(combatant.Tile, 1, true);
        List <Tile> tiles = map.GetTilesInRangeThreadsafe(combatant.Tile.TileData, 1, TeamId.MOVE_THROUGH_ALL)
                            .ConvertAll(t => t.Tile);

        tiles.Remove(combatant.Tile);

        GameObject objToSpawn = new GameObject("Tile Picker - Attack");

        objToSpawn.AddComponent <TilePicker>();
        TilePicker tilePicker = objToSpawn.GetComponent <TilePicker>();

        tilePicker.SetTiles(tiles);
        tilePicker.battleStateTracker.previous = this.parentMenu.battleStateTracker;
        tilePicker.SetBattleOrder(order);

        parentMenu.CleanUp();
    }
Exemplo n.º 5
0
        public void DrawRectangle(RectI area, ref TilePicker tile)
        {
            // Use refs for faster access (really important!) speeds up a lot!
            int w = _world.Header.WorldBounds.W;
            int h = _world.Header.WorldBounds.H;

            // Check boundaries
            area.Rebound(_world.Header.WorldBounds);

            // (needed for refs)
            int x1 = area.Left;
            int x2 = area.Right;
            int y1 = area.Top;
            int y2 = area.Bottom;

            // top and bottom horizontal scanlines
            for (int x = area.Left; x <= area.Right; x++)
            {
                UpdateTile(ref tile, ref x, ref y1, ref w);
                UpdateTile(ref tile, ref x, ref y2, ref w);
            }

            for (int y = area.Top; y <= area.Bottom; y++)
            {
                UpdateTile(ref tile, ref x1, ref y, ref w);
                UpdateTile(ref tile, ref x2, ref y, ref w);
            }
        }
Exemplo n.º 6
0
    private void DrawTiles()
    {
        Dictionary <string, Tile> loadedTiles;

        foreach (KeyValuePair <string, List <Vector3Int> > entry in tiles)
        {
            if (paletteTypes[entry.Key] == PaletteType.Semisolid)
            {
                loadedTiles = loadedTilesSemisolid;
            }
            else if (paletteTypes[entry.Key] == PaletteType.Danger)
            {
                loadedTiles = loadedTilesOutline;
            }
            else
            {
                loadedTiles = loadedTilesFull;
            }
            tilemaps[entry.Key].ClearAllTiles();
            foreach (Vector3Int location in entry.Value)
            {
                tilemaps[entry.Key].SetTile(location, loadedTiles[TilePicker.GetTile(tiles[entry.Key], totalBounds, tileVariations, tileUpdateRadiuses, location, entry.Key, tileNames)]);
            }
        }
    }
Exemplo n.º 7
0
    private void UpdateAllTiles()
    {
        Dictionary <string, Tile> loadedTiles;

        foreach (KeyValuePair <string, Tilemap> entry in tilemaps)
        {
            if (paletteTypes[entry.Key] == PaletteType.Semisolid)
            {
                loadedTiles = loadedTilesSemisolid;
            }
            else if (paletteTypes[entry.Key] == PaletteType.Danger)
            {
                loadedTiles = loadedTilesOutline;
            }
            else
            {
                loadedTiles = loadedTilesFull;
            }

            for (int x = totalBounds.xMin; x <= totalBounds.xMax; x++)
            {
                for (int y = totalBounds.yMin; y <= totalBounds.yMax; y++)
                {
                    if (tilemaps[entry.Key].GetTile <Tile>(new Vector3Int(x, y, 0)) != null &&
                        !(x == 0 && y == 0))
                    {
                        tilemaps[entry.Key].SetTile(new Vector3Int(x, y, 0),
                                                    loadedTiles[TilePicker.GetTile(tiles[entry.Key], totalBounds, tileVariations, tileUpdateRadiuses, new Vector3Int(x, y, 0), entry.Key, tileNames)]);
                    }
                }
            }
        }
    }
Exemplo n.º 8
0
    private void UpdateSurroundingTiles(Vector3Int location, string id)
    {
        Dictionary <string, Tile> loadedTiles;

        if (paletteTypes[id] == PaletteType.Semisolid)
        {
            loadedTiles = loadedTilesSemisolid;
        }
        else if (paletteTypes[id] == PaletteType.Danger)
        {
            loadedTiles = loadedTilesOutline;
        }
        else
        {
            loadedTiles = loadedTilesFull;
        }
        int updateRadius = Mathf.FloorToInt(tileUpdateRadiuses[id]);

        for (int x = -updateRadius; x <= updateRadius; x++)
        {
            for (int y = -updateRadius; y <= updateRadius; y++)
            {
                if (tilemaps[id].GetTile <Tile>(location + new Vector3Int(x, y, 0)) != null &&
                    !(x == 0 && y == 0))
                {
                    tilemaps[id].SetTile(location + new Vector3Int(x, y, 0),
                                         loadedTiles[TilePicker.GetTile(tiles[id], totalBounds, tileVariations, tileUpdateRadiuses, location + new Vector3Int(x, y, 0), id, tileNames)]);
                }
            }
        }
    }
Exemplo n.º 9
0
    private void Awake()
    {
        picker = gameObject.AddComponent <TilePicker>();

        for (int i = 0; i < Enum.GetNames(typeof(TileType)).Length; i++)
        {
            tiles.Add(Resources.Load <TileBase>($"tiles_{i}"));
        }
    }
Exemplo n.º 10
0
        /// <summary>
        /// A Fast Bresenham Type Algorithm For Drawing Ellipses http://homepage.smc.edu/kennedy_john/belipse.pdf
        /// x2 has to be greater than x1 and y2 has to be greater than y1.
        /// </summary>
        public void DrawEllipse(int x1, int y1, int x2, int y2, ref TilePicker tile)
        {
            // Calc center and radius
            int xr = (x2 - x1) >> 1;
            int yr = (y2 - y1) >> 1;
            int xc = x1 + xr;
            int yc = y1 + yr;

            DrawEllipseCentered(xc, yc, xr, yr, ref tile);
        }
Exemplo n.º 11
0
    public void SetCombatant(Combatant combatant)
    {
        this.combatant = combatant;
        sourceTile = combatant.Tile;
        MapManager map = GameObject.FindGameObjectWithTag("Map").GetComponent<MapManager>();
        List<Tile> tiles = map.GetTilesInRange(combatant.Tile, 3, false);
        tiles = TileUtility.FilterOutOccupiedTiles(tiles);

        GameObject objToSpawn;
        objToSpawn = new GameObject("Tile Picker");
        objToSpawn.AddComponent<TilePicker>();
        tilePicker = objToSpawn.GetComponent<TilePicker>();
        tilePicker.SetTiles(tiles);
    }
Exemplo n.º 12
0
    public void SetCombatant(Combatant combatant)
    {
        this.combatant = combatant;
        order.SourceCombatant = combatant;
        order.Action = "attack";
        MapManager map = GameObject.FindGameObjectWithTag("Map").GetComponent<MapManager>();
        List<Tile> tiles = map.GetTilesInRange(combatant.Tile, 1, true);
        tiles.Remove(combatant.Tile);

        GameObject objToSpawn;
        objToSpawn = new GameObject("Tile Picker");
        objToSpawn.AddComponent<TilePicker>();
        tilePicker = objToSpawn.GetComponent<TilePicker>();
        tilePicker.SetTiles(tiles);
    }
Exemplo n.º 13
0
        public void FillRectangle(RectI area, ref TilePicker tile)
        {
            // validate area
            int w = _world.Header.WorldBounds.W;

            area.Rebound(_world.Header.WorldBounds);

            for (int x = area.Left; x <= area.Right; x++)
            {
                for (int y = area.Top; y <= area.Bottom; y++)
                {
                    UpdateTile(ref tile, ref x, ref y, ref w);
                }
            }
        }
Exemplo n.º 14
0
    public void SetCombatant(Combatant combatant)
    {
        this.combatant        = combatant;
        order.SourceCombatant = combatant;
        order.Action          = "attack";
        MapManager  map   = GameObject.FindGameObjectWithTag("Map").GetComponent <MapManager>();
        List <Tile> tiles = map.GetTilesInRange(combatant.Tile, 1, true);

        tiles.Remove(combatant.Tile);

        GameObject objToSpawn;

        objToSpawn = new GameObject("Tile Picker");
        objToSpawn.AddComponent <TilePicker>();
        tilePicker = objToSpawn.GetComponent <TilePicker>();
        tilePicker.SetTiles(tiles);
    }
Exemplo n.º 15
0
    public void SetCombatant(Combatant combatant)
    {
        this.combatant = combatant;
        sourceTile     = combatant.Tile;
        MapManager  map   = GameObject.FindGameObjectWithTag("Map").GetComponent <MapManager>();
        List <Tile> tiles = map.GetTilesInRange(combatant.Tile, 3, false);

        tiles = TileUtility.FilterOutOccupiedTiles(tiles);


        GameObject objToSpawn;

        objToSpawn = new GameObject("Tile Picker");
        objToSpawn.AddComponent <TilePicker>();
        tilePicker = objToSpawn.GetComponent <TilePicker>();
        tilePicker.SetTiles(tiles);
    }
Exemplo n.º 16
0
        private static bool CheckTileMatch(ref Tile originTile, ref Tile nextTile, ref TilePicker tp)
        {
            if ((tp.Tile.IsActive) && (originTile.Type != nextTile.Type))
            {
                return(false);
            }
            if ((tp.Tile.IsActive) && (originTile.IsActive != nextTile.IsActive))
            {
                return(false);
            }

            if ((tp.Tile.IsActive) && (originTile.IsActive != nextTile.IsActive))
            {
                return(false);
            }

            if ((tp.Wall.IsActive) && (originTile.Wall != nextTile.Wall))
            {
                return(false);
            }

            if (tp.Liquid.IsActive)
            {
                if ((originTile.Liquid > 0) != (nextTile.Liquid > 0))
                {
                    return(false);
                }

                if (originTile.IsLava != nextTile.IsLava)
                {
                    return(false);
                }

                if (originTile.Type != nextTile.Type)
                {
                    return(false);
                }

                if (originTile.IsActive != nextTile.IsActive)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 17
0
        private void UpdateTile(ref TilePicker tile, ref int x, ref int y, ref int w)
        {
            if (!tilesChecked[x + y * w] || _properties.IsOutline)
            {
                // Save History

                if (HistMan.SaveHistory)
                {
                    HistMan.AddTileToBuffer(x, y, ref _world.Tiles[x, y]);
                }

                _world.SetTileXY(ref x, ref y, ref tile, ref _selection);
                tilesChecked[x + y * w] = true;
                if (!_properties.IsOutline)
                {
                    _renderer.UpdateWorldImage(new PointInt32(x, y));
                }
            }
        }
Exemplo n.º 18
0
    void LoadForms()
    {
        debugForm         = new DebugForm();
        debugForm.Visible = false;

        layerForm         = new LayerFormAdv();
        layerForm.Visible = false;

        textureForm         = new TextureForm();
        textureForm.Visible = false;

        meshDesigner         = new MeshDesigner();
        meshDesigner.Visible = false;

        outlinerForm         = new OutlinerForm();
        outlinerForm.Visible = false;

        tilePicker = meshDesigner.TilePicker;
    }
Exemplo n.º 19
0
        private void PlaceBrownChest(PointInt32 p)
        {
            // anchor at top-right of chest
            int x = p.X;
            int y = p.Y;

            // Validate free space
            if (!_world.Tiles[x, y].IsActive && !_world.Tiles[x + 1, y].IsActive && !_world.Tiles[x, y + 1].IsActive && !_world.Tiles[x + 1, y + 1].IsActive)
            {
                // Validate floor    WorldSettings.Tiles[].IsSolid
                if ((_world.Tiles[x, y + 2].IsActive && (WorldSettings.Tiles[_world.Tiles[x, y + 2].Type].IsSolid)) &&
                    (_world.Tiles[x + 1, y + 2].IsActive && (WorldSettings.Tiles[_world.Tiles[x + 1, y + 2].Type].IsSolid)))
                {
                    // Place Chest
                    var tp = new TilePicker();
                    SetTileSprite(new PointInt32(x, y), new PointShort(0, 0), 21);
                    SetTileSprite(new PointInt32(x, y + 1), new PointShort(0, 18), 21);
                    SetTileSprite(new PointInt32(x + 1, y), new PointShort(18, 0), 21);
                    SetTileSprite(new PointInt32(x + 1, y + 1), new PointShort(18, 18), 21);
                }
            }
        }
Exemplo n.º 20
0
        public void DrawRectangle(RectI area, ref TilePicker tile)
        {
            // Use refs for faster access (really important!) speeds up a lot!
            int w = _world.Header.WorldBounds.W;
            int h = _world.Header.WorldBounds.H;

            // Check boundaries
            area.Rebound(_world.Header.WorldBounds);

            // (needed for refs)
            int x1 = area.Left;
            int x2 = area.Right;
            int y1 = area.Top;
            int y2 = area.Bottom;

            // top and bottom horizontal scanlines
            for (int x = area.Left; x <= area.Right; x++) {
                UpdateTile(ref tile, ref x, ref y1, ref w);
                UpdateTile(ref tile, ref x, ref y2, ref w);
            }

            for (int y = area.Top; y <= area.Bottom; y++) {
                UpdateTile(ref tile, ref x1, ref y, ref w);
                UpdateTile(ref tile, ref x2, ref y, ref w);
            }
        }
Exemplo n.º 21
0
 public void DrawRectangle(int x1, int y1, int x2, int y2, ref TilePicker tile)
 {
     DrawRectangle(new RectI(x1, x2, y1, y2), ref tile);
 }
Exemplo n.º 22
0
        public void SetTileXY(ref int x, ref int y, ref TilePicker tile, ref SelectionArea selection)
        {
            if (selection.IsValid(new PointInt32(x, y)))
            {
                Tile curTile = this.Tiles[x, y];

                if (tile.Tile.IsActive)
                {
                    if (!tile.TileMask.IsActive || (curTile.Type == tile.TileMask.Value && curTile.IsActive))
                    {
                        if (tile.IsEraser)
                        {
                            curTile.IsActive = false;
                        }
                        else
                        {
                            //TODO: i don't like redundant conditionals, but its a fix
                            if (!tile.TileMask.IsActive)
                            {
                                curTile.IsActive = true;
                            }

                            curTile.Type = tile.Tile.Value;

                            // if the tile is solid and there isn't a mask, remove the liquid
                            if (!tile.TileMask.IsActive && WorldSettings.Tiles[curTile.Type].IsSolid && curTile.Liquid > 0)
                            {
                                curTile.Liquid = 0;
                            }
                        }
                    }
                }


                if (tile.Wall.IsActive)
                {
                    if (!tile.WallMask.IsActive || (curTile.Wall == tile.WallMask.Value))
                    {
                        if (tile.IsEraser)
                        {
                            curTile.Wall = 0;
                        }
                        else
                        {
                            curTile.Wall = tile.Wall.Value;
                        }
                    }
                }

                if (tile.Liquid.IsActive && (!curTile.IsActive || !WorldSettings.Tiles[curTile.Type].IsSolid))
                {
                    if (tile.IsEraser)
                    {
                        curTile.Liquid = 0;
                        curTile.IsLava = false;
                    }
                    else
                    {
                        curTile.Liquid = 255;
                        curTile.IsLava = tile.Liquid.IsLava;
                    }
                }
            }
        }
Exemplo n.º 23
0
        private void DrawLine(PointInt32 endPoint)
        {
            foreach (PointInt32 p in WorldRenderer.DrawLine(_startPoint, endPoint))
            {
                if (_selection.SelectionVisibility == Visibility.Visible)
                {
                    // if selection is active, and point is not inside, skip point
                    if (!_selection.Rectangle.Contains(p))
                    {
                        continue;
                    }
                }

                // center
                int x0 = p.X - _properties.Offset.X;
                int y0 = p.Y - _properties.Offset.Y;

                if (_properties.BrushShape == ToolBrushShape.Square)
                {
                    if (_properties.IsOutline)
                    {
                        TilePicker outline = Utility.DeepCopy(_tilePicker);
                        outline.Wall.IsActive = false;

                        // eraise a center section
                        TilePicker eraser = Utility.DeepCopy(_tilePicker);
                        eraser.IsEraser      = true;
                        eraser.Wall.IsActive = false; // don't erase the wall for the interrior

                        TilePicker wall = Utility.DeepCopy(_tilePicker);
                        wall.Tile.IsActive = false;



                        var interior = new Int32Rect(x0 + _properties.OutlineThickness,
                                                     y0 + _properties.OutlineThickness,
                                                     _properties.Width - (_properties.OutlineThickness * 2),
                                                     _properties.Height - (_properties.OutlineThickness * 2));

                        // Erase center
                        FillRectangle(interior, ref eraser);
                        // Fill center
                        if (wall.Wall.IsActive)
                        {
                            FillRectangle(interior, ref wall);
                        }
                        // Draw outline
                        if (outline.Tile.IsActive)
                        {
                            for (int i = 0; i < _properties.OutlineThickness; i++)
                            {
                                DrawRectangle(new Int32Rect(x0 + i, y0 + i, _properties.Width - (i * 2) - 1, _properties.Height - (i * 2) - 1), ref outline);
                            }
                        }
                    }
                    else
                    {
                        FillRectangle(new Int32Rect(x0, y0, _properties.Width, _properties.Height), ref _tilePicker);
                    }
                }
                else if (_properties.BrushShape == ToolBrushShape.Round)
                {
                    if (_properties.IsOutline)
                    {
                        TilePicker outline = Utility.DeepCopy(_tilePicker);
                        outline.Wall.IsActive = false;

                        // eraise a center section
                        TilePicker eraser = Utility.DeepCopy(_tilePicker);
                        eraser.IsEraser      = true;
                        eraser.Wall.IsActive = false; // don't erase the wall for the interrior

                        TilePicker wall = Utility.DeepCopy(_tilePicker);
                        wall.Tile.IsActive = false;


                        // Draw outline
                        if (outline.Tile.IsActive)
                        {
                            FillEllipse(x0, y0, x0 + _properties.Width, y0 + _properties.Height, ref outline);
                        }

                        // Erase center
                        FillEllipse(x0 + _properties.OutlineThickness,
                                    y0 + _properties.OutlineThickness,
                                    x0 + _properties.Width - _properties.OutlineThickness,
                                    y0 + _properties.Height - _properties.OutlineThickness, ref eraser);
                        // Fill center
                        if (wall.Wall.IsActive)
                        {
                            FillEllipse(x0 + _properties.OutlineThickness,
                                        y0 + _properties.OutlineThickness,
                                        x0 + _properties.Width - _properties.OutlineThickness,
                                        y0 + _properties.Height - _properties.OutlineThickness, ref wall);
                        }



                        eraser = null;
                    }
                    else
                    {
                        FillEllipse(x0, y0, x0 + _properties.Width, y0 + _properties.Height, ref _tilePicker);
                    }
                }
                if (_properties.IsOutline)
                {
                    _renderer.UpdateWorldImage(new Int32Rect(x0, y0, _properties.Width + 1, _properties.Height + 1));
                }
            }
        }
Exemplo n.º 24
0
        private static bool CheckTileMatch(ref Tile originTile, ref Tile nextTile, ref TilePicker tp)
        {
            if ((tp.Tile.IsActive) && (originTile.Type != nextTile.Type))
                return false;
            if ((tp.Tile.IsActive) && (originTile.IsActive != nextTile.IsActive))
                return false;

            if ((tp.Tile.IsActive) && (originTile.IsActive != nextTile.IsActive))
                return false;

            if ((tp.Wall.IsActive) && (originTile.Wall != nextTile.Wall))
                return false;

            if (tp.Liquid.IsActive)
            {
                if ((originTile.Liquid > 0) != (nextTile.Liquid > 0))
                    return false;

                if (originTile.IsLava != nextTile.IsLava)
                    return false;

                if (originTile.Type != nextTile.Type)
                    return false;

                if (originTile.IsActive != nextTile.IsActive)
                    return false;
            }

            return true;
        }
Exemplo n.º 25
0
        private void UpdateTile(ref TilePicker tile, ref int x, ref int y, ref int w)
        {
            if (!tilesChecked[x + y * w] || _properties.IsOutline)
            {
                // Save History

                if (HistMan.SaveHistory)
                    HistMan.AddTileToBuffer(x, y, ref _world.Tiles[x, y]);

                _world.SetTileXY(ref x, ref y, ref tile, ref _selection);
                tilesChecked[x + y * w] = true;
                if (!_properties.IsOutline)
                    _renderer.UpdateWorldImage(new PointInt32(x, y));
            }
        }
Exemplo n.º 26
0
        public void FillRectangle(RectI area, ref TilePicker tile)
        {
            // validate area
            int w = _world.Header.WorldBounds.W;
            area.Rebound(_world.Header.WorldBounds);

            for (int x = area.Left; x <= area.Right; x++) {
                for (int y = area.Top; y <= area.Bottom; y++) {
                    UpdateTile(ref tile, ref x, ref y, ref w);
                }
            }
        }
Exemplo n.º 27
0
        private void LinearFloodFill(ref int x, ref int y, ref TilePicker tp, ref Tile originTile)
        {
            int bitmapWidth = _world.Header.MaxTiles.X;
            int bitmapHeight = _world.Header.MaxTiles.Y;

            //FIND LEFT EDGE OF COLOR AREA
            int lFillLoc = x; //the location to check/fill on the left
            int tileIndex = (bitmapWidth * y) + x;
            while (true)
            {
                if (HistMan.SaveHistory)
                    HistMan.AddTileToBuffer(lFillLoc, y, ref _world.Tiles[x, y]);
                _world.SetTileXY(ref lFillLoc, ref y, ref tp, ref _selection);
                tilesChecked[tileIndex] = true;

                lFillLoc--;
                tileIndex--;
                if (lFillLoc <= 0 || tilesChecked[tileIndex] || !CheckTileMatch(ref originTile, ref _world.Tiles[lFillLoc, y], ref tp) || !_selection.IsValid(new PointInt32(lFillLoc, y)))
                    break;			 	 //exit loop if we're at edge of bitmap or color area

            }
            lFillLoc++;
            if (lFillLoc < minX)
                minX = lFillLoc;
            //FIND RIGHT EDGE OF COLOR AREA
            int rFillLoc = x; //the location to check/fill on the left
            tileIndex = (bitmapWidth * y) + x;
            while (true)
            {
                if (HistMan.SaveHistory)
                    HistMan.AddTileToBuffer(rFillLoc, y, ref _world.Tiles[x, y]);
                _world.SetTileXY(ref rFillLoc, ref y, ref tp, ref _selection);
                tilesChecked[tileIndex] = true;

                rFillLoc++;
                tileIndex++;
                if (rFillLoc >= bitmapWidth || tilesChecked[tileIndex] || !CheckTileMatch(ref originTile, ref _world.Tiles[rFillLoc, y], ref tp) || !_selection.IsValid(new PointInt32(rFillLoc, y)))
                    break;			 	 //exit loop if we're at edge of bitmap or color area

            }
            rFillLoc--;
            if (rFillLoc > maxX)
                maxX = rFillLoc;

            FloodFillRange r = new FloodFillRange(lFillLoc, rFillLoc, y);
            ranges.Enqueue(ref r);
        }
Exemplo n.º 28
0
        private void SetUpUI()
        {
            this.currentUI = null;
            if (this.mainMenu != null)
            {
                UserInterface.Active.RemoveEntity(this.mainMenu);
            }
            if (this.contextMenu != null)
            {
                UserInterface.Active.RemoveEntity(this.contextMenu);
            }
            this.mainMenu = new PanelTabs();
            this.mainMenu.SetAnchor(Anchor.Center);
            this.mainMenu.Size    = new Vector2(1400, 1000);
            this.mainMenu.Visible = false;

            // file menu
            var fileMenu    = (this.mainMenu as PanelTabs).AddTab("File", PanelSkin.Default);
            var newMapPanel = new Panel(new Vector2(800, 120), skin: PanelSkin.Simple, anchor: Anchor.AutoCenter);
            var newMapWidth = new TextInput(false, anchor: Anchor.CenterLeft, size: new Vector2(200, 100));

            newMapWidth.Value = $"{this.Context.Map.Width}";
            newMapPanel.AddChild(newMapWidth);
            var newMapHeight = new TextInput(false, anchor: Anchor.Center, size: new Vector2(200, 100));

            newMapHeight.Value = $"{this.Context.Map.Height}";
            newMapPanel.AddChild(newMapHeight);
            var newMapButton = new Button("New", anchor: Anchor.CenterRight, size: new Vector2(200, 100));

            newMapButton.OnClick += (e) =>
            {
                int width;
                int height;
                if (!int.TryParse(newMapWidth.Value, out width))
                {
                    return;
                }
                if (!int.TryParse(newMapHeight.Value, out height))
                {
                    return;
                }
                this.Context.Reset();
                this.Context.Map = new TileMap(width, height);
            };
            newMapPanel.AddChild(newMapButton);
            fileMenu.panel.AddChild(newMapPanel);

            var processButton = new Button("Process", anchor: Anchor.AutoCenter, size: new Vector2(400, 100));

            processButton.OnClick += (b) =>
            {
                var processor = new PFPTMapProcessor();
                processor.Process(this.Context.Map);
            };
            fileMenu.panel.AddChild(processButton);

            /*var saveBlockStoreButton = new Button("Save BlockStore", anchor: Anchor.AutoCenter, size: new Vector2(400, 100));
             * saveBlockStoreButton.OnClick += (b) =>
             * {
             *  this.SaveBlockStore();
             * };
             * fileMenu.panel.AddChild(saveBlockStoreButton);*/

            /*var saveContextButton = new Button("Save context", anchor: Anchor.AutoCenter, size: new Vector2(400, 100));
             * saveContextButton.OnClick += (b) =>
             * {
             *  BinPlatformContextSerializer.Save("default.ctx", this.Context);
             * };
             * fileMenu.panel.AddChild(saveContextButton);*/

            // 'save map' area
            var savePanel = new Panel(new Vector2(600, 100), skin: PanelSkin.Simple, anchor: Anchor.BottomLeft);

            var filenameInput = new TextInput(false, anchor: Anchor.CenterLeft, size: new Vector2(300, 0));

            filenameInput.Value = DefaultContext;
            savePanel.AddChild(filenameInput);

            var saveButton = new Button("Save", anchor: Anchor.CenterRight, size: new Vector2(200, 0));

            saveButton.OnClick += (b) =>
            {
                var filename = filenameInput.Value.Trim();
                if (string.IsNullOrEmpty(filename))
                {
                    return;
                }
                if (!filename.EndsWith(".ctx", StringComparison.InvariantCultureIgnoreCase))
                {
                    filename           += ".ctx";
                    filenameInput.Value = filename;
                }
                BinPlatformContextSerializer.Save(filenameInput.TextParagraph.Text, this.Context);
            };
            savePanel.AddChild(saveButton);
            fileMenu.panel.AddChild(savePanel);

            // quit button
            var quitButton = new Button("Quit", anchor: Anchor.BottomRight, size: new Vector2(400, 100));

            quitButton.OnClick += (b) =>
            {
                this.SceneEnded = true;
            };
            fileMenu.panel.AddChild(quitButton);

            // tiles menu
            var tilesMenu  = (this.mainMenu as PanelTabs).AddTab("Tiles", PanelSkin.Default);
            var tilePicker = new TilePicker(
                this.Context.BlockStore,
                this.Context.BlockStore.Tiles.Select((s, i) => new Tile(i)),
                anchor: Anchor.CenterLeft,
                size: new Vector2(1000, 0));

            tilesMenu.panel.AddChild(tilePicker);
            var tileSettingsPanel = new Panel(new Vector2(300, 0), skin: PanelSkin.Simple, anchor: Anchor.CenterRight);

            tilesMenu.panel.AddChild(tileSettingsPanel);
            tilePicker.OnItemClick += (e, tile) =>
            {
                var curr = new TileStencil();
                curr[0, 0] = tile;
                this.mode  = new TilePlacement(curr, this.lastLayer);
                tileSettingsPanel.ClearChildren();
                var asTile = tile as Tile;
                if (asTile != null)
                {
                    var flagsLabel = new Label("Flags:", anchor: Anchor.AutoInline);
                    tileSettingsPanel.AddChild(flagsLabel);
                    foreach (var flag in EnumHelper.GetValues <TileFlags>())
                    {
                        if (flag == TileFlags.None)
                        {
                            continue;
                        }
                        var checkBox = new CheckBox($"{flag}", anchor: Anchor.AutoCenter);
                        checkBox.Checked        = this.Context.BlockStore[asTile.Id].HasFlag(flag);
                        checkBox.OnValueChange += (entity) =>
                        {
                            var currState = this.Context.BlockStore[asTile.Id];
                            if (checkBox.Checked)
                            {
                                currState |= flag;
                            }
                            else
                            {
                                currState &= ~flag;
                            }
                            this.Context.BlockStore[asTile.Id] = currState;
                        };
                        tileSettingsPanel.AddChild(checkBox);
                    }
                }
            };
            tilePicker.Scrollbar.Max = (uint)(this.mainMenu.Size.Y * 4); // we have to guess at the maximum height...

            // stencil menu
            var stencilMenu   = (this.mainMenu as PanelTabs).AddTab("Stencils", PanelSkin.Default);
            var stencilPicker = new StencilPicker(this.Context.BlockStore, this.stencils);

            stencilPicker.OnStencilClick += (e, stencil) =>
            {
                this.mode = new TilePlacement(stencil, this.lastLayer);
            };
            stencilPicker.Scrollbar.Max = (uint)(this.mainMenu.Size.Y * 4); // we have to guess at the maximum height...
            stencilMenu.panel.AddChild(stencilPicker);

            // materials menu
            var materialsMenu = (this.mainMenu as PanelTabs).AddTab("Materials", PanelSkin.Default);
            var materialList  = new SelectList(new Vector2(400, 300), anchor: Anchor.TopLeft);
            var settingsPanel = new Panel(new Vector2(600, 0), anchor: Anchor.CenterRight, skin: PanelSkin.Simple);

            materialsMenu.panel.AddChild(settingsPanel);

            foreach (var material in EnumHelper.GetValues <MaterialType>())
            {
                if (material != MaterialType.None)
                {
                    materialList.AddItem($"{material}");
                }
            }
            materialList.OnValueChange += (e) =>
            {
                var material = (MaterialType)(materialList.SelectedIndex + 1);
                settingsPanel.ClearChildren();
                var materialTilePicker = new TilePicker(
                    this.Context.BlockStore,
                    this.Context.BlockStore.Materials[material].Select(id => new Tile(id)),
                    size: new Vector2(0, 700),
                    anchor: Anchor.AutoCenter);
                settingsPanel.AddChild(materialTilePicker);
                var deleteTile = new Button("Delete tile", anchor: Anchor.AutoCenter);
                deleteTile.OnClick += (entity) =>
                {
                    var asTile = materialTilePicker.SelectedItem as Tile;
                    if (asTile != null)
                    {
                        materialTilePicker.RemoveSelected();
                        this.Context.BlockStore.Materials[material].Remove(asTile.Id);
                    }
                };
                settingsPanel.AddChild(deleteTile);
                var addTile = new Button("Add tile", anchor: Anchor.AutoCenter);
                addTile.OnClick += (entity) =>
                {
                    var materialNewTilePicker = new TilePicker(
                        this.Context.BlockStore,
                        this.Context.BlockStore.Tiles.Select((s, i) => new Tile(i)),
                        size: new Vector2(1000, 900),
                        anchor: Anchor.TopCenter);
                    materialNewTilePicker.OnItemClick += (picker, tile) =>
                    {
                        var asTile = tile as Tile;
                        if (asTile != null)
                        {
                            this.Context.BlockStore.Materials[material].Add(asTile.Id);
                            materialTilePicker.AddItem(tile);
                        }
                        UserInterface.Active.RemoveEntity(materialNewTilePicker);
                    };
                    UserInterface.Active.AddEntity(materialNewTilePicker);
                };
                settingsPanel.AddChild(addTile);
            };
            materialsMenu.panel.AddChild(materialList);

            // lights menu
            var lightsMenu  = (this.mainMenu as PanelTabs).AddTab("Lights", PanelSkin.Default);
            var colourPanel = new Panel(new Vector2(0, 250), skin: PanelSkin.Simple, anchor: Anchor.AutoCenter);
            var redLabel    = new Label("Red", anchor: Anchor.AutoCenter);
            var redSlider   = new Slider(min: 0, max: 255, skin: SliderSkin.Default, anchor: Anchor.AutoCenter);

            redSlider.Value = 255;
            var greenLabel  = new Label("Green", anchor: Anchor.AutoCenter);
            var greenSlider = new Slider(min: 0, max: 255, skin: SliderSkin.Default, anchor: Anchor.AutoCenter);

            greenSlider.Value = 255;
            var blueLabel  = new Label("Blue", anchor: Anchor.AutoCenter);
            var blueSlider = new Slider(min: 0, max: 255, skin: SliderSkin.Default, anchor: Anchor.AutoCenter);

            blueSlider.Value = 255;
            colourPanel.AddChild(redLabel);
            colourPanel.AddChild(redSlider);
            colourPanel.AddChild(greenLabel);
            colourPanel.AddChild(greenSlider);
            colourPanel.AddChild(blueLabel);
            colourPanel.AddChild(blueSlider);
            lightsMenu.panel.AddChild(colourPanel);
            var animationPanel    = new Panel(new Vector2(0, 150), skin: PanelSkin.Simple, anchor: Anchor.AutoCenter);
            var animationLabel    = new Label("Animation", anchor: Anchor.AutoCenter);
            var animationDropdown = new DropDown(Vector2.Zero, anchor: Anchor.AutoCenter);

            animationDropdown.AddItem("None");
            animationDropdown.AddItem("Candle");
            animationDropdown.SelectedIndex = 0;
            animationPanel.AddChild(animationLabel);
            animationPanel.AddChild(animationDropdown);
            lightsMenu.panel.AddChild(animationPanel);
            var lightTypeDropdown = new DropDown(new Vector2(0, 100), anchor: Anchor.AutoCenter);

            lightTypeDropdown.AddItem("Ambient");
            lightTypeDropdown.AddItem("Specular");
            lightTypeDropdown.SelectedIndex = 0;
            lightsMenu.panel.AddChild(lightTypeDropdown);

            var updateButton = new Button("Set Light", anchor: Anchor.BottomCenter);

            updateButton.OnClick += (e) =>
            {
                var light = new Light();
                switch (animationDropdown.SelectedIndex)
                {
                case 0:
                    light.animation = null;
                    break;

                case 1:
                    light.animation = Light.Candle;
                    break;

                default:
                    light.animation = null;
                    break;
                }
                light.LightType = (Light.Type)lightTypeDropdown.SelectedIndex;
                light.Colour    = new Color(redSlider.Value, greenSlider.Value, blueSlider.Value);
                this.mode       = new LightPlacement(light);
            };
            lightsMenu.panel.AddChild(updateButton);

            // other placeable items
            var otherMenu      = (this.mainMenu as PanelTabs).AddTab("Other", PanelSkin.Default);
            var setSpawnButton = new Button("Set Spawn Locations", anchor: Anchor.AutoCenter);

            setSpawnButton.OnClick += (e) =>
            {
                this.mode = new SpawnPlacement(new Spawn());
            };
            otherMenu.panel.AddChild(setSpawnButton);

            UserInterface.Active.AddEntity(this.mainMenu);
        }
Exemplo n.º 29
0
        /// <summary>
        /// A Fast Bresenham Type Algorithm For Drawing Ellipses http://homepage.smc.edu/kennedy_john/belipse.pdf
        /// Uses a different parameter representation than DrawEllipse().
        /// </summary>
        /// <param name="bmp">The WriteableBitmap.</param>
        /// <param name="xc">The x-coordinate of the ellipses center.</param>
        /// <param name="yc">The y-coordinate of the ellipses center.</param>
        /// <param name="xr">The radius of the ellipse in x-direction.</param>
        /// <param name="yr">The radius of the ellipse in y-direction.</param>
        /// <param name="color">The color for the line.</param>
        public void DrawEllipseCentered(int xc, int yc, int xr, int yr, ref TilePicker tile)
        {
            // Use refs for faster access (really important!) speeds up a lot!
            int w = _world.Header.WorldBounds.W;
            int h = _world.Header.WorldBounds.H;

            // Init vars
            int uy, ly, lx, rx;
            int x         = xr;
            int y         = 0;
            int xrSqTwo   = (xr * xr) << 1;
            int yrSqTwo   = (yr * yr) << 1;
            int xChg      = yr * yr * (1 - (xr << 1));
            int yChg      = xr * xr;
            int err       = 0;
            int xStopping = yrSqTwo * xr;
            int yStopping = 0;

            // Draw first set of points counter clockwise where tangent line slope > -1.
            while (xStopping >= yStopping)
            {
                // Draw 4 quadrant points at once
                uy = yc + y; // Upper half
                ly = yc - y; // Lower half
                if (uy < 0)
                {
                    uy = 0;         // Clip
                }
                if (uy >= h)
                {
                    uy = h - 1;          // ...
                }
                if (ly < 0)
                {
                    ly = 0;
                }
                if (ly >= h)
                {
                    ly = h - 1;
                }
                rx = xc + x;
                lx = xc - x;
                if (rx < 0)
                {
                    rx = 0;         // Clip
                }
                if (rx >= w)
                {
                    rx = w - 1;          // ...
                }
                if (lx < 0)
                {
                    lx = 0;
                }
                if (lx >= w)
                {
                    lx = w - 1;
                }

                UpdateTile(ref tile, ref rx, ref uy, ref w);
                UpdateTile(ref tile, ref rx, ref ly, ref w);
                UpdateTile(ref tile, ref lx, ref uy, ref w);
                UpdateTile(ref tile, ref lx, ref ly, ref w);

                y++;
                yStopping += xrSqTwo;
                err       += yChg;
                yChg      += xrSqTwo;
                if ((xChg + (err << 1)) > 0)
                {
                    x--;
                    xStopping -= yrSqTwo;
                    err       += xChg;
                    xChg      += yrSqTwo;
                }
            }

            // ReInit vars
            x  = 0;
            y  = yr;
            uy = yc + y; // Upper half
            ly = yc - y; // Lower half
            if (uy < 0)
            {
                uy = 0;         // Clip
            }
            if (uy >= h)
            {
                uy = h - 1;          // ...
            }
            if (ly < 0)
            {
                ly = 0;
            }
            if (ly >= h)
            {
                ly = h - 1;
            }
            xChg      = yr * yr;
            yChg      = xr * xr * (1 - (yr << 1));
            err       = 0;
            xStopping = 0;
            yStopping = xrSqTwo * yr;

            // Draw second set of points clockwise where tangent line slope < -1.
            while (xStopping <= yStopping)
            {
                // Draw 4 quadrant points at once
                rx = xc + x;
                lx = xc - x;
                if (rx < 0)
                {
                    rx = 0;         // Clip
                }
                if (rx >= w)
                {
                    rx = w - 1;          // ...
                }
                if (lx < 0)
                {
                    lx = 0;
                }
                if (lx >= w)
                {
                    lx = w - 1;
                }
                UpdateTile(ref tile, ref rx, ref uy, ref w);
                UpdateTile(ref tile, ref rx, ref ly, ref w);
                UpdateTile(ref tile, ref lx, ref uy, ref w);
                UpdateTile(ref tile, ref lx, ref ly, ref w);

                x++;
                xStopping += yrSqTwo;
                err       += xChg;
                xChg      += yrSqTwo;
                if ((yChg + (err << 1)) > 0)
                {
                    y--;
                    uy = yc + y; // Upper half
                    ly = yc - y; // Lower half
                    if (uy < 0)
                    {
                        uy = 0;         // Clip
                    }
                    if (uy >= h)
                    {
                        uy = h - 1;          // ...
                    }
                    if (ly < 0)
                    {
                        ly = 0;
                    }
                    if (ly >= h)
                    {
                        ly = h - 1;
                    }
                    yStopping -= xrSqTwo;
                    err       += yChg;
                    yChg      += xrSqTwo;
                }
            }
        }
Exemplo n.º 30
0
 // Use this for initialization
 void Start()
 {
     picker = TilePickPanel.GetComponent <TilePicker>();
     grid   = GridPanel.GetComponent <GridControl>();
 }
Exemplo n.º 31
0
 public void DrawRectangle(int x1, int y1, int x2, int y2, ref TilePicker tile)
 {
     DrawRectangle(new RectI(x1, x2, y1, y2), ref tile);
 }
Exemplo n.º 32
0
        public void FillEllipse(int x1, int y1, int x2, int y2, ref TilePicker tile)
        {
            // Calc center and radius
            int xr = (x2 - x1) >> 1;
            int yr = (y2 - y1) >> 1;
            int xc = x1 + xr;
            int yc = y1 + yr;

            FillEllipseCentered(xc, yc, xr, yr, ref tile);
        }
Exemplo n.º 33
0
        public void FillEllipseCentered(int xc, int yc, int xr, int yr, ref TilePicker tile)
        {
            int w = _world.Header.WorldBounds.W;
            int h = _world.Header.WorldBounds.H;

            // Init vars
            int uy, ly, lx, rx;
            int x = xr;
            int y = 0;
            int xrSqTwo = (xr * xr) << 1;
            int yrSqTwo = (yr * yr) << 1;
            int xChg = yr * yr * (1 - (xr << 1));
            int yChg = xr * xr;
            int err = 0;
            int xStopping = yrSqTwo * xr;
            int yStopping = 0;

            // Draw first set of points counter clockwise where tangent line slope > -1.
            while (xStopping >= yStopping)
            {
                // Draw 4 quadrant points at once
                uy = yc + y; // Upper half
                ly = yc - y; // Lower half
                if (uy < 0) uy = 0; // Clip
                if (uy >= h) uy = h - 1; // ...
                if (ly < 0) ly = 0;
                if (ly >= h) ly = h - 1;

                rx = xc + x;
                lx = xc - x;
                if (rx < 0) rx = 0; // Clip
                if (rx >= w) rx = w - 1; // ...
                if (lx < 0) lx = 0;
                if (lx >= w) lx = w - 1;

                // Draw line
                for (int i = lx; i <= rx; i++)
                {
                    UpdateTile(ref tile, ref i, ref uy, ref w);
                    UpdateTile(ref tile, ref i, ref ly, ref w);
                }

                y++;
                yStopping += xrSqTwo;
                err += yChg;
                yChg += xrSqTwo;
                if ((xChg + (err << 1)) > 0)
                {
                    x--;
                    xStopping -= yrSqTwo;
                    err += xChg;
                    xChg += yrSqTwo;
                }
            }

            // ReInit vars
            x = 0;
            y = yr;
            uy = yc + y; // Upper half
            ly = yc - y; // Lower half
            if (uy < 0) uy = 0; // Clip
            if (uy >= h) uy = h - 1; // ...
            if (ly < 0) ly = 0;
            if (ly >= h) ly = h - 1;
            xChg = yr * yr;
            yChg = xr * xr * (1 - (yr << 1));
            err = 0;
            xStopping = 0;
            yStopping = xrSqTwo * yr;

            // Draw second set of points clockwise where tangent line slope < -1.
            while (xStopping <= yStopping)
            {
                // Draw 4 quadrant points at once
                rx = xc + x;
                lx = xc - x;
                if (rx < 0) rx = 0; // Clip
                if (rx >= w) rx = w - 1; // ...
                if (lx < 0) lx = 0;
                if (lx >= w) lx = w - 1;

                // Draw line
                for (int i = lx; i <= rx; i++)
                {
                    UpdateTile(ref tile, ref i, ref uy, ref w);
                    UpdateTile(ref tile, ref i, ref ly, ref w);
                }

                x++;
                xStopping += yrSqTwo;
                err += xChg;
                xChg += yrSqTwo;
                if ((yChg + (err << 1)) > 0)
                {
                    y--;
                    uy = yc + y; // Upper half
                    ly = yc - y; // Lower half
                    if (uy < 0) uy = 0; // Clip
                    if (uy >= h) uy = h - 1; // ...
                    if (ly < 0) ly = 0;
                    if (ly >= h) ly = h - 1;
                    yStopping -= xrSqTwo;
                    err += yChg;
                    yChg += xrSqTwo;
                }
            }
        }
Exemplo n.º 34
0
        private void PlaceBrownChest(PointInt32 p)
        {
            // anchor at top-right of chest
            int x = p.X;
            int y = p.Y;

            // Validate free space
            if (!_world.Tiles[x, y].IsActive && !_world.Tiles[x + 1, y].IsActive && !_world.Tiles[x, y + 1].IsActive && !_world.Tiles[x + 1, y + 1].IsActive)
            {
                // Validate floor    WorldSettings.Tiles[].IsSolid
                if ((_world.Tiles[x, y + 2].IsActive && (WorldSettings.Tiles[_world.Tiles[x, y + 2].Type].IsSolid)) &&
                    (_world.Tiles[x + 1, y + 2].IsActive && (WorldSettings.Tiles[_world.Tiles[x + 1, y + 2].Type].IsSolid)))
                {
                    // Place Chest
                    var tp = new TilePicker();
                    SetTileSprite(new PointInt32(x, y), new PointShort(0, 0), 21);
                    SetTileSprite(new PointInt32(x, y + 1), new PointShort(0, 18), 21);
                    SetTileSprite(new PointInt32(x + 1, y), new PointShort(18, 0), 21);
                    SetTileSprite(new PointInt32(x + 1, y + 1), new PointShort(18, 18), 21);
                }
            }
        }
Exemplo n.º 35
0
    private void LoadTiles()
    {
        Tile   tile;
        Sprite tileSprite;

        char[] splitter = { '/', '\\' };

        string[] fileArray;

        string[] splitFileName;
        string   fileName;

        for (int i = 0; i < tileTypes.Length; i++)
        {
            fileArray = Directory.GetFiles(Application.dataPath + "/Resources/Tiles/" + tileTypes[i], "*.png", SearchOption.AllDirectories);

            for (int j = 0; j < fileArray.Length; j++)
            {
                splitFileName = fileArray[j].Split(splitter);
                fileName      = splitFileName[splitFileName.Length - 1].Split('.')[0];
                tileSprite    = Resources.Load <Sprite>("Tiles/" + tileTypes[i] + "/" + fileName);
                string tempName     = tileSprite.name;
                float  spriteWidth  = tileSprite.rect.width;
                float  spriteHeight = tileSprite.rect.height;
                tileSprite = Sprite.Create(tileSprite.texture, tileSprite.rect,
                                           new Vector2(((tileSprite.pivot.x + ((spriteWidth % 200 == 0) ? -50 : 0)) / spriteWidth),
                                                       ((tileSprite.pivot.y + ((spriteHeight % 200 == 0) ? -50 : 0)) / spriteHeight)));
                tileSprite.name = tempName;

                tileSprite.OverridePhysicsShape(TilePicker.GeneratePhysicsShape(tileSizes[tileTypes[i]], tileSprite, "full"));
                tile        = ScriptableObject.CreateInstance("Tile") as Tile;
                tile.sprite = Instantiate(tileSprite);
                loadedTilesFull.Add(fileName, Instantiate(tile));

                tileSprite.OverridePhysicsShape(TilePicker.GeneratePhysicsShape(tileSizes[tileTypes[i]], tileSprite, "semisolid"));
                tile        = ScriptableObject.CreateInstance("Tile") as Tile;
                tile.sprite = Instantiate(tileSprite);
                loadedTilesSemisolid.Add(fileName, Instantiate(tile));

                tileSprite.OverridePhysicsShape(TilePicker.GeneratePhysicsShape(tileSizes[tileTypes[i]], tileSprite, "outline"));
                tile        = ScriptableObject.CreateInstance("Tile") as Tile;
                tile.sprite = Instantiate(tileSprite);
                loadedTilesOutline.Add(fileName, Instantiate(tile));
            }
        }

        tileNames = new List <string>(loadedTilesFull.Keys);

        GameObject tilemap = new GameObject();

        tilemap.layer = LayerUtilities.LayerNumber(SafeCollidableLayer);
        tilemap.AddComponent <Tilemap>();
        tilemap.AddComponent <TilemapRenderer>();
        tilemap.AddComponent <TilemapCollider2D>();
        tilemap.AddComponent <CompositeCollider2D>();
        tilemap.AddComponent <PlatformEffector2D>();

        tilemap.GetComponent <TilemapCollider2D>().usedByComposite  = true;
        tilemap.GetComponent <PlatformEffector2D>().surfaceArc      = 360f;
        tilemap.GetComponent <CompositeCollider2D>().usedByEffector = true;
        tilemap.GetComponent <CompositeCollider2D>().geometryType   = CompositeCollider2D.GeometryType.Polygons;
        tilemap.GetComponent <Rigidbody2D>().isKinematic            = true;

        GameObject currentMap;

        player.transform.position = Vector3.zero;
        layers.Add("Player", player);
        for (int i = 0; i < tileTypes.Length; i++)
        {
            currentMap      = Instantiate(tilemap, transform);
            currentMap.name = tileTypes[i];
            currentMap.transform.position = Vector3.forward * (i + 1) + new Vector3(-0.5f, -0.5f, 0);
            tilemaps.Add(tileTypes[i], currentMap.GetComponent <Tilemap>());
            layers.Add(tileTypes[i], currentMap);
            //tilemapPhysicsShapes.Add(tileTypes[i], "full");
            paletteTypes.Add(tileTypes[i], PaletteType.Collidable);
            tiles.Add(tileTypes[i], new List <Vector3Int>());
        }
        Destroy(tilemap);
    }