示例#1
0
        public void LoadContent()
        {
            _spriteBatch = new SpriteBatch(_graphics);

            _world = new StaticEntityWorld(_game.Services);

            var pp = _graphics.PresentationParameters;

            _camera              = new DefaultCamera(null, new Viewport(0, 0, pp.BackBufferWidth, pp.BackBufferHeight));
            _cameraNode          = _world.Scene.Root.CreateChild("Camera");
            _cameraNode.Position = new Vector3(_camera.ScreenSize / 2.0f, 0.0f);
            _cameraNode.Scale    = new Vector3(.5f);
            _cameraNode.Attach(_camera);

            // Create the tile map.
            _terrain = new Terrain(new Vector2(102.4f, 102.4f), 51.2f, 9);
            _terrain.DebugEnabled = true;
            _world.Add(_terrain);

            // Create the circle brush.
            _circleBrush = new CircleBrush(2.5f);

            _circleBrushNode = _world.Scene.CreateSceneNode();
            _circleBrushNode.Attach(new CircleRenderable(2.5f, 64)
            {
                Color = Vector3.One
            });
        }
示例#2
0
        public void LoadContent()
        {
            _spriteBatch = new SpriteBatch(_graphics);
            _world       = new DynamicEntityWorld(_game.Services);
            var pp = _graphics.PresentationParameters;

            _debugView = new DebugViewXNA(_world.PhysicsWorld);
            _debugView.LoadContent(_graphics, _content);

            _camera     = new DefaultCamera(null, new Viewport(0, 0, pp.BackBufferWidth, pp.BackBufferHeight));
            _cameraNode = _world.Scene.Root.CreateChild("Camera");
            _cameraNode.Attach(_camera);

            // Create the tile map.
            var terrainSize = new Vector2(4096.0f, 2048.0f);

            _terrain = new Terrain(terrainSize, 128.0f, 7)
            {
                DebugEnabled = false,
                Position     = new Vector3(50.0f, -terrainSize.Y / 2.0f, 0.0f),
                TextureName  = @"Textures\SpaceRock"
            };
            _world.Add(_terrain);

            GenerateTunnels(new Vector2(50.0f, 0));

            // Create the circle brush.
            _circleBrush = new CircleBrush(2.5f);

            _circleBrushNode = _world.Scene.CreateSceneNode();
            _circleBrushNode.Attach(new CircleRenderable(2.5f, 64)
            {
                Color = Vector3.One
            });

            // Dust cloud
            _dustCloud          = _world.Scene.CreateSceneNode("DustCloud");
            _dustCloud.Position = new Vector3(0.0f, 0.0f, -1.0f);
            _dustCloud.Attach(new DustCloud());
            _world.Scene.Root.AddChild(_dustCloud);

            // Player
            _playerEntity = new SpaceShip();
            _playerEntity.Attach(new PlayerController());
            _playerEntity.Orientation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, MathHelper.ToRadians(90.0f));
            _world.Add(_playerEntity);

            _payloadEntity             = new Payload();
            _payloadEntity.Orientation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, MathHelper.ToRadians(90.0f));
            _world.Add(_payloadEntity);

            _payloadChain = PayloadChain.Connect(_playerEntity, _payloadEntity, Vector2.UnitX * -20.0f);
        }
示例#3
0
        /// <summary>
        /// Changes the state of the intersected quads.
        /// </summary>
        /// <param name="brush">The brush.</param>
        /// <param name="state">The state, either enabled or disabled.</param>
        /// <param name="suppressUpdate">If true, does not update if any quads changed state.</param>
        /// <returns>True if any quads were changed.</returns>
        public bool SetQuads(ITerrainBrush brush, bool state, bool suppressUpdate = false)
        {
            bool changed = false;

            foreach (var quadTree in _blockGrid)
            {
                if (quadTree.SetQuads(brush, state) == true)
                {
                    changed = true;
                }
            }

            return(changed);
        }
