Beispiel #1
0
 public virtual void UnloadContent()
 {
     _world.Clear();
     _world = null;
     _worldRenderer = null;
     _textureGenerator = null;
 }
Beispiel #2
0
        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);
                    }
                }
            }
        }
Beispiel #3
0
        public override void UnloadContent()
        {
            base.UnloadContent();

            _world.Clear();
            _world = null;
            _worldRenderer = null;
            _textureGenerator = null;
        }