示例#1
0
        private void StartSelectTilesSequence(PointerEventInfo info, ILevelGeometry viewport)
        {
            bool controlKey = Control.ModifierKeys.HasFlag(Keys.Control);
            bool shiftKey   = Control.ModifierKeys.HasFlag(Keys.Shift);

            if (shiftKey)
            {
                StartDragAdd(info, viewport);
                return;
            }

            if (controlKey)
            {
                StartDragRemove(info, viewport);
                return;
            }

            TileCoord location = TileLocation(info);

            if (!_selectLayer.TileSelectionCoverageAt(location))
            {
                StartDragNew(info, viewport);
            }
            else
            {
                StartMove(info, viewport);
            }
        }
        public void CreateTile(TileCoord pos, Tile tile)
        {
            // Make sure the prefab we want to spawn exists, if it doesn't cry in
            // the console and exit out of this method.
            if (!(tile.prefab >= 0 && tile.prefab < levelSet.items.Length))
            {
                Debug.LogWarning(string.Format("This tile index {0} is not a valid index: Didn't do anything.", tile.prefab));
                return;
            }

            // Check to see if a tile is already here if so, windge about it and
            // return out of this method.
            if (level.data.ContainsKey(pos))
                return;

            if (!spawnedTiles.ContainsKey(pos))
            {
                // Spawn in the prefab.
                Transform inst = (Transform)Instantiate(levelSet.items[tile.prefab].prefab.transform, new Vector3(0.5f + pos.x, 0, 0.5f + pos.y), Quaternion.identity);
                inst.SetParent(transform);
                spawnedTiles.Add(pos, inst);
            }

            level.data.Add(pos, tile);
        }
示例#3
0
    public static List <Tile> GetTilesWithinDistance(int distance, TileCoord coord)
    {
        var allTiles = new List <Tile> {
            GetTile(coord)
        };
        var prevTiles = new List <Tile> {
            GetTile(coord)
        };
        var newTiles = new List <Tile>();

        for (int i = 0; i < distance; i++)
        {
            foreach (var tile in prevTiles)
            {
                var neighbors       = GetNeighbors(tile.Coord);
                var uniqueNeighbors = neighbors.Where(x => !allTiles.Contains(x) && !prevTiles.Contains(x) && !newTiles.Contains(x));
                newTiles.AddRange(uniqueNeighbors);
            }
            allTiles.AddRange(newTiles);
            prevTiles = newTiles;
            newTiles  = new List <Tile>();
        }

        return(allTiles);
    }
示例#4
0
        public void FloodFill(int x, int y)
        {
            _ranges = new FloodFillRangeQueue((_fillLayer.TilesWide + _fillLayer.TilesHigh) / 2 * 5);

            _matchStack = _fillLayer[x, y];

            LinearFill(ref x, ref y);

            while (_ranges.Count > 0)
            {
                FloodFillRange range = _ranges.Dequeue();

                int upY   = range.Y - 1;
                int downY = range.Y + 1;

                TileCoord tid;
                for (int i = range.StartX; i <= range.EndX; i++)
                {
                    tid = new TileCoord(i, upY);
                    if (range.Y > 0 && /*!_sourceStack.Equals(_fillLayer[tid]) &&*/
                        (_matchStack == null ? _matchStack == _fillLayer[tid] : _matchStack.Equals(_fillLayer[tid])))
                    {
                        LinearFill(ref i, ref upY);
                    }

                    tid = new TileCoord(i, downY);
                    if (range.Y < (_fillLayer.TilesHigh - 1) && /*!_sourceStack.Equals(_fillLayer[tid]) &&*/
                        (_matchStack == null ? _matchStack == _fillLayer[tid] : _matchStack.Equals(_fillLayer[tid])))
                    {
                        LinearFill(ref i, ref downY);
                    }
                }
            }
        }