示例#4
0
        /// <summary>
        /// Changes the state of the intersected quads.
        /// </summary>
        /// <param name="brush">The brush.</param>
        /// <param name="state">The state, either enabled or disabled.</param>
        /// <param name="suppressUpdate">If true, does not update if any quads changed state.</param>
        /// <returns>True if any quads were changed.</returns>
        public bool SetQuads(ITerrainBrush brush, bool state, bool suppressUpdate = false)
        {
            var position = Position;
            var offset   = new Vector2(position.X, position.Y);

            bool result = Root.SetQuads(brush, offset, state);

            if (result)
            {
                CollectGeometry(true, ref _enabledVertexBuffer, ref _enabledIndexBuffer);
                CollectGeometry(false, ref _disabledVertexBuffer, ref _disabledIndexBuffer);

                Root.UpdateFixtures(Body);
            }

            return(result);
        }
示例#5
0
        /// <summary>
        /// Changes the state of the intersected quads.
        /// </summary>
        /// <param name="brush">The brush.</param>
        /// <param name="state">The state, either enabled or disabled.</param>
        /// <param name="suppressUpdate">If true, does not update if any quads changed state.</param>
        /// <returns>True if any quads were changed.</returns>
        public bool SetQuads(ITerrainBrush brush, bool state, bool suppressUpdate = false)
        {
            var position = Position;
            var offset = new Vector2(position.X, position.Y);

            bool result = Root.SetQuads(brush, offset, state);
            if (result)
            {
                CollectGeometry(true, ref _enabledVertexBuffer, ref _enabledIndexBuffer);
                CollectGeometry(false, ref _disabledVertexBuffer, ref _disabledIndexBuffer);

                Root.UpdateFixtures(Body);
            }

            return result;
        }
示例#6
0
        /// <summary>
        /// Changes the state of the intersected quads.
        /// </summary>
        /// <param name="brush">The brush.</param>
        /// <param name="state">The state, either enabled or disabled.</param>
        /// <param name="suppressUpdate">If true, does not update if any quads changed state.</param>
        /// <returns>True if any quads were changed.</returns>
        public bool SetQuads(ITerrainBrush brush, bool state, bool suppressUpdate = false)
        {
            bool changed = false;
            foreach (var quadTree in _blockGrid)
            {
                if (quadTree.SetQuads(brush, state) == true)
                {
                    changed = true;
                }
            }

            return changed;
        }
示例#7
0
        public void LoadContent()
        {
            _spriteBatch = new SpriteBatch(_graphics);
            _world = new DynamicEntityWorld(_game.Services);
            var pp = _graphics.PresentationParameters;

            _debugView = new DebugViewXNA(_world.PhysicsWorld);
            _debugView.LoadContent(_graphics, _content);

            _camera = new DefaultCamera(null, new Viewport(0, 0, pp.BackBufferWidth, pp.BackBufferHeight));
            _cameraNode = _world.Scene.Root.CreateChild("Camera");
            _cameraNode.Attach(_camera);

            // Create the tile map.
            var terrainSize = new Vector2(4096.0f, 2048.0f);
            _terrain = new Terrain(terrainSize, 128.0f, 7)
            {
                DebugEnabled = false,
                Position = new Vector3(50.0f, -terrainSize.Y / 2.0f, 0.0f),
                TextureName = @"Textures\SpaceRock"
            };
            _world.Add(_terrain);

            GenerateTunnels(new Vector2(50.0f, 0));

            // Create the circle brush.
            _circleBrush = new CircleBrush(2.5f);

            _circleBrushNode = _world.Scene.CreateSceneNode();
            _circleBrushNode.Attach(new CircleRenderable(2.5f, 64)
            {
                Color = Vector3.One
            });

            // Dust cloud
            _dustCloud = _world.Scene.CreateSceneNode("DustCloud");
            _dustCloud.Position = new Vector3(0.0f, 0.0f, -1.0f);
            _dustCloud.Attach(new DustCloud());
            _world.Scene.Root.AddChild(_dustCloud);

            // Player
            _playerEntity = new SpaceShip();
            _playerEntity.Attach(new PlayerController());
            _playerEntity.Orientation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, MathHelper.ToRadians(90.0f));
            _world.Add(_playerEntity);

            _payloadEntity = new Payload();
            _payloadEntity.Orientation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, MathHelper.ToRadians(90.0f));
            _world.Add(_payloadEntity);

            _payloadChain = PayloadChain.Connect(_playerEntity, _payloadEntity, Vector2.UnitX * -20.0f);
        }
