Esempio n. 1
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="tileMapPath">Path to the tile map file.</param>
        public Scene(string tileMapPath)
        {
            collisionGrid    = null;
            this.tileMapPath = tileMapPath;
            position         = Vector2.Zero;
            dimensions       = Dimensions2.Zero;

            viewport       = BaseGame.Instance.GraphicsDevice.Viewport;
            positionOffset = new Vector2((viewport.Width / 2) - 16, (viewport.Height / 2) - 16);

            positionMinBounds = Vector2.Zero;
            positionMaxBounds = Vector2.Zero;
            nodeMaxBounds     = Vector2.Zero;

            sceneNodeDictionary = new Dictionary <string, SceneNode>();
            prevEntityPositions = new Dictionary <string, Vector2>();
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a collision grid for the scene.
        /// </summary>
        /// <param name="gridDimensions">Dimensions (in cells) of the collision grid.</param>
        public void CreateCollisionGrid(Dimensions2 gridDimensions)
        {
            Dimensions2 sceneDimensions = tileMap.Dimensions * tileMap.TileDimensions;

            collisionGrid = new CollisionGrid(sceneDimensions, gridDimensions);

            // Add tiles to the proper collision grid cell
            foreach (Tile tile in tileMap.TileArray)
            {
                collisionGrid.GetCellAtPosition(tile.Position).TileList.Add(tile);
            }

            // Add scene nodes to the proper collision grid cell
            foreach (SceneNode node in sceneNodeDictionary.Values)
            {
                CollisionCell cell = collisionGrid.GetCellAtPosition(node.Position);
                cell.SceneNodeList.Add(node);
                node.CollisionCell         = cell;
                node.CollisionCellsToCheck = getCellsToCheck(node);
            }
        }