示例#5
0
            public override void HandlePointerPosition(PointerEventInfo info)
            {
                if (_form._tileController == null || _form._layer == null)
                {
                    return;
                }

                TileCoord location = TileLocation(info);

                if (!TileInRange(location))
                {
                    return;
                }

                if (_form._tileController.SelectedTile != null)
                {
                    if (_form._tileController.SelectedTile.Width != _form._layer.TileWidth ||
                        _form._tileController.SelectedTile.Height != _form._layer.TileHeight)
                    {
                        MessageBox.Show("Selected tile not compatible with brush tile dimensions.", "Incompatible Tile", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    _form._layer.ClearTile(location.X, location.Y);
                    if (!_erase)
                    {
                        _form._layer.AddTile(location.X, location.Y, _form._tileController.SelectedTile);
                    }
                }
            }
示例#6
0
        public Tile Add(TextureResource texture)
        {
            if (texture.Width != TileWidth || texture.Height != TileHeight)
            {
                throw new ArgumentException("Supplied texture does not have tile dimensions", "texture");
            }

            Tile tile = new PhysicalTile()
            {
                Pool = _pool
            };

            if (ShouldExpandTexture())
            {
                ExpandTexture();
            }

            TileCoord coord = _openLocations[_openLocations.Count - 1];

            _openLocations.RemoveAt(_openLocations.Count - 1);

            _tileSource.Set(texture, new Point(coord.X * TileWidth, coord.Y * TileHeight));
            _texturePool.Invalidate(_tileSource.Uid);

            _locations[tile.Uid] = coord;

            Add(tile);

            return(tile);
        }
        public void QueueReplacement(TileCoord coord, Tile replacement)
        {
            TileStack srcStack = null;

            if (_tileSource.InRange(coord))
            {
                srcStack = new TileStack(_tileSource[coord]);
            }

            TileStack stack = null;

            if (replacement != null)
            {
                stack = new TileStack();
                stack.Add(replacement);
            }

            if (_tiles.ContainsKey(coord))
            {
                _tiles[coord] = new TileRecord(_tiles[coord].Original, stack);
            }
            else
            {
                _tiles[coord] = new TileRecord(srcStack, stack);
            }
        }
        public void QueueAdd(TileCoord coord, TileStack stack)
        {
            if (stack != null)
            {
                TileStack srcStack = null;
                if (_tileSource.InRange(coord))
                {
                    srcStack = new TileStack(_tileSource[coord]);
                }

                TileStack newStack = new TileStack(srcStack);
                foreach (Tile t in stack)
                {
                    newStack.Add(t);
                }

                if (_tiles.ContainsKey(coord))
                {
                    _tiles[coord] = new TileRecord(_tiles[coord].Original, stack);
                }
                else
                {
                    _tiles[coord] = new TileRecord(srcStack, newStack);
                }
            }
        }
        public MultiTileSelectionAnnot(Point start)
        {
            _selectedLocations = new HashSet <TileCoord>();

            TileMinExtant = new TileCoord(Int32.MaxValue, Int32.MaxValue);
            TileMaxExtant = new TileCoord(Int32.MinValue, Int32.MinValue);
        }
示例#10
0
        public MultiTileSelectionAnnot(Point start)
        {
            _selectedLocations = new HashSet<TileCoord>();

            TileMinExtant = new TileCoord(Int32.MaxValue, Int32.MaxValue);
            TileMaxExtant = new TileCoord(Int32.MinValue, Int32.MinValue);
        }
示例#11
0
 public void RemoveTile(TileCoord coord, Tile tile)
 {
     if (_tiles.ContainsKey(coord))
     {
         _tiles[coord].Remove(tile);
     }
 }
示例#12
0
        public void FloodFill(int x, int y)
        {
            _ranges = new FloodFillRangeQueue((_fillLayer.TilesWide + _fillLayer.TilesHigh) / 2 * 5);

            _matchStack = _fillLayer[x, y];

            LinearFill(ref x, ref y);

            while (_ranges.Count > 0) {
                FloodFillRange range = _ranges.Dequeue();

                int upY = range.Y - 1;
                int downY = range.Y + 1;

                TileCoord tid;
                for (int i = range.StartX; i <= range.EndX; i++) {
                    tid = new TileCoord(i, upY);
                    if (range.Y > 0 && /*!_sourceStack.Equals(_fillLayer[tid]) &&*/
                        (_matchStack == null ? _matchStack == _fillLayer[tid] : _matchStack.Equals(_fillLayer[tid])))
                        LinearFill(ref i, ref upY);

                    tid = new TileCoord(i, downY);
                    if (range.Y < (_fillLayer.TilesHigh - 1) && /*!_sourceStack.Equals(_fillLayer[tid]) &&*/
                        (_matchStack == null ? _matchStack == _fillLayer[tid] : _matchStack.Equals(_fillLayer[tid])))
                        LinearFill(ref i, ref downY);
                }
            }
        }
示例#13
0
    public static void RemoveTile(TileCoord coord)
    {
        var tile = GetTile(coord);

        if (tile == null)
        {
            return;
        }
        foreach (var tileConnection in tile.Connections)
        {
            if (tileConnection != null)
            {
                Destroy(tileConnection.gameObject);
            }
        }
        Tiles.Remove(coord);
        Destroy(tile.gameObject);
        foreach (var playerToken in PlayerTokens.Values)
        {
            if (playerToken.Coord == coord)
            {
                playerToken.RpcClearCoord();
            }
        }
    }
示例#14
0
    public static void AddTile(TileCoord coord)
    {
        var tile = Instantiate(_tilePrefabs[Random.Range(0, _tilePrefabs.Count)]).GetComponent <Tile>();

        Tiles[coord] = tile;
        NetworkServer.Spawn(tile.gameObject);
        tile.RpcMove(coord.R, coord.Q);

        Tuple <ConnectionDirection, TileCoord>[] directions = new[]
        {
            new Tuple <ConnectionDirection, TileCoord>(ConnectionDirection.East, new TileCoord(1, 0)),
            new Tuple <ConnectionDirection, TileCoord>(ConnectionDirection.SouthEast, new TileCoord(0, 1)),
            new Tuple <ConnectionDirection, TileCoord>(ConnectionDirection.SouthWest, new TileCoord(-1, 1)),
            new Tuple <ConnectionDirection, TileCoord>(ConnectionDirection.West, new TileCoord(-1, 0)),
            new Tuple <ConnectionDirection, TileCoord>(ConnectionDirection.NorthWest, new TileCoord(0, -1)),
            new Tuple <ConnectionDirection, TileCoord>(ConnectionDirection.NorthEast, new TileCoord(1, -1)),
        };

        foreach (var(dir, dirCoord) in directions)
        {
            var neighborCoord = new TileCoord(coord.R + dirCoord.R, coord.Q + dirCoord.Q);
            if (Tiles.ContainsKey(neighborCoord))
            {
                var neighborTile = Tiles[neighborCoord];
                var connection   = Instantiate(_connectionPrefab).GetComponent <Connection>();
                NetworkServer.Spawn(connection.gameObject);
                tile.Connections[(int)dir] = connection;
                neighborTile.Connections[((int)dir + 3) % 6] = connection;
                connection.Left  = tile;
                connection.Right = neighborTile;
                connection.RpcSetPosition(coord.R, coord.Q, neighborCoord.R, neighborCoord.Q);
            }
        }
    }
示例#15
0
    public static void MoveToken(Player player, TileCoord coord, bool snapToTile = false)
    {
        var token       = GetToken(player);
        var currentTile = GetTile(token.Coord);

        if (currentTile != null)
        {
            currentTile.Token = null;
        }
        if (snapToTile)
        {
            token.RpcSetCoord(coord.R, coord.Q);
            GetTile(coord).Token = token;
        }
        else
        {
            var tiles = GetTilesAlongPath(token.Coord, coord);
            var rs    = new List <int>();
            var qs    = new List <int>();
            foreach (var tile in tiles)
            {
                rs.Add(tile.Coord.R);
                qs.Add(tile.Coord.Q);
            }
            token.RpcMoveAlongPath(rs.ToArray(), qs.ToArray());
            tiles.Last().Token = token;
        }
        token.Coord = coord;
    }
示例#16
0
        private bool FloodFill_Sprite(int nMapX, int nMapY,
                                      Sprite spriteOld, int subpaletteOld,
                                      Sprite spriteNew, int tileNew, int subpaletteNew)
        {
            int spriteWidth  = spriteNew == null ? 1 : spriteNew.TileWidth;
            int spriteHeight = spriteNew == null ? 1 : spriteNew.TileHeight;

            // Stack of tiles to process.
            m_stackTiles = new Stack <TileCoord>();
            m_tilesDone  = new Dictionary <TileCoord, bool>();

            TileCoord t = new TileCoord(nMapX, nMapY);

            m_stackTiles.Push(t);
            m_tilesDone.Add(t, true);

            // Adjust the mapclick origin off the map (negative) so that all of our
            // offset calculations are guaranteed to be positive.
            while (nMapX > 0)
            {
                nMapX -= spriteWidth;
            }
            while (nMapY > 0)
            {
                nMapY -= spriteHeight;
            }

            while (m_stackTiles.Count != 0)
            {
                t = m_stackTiles.Pop();

                // Calc tile within sprite that we're painting:
                //
                //  Current sprite:   abcd
                //                    efgh
                //
                //  Original:    Click:       After:
                //  ___...___    ___...___    ___efg___
                //  __.....__    __.x...__    __dabcd__
                //  __...____    __...____    __hef____
                //  ____.____    ____.____    ____b____
                //
                //  '.' marks the map coords that belong to the same sprite
                //    (regardless of the particular tile within the sprite).
                int dx   = (t.X - nMapX) % spriteWidth;
                int dy   = (t.Y - nMapY) % spriteHeight;
                int tile = tileNew + dx + dy * spriteWidth;

                m_map.SetTile(t.X, t.Y, tile, subpaletteNew);

                FloodFill_CheckTile(t.X - 1, t.Y, spriteOld, subpaletteOld);
                FloodFill_CheckTile(t.X + 1, t.Y, spriteOld, subpaletteOld);
                FloodFill_CheckTile(t.X, t.Y - 1, spriteOld, subpaletteOld);
                FloodFill_CheckTile(t.X, t.Y + 1, spriteOld, subpaletteOld);
            }

            m_stackTiles = null;
            m_tilesDone  = null;
            return(true);
        }
示例#17
0
        protected override void Write(ContentWriter output, TileRegistryContent value)
        {
            output.Write(value.Version);

            Guid     id   = value.Id;
            TilePool pool = value.TilePool;

            output.Write((short)id);
            output.Write((short)pool.TileWidth);
            output.Write((short)pool.TileHeight);
            output.Write(value.TextureAsset);

            WritePropertyBlock(output, pool.CustomProperties);

            output.Write((short)pool.Count);
            foreach (Tile tile in pool)
            {
                TileCoord coord = pool.GetTileLocation(tile.Uid);

                output.Write((short)tile.Uid);
                output.Write((short)coord.X);
                output.Write((short)coord.Y);

                WritePropertyBlock(output, tile.CustomProperties);
            }
        }
示例#18
0
    // Use this for initialization
    public override void Start()
    {
        base.Start();

        player = FindObjectOfType(typeof(Player_Script)) as Player_Script;

        //Stats bar
        Name_Text.text = myName;
        Att_Text.text  = attack.ToString();
        HP_Text.text   = health.ToString();
        Def_Text.text  = defence.ToString();
        Stats_Bar.SetActive(true);

        //information board
        Name_Text2.text = myName;
        Att_Text2.text  = attack.ToString();
        HP_Text2.text   = health.ToString();
        Def_Text2.text  = defence.ToString();
        information_board.SetActive(false);

        TurnState = State.NONE;
        RunOnce   = false;
        //for sleeper
        MaxHp = health;

        speed = player.speed;

        DesTileID = CurrentTileID;
    }
示例#19
0
    /// <summary>
    /// Create a link between the tile at the coordinates indicated in the 1st chunk and
    /// the tile indicated by the coordinates in the 2nd chunk.
    /// Can be used to link tiles within the same chunk.
    /// Can even be used to link a tile to itself.
    /// </summary>
    /// <param name="chunk1"></param>
    /// <param name="chunk2"></param>
    /// <param name="tile1"></param>
    /// <param name="tile2"></param>
    public static void createTwoWayLink(Node[,] chunkFrom, Node[,] chunkTo, TileCoord tileFrom, TileCoord tileTo, GameManager.Direction dir)
    {
        int opposite = ((int)dir + 2) % 4;

        chunkFrom[tileFrom.x, tileFrom.y].defaultConn[(int)dir] = chunkTo[tileTo.x, tileTo.y].index;
        chunkTo[tileTo.x, tileTo.y].defaultConn[opposite]       = chunkFrom[tileFrom.x, tileFrom.y].index;
    }
示例#20
0
 public void MoveSelectionByOffset(TileCoord offset)
 {
     if (_selection != null)
     {
         _selection.Offset = new TileCoord(_selection.Offset.X + offset.X, _selection.Offset.Y + offset.Y);
     }
 }
示例#21
0
    void VerifyBoard()
    {
        List <int> remove;

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                TileCoord pos  = new TileCoord(x, y);
                int       type = getTileType(pos);
                if (type <= 0)
                {
                    continue;
                }
                remove = new List <int>();
                while (matchFinder(pos, true).Count > 0)
                {
                    type = getTileType(pos);
                    if (!remove.Contains(type))
                    {
                        remove.Add(type);
                    }
                    setTileType(pos, newType(ref remove));
                }
            }
        }
    }