示例#8
0
        /// <summary>
        /// Changes the state of the intersected quads.
        /// </summary>
        /// <param name="brush">The brush.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="state">The state, either enabled or disabled.</param>
        /// <returns>True if any quads were changed.</returns>
        public bool SetQuads(ITerrainBrush brush, Vector2 offset, bool state)
        {
            var changed = false;

            var boundingBox = new BoundingBox(
                _boundingBox.Min + new Vector3(offset, 0.0f),
                _boundingBox.Max + new Vector3(offset, 0.0f));

            if (IsEnabled != state || HasChilds)
            {
                var containment = brush.Contains(ref boundingBox);
                if (containment == ContainmentType.Contains)
                {
                    IsEnabled = state;
                    if (!IsEnabled)
                    {
                        DestroyFixtures();
                    }

                    Childs  = null;
                    changed = true;
                }
                else if (containment == ContainmentType.Intersects)
                {
                    // If we only intersect and are not contained by the brush, we need to recurse down
                    // until we have reached the maximum depth, or have found a child which is contained.

                    // Create childs if necessary.
                    if (Childs == null && Depth < _maxDepth)
                    {
                        var min    = _boundingBox.Min;
                        var max    = _boundingBox.Max;
                        var center = min + ((max - min) / 2.0f);

                        Childs = new[]
                        {
                            new QuadTreeNode(this, _maxDepth, new BoundingBox(min, center), IsEnabled),
                            new QuadTreeNode(this, _maxDepth, new BoundingBox(new Vector3(center.X, min.Y, 0.0f), new Vector3(max.X, center.Y, 0.0f)), IsEnabled),
                            new QuadTreeNode(this, _maxDepth, new BoundingBox(new Vector3(min.X, center.Y, 0.0f), new Vector3(center.X, max.Y, 0.0f)), IsEnabled),
                            new QuadTreeNode(this, _maxDepth, new BoundingBox(center, max), IsEnabled)
                        };

                        changed = true;
                    }

                    // Recurse down.
                    if (Childs != null)
                    {
                        // Try to change the state of our child quads.
                        var canCollapse = true;
                        foreach (var child in Childs)
                        {
                            if (child.SetQuads(brush, offset, state))
                            {
                                changed = true;
                            }

                            // We can't collapse if any of our child also has childs,
                            // or if one of our childs has a different state.
                            if (child.IsEnabled != state || child.HasChilds)
                            {
                                canCollapse = false;
                            }
                        }

                        if (canCollapse)
                        {
                            // All childs have the same correct state, so simplify.
                            IsEnabled = state;
                            if (!IsEnabled)
                            {
                                DestroyFixtures();
                            }

                            foreach (var child in Childs)
                            {
                                child.DestroyFixtures();
                            }
                            Childs = null;
                        }
                        else
                        {
                            // Not all childs have the same state, so we have to be enabled.
                            IsEnabled = true;
                        }
                    }
                    else
                    {
                        // We can't recure down because we are at the maximum depth,
                        // so handle as if we were "contained".
                        IsEnabled = state;
                        if (!IsEnabled)
                        {
                            DestroyFixtures();
                        }

                        changed = true;
                    }
                }
            }

            return(changed);
        }
