Example #1
0
        public MovingBlock(QuickGameScene scene, AdjacentTileGroup <MovingBlockPiece> tiles, AdjacentTileGroup <PathPoint> path)
        {
            Scene         = scene;
            motionManager = new MotionManager(this);

            SpriteGrid = new SpriteGrid
            {
                Texture = Textures.MovingBlockTexture
            };

            Position = tiles.GetBoundingBox();

            float tilesX = (float)Position.Width / 16f; //todo
            float tilesY = (float)Position.Height / 16f;

            SpriteGrid.Cells = new ArrayGrid <int>(new Vector2(tilesX, tilesY));
            foreach (var pt in SpriteGrid.Cells.Points)
            {
                //todo, nonstandard shapes
                SpriteGrid.Cells.Set(pt, 0);
            }

            new PathMoverBehavior <MovingBlock>(this, path);

            Scene.SolidLayer.AddObject(this);
        }
Example #2
0
        /// <summary>
        /// Combines adjacent pieces into MovingBlock objects and adds them to the scene
        /// </summary>
        /// <param name="allPieces"></param>
        public static void CreateBlocks(QuickGameScene scene, IEnumerable <MovingBlockPiece> allPieces, IEnumerable <PathPoint> pathPoints)
        {
            var groups = AdjacentTileGroup <MovingBlockPiece> .ExtractGroups(allPieces);

            var paths = AdjacentTileGroup <PathPoint> .ExtractGroups(pathPoints);

            //don't like this here
            scene.SinglePathPoints = paths.Where(p => p.Tiles.Length == 1).Select(p => p.Tiles[0]).ToArray();

            paths = paths.Where(p => p.Tiles.Length > 1).ToArray();

            foreach (var group in groups)
            {
                var groupBox = group.GetBoundingBox();
                var path     = paths.FirstOrDefault(p => p.Tiles.Any(q => groupBox.CollidesWith(q.Position, false)));
                if (path != null)
                {
                    new MovingBlock(scene, group, path);
                }
            }
        }