示例#22
0
 public void SetSelectionOffset(TileCoord offset)
 {
     if (_selection != null)
     {
         _selection.Offset = offset;
     }
 }
示例#23
0
    public void RotatePieces(TileCoord topLeft, bool direction)
    {
        Tile      one        = getTile(topLeft);
        TilePiece pieceOne   = one.getPiece();
        Tile      two        = getTile(TileCoord.add(topLeft, TileCoord.right));
        TilePiece pieceTwo   = two.getPiece();
        Tile      three      = getTile(TileCoord.add(topLeft, TileCoord.up));
        TilePiece pieceThree = three.getPiece();
        Tile      four       = getTile(TileCoord.add(topLeft, TileCoord.add(TileCoord.right, TileCoord.up)));
        TilePiece pieceFour  = four.getPiece();

        Debug.Log("P00: " + getTileType(one.pos) + " P10: " + getTileType(two.pos) + " P01: " + getTileType(three.pos) + " P11: " + getTileType(four.pos));
        if (direction)
        {
            one.SetPiece(pieceThree);
            two.SetPiece(pieceOne);
            three.SetPiece(pieceFour);
            four.SetPiece(pieceTwo);
        }
        else
        {
            one.SetPiece(pieceTwo);
            two.SetPiece(pieceFour);
            three.SetPiece(pieceOne);
            four.SetPiece(pieceThree);
        }
        Debug.Log("P00: " + getTileType(one.pos) + " P10: " + getTileType(two.pos) + " P01: " + getTileType(three.pos) + " P11: " + getTileType(four.pos));
        update.Add(pieceOne);
        update.Add(pieceTwo);
        update.Add(pieceThree);
        update.Add(pieceFour);
    }
