public void Draw(GameTime gameTime, SpriteBatch spriteBatch) { spriteBatch.Begin(0, null, null, null, null, null, _camera.View); foreach (var entity in _WorldEntity.WorldElements) { if (entity is PhysicsWorldElementEntity) { PhysicsWorldElementEntity physicsEntity = entity as PhysicsWorldElementEntity; if (physicsEntity.Texture2D != null) { spriteBatch.Draw(physicsEntity.Texture2D, ConvertUnits.ToDisplayUnits(physicsEntity.Position), null, Color.White, physicsEntity.Rotation, physicsEntity.Origin, 1f, SpriteEffects.None, 0f); } } else if (entity is TextElementEntity) { TextElementEntity textEntity = entity as TextElementEntity; spriteBatch.DrawString(textEntity.Font, textEntity.Text, ConvertUnits.ToDisplayUnits(textEntity.Position), textEntity.FillColor); } //switch (entity.ElementType) //{ // case ElementType.Circle: // _CircleElementRenderer.Draw(gameTime, entity as CircleElementEntity); // break; // case ElementType.Elipsis: // throw new NotImplementedException(); // case ElementType.Polygon: // throw new NotImplementedException(); // case ElementType.Rectangle: // throw new NotImplementedException(); // default: // throw new NotSupportedException(); //} } spriteBatch.End(); }
public Texture2D TextureFromWorldElement(PhysicsWorldElementEntity elementEntity) { Vertices vertices; switch (elementEntity.ElementType) { case ElementType.Circle: throw new NotImplementedException(); case ElementType.Elipsis: throw new NotImplementedException(); case ElementType.Polygon: PolygonElementEntity polygon = elementEntity as PolygonElementEntity; vertices = new Vertices(polygon.Vertices.Count); foreach (var vertex in polygon.Vertices) { vertices.Add(ConvertUnits.ToDisplayUnits(vertex)); } polygon.Origin = polygon.Vertices.GetCentroid(); break; case ElementType.Rectangle: RectangleElementEntity rectangle = elementEntity as RectangleElementEntity; vertices = new Vertices(4); vertices.Add(Vector2.Zero); vertices.Add(new Vector2(ConvertUnits.ToDisplayUnits(rectangle.Width), 0)); vertices.Add(new Vector2(ConvertUnits.ToDisplayUnits(rectangle.Width), ConvertUnits.ToDisplayUnits(rectangle.Height))); vertices.Add(new Vector2(0, ConvertUnits.ToDisplayUnits(rectangle.Height))); rectangle.Origin = new Vector2(ConvertUnits.ToDisplayUnits(rectangle.Width / 2f), ConvertUnits.ToDisplayUnits(rectangle.Height / 2f)); break; default: throw new NotSupportedException(String.Format("ElementType '{0}' is not supported", elementEntity.ElementType)); } return(TextureFromVertices(vertices, elementEntity.Material, elementEntity.FillColor, elementEntity.OutlineColor.A != 0, elementEntity.OutlineColor, elementEntity.MaterialScale)); }
public XElement FromWorldElementEntity(PhysicsWorldElementEntity entity) { throw new NotImplementedException(); }
public override void LoadContent() { base.LoadContent(); XElement xElement = XElement.Load(_levelXml); var test = xElement.Elements(); foreach (var t in test) { System.Console.WriteLine(t.Name); } _worldEntity = WorldTransformer.Instance.ToEntity(xElement); Debug.Assert(_worldEntity != null); _worldRenderer = new WorldRenderer(ScreenManager.GraphicsDevice, _worldEntity); _textureGenerator = new TextureGenerator(ScreenManager.GraphicsDevice, _materials); _world = new World(_worldEntity.PhysicsSettings.Gravity); WorldElements = new Dictionary <string, IWorldElementEntity>(_worldEntity.WorldElements.Count); foreach (var entity in _worldEntity.WorldElements) { if (entity is PhysicsWorldElementEntity) { PhysicsWorldElementEntity physicsEntity = entity as PhysicsWorldElementEntity; physicsEntity.Texture2D = _textureGenerator.TextureFromWorldElement(physicsEntity); Body body; switch (physicsEntity.ElementType) { case ElementType.Circle: var circleEntity = physicsEntity as CircleElementEntity; body = BodyFactory.CreateCircle(_world, circleEntity.Radius, circleEntity.Density, physicsEntity.Position); break; case ElementType.Elipsis: var elipsisEntity = physicsEntity as ElipsisElementEntity; body = BodyFactory.CreateEllipse(_world, elipsisEntity.Radius.X, elipsisEntity.Radius.Y, 8, elipsisEntity.Density, physicsEntity.Position); break; case ElementType.Polygon: var polygonEntity = physicsEntity as PolygonElementEntity; body = BodyFactory.CreatePolygon(_world, polygonEntity.Vertices, polygonEntity.Density, physicsEntity.Position); break; case ElementType.Rectangle: var rectangleEntity = physicsEntity as RectangleElementEntity; body = BodyFactory.CreateRectangle(_world, rectangleEntity.Width, rectangleEntity.Height, rectangleEntity.Density, physicsEntity.Position); break; default: throw new NotSupportedException(); } body.BodyType = physicsEntity.BodyType; //body.Position = physicsEntity.Position; body.Rotation = physicsEntity.Rotation; //body.Inertia = 0.1f; physicsEntity.Body = body; if (physicsEntity.Name != null) { //TODO prevent duplicate names... or something else WorldElements.Add(physicsEntity.Name, physicsEntity); } } } }