public ApplyImpulse ( Vector2 direction, Vector2 acceleration ) : void | ||
direction | Vector2 | |
acceleration | Vector2 | |
return | void |
private void Split(CollisionConvexPolygon box) { var newPolygonShape = _structure.Split(box); var center = box.GetCenterInWorldSpace(); // TODO: Part is dead? // A boss part is dead when its center is dead? // or when the number of sub-parts is less than a number? if (center.X > (Size.X / 2f - 2 * _step) + Position.X - Origin.X && center.X < (Size.X / 2f + 2 * _step) + Position.X - Origin.X) { TakeDamage(99999); } else { var boxLocalPosition = box.GetLocalPosition(); // Left (1) or right (-1) part? var factor = (boxLocalPosition.X > Origin.X) ? 1 : -1; // If the break out part is not large enough => we don't create another part if (newPolygonShape.Vertices != null && newPolygonShape.GetArea() > Config.MinBossPartArea) { var bossPart = new BossPart( GameRef, _bossRef, _players, _moverManager, null, _color, _health, 0, 25f, null, newPolygonShape ); bossPart.Initialize(); var bossPartSize = newPolygonShape.GetSize(); var boxWorldPosition = box.GetWorldPosition(); // Compute new boss part's world position var worldPosition = Vector2.Zero; worldPosition.Y = boxWorldPosition.Y - boxLocalPosition.Y; // Left part if (factor == 1) worldPosition.X = boxWorldPosition.X - bossPartSize.X; // Right part else if (factor == -1) worldPosition.X = boxWorldPosition.X + _step; // Update world position according to parent rotation bossPart.Scale = Scale; bossPart.Rotation = Rotation; var newLocalPosition = Vector2.Zero; newLocalPosition.X = (Position.X - Origin.X) + (boxLocalPosition.X); newLocalPosition.Y = (Position.Y - Origin.Y); if (factor == -1) newLocalPosition.X -= bossPartSize.X; else newLocalPosition.X += _step; var newOrigin = newPolygonShape.GetCenter(); newLocalPosition += newOrigin; var rotationOrigin = Position; newLocalPosition = Vector2.Transform(newLocalPosition - rotationOrigin, Matrix.CreateRotationZ(Rotation)) + rotationOrigin; bossPart.Origin = newOrigin; bossPart.Position = newLocalPosition; _bossRef.Parts.Add(bossPart); // Give to this new BossPart an impulsion to (pseudo) random direction due to explosion var random = (float)(GameRef.Rand.NextDouble() * (1f - 0.75f)) + 0.75f; bossPart.ApplyImpulse(new Vector2(factor, random * factor), new Vector2(random / 5f)); ApplyImpulse(new Vector2(-factor, random * -factor), new Vector2(random / 5f)); } // Remove destroyed bounding boxes if (factor == -1) CollisionBoxes.RemoveAll(bb => bb.GetCenter().X < boxLocalPosition.X); else CollisionBoxes.RemoveAll(bb => bb.GetCenter().X > boxLocalPosition.X); // This is the bounding that the player has destroyed, so we remove it from the list CollisionBoxes.Remove(box); } }
private void Split(CollisionConvexPolygon box) { var newPolygonShape = _structure.Split(box); var center = box.GetCenterInWorldSpace(); // TODO: Part is dead? // A boss part is dead when its center is dead? // or when the number of sub-parts is less than a number? if (center.X > (Size.X / 2f - 2 * _step) + Position.X - Origin.X && center.X < (Size.X / 2f + 2 * _step) + Position.X - Origin.X) { TakeDamage(99999); } else { var boxLocalPosition = box.GetLocalPosition(); // Left (1) or right (-1) part? var factor = (boxLocalPosition.X > Origin.X) ? 1 : -1; // If the break out part is not large enough => we don't create another part if (newPolygonShape.Vertices != null && newPolygonShape.GetArea() > Config.MinBossPartArea) { var bossPart = new BossPart( GameRef, _bossRef, _players, _moverManager, null, _color, _health, 0, 25f, null, newPolygonShape ); bossPart.Initialize(); var bossPartSize = newPolygonShape.GetSize(); var boxWorldPosition = box.GetWorldPosition(); // Compute new boss part's world position var worldPosition = Vector2.Zero; worldPosition.Y = boxWorldPosition.Y - boxLocalPosition.Y; // Left part if (factor == 1) { worldPosition.X = boxWorldPosition.X - bossPartSize.X; } // Right part else if (factor == -1) { worldPosition.X = boxWorldPosition.X + _step; } // Update world position according to parent rotation bossPart.Scale = Scale; bossPart.Rotation = Rotation; var newLocalPosition = Vector2.Zero; newLocalPosition.X = (Position.X - Origin.X) + (boxLocalPosition.X); newLocalPosition.Y = (Position.Y - Origin.Y); if (factor == -1) { newLocalPosition.X -= bossPartSize.X; } else { newLocalPosition.X += _step; } var newOrigin = newPolygonShape.GetCenter(); newLocalPosition += newOrigin; var rotationOrigin = Position; newLocalPosition = Vector2.Transform(newLocalPosition - rotationOrigin, Matrix.CreateRotationZ(Rotation)) + rotationOrigin; bossPart.Origin = newOrigin; bossPart.Position = newLocalPosition; _bossRef.Parts.Add(bossPart); // Give to this new BossPart an impulsion to (pseudo) random direction due to explosion var random = (float)(GameRef.Rand.NextDouble() * (1f - 0.75f)) + 0.75f; bossPart.ApplyImpulse(new Vector2(factor, random * factor), new Vector2(random / 5f)); ApplyImpulse(new Vector2(-factor, random * -factor), new Vector2(random / 5f)); } // Remove destroyed bounding boxes if (factor == -1) { CollisionBoxes.RemoveAll(bb => bb.GetCenter().X < boxLocalPosition.X); } else { CollisionBoxes.RemoveAll(bb => bb.GetCenter().X > boxLocalPosition.X); } // This is the bounding that the player has destroyed, so we remove it from the list CollisionBoxes.Remove(box); } }