示例#24
0
    void RemovePiece(TileCoord pos)
    {
        List <RemovedPiece> available = new List <RemovedPiece>();

        for (int i = 0; i < removed.Count; i++)
        {
            if (!removed[i].falling)
            {
                available.Add(removed[i]);
            }
        }
        RemovedPiece set = null;

        if (available.Count > 0)
        {
            set = available[0];
        }
        else
        {
            GameObject   remove = GameObject.Instantiate(removedPiece, removedBoard);
            RemovedPiece kPiece = remove.GetComponent <RemovedPiece>();
            set = kPiece;
            removed.Add(kPiece);
        }
        int tile = getTileType(pos) - 1;

        if (set != null && tile >= 0 && tile < tiles.Length)
        {
            set.Initialize(tiles[tile], getPositionFromCoord(pos));
        }
    }
示例#25
0
        private void StartFillSequence(PointerEventInfo info)
        {
            if (!SourceValid)
            {
                return;
            }

            TileCoord location = TileLocation(info);

            if (!TileInRange(location))
            {
                return;
            }

            if (SourceType == TileSourceType.Brush)
            {
                Layer.TileAdding   += TileAddingHandler;
                Layer.TileRemoving += TileRemovingHandler;
            }

            _fillLayer   = Layer;
            _sourceStack = new TileStack();
            _sourceStack.Add(ActiveTile);

            _fillCommand = new TileReplace2DCommand(Layer);
            FloodFill(location.X, location.Y);

            if (SourceType == TileSourceType.Brush)
            {
                Layer.TileAdding   -= TileAddingHandler;
                Layer.TileRemoving -= TileRemovingHandler;
            }

            History.Execute(_fillCommand);
        }
示例#26
0
 public TileStack this[TileCoord location]
 {
     get { return this[location.X, location.Y]; }
     set
     {
         this[location.X, location.Y] = value;
     }
 }
示例#27
0
    public void RpcSetPosition(int leftR, int leftQ, int rightR, int rightQ)
    {
        var left  = new TileCoord(leftR, leftQ);
        var right = new TileCoord(rightR, rightQ);

        transform.position = Vector3.Lerp(left.Position, right.Position, 0.5f);
        transform.LookAt(left.Position);
    }
示例#28
0
    public static List <Tile> GetNeighbors(TileCoord coord)
    {
        var tile = GetTile(coord);
        var traversableConnections = tile.Connections.Where(x => x != null && x.Traversable).ToList();
        var tiles = traversableConnections.Select(conn => conn.From(tile)).ToList();

        return(tiles);
    }
示例#29
0
 public TileStack this[TileCoord location]
 {
     get { return(this[location.X, location.Y]); }
     set
     {
         this[location.X, location.Y] = value;
     }
 }
示例#30
0
 int getTileType(TileCoord pos)
 {
     if (pos.x < 0 || pos.x >= width || pos.y < 0 || pos.y >= height)
     {
         return(-1);
     }
     return(board[pos.x, pos.y].type);
 }
示例#31
0
    protected void TryResetPos()
    {
        GroundManager.Inst.logic.TryResetMapChild(this);
        Vector3 localPos;

        tilePos = GroundManager.Inst.logic.GetMapTile(this, out localPos);

        GroundManager.Inst.graphic.SetIntoTile(graphicInstance.transform, tilePos, localPos);
    }
示例#32
0
    public void Initialize(int type, TileCoord pos, Sprite tile)
    {
        img  = GetComponent <Image>();
        rect = GetComponent <RectTransform>();

        this.type = type;
        SetIndex(pos);
        img.sprite = tile;
    }
示例#33
0
        public bool TileSelectionCoverageAt(TileCoord coord)
        {
            if (_selection == null)
            {
                return(false);
            }

            return(_selection.CoverageAt(coord));
        }
示例#34
0
        public TileStack TileStacksAt(TileCoord location)
        {
            if (!CheckBounds(location.X, location.Y))
            {
                return(null);
            }

            return(_tiles[YIndex(location.Y), XIndex(location.X)]);
        }
