示例#1
0
        /// <summary>
        /// Create a block by spawning multiple block modules.
        /// </summary>
        /// <param name="worm">Worm</param>
        /// <param name="manager">Block manager</param>
        /// <returns>Module</returns>
        public BlockModule Spawn(Worm worm, Blocks manager)
        {
            color  = worm.Color;
            bottom = height;
            left   = width;
            top    = 0;
            right  = 0;
            bool spawn = InitBuffer(worm.firstModule, worm.Length);

            for (int y = bottom; y <= top; y++)
            {
                for (int x = left; x <= right; x++)
                {
                    if (optimizationBuffer[x, y] == true)
                    {
                        optimizationBuffer[x, y] = false;
                        if (firstModule == null)
                        {
                            lastModule  = manager.Enable().Initialize(color, x, y);
                            firstModule = lastModule;
                        }
                        else
                        {
                            lastModule.Next = manager.Enable().Initialize(color, x, y);
                            lastModule      = lastModule.Next;
                        }
                        lastModule.First = firstModule;
                        if (ExpandBothX(x, y))
                        {
                            ExpandY(x, y);
                        }
                        else
                        {
                            ExpandX(x, y);
                        }
                        eraser.Erase(lastModule);
                        if (spawn)
                        {
                            lastModule.Spawn();
                        }
                    }
                }
            }
            if (!spawn)
            {
                firstModule.Disable();
            }
            firstModule = null;
#if DEBUG
            if (visualize)
            {
                Visualize();
            }
#endif
            return(firstModule);
        }
示例#2
0
 /// <summary>
 /// Erases a part of a worm under a block module.
 /// </summary>
 /// <param name="blockModule">Block module</param>
 public void Erase(BlockModule blockModule)
 {
     Enable().Spawn(collision.EntityX(blockModule.X) - halfSize, collision.EntityY(blockModule.Y) - halfSize, blockModule.Width, blockModule.Height);
     game.Coroutine.Start(EraseEraser());
 }