protected override void Update(PhysicsShapeBuilderContext context, TileGridBlock block) { Rectangle cellSelection = new Rectangle(0, 0, 1, 1); for (int y = 0; y < block.BlockSize; y++) { for (int x = 0; x < block.BlockSize; x++) { var tile = block.GetCell(x, y); if (!tile.IsEmpty) { context.AddColliderShape(context.ColliderShapeProvider.CalculateColliderShape(ref cellSelection, block)); } cellSelection.X += 1; } cellSelection.Y += 1; cellSelection.X = 0; } }
protected override void Update(PhysicsShapeBuilderContext context, TileGridBlock block) { throw new NotImplementedException(); //Rectangle cellSelection = new Rectangle(0, 0, 1, 1); //int left = 0; //Rectangle adjacent = default(Rectangle); //bool hasAdjacent = false; //for (int y = 0; y < block.BlockSize; y++) //{ // for (int x = 0; x < block.BlockSize; x++) // { // var tile = block.GetCell(x, y); // if (!tile.IsEmpty) // { // if (IsLeftEdge(block, ref x, ref y)) // { // cellSelection.X = left = x; // cellSelection.Width = 1; // if (hasAdjacent = previousBounds.TryGetValue(x, out adjacent)) // previousBounds.Remove(x); // } // if (IsRightEdge(block, ref x, ref y)) // { // if (hasAdjacent) // { // if (adjacent.Width == cellSelection.Width) // { // adjacent.Height += 1; // currentBounds[left] = adjacent; // } // else // { // context.AddColliderShape(context.ColliderShapeProvider.CalculateColliderShape(ref adjacent, block)); // currentBounds[left] = cellSelection; // } // hasAdjacent = false; // } // else // { // currentBounds[left] = cellSelection; // } // } // else // { // cellSelection.Width += 1; // } // } // } // cellSelection.Y += 1; // cellSelection.X = left = 0; // cellSelection.Width = 1; // foreach (var item in previousBounds.Values) // { // var leftOver = item; // context.AddColliderShape(context.ColliderShapeProvider.CalculateColliderShape(ref leftOver, block)); // } // Utilities.Swap(ref previousBounds, ref currentBounds); // currentBounds.Clear(); //} //foreach (var item in previousBounds.Values) //{ // var leftOver = item; // context.AddColliderShape(context.ColliderShapeProvider.CalculateColliderShape(ref leftOver, block)); //} //previousBounds.Clear(); }
protected override void Update(PhysicsShapeBuilderContext context, TileGridBlock block) { Rectangle cellSelection = new Rectangle(0, 0, 1, 1); int left = 0; Rectangle adjacent = default(Rectangle); bool hasAdjacent = false; for (int y = 0; y < block.BlockSize; y++) { for (int x = 0; x < block.BlockSize; x++) { var tile = block.GetCell(x, y); if (!tile.IsEmpty) { if (IsLeftEdge(block, ref x, ref y)) { cellSelection.X = left = x; cellSelection.Width = 1; if (hasAdjacent = previousBounds.TryGetValue(x, out adjacent)) { previousBounds.Remove(x); } } if (IsRightEdge(block, ref x, ref y)) { if (hasAdjacent) { if (adjacent.Width == cellSelection.Width) { adjacent.Height += 1; currentBounds[left] = adjacent; } else { context.AddColliderShape(context.ColliderShapeProvider.CalculateColliderShape(ref adjacent, block)); currentBounds[left] = cellSelection; } hasAdjacent = false; } else { currentBounds[left] = cellSelection; } } else { cellSelection.Width += 1; } } } cellSelection.Y += 1; cellSelection.X = left = 0; cellSelection.Width = 1; foreach (var item in previousBounds.Values) { var leftOver = item; context.AddColliderShape(context.ColliderShapeProvider.CalculateColliderShape(ref leftOver, block)); } Utilities.Swap(ref previousBounds, ref currentBounds); currentBounds.Clear(); } foreach (var item in previousBounds.Values) { var leftOver = item; context.AddColliderShape(context.ColliderShapeProvider.CalculateColliderShape(ref leftOver, block)); } previousBounds.Clear(); }
protected abstract void Update(PhysicsShapeBuilderContext context, TileGridBlock block);