public override void LoadContent() { base.LoadContent(); World.Gravity = Vector2.Zero; _border = new Border(World, Lines, Framework.GraphicsDevice); for (int i = 0; i < 3; i++) { _breakableCookie[i] = Framework.Content.Load <BodyContainer>("Pipeline/BreakableBody")["Cookie"].CreateBreakable(World); _breakableCookie[i].Strength = 120f; _breakableCookie[i].MainBody.Position = new Vector2(-20.33f + 15f * i, -5.33f); } _breakableSprite = new List <Sprite>(); List <Texture2D> textures = ContentWrapper.BreakableTextureFragments(_breakableCookie[0], "Cookie"); for (int i = 0; i < _breakableCookie[0].Parts.Count; i++) { AABB bounds; Transform transform; _breakableCookie[0].Parts[i].Body.GetTransform(out transform); _breakableCookie[0].Parts[i].Shape.ComputeAABB(out bounds, ref transform, 0); Vector2 origin = ConvertUnits.ToDisplayUnits(_breakableCookie[0].Parts[i].Body.Position - bounds.LowerBound); _breakableSprite.Add(new Sprite(textures[i], origin)); } _completeSprite = new Sprite(ContentWrapper.GetTexture("Cookie"), Vector2.Zero); }
public override void LoadContent() { base.LoadContent(); LoadOptions(); Viewport viewport = Framework.GraphicsDevice.Viewport; _font = ContentWrapper.GetFont("MenuFont"); _checkmark = ContentWrapper.GetTexture("Checkmark"); _optionStart = (viewport.Height - (_optionEntries.Count - 1) * (_optionEntrySize.Y + EntrySpacer)) / 2f; _optionSpacing = _optionEntrySize.Y + EntrySpacer; for (int i = 0; i < _optionEntries.Count; i++) { _optionEntries[i].InitializePosition(new Vector2(viewport.Width / 2f, _optionStart + _optionSpacing * i)); } // The background includes a border somewhat larger than the text itself. _topLeft.X = viewport.Width / 2f - _optionEntrySize.X / 2f - HorizontalPadding; _topLeft.Y = _optionStart - _optionEntrySize.Y / 2f - VerticalPadding; _bottomRight.X = viewport.Width / 2f + _optionEntrySize.X / 2f + HorizontalPadding; _bottomRight.Y = _optionStart + (_optionEntries.Count - 1) * _optionSpacing + _optionEntrySize.Y / 2f + VerticalPadding; }
public override void LoadContent() { base.LoadContent(); World.Gravity = Vector2.Zero; _border = new Border(World, LineBatch, Framework.GraphicsDevice); List <Vertices> tracedObject = Framework.Content.Load <List <Vertices> >("Pipeline/Object"); //scale the vertices from graphics space to sim space Vector2 vertScale = new Vector2(1f / 24f); AABB aabb = new AABB(); foreach (Vertices vertices in tracedObject) { vertices.Scale(new Vector2(1f, -1f)); vertices.Translate(new Vector2(0f, 0f)); var vaabb = vertices.GetAABB(); aabb.Combine(ref vaabb); } _polygonSize = new Vector2(aabb.Width, aabb.Height); // Create a single body with multiple fixtures _compound = World.CreateCompoundPolygon(tracedObject, 1f, Vector2.Zero, 0, BodyType.Dynamic); SetUserAgent(_compound, 200f, 200f); _objectSprite = new Sprite(ContentWrapper.GetTexture("Logo"), ContentWrapper.CalculateOrigin(_compound, 24f)); }
/// <summary> /// Loads graphics content for this screen. The background texture is quite /// big, so we use our own local ContentManager to load it. This allows us /// to unload before going from the menus into the game itself, wheras if we /// used the shared ContentManager provided by the Game class, the content /// would remain loaded forever. /// </summary> public override void LoadContent() { _logoTexture = ContentWrapper.GetTexture("Logo"); Viewport viewport = Framework.GraphicsDevice.Viewport; _logoPosition = new Vector2((viewport.Width - _logoTexture.Width) / 2f - 100f, (viewport.Height - _logoTexture.Height) / 2f); }
public void LoadContent(Viewport viewport) { Texture2D cursorTexture; cursorTexture = ContentWrapper.GetTexture("Cursor"); _cursorSprite = new Sprite(cursorTexture, Vector2.One); _viewport = viewport; }
public override void LoadContent() { base.LoadContent(); World.Gravity = Vector2.Zero; _border = new Border(World, LineBatch, Framework.GraphicsDevice); BodyContainer bodyContainer = Framework.Content.Load <BodyContainer>("Pipeline/BreakableBody"); BodyTemplate bodyTemplate = bodyContainer["Cookie"]; if (!_isLoaded) //we flip vertices once. { foreach (FixtureTemplate f in bodyTemplate.Fixtures) { var shape = (PolygonShape)f.Shape; shape.Vertices.Scale(new Vector2(1f, -1f)); // flip Vert shape.Vertices.Translate(new Vector2(-5.33f, 5.33f)); } _isLoaded = true; } for (int i = 0; i < 3; i++) { List <Shape> shapes = new List <Shape>(); foreach (FixtureTemplate f in bodyTemplate.Fixtures) { shapes.Add(f.Shape); } _breakableCookie[i] = new tainicom.Aether.Physics2D.Common.PhysicsLogic.BreakableBody(World, shapes); _breakableCookie[i].Strength = 120f; _breakableCookie[i].MainBody.Position = new Vector2(-15.0f + 15f * i, 0f); } _breakableSprite = new List <Sprite>(); List <Texture2D> textures = ContentWrapper.BreakableTextureFragments(_breakableCookie[0], "Cookie", 24f); for (int i = 0; i < _breakableCookie[0].Parts.Count; i++) { AABB bounds; Transform transform; _breakableCookie[0].Parts[i].Body.GetTransform(out transform); _breakableCookie[0].Parts[i].Shape.ComputeAABB(out bounds, ref transform, 0); Vector2 origin = 24f * (_breakableCookie[0].Parts[i].Body.Position - bounds.LowerBound); _breakableSprite.Add(new Sprite(textures[i], origin)); } _completeSprite = new Sprite(ContentWrapper.GetTexture("Cookie")); }
public override void LoadContent() { base.LoadContent(); World.Gravity = Vector2.Zero; _border = new Border(World, Lines, Framework.GraphicsDevice); List <Vertices> tracedObject = Framework.Content.Load <List <Vertices> >("Pipeline/Object"); // Create a single body with multiple fixtures _compound = BodyFactory.CreateCompoundPolygon(World, tracedObject, 1f, Vector2.Zero, 0, BodyType.Dynamic); SetUserAgent(_compound, 200f, 200f); _objectSprite = new Sprite(ContentWrapper.GetTexture("Logo"), ContentWrapper.CalculateOrigin(_compound)); }
public override void LoadContent() { base.LoadContent(); Viewport viewport = Framework.GraphicsDevice.Viewport; _font = ContentWrapper.GetFont("MenuFont"); _samplesLogo = ContentWrapper.GetTexture("SamplesLogo"); _titleOrigin = new Vector2(_samplesLogo.Width, _samplesLogo.Height) / 2f; _titlePosition = new Vector2(viewport.Width / 2f, TitleBarHeight / 2f); float horizontalSpacing = (viewport.Width / 2f - _menuEntrySize.X - EntrySpacer - _menuEntrySize.Y) / 3f; float verticalSpacing = (viewport.Height - TitleBarHeight - NumEntries * (_menuEntrySize.Y + EntrySpacer) + EntrySpacer) / 2f; _previewOrigin = new Vector2(viewport.Width / 4f, viewport.Height / 4f); PreviewPosition = new Vector2(viewport.Width - _previewOrigin.X - horizontalSpacing, (viewport.Height - TitleBarHeight) / 2f + TitleBarHeight); _menuStart = _menuEntrySize.Y / 2f + verticalSpacing + TitleBarHeight; _menuSpacing = _menuEntrySize.Y + EntrySpacer; _menuEntries.Sort(); MenuEntry.InitializeEntries(-_menuEntrySize.X / 2f, _menuEntrySize.X / 2f + horizontalSpacing); for (int i = 0; i < _menuEntries.Count; i++) { _menuEntries[i].InitializePosition(_menuStart + _menuSpacing * i, i < NumEntries); } _menuSlider = new MenuSlider(new Vector2(_menuEntrySize.X + horizontalSpacing + EntrySpacer + _menuEntrySize.Y / 2f, _menuStart)); if (_menuEntries.Count > NumEntries) { _scrollSpacing = _menuSpacing * (NumEntries - 1) / (_menuEntries.Count - NumEntries); } else { _scrollSpacing = 0f; } _scrollHover = false; _scrollLock = false; }
public override void LoadContent() { base.LoadContent(); World.Gravity = new Vector2(0f, 10f); _loadedVertices = Framework.Content.Load <VerticesContainer>("Pipeline/Body"); _heartBody = Create(_loadedVertices["Heart"]); _heart = new Sprite(ContentWrapper.GetTexture("Heart"), ContentWrapper.CalculateOrigin(_heartBody)); _clubBody = Create(_loadedVertices["Club"]); _club = new Sprite(ContentWrapper.GetTexture("Club"), ContentWrapper.CalculateOrigin(_clubBody)); _spadeBody = Create(_loadedVertices["Spade"]); _spade = new Sprite(ContentWrapper.GetTexture("Spade"), ContentWrapper.CalculateOrigin(_spadeBody)); _diamondBody = Create(_loadedVertices["Diamond"]); _diamond = new Sprite(ContentWrapper.GetTexture("Diamond"), ContentWrapper.CalculateOrigin(_diamondBody)); }
public override void LoadContent() { base.LoadContent(); World.Gravity = new Vector2(0f, 10f); _border = new Border(World, Lines, Framework.GraphicsDevice); _body = Framework.Content.Load <BodyContainer>("Pipeline/Body"); _heartBody = _body["Heart"].Create(World); _heart = new Sprite(ContentWrapper.GetTexture("Heart"), ContentWrapper.CalculateOrigin(_heartBody)); _clubBody = _body["Club"].Create(World); _club = new Sprite(ContentWrapper.GetTexture("Club"), ContentWrapper.CalculateOrigin(_clubBody)); _spadeBody = _body["Spade"].Create(World); _spade = new Sprite(ContentWrapper.GetTexture("Spade"), ContentWrapper.CalculateOrigin(_spadeBody)); _diamondBody = _body["Diamond"].Create(World); _diamond = new Sprite(ContentWrapper.GetTexture("Diamond"), ContentWrapper.CalculateOrigin(_diamondBody)); }
public void Draw(Matrix projection, Matrix view) { _graphics.SamplerStates[0] = SamplerState.AnisotropicWrap; _graphics.RasterizerState = RasterizerState.CullNone; _basicEffect.Projection = projection; _basicEffect.View = view; _basicEffect.Texture = ContentWrapper.GetTexture("Blank"); _basicEffect.DiffuseColor = ContentWrapper.Black.ToVector3(); _basicEffect.CurrentTechnique.Passes[0].Apply(); _graphics.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, _borderVertices, 0, 8, _indexBuffer, 0, 8); _basicEffect.Texture = ContentWrapper.GetTexture("Stripe"); _basicEffect.DiffuseColor = ContentWrapper.Grey.ToVector3(); _basicEffect.CurrentTechnique.Passes[0].Apply(); _graphics.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, _borderVertices, 0, 8, _indexBuffer, 0, 8); _lines.Begin(projection, view); _lines.DrawLineShape(_anchor.FixtureList[0].Shape); _lines.End(); }
public override void LoadContent() { base.LoadContent(); World.Gravity = new Vector2(0f, -10f); _border = new Border(World, LineBatch, Framework.GraphicsDevice); _BodyContainer = Framework.Content.Load <BodyContainer>("Pipeline/Body"); _heart = new Sprite(ContentWrapper.GetTexture("Heart")); _club = new Sprite(ContentWrapper.GetTexture("Club")); _spade = new Sprite(ContentWrapper.GetTexture("Spade")); _diamond = new Sprite(ContentWrapper.GetTexture("Diamond")); if (!_flipped) { foreach (var b in _BodyContainer.Values) { foreach (var f in b.Fixtures) { var shape = (PolygonShape)f.Shape; shape.Vertices.Scale(new Vector2(1f, -1f)); // flip Vertices } } _flipped = true; } _heartBody = _BodyContainer["Heart"].Create(World); _clubBody = _BodyContainer["Club"].Create(World); _spadeBody = _BodyContainer["Spade"].Create(World); _diamondBody = _BodyContainer["Diamond"].Create(World); _heart.Origin = ContentWrapper.CalculateOrigin(_heartBody, 24f); _club.Origin = ContentWrapper.CalculateOrigin(_clubBody, 24f); _spade.Origin = ContentWrapper.CalculateOrigin(_spadeBody, 24f); _diamond.Origin = ContentWrapper.CalculateOrigin(_diamondBody, 24f); }
public WebOfGoo(World world, Vector2 position, float radius, int rings, int sides) { _ringBodys = new List <List <Body> >(rings); _ringJoints = new List <DistanceJoint>(); for (int i = 1; i < rings; i++) { Vertices vertices = PolygonTools.CreateCircle(i * 2.9f, sides); vertices.Translate(ref position); List <Body> bodies = new List <Body>(sides); //Create the first goo Body previous = BodyFactory.CreateCircle(world, radius, 0.2f, vertices[0]); previous.BodyType = BodyType.Dynamic; bodies.Add(previous); //Connect the first goo to the next for (int j = 1; j < vertices.Count; j++) { Body current = BodyFactory.CreateCircle(world, radius, 0.2f, vertices[j]); current.BodyType = BodyType.Dynamic; DistanceJoint joint = new DistanceJoint(previous, current, Vector2.Zero, Vector2.Zero); joint.Frequency = 4.0f; joint.DampingRatio = 0.5f; joint.Breakpoint = Breakpoint; world.AddJoint(joint); _ringJoints.Add(joint); previous = current; bodies.Add(current); } //Connect the first and the last goo DistanceJoint jointClose = new DistanceJoint(bodies[0], bodies[bodies.Count - 1], Vector2.Zero, Vector2.Zero); jointClose.Frequency = 4.0f; jointClose.DampingRatio = 0.5f; jointClose.Breakpoint = Breakpoint; world.AddJoint(jointClose); _ringJoints.Add(jointClose); _ringBodys.Add(bodies); } //Create an outer ring Vertices frame = PolygonTools.CreateCircle(rings * 2.9f - 0.9f, sides); frame.Translate(ref position); Body anchor = new Body(world, position); anchor.BodyType = BodyType.Static; //Attach the outer ring to the anchor for (int i = 0; i < _ringBodys[rings - 2].Count; i++) { DistanceJoint joint = new DistanceJoint(anchor, _ringBodys[rings - 2][i], frame[i], _ringBodys[rings - 2][i].Position, true); joint.Frequency = 8.0f; joint.DampingRatio = 0.5f; joint.Breakpoint = Breakpoint; world.AddJoint(joint); _ringJoints.Add(joint); } //Interconnect the rings for (int i = 1; i < _ringBodys.Count; i++) { for (int j = 0; j < sides; j++) { DistanceJoint joint = new DistanceJoint(_ringBodys[i - 1][j], _ringBodys[i][j], Vector2.Zero, Vector2.Zero); joint.Frequency = 4.0f; joint.DampingRatio = 0.5f; joint.Breakpoint = Breakpoint; world.AddJoint(joint); _ringJoints.Add(joint); } } _link = new Sprite(ContentWrapper.GetTexture("Link")); _goo = new Sprite(ContentWrapper.GetTexture("Goo")); }
public override void LoadContent() { base.LoadContent(); World.Gravity = new Vector2(0f, 10f); HasCursor = false; EnableCameraControl = true; _hzFront = 8.5f; _hzBack = 5.0f; _zeta = 0.85f; _maxSpeed = 50.0f; // terrain _ground = BodyFactory.CreateBody(World); { Vertices terrain = new Vertices(); terrain.Add(new Vector2(-20f, -5f)); terrain.Add(new Vector2(-20f, 0f)); terrain.Add(new Vector2(20f, 0f)); terrain.Add(new Vector2(25f, -0.25f)); terrain.Add(new Vector2(30f, -1f)); terrain.Add(new Vector2(35f, -4f)); terrain.Add(new Vector2(40f, 0f)); terrain.Add(new Vector2(45f, 0f)); terrain.Add(new Vector2(50f, 1f)); terrain.Add(new Vector2(55f, 2f)); terrain.Add(new Vector2(60f, 2f)); terrain.Add(new Vector2(65f, 1.25f)); terrain.Add(new Vector2(70f, 0f)); terrain.Add(new Vector2(75f, -0.3f)); terrain.Add(new Vector2(80f, -1.5f)); terrain.Add(new Vector2(85f, -3.5f)); terrain.Add(new Vector2(90f, 0f)); terrain.Add(new Vector2(95f, 0.5f)); terrain.Add(new Vector2(100f, 1f)); terrain.Add(new Vector2(105f, 2f)); terrain.Add(new Vector2(110f, 2.5f)); terrain.Add(new Vector2(115f, 1.3f)); terrain.Add(new Vector2(120f, 0f)); terrain.Add(new Vector2(160f, 0f)); terrain.Add(new Vector2(159f, 10f)); terrain.Add(new Vector2(201f, 10f)); terrain.Add(new Vector2(200f, 0f)); terrain.Add(new Vector2(240f, 0f)); terrain.Add(new Vector2(250f, -5f)); terrain.Add(new Vector2(250f, 10f)); terrain.Add(new Vector2(270f, 10f)); terrain.Add(new Vector2(270f, 0)); terrain.Add(new Vector2(310f, 0)); terrain.Add(new Vector2(310f, -5)); for (int i = 0; i < terrain.Count - 1; ++i) { FixtureFactory.AttachEdge(terrain[i], terrain[i + 1], _ground); } _ground.Friction = 0.6f; } // teeter board { _board = BodyFactory.CreateBody(World); _board.BodyType = BodyType.Dynamic; _board.Position = new Vector2(140.0f, -1.0f); PolygonShape box = new PolygonShape(1f); box.Vertices = PolygonUtils.CreateRectangle(10.0f, 0.25f); _teeter = new Sprite(ContentWrapper.TextureFromShape(box, "Stripe", ContentWrapper.Gold, ContentWrapper.Black, ContentWrapper.Black, 1f)); _board.CreateFixture(box); RevoluteJoint teeterAxis = JointFactory.CreateRevoluteJoint(World, _ground, _board, Vector2.Zero); teeterAxis.LowerLimit = -8.0f * MathConstants.Pi / 180.0f; teeterAxis.UpperLimit = 8.0f * MathConstants.Pi / 180.0f; teeterAxis.LimitEnabled = true; _board.ApplyAngularImpulse(-100.0f); } // bridge { _bridgeSegments = new List <Body>(); const int segmentCount = 20; PolygonShape shape = new PolygonShape(1f); shape.Vertices = PolygonUtils.CreateRectangle(1.0f, 0.125f); _bridge = new Sprite(ContentWrapper.TextureFromShape(shape, ContentWrapper.Gold, ContentWrapper.Black)); Body prevBody = _ground; for (int i = 0; i < segmentCount; ++i) { Body body = BodyFactory.CreateBody(World); body.BodyType = BodyType.Dynamic; body.Position = new Vector2(161f + 2f * i, 0.125f); Fixture fix = body.CreateFixture(shape); fix.Friction = 0.6f; JointFactory.CreateRevoluteJoint(World, prevBody, body, -Vector2.UnitX); prevBody = body; _bridgeSegments.Add(body); } JointFactory.CreateRevoluteJoint(World, _ground, prevBody, Vector2.UnitX); } // boxes { _boxes = new List <Body>(); PolygonShape box = new PolygonShape(1f); box.Vertices = PolygonUtils.CreateRectangle(0.5f, 0.5f); _box = new Sprite(ContentWrapper.TextureFromShape(box, "Square", ContentWrapper.Sky, ContentWrapper.Sunset, ContentWrapper.Black, 1f)); Body body = BodyFactory.CreateBody(World); body.BodyType = BodyType.Dynamic; body.Position = new Vector2(220f, -0.5f); body.CreateFixture(box); _boxes.Add(body); body = BodyFactory.CreateBody(World); body.BodyType = BodyType.Dynamic; body.Position = new Vector2(220f, -1.5f); body.CreateFixture(box); _boxes.Add(body); body = BodyFactory.CreateBody(World); body.BodyType = BodyType.Dynamic; body.Position = new Vector2(220f, -2.5f); body.CreateFixture(box); _boxes.Add(body); } // car { Vertices vertices = new Vertices(8); vertices.Add(new Vector2(-2.5f, 0.08f)); vertices.Add(new Vector2(-2.375f, -0.46f)); vertices.Add(new Vector2(-0.58f, -0.92f)); vertices.Add(new Vector2(0.46f, -0.92f)); vertices.Add(new Vector2(2.5f, -0.17f)); vertices.Add(new Vector2(2.5f, 0.205f)); vertices.Add(new Vector2(2.3f, 0.33f)); vertices.Add(new Vector2(-2.25f, 0.35f)); PolygonShape chassis = new PolygonShape(vertices, 2f); _car = BodyFactory.CreateBody(World); _car.BodyType = BodyType.Dynamic; _car.Position = new Vector2(0.0f, -1.0f); _car.CreateFixture(chassis); _wheelBack = BodyFactory.CreateBody(World); _wheelBack.BodyType = BodyType.Dynamic; _wheelBack.Position = new Vector2(-1.709f, -0.78f); Fixture fix = _wheelBack.CreateFixture(new CircleShape(0.5f, 0.8f)); fix.Friction = 0.9f; _wheelFront = BodyFactory.CreateBody(World); _wheelFront.BodyType = BodyType.Dynamic; _wheelFront.Position = new Vector2(1.54f, -0.8f); _wheelFront.CreateFixture(new CircleShape(0.5f, 1f)); Vector2 axis = new Vector2(0.0f, -1.2f); _springBack = new WheelJoint(_car, _wheelBack, _wheelBack.Position, axis, true); _springBack.MotorSpeed = 0.0f; _springBack.MaxMotorTorque = 20.0f; _springBack.MotorEnabled = true; _springBack.Frequency = _hzBack; _springBack.DampingRatio = _zeta; World.AddJoint(_springBack); _springFront = new WheelJoint(_car, _wheelFront, _wheelFront.Position, axis, true); _springFront.MotorSpeed = 0.0f; _springFront.MaxMotorTorque = 10.0f; _springFront.MotorEnabled = false; _springFront.Frequency = _hzFront; _springFront.DampingRatio = _zeta; World.AddJoint(_springFront); // GFX _carBody = new Sprite(ContentWrapper.GetTexture("Car"), ContentWrapper.CalculateOrigin(_car)); _wheel = new Sprite(ContentWrapper.GetTexture("Wheel")); } Camera.MinRotation = -0.05f; Camera.MaxRotation = 0.05f; Camera.TrackingBody = _car; Camera.EnableTracking = true; }