private void CreateGFX(AssetCreator assets) { _face = new Sprite(assets.CircleTexture(0.9f, MaterialType.Squares, Color.Gray, 1f, 24f)); _torso = new Sprite(assets.TextureFromVertices(PolygonTools.CreateRoundedRectangle(2f, 4f, 0.5f, 0.7f, 2), MaterialType.Squares, Color.LightSlateGray, 0.8f, 24f)); _upperArm = new Sprite(assets.TextureFromVertices(PolygonTools.CreateCapsule(1.9f, 0.45f, 16), MaterialType.Squares, Color.DimGray, 0.8f, 24f)); _lowerArm = new Sprite(assets.TextureFromVertices(PolygonTools.CreateCapsule(1.9f, 0.45f, 16), MaterialType.Squares, Color.DarkSlateGray, 0.8f, 24f)); _upperLeg = new Sprite(assets.TextureFromVertices(PolygonTools.CreateCapsule(2f, 0.5f, 16), MaterialType.Squares, Color.DimGray, 0.8f, 24f)); _lowerLeg = new Sprite(assets.TextureFromVertices(PolygonTools.CreateCapsule(2f, 0.5f, 16), MaterialType.Squares, Color.DarkSlateGray, 0.8f, 24f)); }
private void CreateGFX(AssetCreator assets) { _face = new Sprite(assets.CircleTexture(1f, MaterialType.Squares, Color.Gray, 1f, 24f)); _torso = new Sprite(assets.TextureFromVertices(PolygonTools.CreateRectangle(2f, 4f), MaterialType.Squares, Color.LightSlateGray, 0.8f, 24f)); _leftJetEngine = new Sprite(assets.CircleTexture(1f, MaterialType.Waves, Color.Gray, 1f, 24f)); _rightJetEngine = new Sprite(assets.CircleTexture(1f, MaterialType.Waves, Color.Gray, 1f, 24f)); }
private void CreateLegTextures(AssetCreator assets) { Vector2 p1 = new Vector2(-5.4f, -6.1f); Vector2 p2 = new Vector2(-7.2f, -1.2f); Vector2 p3 = new Vector2(-4.3f, -1.9f); Vector2 p4 = Vector2.Zero; Vector2 p5 = new Vector2(-2.9f, 0.7f); Vector2 p6 = new Vector2(0.6f, 2.9f); Vertices vertices = new Vertices(3); vertices.Add(p1); vertices.Add(p3); vertices.Add(p2); _leftLeg = new Sprite(assets.TextureFromVertices(vertices, MaterialType.Blank, Color.IndianRed * 0.8f, 1f, 24f)); vertices[0] = p4; vertices[1] = p5; vertices[2] = p6; _leftShoulder = new Sprite(assets.TextureFromVertices(vertices, MaterialType.Blank, Color.Beige * 0.8f, 1f, 24f)); p1.X *= -1f; p2.X *= -1f; p3.X *= -1f; p5.X *= -1f; p6.X *= -1f; vertices[0] = p1; vertices[1] = p2; vertices[2] = p3; _rightLeg = new Sprite(assets.TextureFromVertices(vertices, MaterialType.Blank, Color.IndianRed * 0.8f, 1f, 24f)); vertices[0] = p4; vertices[1] = p6; vertices[2] = p5; _rightShoulder = new Sprite(assets.TextureFromVertices(vertices, MaterialType.Blank, Color.Beige * 0.8f, 1f, 24f)); _leftShoulder.Origin = AssetCreator.CalculateOrigin(_leftShoulders[0], 24f); _leftLeg.Origin = AssetCreator.CalculateOrigin(_leftLegs[0], 24f); _rightShoulder.Origin = AssetCreator.CalculateOrigin(_rightShoulders[0], 24f); _rightLeg.Origin = AssetCreator.CalculateOrigin(_rightLegs[0], 24f); }
private void CreateLegTextures(AssetCreator assets) { Vector2 p1 = new Vector2(-5.4f, 6.1f); Vector2 p2 = new Vector2(-7.2f, 1.2f); Vector2 p3 = new Vector2(-4.3f, 1.9f); Vector2 p4 = new Vector2(-2.9f, -0.7f); Vector2 p5 = new Vector2(0.6f, -2.9f); Vertices vertices = new Vertices(3); vertices.Add(p1); vertices.Add(p2); vertices.Add(p3); _leftLeg = new Sprite(assets.TextureFromVertices(vertices, MaterialType.Blank, Color.IndianRed * 0.8f, 1f)); vertices[0] = Vector2.Zero; vertices[1] = p4; vertices[2] = p5; _leftShoulder = new Sprite(assets.TextureFromVertices(vertices, MaterialType.Blank, Color.Beige * 0.8f, 1f)); p1.X *= -1f; p2.X *= -1f; p3.X *= -1f; p4.X *= -1f; p5.X *= -1f; vertices[0] = p1; vertices[1] = p3; vertices[2] = p2; _rightLeg = new Sprite(assets.TextureFromVertices(vertices, MaterialType.Blank, Color.IndianRed * 0.8f, 1f)); vertices[0] = Vector2.Zero; vertices[1] = p5; vertices[2] = p4; _rightShoulder = new Sprite(assets.TextureFromVertices(vertices, MaterialType.Blank, Color.Beige * 0.8f, 1f)); }
public Pyramid(World world, ScreenManager screenManager, Vector2 position, int count, float density) { _batch = screenManager.SpriteBatch; Vertices rect = PolygonTools.CreateRectangle(1f / 2f, 1f / 2f); PolygonShape shape = new PolygonShape(rect, density); Vector2 rowStart = position; rowStart.Y -= 0.5f + count * 1.1f; Vector2 deltaRow = new Vector2(-0.625f, -1.1f); const float spacing = 1.25f; _boxes = new List <Body>(); for (int i = 0; i < count; ++i) { Vector2 pos = rowStart; for (int j = 0; j < i + 1; ++j) { Body body = world.CreateBody(); body.BodyType = BodyType.Dynamic; body.Position = pos; body.CreateFixture(shape); _boxes.Add(body); pos.X += spacing; } rowStart += deltaRow; } //GFX AssetCreator creator = screenManager.Assets; _box = new Sprite(creator.TextureFromVertices(rect, MaterialType.Dots, Color.SaddleBrown, 2f, 24f)); }
public Agent(World world, PhysicsGameScreen screen, Vector2 position) { _collidesWith = Category.All; _collisionCategories = Category.All; _agentBody = BodyFactory.CreateBody(world, position); _agentBody.BodyType = BodyType.Dynamic; //Center FixtureFactory.AttachCircle(0.5f, 0.5f, _agentBody); //Left arm FixtureFactory.AttachRectangle(1.5f, 0.4f, 1f, new Vector2(-1f, 0f), _agentBody); FixtureFactory.AttachCircle(0.5f, 0.5f, _agentBody, new Vector2(-2f, 0f)); //Right arm FixtureFactory.AttachRectangle(1.5f, 0.4f, 1f, new Vector2(1f, 0f), _agentBody); FixtureFactory.AttachCircle(0.5f, 0.5f, _agentBody, new Vector2(2f, 0f)); //Top arm FixtureFactory.AttachRectangle(0.4f, 1.5f, 1f, new Vector2(0f, 1f), _agentBody); FixtureFactory.AttachCircle(0.5f, 0.5f, _agentBody, new Vector2(0f, 2f)); //Bottom arm FixtureFactory.AttachRectangle(0.4f, 1.5f, 1f, new Vector2(0f, -1f), _agentBody); FixtureFactory.AttachCircle(0.5f, 0.5f, _agentBody, new Vector2(0f, -2f)); _screen = screen; //GFX AssetCreator creator = _screen.ScreenManager.Assets; _box = new Sprite(creator.TextureFromVertices(PolygonTools.CreateRectangle(1.75f, 0.2f), MaterialType.Blank, Color.White, 1f)); _knob = new Sprite(creator.CircleTexture(0.5f, MaterialType.Blank, Color.Orange, 1f)); _offset = ConvertUnits.ToDisplayUnits(2f); }
public Objects(World world, ScreenManager screenManager, Vector2 startPosition, Vector2 endPosition, int count, float radius, ObjectType type, float toothHeight = 1f) { _batch = screenManager.SpriteBatch; _bodyRadius = radius; BodyList = new List <Body>(count); for (int i = 0; i < count; i++) { switch (type) { case ObjectType.Circle: BodyList.Add(world.CreateCircle(radius, 1f)); break; case ObjectType.Rectangle: BodyList.Add(world.CreateRectangle(radius, radius, 1f)); _bodyRadius = radius / 2f; break; case ObjectType.Star: BodyList.Add(world.CreateGear(radius, 10, 0f, toothHeight, 1f)); _bodyRadius = radius * 2.7f; break; case ObjectType.Gear: BodyList.Add(world.CreateGear(radius, 10, 100f, toothHeight, 1f)); _bodyRadius = radius * 2.7f; break; } } for (int i = 0; i < BodyList.Count; i++) { Body body = BodyList[i]; body.BodyType = BodyType.Dynamic; body.Position = Vector2.Lerp(startPosition, endPosition, i / (float)(count - 1)); foreach (Fixture fixture in body.FixtureList) { fixture.Restitution = 0.7f; fixture.Friction = 0.2f; fixture.CollisionCategories = Category.All; fixture.CollidesWith = Category.All; } } //GFX AssetCreator creator = screenManager.Assets; switch (type) { case ObjectType.Circle: _object = new Sprite(creator.CircleTexture(radius, MaterialType.Dots, Color.DarkRed, 0.8f, 24f)); break; case ObjectType.Rectangle: _object = new Sprite(creator.TextureFromVertices(PolygonTools.CreateRectangle(radius / 2f, radius / 2f), MaterialType.Dots, Color.Blue, 0.8f, 24f)); break; case ObjectType.Star: _object = new Sprite(creator.TextureFromVertices(PolygonTools.CreateGear(radius, 10, 0f, toothHeight), MaterialType.Dots, Color.Yellow, 0.8f, 24f)); break; case ObjectType.Gear: _object = new Sprite(creator.TextureFromVertices(PolygonTools.CreateGear(radius, 10, 100f, toothHeight), MaterialType.Dots, Color.DarkGreen, 0.8f, 24f)); break; } }
public Objects(World world, PhysicsGameScreen screen, Vector2 startPosition, Vector2 endPosition, int count, float radius, ObjectType type) { _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; } _screen = screen; //GFX AssetCreator creator = _screen.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; } }