public override bool Equals(object obj) { if (obj is WorldEntity) { WorldEntity w2 = obj as WorldEntity; if (!PhysicsSettings.Equals(w2.PhysicsSettings)) { return(false); } if (WorldInfo.Equals(w2.WorldInfo)) { return(false); } foreach (var e1 in WorldElements) { bool contains = false; foreach (var e2 in w2.WorldElements) { if (e1.Equals(e2)) { contains = true; break; } } if (!contains) { return(false); } } return(true); } return(base.Equals(obj)); }
private WorldEntity createTestWorld() { WorldEntity world = new WorldEntity(); world.WorldInfo = new WorldInfoEntity(); world.WorldInfo.Language = "en"; world.WorldInfo.Name = "UnitTestLevel"; world.WorldInfo.Description = "Test \n \"Description"; world.PhysicsSettings = new PhysicsSettingsEntity(); world.PhysicsSettings.Gravity = Vector2.Zero; RectangleElementEntity rectangle = new RectangleElementEntity(); rectangle.FillColor = Color.Wheat; rectangle.OutlineColor = Color.Black; rectangle.Position = new Vector2(5, 5); rectangle.Width = 5; rectangle.Height = 5; world.WorldElements.Add(rectangle); return world; }
public WorldRenderer(GraphicsDevice graphicsDevice, WorldEntity worldEntity) { _WorldEntity = worldEntity; _camera = new Camera2D(graphicsDevice); }
public virtual void 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(GraphicsDevice, _worldEntity); _textureGenerator = new TextureGenerator(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); } } } }