public Objects(World world, ScreenManager screenManager, Vector2 startPosition, Vector2 endPosition, int count, float radius, ObjectType type)
{
_batch = screenManager.SpriteBatch;
_bodies = new List<Body>(count);
CollidesWith = Category.All;
CollisionCategories = Category.All;
for (int i = 0; i < count; ++i)
{
switch (type)
{
case ObjectType.Circle:
_bodies.Add(BodyFactory.CreateCircle(world, radius, 1f));
break;
case ObjectType.Rectangle:
_bodies.Add(BodyFactory.CreateRectangle(world, radius, radius, 1f));
break;
case ObjectType.Star:
_bodies.Add(BodyFactory.CreateGear(world, radius, 10, 0f, 1f, 1f));
break;
case ObjectType.Gear:
_bodies.Add(BodyFactory.CreateGear(world, radius, 10, 100f, 1f, 1f));
break;
}
}
for (int i = 0; i < _bodies.Count; ++i)
{
Body body = _bodies[i];
body.BodyType = BodyType.Dynamic;
body.Position = Vector2.Lerp(startPosition, endPosition, i / (float)(count - 1));
body.Restitution = .7f;
body.Friction = .2f;
body.CollisionCategories = CollisionCategories;
body.CollidesWith = CollidesWith;
}
//GFX
AssetCreator creator = screenManager.Assets;
switch (type)
{
case ObjectType.Circle:
_object = new Sprite(creator.CircleTexture(radius, MaterialType.Dots, Color.DarkRed, 0.8f));
break;
case ObjectType.Rectangle:
_object = new Sprite(creator.TextureFromVertices(PolygonTools.CreateRectangle(radius / 2f, radius / 2f), MaterialType.Dots, Color.Blue, 0.8f));
break;
case ObjectType.Star:
_object = new Sprite(creator.TextureFromVertices(PolygonTools.CreateGear(radius, 10, 0f, 1f), MaterialType.Dots, Color.Yellow, 0.8f));
break;
case ObjectType.Gear:
_object = new Sprite(creator.TextureFromVertices(PolygonTools.CreateGear(radius, 10, 100f, 1f), MaterialType.Dots, Color.DarkGreen, 0.8f));
break;
}
}