示例#35
0
 public override Dictionary<TileCoord, Tile> GetBrush(int radius, TileCoord pos, Tile fill)
 {
     Dictionary<TileCoord, Tile> brush = new Dictionary<TileCoord, Tile>();
     for (int y, x = pos.x - radius; x <= (pos.x + radius); x++)
     {
         for (y = pos.y - radius; y <= (pos.y + radius); y++)
         {
             brush.Add(new TileCoord(x, y), fill);
         }
     }
     return brush;
 }
示例#36
0
        private void LinearFill(ref int x, ref int y)
        {
            // Find left edge
            int lFillLoc = x;

            while (true) {
                TileCoord tid = new TileCoord(lFillLoc, y);

                if (SourceType == TileSourceType.Brush && ActiveBrush != null) {
                    ActiveBrush.ApplyBrush(_fillLayer, tid.X, tid.Y);
                }
                else {
                    _fillCommand.QueueReplacement(tid, _sourceStack);
                    _fillLayer[tid] = _sourceStack;
                }

                lFillLoc--;
                tid = new TileCoord(lFillLoc, y);

                if (lFillLoc < 0 || /*_sourceStack.Equals(_fillLayer[tid]) ||*/
                    !(_matchStack == null ? _matchStack == _fillLayer[tid] : _matchStack.Equals(_fillLayer[tid])))
                    break;
            }
            lFillLoc++;

            // Find right edge
            int rFillLoc = x;

            while (true) {
                TileCoord tid = new TileCoord(rFillLoc, y);

                /*if (!_sourceStack.Equals(_fillLayer[tid])) {*/
                    if (SourceType == TileSourceType.Brush && ActiveBrush != null) {
                        ActiveBrush.ApplyBrush(_fillLayer, tid.X, tid.Y);
                    }
                    else {
                        _fillCommand.QueueReplacement(tid, _sourceStack);
                        _fillLayer[tid] = _sourceStack;
                    }
                //}

                rFillLoc++;
                tid = new TileCoord(rFillLoc, y);

                if (rFillLoc >= _fillLayer.TilesWide || /*_sourceStack.Equals(_fillLayer[tid]) ||*/
                    !(_matchStack == null ? _matchStack == _fillLayer[tid] : _matchStack.Equals(_fillLayer[tid])))
                    break;
            }
            rFillLoc--;

            FloodFillRange r = new FloodFillRange(lFillLoc, rFillLoc, y);
            _ranges.Enqueue(ref r);
        }
示例#37
0
 public static TileCoord getClosestDirection ( TileCoord from, TileCoord to ) {
     TileCoord diff = to - from;
     if ( diff.x == diff.y ) {
         return null;
     }
     else
         if ( Mathf.Abs ( diff.x ) > Mathf.Abs ( diff.y ) ) {
             return new TileCoord ( ( diff.x > 0 ) ? +1 : -1, 0 );
         }
         else {
             return new TileCoord ( 0, ( diff.y > 0 ) ? +1 : -1 );
         }
 }
        // Return an array of Tiles that fit inside a square the size of radius
        // with an offset.
        public TileCoord[] InsideSquare(int radius, TileCoord offset)
        {
            List<TileCoord> tiles = new List<TileCoord>();
            for (int y, x = offset.x - radius; x <= (offset.x + radius); x++)
            {
                for (y = offset.y - radius; y <= (offset.y + radius); y++)
                {
                    tiles.Add(new TileCoord(x, y));
                }
            }

            return tiles.ToArray();
        }
        // Return an array of Tiles that fit inside a square the size of radius
        // with an offset of the same type of 'type'.
        public TileCoord[] InsideSquareOfType(int radius, TileCoord offset, Tile type)
        {
            List<TileCoord> tiles = new List<TileCoord>();
            for (int y, x = offset.x - radius; x <= (offset.x + radius); x++)
            {
                for (y = offset.y - radius; y <= (offset.y + radius); y++)
                {
                    if (level.GetTile(new TileCoord(x, y)) == type)
                        tiles.Add(new TileCoord(x, y));
                }
            }

            return tiles.ToArray();
        }
 public void VisualiseBrush(Brush brush, int radius, TileCoord start, TileCoord end)
 {
     tiles = new List<TileCoord>();
     foreach (TileCoord lineTile in editor.getTiles.AlongLine(start, end))
     {
         foreach (TileCoord tile in brush.GetBrush(radius, lineTile, new Cow.Tile(0)).Keys)
         {
             if (!tiles.Contains(tile))
                 tiles.Add(tile);
         }
     }
     tiles = new List<TileCoord>(brush.GetBrush(radius, new TileCoord(), new Tile(0)).Keys);
     RenderTiles();
 }
        public void MouseHold(TileCoord pos)
        {
            // Only paint a line if the cursor has moved more than one unit else
            // just paint a single tile at the new cursor pos. Also set the lastPos
            // to the current pos for the next time the cursor moves.
            if (pos.x > lastPos.x + 1 || pos.x < lastPos.x - 1 || pos.y > lastPos.y + 1 || pos.y < lastPos.y - 1)
                // Just loop through each tile in the line and paint a brush over
                // the tile.
                foreach (TileCoord posInLine in getTiles.AlongLine(lastPos, pos))
                    Paint(posInLine, currTile);
            else
                Paint(pos, currTile);

            lastPos = pos;
        }
