Ejemplo n.º 1
0
 /// <summary>
 /// This function will export the given textures to the given directory.
 /// </summary>
 /// <param name="textures">The textures to export.</param>
 /// <param name="directory">The directory to export the textures to.</param>
 public static void ExportTextures(CGameTextures textures, string directory)
 {
     SaveImage(textures.EnemyIcon, directory + "\\Enemy.bmp");
     SaveImage(textures.GoalIcon, directory + "\\Goal.bmp");
     SaveImage(textures.PlayerIcon, directory + "\\Player.bmp");
     SaveImage(textures.WallTexture, directory + "\\Wall.bmp");
     SaveImage(textures.FloorTexture, directory + "\\Floor.bmp");
     SaveImage(textures.FireIcon, directory + "\\Fire.bmp");
 }
Ejemplo n.º 2
0
        /// <summary>
        /// This function imports the game textures into a CGameTexture
        /// object from the given directory. All textures should be present.
        /// </summary>
        /// <param name="directory">The directory where the textures are stored</param>
        /// <returns>An object storing the loading texteures.</returns>
        public static CGameTextures ImportTextures(string directory)
        {
            CGameTextures ret = new CGameTextures();

            ret.EnemyIcon    = LockFreeBmpLoad(directory + "\\Enemy.bmp");
            ret.GoalIcon     = LockFreeBmpLoad(directory + "\\Goal.bmp");
            ret.PlayerIcon   = LockFreeBmpLoad(directory + "\\Player.bmp");
            ret.WallTexture  = LockFreeBmpLoad(directory + "\\Wall.bmp");
            ret.FloorTexture = LockFreeBmpLoad(directory + "\\Floor.bmp");
            ret.FireIcon     = LockFreeBmpLoad(directory + "\\Fire.bmp");

            return(ret);
        }
Ejemplo n.º 3
0
        //****************************************************************//
        // This function is used as an event handler for the load click  *//
        // event. This is used to load a new level. In addition to       *//
        // the data required for the level it also ensures the board is  *//
        // displayed.                                                    *//
        //****************************************************************//
        private void btnLoad_Click(object sender, RoutedEventArgs e)
        {
            ////////////////////////////////////////////////////////////
            // clear any existing children from the canvas.

            cvsMainScreen.Children.Clear();

            ///////////////////////////////////////////////////////////
            // Get the directory where the level data is stored and
            // load the data in.

            string fileDir = txtLevelDir.Text;

            currentLevel = CLevelParser.ImportLevel(fileDir);
            gameTextures = CLevelParser.ImportTextures(fileDir);


            ///////////////////////////////////////////////////////////
            // Draw the set of wall and floor tiles for the current
            // level and the goal icon. This is part of the game
            // we do not expect to change as it cannot move.

            DrawLevel();


            //////////////////////////////////////////////////////////
            // Add a game state, this represents the position and velocity
            // of all the enemies and the player. Basically, anything
            // that is dynamic that we expect to move around.

            gameState = new CGameState(currentLevel.EnemyPositions.Count());


            ///////////////////////////////////////////////////////////
            // Set up the player to have the correct .bmp and set it to
            // its initial starting point. The player's position is stored
            // as a tile index on the Clevel class, this must be converted
            // to a pixel position on the game state.

            playerIcon        = new Image();
            playerIcon.Width  = CGameTextures.TILE_SIZE;
            playerIcon.Height = CGameTextures.TILE_SIZE;

            playerIcon.Source = gameTextures.PlayerIcon;

            cvsMainScreen.Children.Add(playerIcon);


            //////////////////////////////////////////////////////////
            // Create instances of the enemies and fires for display. We must do
            // this as each child on a canvas must be a distinct object,
            // we could not simply add the same image multiple times.

            enemyIcons = new Image[currentLevel.EnemyPositions.Count()];

            for (int i = 0; i < currentLevel.EnemyPositions.Count(); i++)
            {
                enemyIcons[i] = new Image();

                enemyIcons[i].Width  = CGameTextures.TILE_SIZE;
                enemyIcons[i].Height = CGameTextures.TILE_SIZE;

                enemyIcons[i].Source = gameTextures.EnemyIcon;

                cvsMainScreen.Children.Add(enemyIcons[i]);
            }


            fireIcons = new Image[currentLevel.FirePositions.Count()];

            for (int i = 0; i < currentLevel.FirePositions.Count(); i++)
            {
                fireIcons[i] = new Image();

                fireIcons[i].Width  = CGameTextures.TILE_SIZE;
                fireIcons[i].Height = CGameTextures.TILE_SIZE;

                fireIcons[i].Source = gameTextures.FireIcon;

                cvsMainScreen.Children.Add(fireIcons[i]);

                CPoint2i tilePosition = CLevelUtils.GetPixelFromTileCoordinates(new CPoint2i(currentLevel.FirePositions[i].X, currentLevel.FirePositions[i].Y));


                Canvas.SetLeft(fireIcons[i], tilePosition.X);
                Canvas.SetTop(fireIcons[i], tilePosition.Y);
            }

            loadTextures();
            ////////////////////////////////////////////////////////////
            // Set each instance of a dynamic object to its initial position
            // as defined by the current level object.

            InitialiseGameState();


            ////////////////////////////////////////////////////////////
            // Render the current game state, this will render the player
            // and the enemies in their initial position.

            RenderGameState();
        }