示例#9
0
        /// <summary>
        /// Changes the state of the intersected quads.
        /// </summary>
        /// <param name="brush">The brush.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="state">The state, either enabled or disabled.</param>
        /// <returns>True if any quads were changed.</returns>
        public bool SetQuads(ITerrainBrush brush, Vector2 offset, bool state)
        {
            var changed = false;

            var boundingBox = new BoundingBox(
                _boundingBox.Min + new Vector3(offset, 0.0f),
                _boundingBox.Max + new Vector3(offset, 0.0f));

            if (IsEnabled != state || HasChilds)
            {
                var containment = brush.Contains(ref boundingBox);
                if (containment == ContainmentType.Contains)
                {
                    IsEnabled = state;
                    if (!IsEnabled)
                    {
                        DestroyFixtures();
                    }

                    Childs = null;
                    changed = true;
                }
                else if (containment == ContainmentType.Intersects)
                {
                    // If we only intersect and are not contained by the brush, we need to recurse down
                    // until we have reached the maximum depth, or have found a child which is contained.

                    // Create childs if necessary.
                    if (Childs == null && Depth < _maxDepth)
                    {
                        var min = _boundingBox.Min;
                        var max = _boundingBox.Max;
                        var center = min + ((max - min) / 2.0f);

                        Childs = new[]
                        {
                            new QuadTreeNode(this, _maxDepth, new BoundingBox(min, center), IsEnabled),
                            new QuadTreeNode(this, _maxDepth, new BoundingBox(new Vector3(center.X, min.Y, 0.0f), new Vector3(max.X, center.Y, 0.0f)), IsEnabled),
                            new QuadTreeNode(this, _maxDepth, new BoundingBox(new Vector3(min.X, center.Y, 0.0f), new Vector3(center.X, max.Y, 0.0f)), IsEnabled),
                            new QuadTreeNode(this, _maxDepth, new BoundingBox(center, max), IsEnabled)
                        };

                        changed = true;
                    }

                    // Recurse down.
                    if (Childs != null)
                    {
                        // Try to change the state of our child quads.
                        var canCollapse = true;
                        foreach (var child in Childs)
                        {
                            if (child.SetQuads(brush, offset, state))
                            {
                                changed = true;
                            }

                            // We can't collapse if any of our child also has childs,
                            // or if one of our childs has a different state.
                            if (child.IsEnabled != state || child.HasChilds)
                            {
                                canCollapse = false;
                            }
                        }

                        if (canCollapse)
                        {
                            // All childs have the same correct state, so simplify.
                            IsEnabled = state;
                            if (!IsEnabled)
                            {
                                DestroyFixtures();
                            }

                            foreach (var child in Childs)
                            {
                                child.DestroyFixtures();
                            }
                            Childs = null;
                        }
                        else
                        {
                            // Not all childs have the same state, so we have to be enabled.
                            IsEnabled = true;
                        }
                    }
                    else
                    {
                        // We can't recure down because we are at the maximum depth,
                        // so handle as if we were "contained".
                        IsEnabled = state;
                        if (!IsEnabled)
                        {
                            DestroyFixtures();
                        }

                        changed = true;
                    }
                }
            }

            return changed;
        }
示例#10
0
        public void LoadContent()
        {
            _spriteBatch = new SpriteBatch(_graphics);

            _world = new StaticEntityWorld(_game.Services);

            var pp = _graphics.PresentationParameters;
            _camera = new DefaultCamera(null, new Viewport(0, 0, pp.BackBufferWidth, pp.BackBufferHeight));
            _cameraNode = _world.Scene.Root.CreateChild("Camera");
            _cameraNode.Position = new Vector3(_camera.ScreenSize / 2.0f, 0.0f);
            _cameraNode.Scale = new Vector3(.5f);
            _cameraNode.Attach(_camera);

            // Create the tile map.
            _terrain = new Terrain(new Vector2(102.4f, 102.4f), 51.2f, 9);
            _terrain.DebugEnabled = true;
            _world.Add(_terrain);

            // Create the circle brush.
            _circleBrush = new CircleBrush(2.5f);

            _circleBrushNode = _world.Scene.CreateSceneNode();
            _circleBrushNode.Attach(new CircleRenderable(2.5f, 64)
            {
                Color = Vector3.One
            });
        }