Exemple #1
0
        public void AddToGroupAndFindChildren(SolidExtension from, ConnectedSolid master, List <SolidExtension> extensions)
        {
            from.HasGroup = true;
            extensions.Add(from);

            if (from.X < master.GroupBoundsMin.X)
            {
                master.GroupBoundsMin.X = (int)from.X;
            }
            if (from.Y < master.GroupBoundsMin.Y)
            {
                master.GroupBoundsMin.Y = (int)from.Y;
            }
            if (from.Right > master.GroupBoundsMax.X)
            {
                master.GroupBoundsMax.X = (int)from.Right;
            }
            if (from.Bottom > master.GroupBoundsMax.Y)
            {
                master.GroupBoundsMax.Y = (int)from.Bottom;
            }

            foreach (SolidExtension extention in Scene.Tracker.GetEntities <SolidExtension>())
            {
                if (!extention.HasGroup &&
                    (Scene.CollideCheck(new Rectangle((int)from.X - 1, (int)from.Y, (int)from.Width + 2, (int)from.Height), extention) ||
                     Scene.CollideCheck(new Rectangle((int)from.X, (int)from.Y - 1, (int)from.Width, (int)from.Height + 2), extention) ||
                     Scene.CollideCheck(new Rectangle((int)master.X - 1, (int)master.Y, (int)master.Width + 2, (int)master.Height), extention) ||
                     Scene.CollideCheck(new Rectangle((int)master.X, (int)master.Y - 1, (int)master.Width, (int)master.Height + 2), extention)))
                {
                    AddToGroupAndFindChildren(extention, master, extensions);
                }
            }
        }
        public override void Awake(Scene scene)
        {
            List <SolidExtension> extensions = new List <SolidExtension>();

            FindExtensions(extensions);

            GroupOffset  = new Vector2(GroupBoundsMin.X, GroupBoundsMin.Y) - Position;
            Colliders    = new Hitbox[extensions.Count(ext => ext.HasHitbox) + 1];
            AllColliders = new Hitbox[extensions.Count + 1];

            int j = 0;

            for (int i = 0; i < extensions.Count; i++)
            {
                SolidExtension e      = extensions[i];
                Vector2        offset = e.Position - Position;
                Hitbox         hitbox = new Hitbox(e.Width, e.Height, offset.X, offset.Y);
                if (e.HasHitbox)
                {
                    Colliders[j] = hitbox;
                    j++;
                }
                AllColliders[i] = hitbox;
                e.RemoveSelf();
                // You don't want disabled Solids hanging around in the level, so you remove them.
            }

            int tWidth  = (int)((GroupBoundsMax.X - GroupBoundsMin.X) / 8);
            int tHeight = (int)((GroupBoundsMax.Y - GroupBoundsMin.Y) / 8);

            GroupTiles    = new bool[tWidth + 2, tHeight + 2];
            AllGroupTiles = new bool[tWidth + 2, tHeight + 2];

            Colliders[Colliders.Length - 1]       = (Hitbox)Collider;
            AllColliders[AllColliders.Length - 1] = (Hitbox)Collider;

            Collider = new ColliderList(AllColliders);
            for (int x = 0; x < tWidth + 2; x++)
            {
                for (int y = 0; y < tHeight + 2; y++)
                {
                    AllGroupTiles[x, y] = TileCollideWithGroup(x - 1, y - 1);
                }
            }

            Collider = new ColliderList(Colliders);
            for (int x = 0; x < tWidth + 2; x++)
            {
                for (int y = 0; y < tHeight + 2; y++)
                {
                    GroupTiles[x, y] = TileCollideWithGroup(x - 1, y - 1);
                }
            }

            scene.Add(BGRenderer = new BGTilesRenderer(this));

            base.Awake(scene);
        }