示例#42
0
        public TileSelection(TileSelection selection)
        {
            if (selection != null) {
                _offset = selection._offset;

                _tileAnnot = new MultiTileSelectionAnnot(selection._tileAnnot);

                _active = selection._active;
                _floating = selection._floating;

                _tiles = new Dictionary<TileCoord, TileStack>();
                foreach (KeyValuePair<TileCoord, TileStack> kvp in selection._tiles)
                    _tiles.Add(kvp.Key, new TileStack(kvp.Value));
            }
        }
示例#43
0
        public void QueueAdd(TileCoord coord, Tile tile)
        {
            if (tile != null) {
                TileStack srcStack = null;
                if (_tileSource.InRange(coord))
                    srcStack = new TileStack(_tileSource[coord]);

                TileStack stack = new TileStack(srcStack);
                stack.Add(tile);

                if (_tiles.ContainsKey(coord))
                    _tiles[coord] = new TileRecord(_tiles[coord].Original, stack);
                else
                    _tiles[coord] = new TileRecord(srcStack, stack);
            }
        }
示例#44
0
        public override Dictionary<TileCoord, Tile> GetBrush(int radius, TileCoord pos, Tile fill)
        {
            Dictionary<TileCoord, Tile> brush = new Dictionary<TileCoord, Tile>();

            TileCoord centre;
            int sqrRadius = radius * radius;

            for (int y, x = pos.x - radius; x <= (pos.x + radius); x++)
            {
                for (y = pos.y - radius; y <= (pos.y + radius); y++)
                {
                    centre.x = x - pos.x;
                    centre.y = y - pos.y;

                    if(centre.x * centre.x + centre.y * centre.y <= sqrRadius)
                        brush.Add(new TileCoord(x, y), fill);
                }
            }
            return brush;
        }
 public void Tile(TileCoord pos)
 {
     //Create the top face
     Quad(
         new Vector3(pos.x + 0, height, pos.y + 0),
         new Vector3(pos.x + 0, height, pos.y + 1),
         new Vector3(pos.x + 1, height, pos.y + 1),
         new Vector3(pos.x + 1, height, pos.y + 0));
     if (!tiles.Contains(new TileCoord(pos.x - 1, pos.y)))
     {
         Quad(
             new Vector3(pos.x + 0, height, pos.y + 1),
             new Vector3(pos.x + 0, height, pos.y + 0),
             new Vector3(pos.x + 0, 0, pos.y + 0),
             new Vector3(pos.x + 0, 0, pos.y + 1));
     }
     if (!tiles.Contains(new TileCoord(pos.x + 1, pos.y)))
     {
         Quad(
             new Vector3(pos.x + 1, height, pos.y + 0),
             new Vector3(pos.x + 1, height, pos.y + 1),
             new Vector3(pos.x + 1, 0, pos.y + 1),
             new Vector3(pos.x + 1, 0, pos.y + 0));
     }
     if (!tiles.Contains(new TileCoord(pos.x, pos.y-1)))
     {
         Quad(
             new Vector3(pos.x + 0, height, pos.y + 0),
             new Vector3(pos.x + 1, height, pos.y + 0),
             new Vector3(pos.x + 1, 0, pos.y + 0),
             new Vector3(pos.x + 0, 0, pos.y + 0));
     }
     if (!tiles.Contains(new TileCoord(pos.x, pos.y + 1)))
     {
         Quad(
             new Vector3(pos.x + 1, height, pos.y + 1),
             new Vector3(pos.x + 0, height, pos.y + 1),
             new Vector3(pos.x + 0, 0, pos.y + 1),
             new Vector3(pos.x + 1, 0, pos.y + 1));
     }
 }
        // Returns an array of tiles along a line from start to end.
        public TileCoord[] AlongLine(TileCoord start, TileCoord end)
        {
            // This if statement just swaps the start and end around if the start
            // is left of the end.
            if (start.x > end.x)
            {
                TileCoord swapTile = start;
                start = end;
                end = swapTile;
            }

            // Bresenham's line algorithm.
            // http://wki.pe/Bresenham's_line_algorithm
            // C.O.W. C# Implementation written by Tom Parker.
            List<TileCoord> tiles = new List<TileCoord>();

            float deltaX = end.x - start.x;
            float deltaY = end.y - start.y;
            float error = 0;
            float deltaError = Mathf.Abs(deltaY / deltaX);

            int y = start.y;

            for (int x = start.x; x < end.x; x++)
            {
                tiles.Add(new TileCoord(x, y));
                error += deltaError;
                while (error >= 0.5f)
                {
                    tiles.Add(new TileCoord(x, y));
                    y += (int)Mathf.Sign(end.y - start.y);
                    error -= 1;
                }
            }

            return tiles.ToArray();
        }
