Ejemplo n.º 1
0
        /// <summary>
        /// Changes the current scene to a new one. Also unloads content for the old scene and loads content for the new scene.
        /// </summary>
        /// <param name="newSceneName">Name of the new scene.</param>
        public void ChangeScene(string newSceneName)
        {
            // Check for .xml suffix on scene name
            string newSceneFileName = newSceneName;

            if (!newSceneFileName.EndsWith(".xml"))
            {
                newSceneFileName += ".xml";
            }

            logger.PostEntry(LogEntryType.Info, "Loading scene from file: " + newSceneFileName);

            // Unload old scene
            if (currentScene != null)
            {
                currentScene.UnloadContent();
            }

            // Open Xml scene document
            XmlDocument sceneFile = new XmlDocument();

            sceneFile.Load(SCENE_BASE_PATH + newSceneFileName);

            // Get parent node and child node list
            XmlNode sceneParentNode = sceneFile.DocumentElement;

            // Get tile map information
            string tileMapPath = sceneParentNode["TileMap"].InnerText;

            // Get all scene nodes
            XmlNodeList sceneNodeList = sceneParentNode.SelectNodes("SceneNode");

            Scene newScene = new Scene(tileMapPath);

            // Load individual scene nodes
            foreach (XmlNode curSceneNode in sceneNodeList)
            {
                SceneNode sceneNode = loadSceneNode(curSceneNode);

                // Check for name duplicate
                if (newScene.SceneNodeDictionary.ContainsKey(sceneNode.Name))
                {
                    throw new Exception("A scene node with the name " + sceneNode.Name + " already exists.");
                }
                newScene.SceneNodeDictionary.Add(sceneNode.Name, sceneNode);

                logger.PostEntry(LogEntryType.Info, "Scene node " + sceneNode.Name + " loaded.");
            }

            newScene.LoadContent(contentManager);

            // Get dimensions of the scene collision grid
            string[]    collisionGridDimensionsSplitString = sceneParentNode["CollisionGridDimensions"].InnerText.Split(',');
            Dimensions2 collisionGridDimensions            = new Dimensions2(int.Parse(collisionGridDimensionsSplitString[0]),
                                                                             int.Parse(collisionGridDimensionsSplitString[1]));

            newScene.CreateCollisionGrid(collisionGridDimensions);

            currentScene = newScene;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads content for the scene.
        /// </summary>
        /// <param name="contentManager">Content manager object.</param>
        public void LoadContent(ContentManager contentManager)
        {
            // Load tile map and related content
            tileMap = TileMapFileHandler.LoadTileMap(tileMapPath);
            tileMap.LoadContent(contentManager);

            // Set scene dimensions
            dimensions = tileMap.Dimensions * tileMap.TileDimensions;

            // Load content for all entities
            foreach (SceneNode node in sceneNodeDictionary.Values)
            {
                node.LoadContent(contentManager);

                if (node is Entity)
                {
                    Entity entity = node as Entity;
                    // Create previous position for entity
                    prevEntityPositions.Add(entity.Name, entity.Position);
                }
            }

            positionMinBounds = new Vector2(0 - (dimensions.X - viewport.Width),
                                            0 - (dimensions.Y - viewport.Height));

            position   = -sceneNodeDictionary["Player"].Position;
            position  += positionOffset;
            position.X = MathHelper.Clamp(position.X, positionMinBounds.X, positionMaxBounds.X);
            position.Y = MathHelper.Clamp(position.Y, positionMinBounds.Y, positionMaxBounds.Y);

            nodeMaxBounds.X = dimensions.X;
            nodeMaxBounds.Y = dimensions.Y;
        }
Ejemplo n.º 3
0
 public override void StartDrawing(Dimensions2 screenSize)
 {
     while (tkRendering)
     {
     }
     arrayRendering = true;
     triangles.Clear();
 }
Ejemplo n.º 4
0
    public Chunk(Dimensions2 coordinates)
    {
        //tile_width = DEFAULT_CHUNK_TILE_WIDTH;
        this.coordinates = coordinates;

        tileMap = new Tile[tile_width, tile_width];
        Generate();
    }
Ejemplo n.º 5
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="texturePath">Path to the image texture.</param>
        public TileSetImage(string texturePath, Dimensions2 tileSetDimensions, Dimensions2 tileDimensions)
            : base("Textures/TileSets/" + texturePath)
        {
            this.fileName          = texturePath;
            this.tileSetDimensions = tileSetDimensions;
            this.tileDimensions    = tileDimensions;

            screenDimensions = tileDimensions;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="dimensions">Dimensions of the tile map.</param>
        /// <param name="tileDimensions">Dimensions of tile elements.</param>
        /// <param name="tileArray">Array of tiles.</param>
        /// <param name="tileSetImageArray">Array of tile set images.</param>
        public TileMap(Dimensions2 dimensions, Dimensions2 tileDimensions, Tile[,] tileArray, TileSetImage[] tileSetImageArray)
        {
            this.dimensions     = dimensions;
            this.tileDimensions = tileDimensions;

            this.tileArray = tileArray;

            this.tileSetImageArray = tileSetImageArray;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Constructor creating the tile from an existing tile set image.
        /// </summary>
        /// <param name="tileSetImage">Tile set image.</param>
        public Tile(TileSetImage tileSetImage, int tileIndex, int tileSetIndex, TileCollisionValue collisionValue)
        {
            this.tileIndex    = tileIndex;
            this.tileSetIndex = tileSetIndex;
            this.tileSetImage = tileSetImage;
            dimensions        = tileSetImage.TileDimensions;
            sourceRect        = tileSetImage.GetSourceRectangle(tileIndex);

            this.collisionValue = collisionValue;

            boundingBox = new BoundingBoxAA(Vector2.Zero, new Vector2(dimensions.X, dimensions.Y));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Loads the texture for the image object.
        /// </summary>
        /// <param name="contentManager">Content manager object.</param>
        public void LoadContent(ContentManager contentManager)
        {
            if (texture == null)
            {
                // Load texture from the texture path
                texture = contentManager.Load <Texture2D>(texturePath);
            }

            // Set image dimensions
            dimensions       = new Dimensions2(texture.Width, texture.Height);
            screenDimensions = dimensions;
            // Set default source rectangle
            sourceRect = new Rectangle(0, 0, texture.Width, texture.Height);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="sceneDimensions">Dimensions (in pixels) of the scene.</param>
        /// <param name="gridDimensions">Dimensions (in cells) of the collision grid.</param>
        public CollisionGrid(Dimensions2 sceneDimensions, Dimensions2 gridDimensions)
        {
            cells = new CollisionCell[gridDimensions.X, gridDimensions.Y];

            cellDimensions = new Dimensions2(sceneDimensions.X / gridDimensions.X,
                                             sceneDimensions.Y / gridDimensions.Y);

            for (int i = 0; i < gridDimensions.X; i++)
            {
                for (int j = 0; j < gridDimensions.Y; j++)
                {
                    cells[i, j] = new CollisionCell(i, j);
                }
            }
        }
Ejemplo n.º 10
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>();
        }
Ejemplo n.º 11
0
        public OpenTKRenderer(Dimensions2 size, string title)
        {
            //Run takes a double, which is how many frames per second it should strive to reach.
            //You can leave that out and it'll just update as fast as the hardware will allow it.
            new System.Threading.Thread(() => {
                window = new OpenTKWindow((int)size.width, (int)size.height, title);
                GL.MatrixMode(MatrixMode.Projection);
                GL.LoadIdentity();

                GL.MatrixMode(MatrixMode.Projection);
                GL.Ortho(0, 480, 320, 0, 0, 1000);

                GL.MatrixMode(MatrixMode.Modelview);
                GL.LoadIdentity();
                GL.Translate(0, 0, -10);
                window.RenderFrame += Window_UpdateFrame; window.Run(60.0, 60.0);
            }).Start();
        }
Ejemplo n.º 12
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);
            }
        }
Ejemplo n.º 13
0
 public void UpdateScreenSize(Dimensions2 screenSize)
 {
     this.screenSize = screenSize;
 }
Ejemplo n.º 14
0
    protected Chunk generateChunk(Dimensions2 coordinates)
    {
        Chunk newChunk = new Chunk(coordinates);

        return(newChunk);
    }
Ejemplo n.º 15
0
 public bool OutOfBounds(Dimensions2 bounds, Point2 p1, Point2 p2)
 {
     return((!new Rectangle(new Point(0, 0), bounds).IntersectsWith(new Rectangle(p1.ToWinFormsPoint(), new Size(1, 1)))) && (!new Rectangle(new Point(0, 0), bounds).IntersectsWith(new Rectangle(p2.ToWinFormsPoint(), new Size(1, 1)))));
 }