예제 #1
0
        /// <summary>
        /// Loads the next level.
        /// </summary>
        public void LoadNextLevel()
        {
            //Set the next level
            levelIndex = (levelIndex + 1) % numberOfLevels;

            if (level != null)
                level.Dispose();

            //Load the level
            string levelPath = string.Format("Content/Levels/{0}.map", levelIndex);

            level = new Level(Services, levelPath, levelIndex);
        }
예제 #2
0
        /// <summary>
        /// Constructor to instantiate a new player.
        /// </summary>
        /// <param name="level">
        /// Get level to use its ContentManager.
        /// </param>
        /// <param name="position">
        /// Set starting position of the player.
        /// </param>
        public Player(Level level, Vector2 position)
        {
            this.level = level;
            lives = 3;

            idle = new Animation(Level.Content.Load<Texture2D>("Sprites/Player/Idle"), 0.1f, true);
            run = new Animation(Level.Content.Load<Texture2D>("Sprites/Player/Run"), 0.1f, true);
            jump = new Animation(Level.Content.Load<Texture2D>("Sprites/Player/Jump"), 0.1f, false);
            win = new Animation(Level.Content.Load<Texture2D>("Sprites/Player/Win"), 0.1f, false);
            death = new Animation(Level.Content.Load<Texture2D>("Sprites/Player/Die"), 0.1f, false);

            int width = (int)(idle.FrameWidth * 0.4);
            int left = (idle.FrameWidth - width) / 2;
            int height = (int)(idle.FrameWidth * 0.8);
            int top = idle.FrameHeight - height;
            localBounds = new Rectangle(left, top, width, height);

            deathSound = Level.Content.Load<SoundEffect>("Sounds/death");

            Reset(position);
        }
예제 #3
0
        /// <summary>
        /// Creates a level using Tiles and Map Cells.
        /// </summary>
        /// <param name="levelPath">
        /// Path of the file containing tile placement within the level.
        /// </param>
        /// <param name="tileTexture">
        /// Tile sheet texture used to draw the level.
        /// </param>
        /// <param name="tileWidth">
        /// //Width of each tile in texture.
        /// </param>
        /// <param name="tileHeight">
        /// //Height of each tile in texture.
        /// </param>
        /// <param name="spacing">
        /// //Spacing between each tile in texture.
        /// </param>
        public TileMap(Level level, int levelIndex, Texture2D tileSheet)
        {
            this.tileSheet = tileSheet;

            string levelPath = string.Format("Content/Levels/{0}.map", levelIndex);

            using (StreamReader sr = new StreamReader(levelPath))
            {
                int curY = 0;
                while (sr.Peek() >= 0)
                {
                    string line = sr.ReadLine();
                    //gets map dimensions and draws a blank map on first read
                    if (curY == 0)
                    {
                        string[] dimensions = line.Split(',');
                        mapWidth = int.Parse(dimensions[0]);
                        mapHeight = int.Parse(dimensions[1]);
                        Camera.worldWidth = mapWidth * Tile.WIDTH;
                        Camera.worldHeight = mapHeight * Tile.HEIGHT;

                        for (int y = 0; y < mapHeight; y++)
                        {
                            MapRow newRow = new MapRow();
                            for (int x = 0; x < mapWidth; x++)
                            {
                                newRow.columns.Add(new Tile(0, TileCollision.Passable));
                            } //end for
                            rows.Add(newRow);
                        } //end for
                    } //end if
                    else
                    {

                        //second line contains base layer info
                        if (curY >= 1 && curY <= mapHeight)
                        {
                            int curX = 0;
                            string[] tiles = line.Split(',');

                            //reads line in as tiles
                            for (int i = 0; i < tiles.Length; i++)
                            {
                                try
                                {
                                    int check = int.Parse(tiles[i]);
                                    if (check != 0)
                                    {
                                        rows[curY - 1].columns[i].tileID = check;
                                        rows[curY - 1].columns[i].collision = TileCollision.Impassable;
                                    } //end if
                                } //end try
                                catch (Exception)
                                {
                                    try
                                    {
                                        char check = tiles[i][0];

                                        switch (check)
                                        {
                                            case 'S':
                                                rows[curY - 1].columns[i].tileID = 0;
                                                rows[curY - 1].columns[i].collision = TileCollision.Passable;
                                                level.SetStart(curX, curY - 1);
                                                break;
                                            case 'C':
                                                rows[curY - 1].columns[i].tileID = 3;
                                                rows[curY - 1].columns[i].collision = TileCollision.Passable;
                                                level.SetCheck(curX, curY - 1);
                                                break;
                                            case 'X':
                                                rows[curY - 1].columns[i].tileID = 3;
                                                rows[curY - 1].columns[i].collision = TileCollision.Passable;
                                                level.SetEnd(curX, curY - 1);
                                                break;
                                            default:
                                                break;
                                        } //end switch
                                    } //end try
                                    catch (Exception) { }

                                } //end catch
                                curX++;
                            } //end for
                        } //end if
                    } //end else
                    curY++;
                } //end while
            } //end using
        }
        /// <summary>
        /// Loads the next level.
        /// </summary>
        public void LoadNextLevel()
        {
            //Set the next level
            int oldLives = 3; //variable used to set lives, by default is 3
            levelIndex = (levelIndex + 1) % numberOfLevels;

            if (level != null)
                level.Dispose();

            if (levelIndex > 0) //if this isn't the starting level, set lives to equal the old ones
            {
                if (!firstRun)
                oldLives = level.Player.Lives;
            }

            level = new Level(ScreenManager.Game.Services, levelIndex);

            level.Player.addLives(oldLives); //set the lives
            firstRun = false;
        }
        /// <summary>
        /// Loads the next level.
        /// </summary>
        public void LoadNextLevel()
        {
            //Set the next level
            levelIndex = (levelIndex + 1) % numberOfLevels;

            if (level != null)
                level.Dispose();

            level = new Level(ScreenManager.Game.Services, levelIndex);
        }