示例#47
0
 private void UpdateExtants(TileCoord coord)
 {
     if (coord.X < _minX)
         _minX = coord.X;
     if (coord.X > _maxX)
         _maxX = coord.X;
     if (coord.Y < _minY)
         _minY = coord.Y;
     if (coord.Y > _maxY)
         _maxY = coord.Y;
 }
示例#48
0
 public void RemoveTile(TileCoord coord, Tile tile)
 {
     if (_tiles.ContainsKey(coord))
         _tiles[coord].Remove(tile);
 }
示例#49
0
 public void ClearTile(TileCoord coord)
 {
     _tiles.Remove(coord);
     ResetExtants();
 }
示例#50
0
        public void AddTile(TileCoord coord, Tile tile)
        {
            if (!_tiles.ContainsKey(coord))
                _tiles.Add(coord, new TileStack());

            _tiles[coord].Remove(tile);
            _tiles[coord].Add(tile);

            UpdateExtants(coord);
        }
示例#51
0
        public void QueueReplacement(TileCoord coord, Tile replacement)
        {
            TileStack srcStack = null;
            if (_tileSource.InRange(coord))
                srcStack = new TileStack(_tileSource[coord]);

            TileStack stack = null;
            if (replacement != null) {
                stack = new TileStack();
                stack.Add(replacement);
            }

            if (_tiles.ContainsKey(coord))
                _tiles[coord] = new TileRecord(_tiles[coord].Original, stack);
            else
                _tiles[coord] = new TileRecord(srcStack, stack);
        }
示例#52
0
 private void AddTile(MultiTileGridLayer layer, TileCoord location)
 {
     if (!_tiles.ContainsKey(location)) {
         TileStack stack = layer.TileStacksAt(location);
         if (!TileStack.NullOrEmpty(stack))
             _tiles.Add(location, stack);
         _tileAnnot.AddTileLocation(location);
     }
 }
示例#53
0
 private TileCoord AdjustLocation(TileCoord location)
 {
     return new TileCoord(location.X - _offset.X, location.Y - _offset.Y);
 }
示例#54
0
 public bool TileAt(TileCoord location)
 {
     return _tiles.ContainsKey(AdjustLocation(location));
 }
示例#55
0
 public bool CoverageAt(TileCoord location)
 {
     return _tileAnnot.TileLocations.Contains(AdjustLocation(location));
 }
示例#56
0
 public void ClearTiles()
 {
     _tiles.Clear();
     _offset = new TileCoord(0, 0);
 }
示例#57
0
        private void ShowPreviewMarker(TileCoord location)
        {
            if (!_previewMarkerVisible) {
                if (_previewMarker == null) {
                    _previewMarker = new SelectionAnnot();
                    _previewMarker.Fill = new SolidColorBrush(new Color(192, 0, 0, 128));
                }

                _annots.Add(_previewMarker);
                _previewMarkerVisible = true;
            }

            int x = (int)(location.X * Layer.TileWidth);
            int y = (int)(location.Y * Layer.TileHeight);

            _previewMarker.Start = new Point(x, y);
            _previewMarker.End = new Point(x + Layer.TileWidth, y + Layer.TileHeight);
        }
示例#58
0
 private TileSelection()
 {
     _tiles = new Dictionary<TileCoord, TileStack>();
     _offset = new TileCoord(0, 0);
     _tileAnnot = new MultiTileSelectionAnnot();
 }
示例#59
0
            private bool TileInRange(TileCoord location)
            {
                if (location.X < 0 || location.X >= _form._layer.TilesWide)
                    return false;
                if (location.Y < 0 || location.Y >= _form._layer.TilesHigh)
                    return false;

                return true;
            }
示例#60
0
        public void QueueReplacement(TileCoord coord, TileStack replacement)
        {
            TileStack srcStack = null;
            if (_tileSource.InRange(coord))
                srcStack = new TileStack(_tileSource[coord]);

            replacement = (replacement != null) ? new TileStack(replacement) : null;

            if (_tiles.ContainsKey(coord))
                _tiles[coord] = new TileRecord(_tiles[coord].Original, replacement);
            else
                _tiles[coord] = new TileRecord(srcStack, replacement);
        }