private Body BuildHexagon(BodyRenderer renderer, Color color, Vector2 pos, float radius, float spacing) { var poly = ShapeFactory.Hexagon(Vector2.Zero, radius); var body = Physic.World.CreatePolygon(new Vertices(poly), 1, pos); body.SetCollisionType(HexPhysicTypes.Ground); if (radius < 5) { body.BodyType = BodyType.Dynamic; body.AngularDamping = 5f; /*var distanceJoint = K2.Physic.JointFactory.CreateFixedDistanceJoint(body, Vector2.Zero, pos); distanceJoint.Frequency = 10; distanceJoint.Length = radius * .2f; distanceJoint.DampingRatio = 1;*/ var j = new FixedMouseJoint(body, pos) { Frequency = 1000, MaxForce = 100, DampingRatio = 1, Breakpoint = 150, }; Physic.World.AddJoint(j); } renderer.Add(body, color); return body; }
public HexActor(BodyRenderer renderer, Rectangle area) { var palette = Palette.FromXmlFile(DataPack.Colors.RedAndBlue); var color = palette.GetColors(3).ToArray()[2]; var poly = ShapeFactory.Hexagon(Vector2.Zero, .5f); // body var body = Add(new Body(Physic.World) { BodyType = BodyType.Dynamic, Position = area.Center.ToVector2(), //LinearDamping = 10, AngularDamping = 5, IsBullet = true }); Add(new BodyStateRecorder(body, "cameraTarget")); Add(new SoundListener(body)); // main fixture var bodyFixture = body.AttachPolygon(new Vertices(poly), 1); bodyFixture.Restitution = 0; bodyFixture.Friction = 0f; bodyFixture.SetCollisionType(HexPhysicTypes.Actor); // control var ui = Add(new GameUI()); var surfaceController = Add(new SurfaceMovementControl(body, 200f, 300f)); var boost = ui.Add(new BoostController(body) { BoostMin = 500, BoostMax = 10000 }); ui.Add(new MovementKeyboardInput(surfaceController, boost)); Add(new GroundConstraint(body, bodyFixture, surfaceController)); ui.Add(new Cursor(DataPack.Textures.Square) { Color = color, Size = 5f }); // camera var tracker = ui.Add(new BodyMouseTracker(body, .4f)); ui.Add(new TrackingBodyCameraController(tracker, UpdateTime.Sim)); ui.Add(new CameraStateRecorder()); var camConstraint = ui.Add(new CameraConstraint { TopLeft = Vector2.Zero, BottomRight = new Vector2(area.Width, area.Height) }); ui.Add(new MouseZoomController(.1f, .5f) { WheelRange = 3 }); Render.Camera.Position = body.Position; // render renderer.Add(body, color); Add(new Disposer(() => renderer.Remove(body))); }