Skip to content

Instantly share code, notes, and snippets.

@rzfury
Created March 6, 2023 17:52
Show Gist options
  • Save rzfury/6489b0f12008623248150d55e2ca5712 to your computer and use it in GitHub Desktop.
Save rzfury/6489b0f12008623248150d55e2ca5712 to your computer and use it in GitHub Desktop.
STG Shoot Shape Thing
private void ShootShape(Vector2 pos, float speedMul, float angle, float sides, float count)
{
for(float i = 0f; i < sides; i++)
{
float a = angle + (i * 360f / sides);
Vector2 posA = new Vector2(
pos.X + MathF.Cos(MathHelper.ToRadians(a)),
pos.Y + MathF.Sin(MathHelper.ToRadians(a)));
float b = angle + ((i + 1f) * 360f / sides);
Vector2 posB = new Vector2(
pos.X + MathF.Cos(MathHelper.ToRadians(b)),
pos.Y + MathF.Sin(MathHelper.ToRadians(b)));
float putAngle = MathF.Atan2(posB.Y - posA.Y, posB.X - posA.X);
float putRadius = MathF.Sqrt(MathF.Pow(posB.X - posA.X, 2f) + MathF.Pow(posB.Y - posA.Y, 2f));
for (float j = 0f; j < count; j++)
{
Vector2 posAdjust = new Vector2(
posA.X + putRadius / count * j * MathF.Cos(putAngle),
posA.Y + putRadius / count * j * MathF.Sin(putAngle));
float actualSpeed = speedMul * MathF.Sqrt(MathF.Pow(posAdjust.X - pos.X, 2f) + MathF.Pow(posAdjust.Y - pos.Y, 2f));
float actualAngle = MathHelper.ToDegrees(MathF.Atan2(posAdjust.Y - pos.Y, posAdjust.X - pos.X));
ShotBullet(pos, actualSpeed, actualAngle, 0.1f);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment