public void LoadPlatforms() { //_platform1 int width = Convert.ToInt32(ScreenManager.ScreenWidth * platform1WidthRatio); int height = Convert.ToInt32(ScreenManager.ScreenHeight * platform1HeightRatio); Vector2 position = new Vector2(-5 + width / 2f, 5 + ScreenManager.ScreenHeight - height / 2f); _platform1 = new RectanglePlatform(width, height, position, Color.White, Color.Black, 100); _platform1.Load(ScreenManager.GraphicsDevice, PhysicsSimulator); _angularSpringLever1 = new AngularSpringLever(); _angularSpringLever1.AttachPoint = 0; _angularSpringLever1.RectangleWidth = 200; _angularSpringLever1.RectangleHeight = 20; _angularSpringLever1.SpringConstant = 1000000; _angularSpringLever1.DampningConstant = 5000; _angularSpringLever1.CollisionGroup = 100; Vector2 springPosition = position + new Vector2(width / 2f, -height / 2f) + new Vector2(-_angularSpringLever1.RectangleHeight - 5, .4f * height); _angularSpringLever1.Position = springPosition; _angularSpringLever1.Load(ScreenManager.GraphicsDevice, PhysicsSimulator); //platform 2 width = Convert.ToInt32(ScreenManager.ScreenWidth * platform2WidthRatio); height = Convert.ToInt32(ScreenManager.ScreenHeight * platform2HeightRatio); position = new Vector2(ScreenManager.ScreenCenter.X, 5 + ScreenManager.ScreenHeight - height / 2f); _platform2 = new RectanglePlatform(width, height, position, Color.White, Color.Black, 100); _platform2.Load(ScreenManager.GraphicsDevice, PhysicsSimulator); _angularSpringLever2 = new AngularSpringLever(); _angularSpringLever2.AttachPoint = 2; _angularSpringLever2.RectangleWidth = 200; _angularSpringLever2.RectangleHeight = 20; _angularSpringLever2.SpringConstant = 1000000; _angularSpringLever2.DampningConstant = 5000; _angularSpringLever2.CollisionGroup = 100; springPosition = position + new Vector2(-width / 2f, -height / 2f) + new Vector2(_angularSpringLever2.RectangleHeight + 5, .2f * height); _angularSpringLever2.Position = springPosition; _angularSpringLever2.Load(ScreenManager.GraphicsDevice, PhysicsSimulator); _angularSpringLever3 = new AngularSpringLever(); _angularSpringLever3.AttachPoint = 0; _angularSpringLever3.RectangleWidth = 150; _angularSpringLever3.RectangleHeight = 20; _angularSpringLever3.SpringConstant = 10000000; _angularSpringLever3.DampningConstant = 1000; _angularSpringLever3.CollisionGroup = 100; springPosition = position + new Vector2(width / 2f, -height / 2f) + new Vector2(-_angularSpringLever3.RectangleHeight - 5, .1f * height); _angularSpringLever3.Position = springPosition; _angularSpringLever3.Load(ScreenManager.GraphicsDevice, PhysicsSimulator); _springRectangleRope1 = new SpringRectangleRope(); _springRectangleRope1.Position = springPosition + new Vector2(_angularSpringLever3.RectangleWidth - 5, 25); _springRectangleRope1.RectangleCount = 20; _springRectangleRope1.RectangleWidth = 15; _springRectangleRope1.RectangleHeight = 15; _springRectangleRope1.RectangleMass = .5f; _springRectangleRope1.SpringLength = 15; _springRectangleRope1.SpringConstant = 400; _springRectangleRope1.DampningConstant = 3f; _springRectangleRope1.Load(ScreenManager.GraphicsDevice, PhysicsSimulator); ControllerFactory.Instance.CreateLinearSpring(PhysicsSimulator, _angularSpringLever3.Body, new Vector2( _angularSpringLever3.RectangleWidth / 2f, 0), _springRectangleRope1.FirstBody, Vector2.Zero, 400, 3); //platform 3 width = Convert.ToInt32(ScreenManager.ScreenWidth * platform3WidthRatio); height = Convert.ToInt32(ScreenManager.ScreenHeight * platform3HeightRatio); position = new Vector2(ScreenManager.ScreenWidth + 5 - width / 2f, 5 + ScreenManager.ScreenHeight - height / 2f); _platform3 = new RectanglePlatform(width, height, position, Color.White, Color.Black, 100); _platform3.Load(ScreenManager.GraphicsDevice, PhysicsSimulator); _hangingTexture = DrawingHelper.CreateCircleTexture(ScreenManager.GraphicsDevice, 40, Color.White, Color.Black); _hangingBody = BodyFactory.Instance.CreateCircleBody(PhysicsSimulator, 40, 1); _hangingBody.Position = new Vector2(position.X - 200, 200); _hangingGeom = GeomFactory.Instance.CreateCircleGeom(PhysicsSimulator, _hangingBody, 40, 20); ControllerFactory.Instance.CreateFixedLinearSpring(PhysicsSimulator, _hangingBody, new Vector2(0, -35), new Vector2(position.X - 200, 100), 2, .1f); _angularSpringLever4 = new AngularSpringLever(); _angularSpringLever4.AttachPoint = 2; _angularSpringLever4.RectangleWidth = 200; _angularSpringLever4.RectangleHeight = 20; _angularSpringLever4.SpringConstant = 1000000; _angularSpringLever4.DampningConstant = 1000; _angularSpringLever4.CollisionGroup = 100; springPosition = position + new Vector2(-width / 2f, -height / 2f) + new Vector2(_angularSpringLever4.RectangleHeight + 5, .7f * height); _angularSpringLever4.Position = springPosition; _angularSpringLever4.Load(ScreenManager.GraphicsDevice, PhysicsSimulator); height = (int)(ScreenManager.ScreenHeight * .05f); _floor = new RectanglePlatform(ScreenManager.ScreenWidth + 10, height, new Vector2(ScreenManager.ScreenCenter.X, ScreenManager.ScreenHeight + 5 - height / 2), Color.White, Color.Black, 0); _floor.Load(ScreenManager.GraphicsDevice, PhysicsSimulator); _springRectangleRope2 = new SpringRectangleRope(); _springRectangleRope2.Position = new Vector2(ScreenManager.ScreenCenter.X, 100); _springRectangleRope2.RectangleCount = 20; _springRectangleRope2.RectangleWidth = 10; _springRectangleRope2.RectangleHeight = 10; _springRectangleRope2.RectangleMass = .2f; _springRectangleRope2.SpringLength = 10; _springRectangleRope2.SpringConstant = 200; _springRectangleRope2.DampningConstant = 4f; _springRectangleRope2.CollisionGroup = 1; //same as _agent collision group _springRectangleRope2.Load(ScreenManager.GraphicsDevice, PhysicsSimulator); ControllerFactory.Instance.CreateLinearSpring(PhysicsSimulator, _agent.Body, Vector2.Zero, _springRectangleRope2.FirstBody, Vector2.Zero, 200, 4f); }
public void LoadPlatforms() { //platform1 int width = Convert.ToInt32(ScreenWidth * _platform1WidthRatio); int height = Convert.ToInt32(ScreenHeight * _platform1HeightRatio); Vector2 position = new Vector2(-5 + width / 2f, 5 + ScreenHeight - height / 2f); Vector2 springPosition = Vector2.Zero; _platform1 = new RectanglePlatform(width, height, position, 100); _platform1.Load(this, physicsSimulator); _angularSpringLever1 = new AngularSpringLever(); _angularSpringLever1.AttachPoint = 0; _angularSpringLever1.RectangleWidth = 200; _angularSpringLever1.RectangleHeight = 20; _angularSpringLever1.SpringConstant = 1000000; _angularSpringLever1.DampningConstant = 5000; _angularSpringLever1.CollisionGroup = 100; springPosition = position + new Vector2(width / 2f, -height / 2f) + new Vector2(-_angularSpringLever1.RectangleHeight - 5, .4f * height); _angularSpringLever1.Position = springPosition; _angularSpringLever1.Load(this, physicsSimulator); //platform 2 width = Convert.ToInt32(ScreenWidth * _platform2WidthRatio); height = Convert.ToInt32(ScreenHeight * _platform2HeightRatio); position = new Vector2(ScreenCenter.X, 5 + ScreenHeight - height / 2f); _platform2 = new RectanglePlatform(width, height, position, 100); _platform2.Load(this, physicsSimulator); _angularSpringLever2 = new AngularSpringLever(); _angularSpringLever2.AttachPoint = 2; _angularSpringLever2.RectangleWidth = 200; _angularSpringLever2.RectangleHeight = 20; _angularSpringLever2.SpringConstant = 1000000; _angularSpringLever2.DampningConstant = 5000; _angularSpringLever2.CollisionGroup = 100; springPosition = position + new Vector2(-width / 2f, -height / 2f) + new Vector2(_angularSpringLever2.RectangleHeight + 5, .2f * height); _angularSpringLever2.Position = springPosition; _angularSpringLever2.Load(this, physicsSimulator); _angularSpringLever3 = new AngularSpringLever(); _angularSpringLever3.AttachPoint = 0; _angularSpringLever3.RectangleWidth = 150; _angularSpringLever3.RectangleHeight = 20; _angularSpringLever3.SpringConstant = 1000000; _angularSpringLever3.DampningConstant = 1000; _angularSpringLever3.CollisionGroup = 100; springPosition = position + new Vector2(width / 2f, -height / 2f) + new Vector2(-_angularSpringLever3.RectangleHeight - 5, .1f * height); _angularSpringLever3.Position = springPosition; _angularSpringLever3.Load(this, physicsSimulator); _springRectangleRope1 = new SpringRectangleRope(); _springRectangleRope1.Position = springPosition + new Vector2(_angularSpringLever3.RectangleWidth - 5, 25); _springRectangleRope1.RectangleCount = 20; _springRectangleRope1.RectangleWidth = 15; _springRectangleRope1.RectangleHeight = 15; _springRectangleRope1.RectangleMass = .5f; _springRectangleRope1.SpringLength = 15; _springRectangleRope1.SpringConstant = 400; _springRectangleRope1.DampningConstant = 3f; _springRectangleRope1.Load(this, physicsSimulator); SpringFactory.Instance.CreateLinearSpring(physicsSimulator, _angularSpringLever3.Body, new Vector2( _angularSpringLever3.RectangleWidth / 2f, 0), _springRectangleRope1.FirstBody, Vector2.Zero, 400, 3); //platform 3 width = Convert.ToInt32(ScreenWidth * _platform3WidthRatio); height = Convert.ToInt32(ScreenHeight * _platform3HeightRatio); position = new Vector2(ScreenWidth + 5 - width / 2f, 5 + ScreenHeight - height / 2f); _platform3 = new RectanglePlatform(width, height, position, 100); _platform3.Load(this, physicsSimulator); _hangingBody = BodyFactory.Instance.CreateCircleBody(physicsSimulator, 40, 1); AddCircleToCanvas(_hangingBody, 40); _hangingBody.Position = new Vector2(position.X - 200, 200); GeomFactory.Instance.CreateCircleGeom(physicsSimulator, _hangingBody, 40, 20); SpringFactory.Instance.CreateFixedLinearSpring(physicsSimulator, _hangingBody, new Vector2(0, -35), new Vector2(position.X - 200, 100), 2, .1f); _angularSpringLever4 = new AngularSpringLever(); _angularSpringLever4.AttachPoint = 2; _angularSpringLever4.RectangleWidth = 200; _angularSpringLever4.RectangleHeight = 20; _angularSpringLever4.SpringConstant = 1000000; _angularSpringLever4.DampningConstant = 1000; _angularSpringLever4.CollisionGroup = 100; springPosition = position + new Vector2(-width / 2f, -height / 2f) + new Vector2(_angularSpringLever4.RectangleHeight + 5, .7f * height); _angularSpringLever4.Position = springPosition; _angularSpringLever4.Load(this, physicsSimulator); height = (int)(ScreenHeight * .05f); _floor = new RectanglePlatform((int)(ScreenWidth + 10), height, new Vector2(ScreenCenter.X, ScreenHeight + 5 - height / 2), 0); _floor.Load(this, physicsSimulator); _springRectangleRope2 = new SpringRectangleRope(); _springRectangleRope2.Position = new Vector2(ScreenCenter.X, 100); _springRectangleRope2.RectangleCount = 20; _springRectangleRope2.RectangleWidth = 8; _springRectangleRope2.RectangleHeight = 8; _springRectangleRope2.RectangleMass = .2f; _springRectangleRope2.SpringLength = 8; _springRectangleRope2.SpringConstant = 200; _springRectangleRope2.DampningConstant = 4f; _springRectangleRope2.CollisionGroup = 1; //same as agent collision group _springRectangleRope2.Load(this, physicsSimulator); SpringFactory.Instance.CreateLinearSpring(physicsSimulator, _agent.Body, Vector2.Zero, _springRectangleRope2.FirstBody, Vector2.Zero, 200, 2f); }