Ejemplo n.º 1
0
Archivo: Scene.cs Proyecto: XF9/Fenrir
        /// <summary>
        /// INTERNAL USE ONLY!
        /// this will NOT destruct a block
        /// this is a destruction handler!
        /// </summary>
        private void OnDestructBlockEvent(Block block)
        {
            if (blocks[block.Depth].ContainsKey(block.GridPosition))
            {
                this.blocks[block.Depth].Remove(block.GridPosition);

                // block behind
                if(block.Depth < this.Properties.MaxBlockDepth)
                    this.ConstructBlock(block.GridPosition, block.Depth + 1, true);

                // surrounding blocks
                Point tmp = new Point();
                int depth;

                for (int x = -1; x < 2; x++)
                    for (int y = -1; y < 2; y++)
                    {
                        tmp.X = block.GridPosition.X + x;
                        tmp.Y = block.GridPosition.Y + y;
                        depth = this.GetBlockDepth(tmp);
                        if(depth <= block.Depth)
                            this.ConstructBlock(tmp, block.Depth);
                    }
            }

            // remove marker
            if (this.markers.ContainsKey(block.GridPosition) && block.Depth == this.markers[block.GridPosition].Depth - 1)
            {
                if (this.markers[block.GridPosition].Type == MarkerType.Cave)
                    foreach (Cave cave in this.caves)
                        cave.CaveBlockMined(block.GridPosition);

                this.markers.Remove(block.GridPosition);
            }
        }
Ejemplo n.º 2
0
Archivo: Scene.cs Proyecto: XF9/Fenrir
        /// <summary>
        /// Generates a block if possible
        /// </summary>
        /// <param name="position">position of the block to be created</param>
        /// <param name="depth">depth layer of the block</param>
        /// <param name="force">force the block to be created what ever comes</param>
        /// <returns>the created Block or null</returns>
        public Block ConstructBlock(Point position, int depth = 0, Boolean force = false)
        {
            // Block already present - skip this
            if (this.blocks[depth].ContainsKey(position))
                return this.blocks[depth][position];

            // block not already mined && block not in starting area
            // maxbe needs a check for a valid depth value
            if (force || (!( this.GetBlockDepth(position) > depth) && !this.IntersectsStartingArea(position)))
            {
                Block newBlock = new Block(position, depth, !this.IntersectsStartingArea(position));
                this.blocks[depth].Add(position, newBlock);
                newBlock.destruction += new EventHandler<BlockDestructEvent>(OnBlockDestructed);
                return newBlock;
            }
            return null;
        }