示例#1
0
        //basic game screen constructor
        public GameScreen(Game1 game)
        {
            this.game = game;
            gameState = new GameState(game); //creates new gameState object and assigns it to game screen
            font1 = game.Content.Load<SpriteFont>("Font1"); //loads Font1

            drawList = new List<GameObject>();
            enemyList = new List<Enemy>();
            timeSinceLastMove = 0;
            enemyPathList = new List<EnemyPathEnd>();
            colList = new List<Rectangle>();
            gemsList = new List<Gold>();
            bulletList = new List<Bullet>();
            platformList = new List<Platform>();

            SaveInfo info = new SaveInfo();
            Dictionary<string, int> highscoreDict = info.ReadHighScore();
            highScore = highscoreDict[levelName];
            // reading in the file
            StreamReader input = null;

            input = new StreamReader(levelFile); // this will load in whatever level the player picks
            string text = "";
            level = input.ReadLine(); // brings in the level name
            text = input.ReadLine(); // brings in the high score as a string
            //int.TryParse(text, out highScore); // now its an int
            text = input.ReadLine(); // brings in the best time as a string
            double.TryParse(text, out bestTime); // now its a double

            text = input.ReadLine(); // read in width
            int.TryParse(text, out gameWidth);

            text = input.ReadLine(); // read in height
            int.TryParse(text, out gameHeight);

            int xPos = game.screenWidth / gameWidth;
            //int yPos = game.screenHeight / gameHeight;

            grappleableObjectList = new List<GameObject>();
            int y = -gameHeight + 8;
            while ((text = input.ReadLine()) != null)
            {

                int x = 0;
                string[] gamePiece = text.Split();
                foreach (string piece in gamePiece)
                {
                    if (piece == "w")
                    {
                        Platform block = new Platform(game.wallSprite, xPos * x + x, xPos * y + y, xPos, xPos);
                        drawList.Add(block);
                        colList.Add(block.rect);
                        platformList.Add(block);
                        grappleableObjectList.Add(block);
                    }
                    else if (piece == "c")
                    {
                        player = new Player(game.playerSprite, xPos * x + x, xPos * y + y, game.playerSprite.Width * 4, game.playerSprite.Height * 4, colList, game, this, enemy, block);
                    }
                    else if (piece == "f")
                    {
                        endGoal = new Goal(game.goalSprite, xPos * x + x, xPos * y + y, xPos, xPos, game, this);
                    }
                    else if (piece == "g")
                    {
                        gem = new Gold(game.gemSprite, xPos * x + 25, xPos * y + 35, game.gemSprite.Width, game.gemSprite.Height, this, game.coinS);
                        gemsList.Add(gem);
                    }
                    else if (piece == "e")
                    {
                        enemy = new Enemy(game.enemySprite, xPos * x, xPos * y + y, game.enemySprite.Width, game.enemySprite.Height, game, this, true, bulletList);
                        enemyList.Add(enemy);
                        bulletList.Add(enemy.MyBullet);
                    }
                    else if (piece == "t")
                    {
                        epe = new EnemyPathEnd(xPos * x + x, xPos * y + y, game.wallSprite.Width, 1, true, game);
                        enemyPathList.Add(epe);
                    }

                    // will add code later for all the other objects that are going to be shown

                    x++;
                }
                y++;
            }
            input.Close();
            input.Close();
            y--;
            lavaRect = new Rectangle(0, game.screenHeight - game.lavaBack.Height, game.screenWidth, game.lavaBack.Height);
        }
示例#2
0
        //basic game screen constructor
        public GameScreen(Game1 game)
        {
            this.game = game;
            gameState = new GameState(game);                     //creates new gameState object and assigns it to game screen
            font1     = game.Content.Load <SpriteFont>("Font1"); //loads Font1

            drawList          = new List <GameObject>();
            enemyList         = new List <Enemy>();
            timeSinceLastMove = 0;
            enemyPathList     = new List <EnemyPathEnd>();
            colList           = new List <Rectangle>();
            gemsList          = new List <Gold>();
            bulletList        = new List <Bullet>();
            platformList      = new List <Platform>();

            SaveInfo info = new SaveInfo();
            Dictionary <string, int> highscoreDict = info.ReadHighScore();

            highScore = highscoreDict[levelName];
            // reading in the file
            StreamReader input = null;

            input = new StreamReader(levelFile); // this will load in whatever level the player picks
            string text = "";

            level = input.ReadLine();            // brings in the level name
            text  = input.ReadLine();            // brings in the high score as a string
            //int.TryParse(text, out highScore); // now its an int
            text = input.ReadLine();             // brings in the best time as a string
            double.TryParse(text, out bestTime); // now its a double

            text = input.ReadLine();             // read in width
            int.TryParse(text, out gameWidth);

            text = input.ReadLine(); // read in height
            int.TryParse(text, out gameHeight);

            int xPos = game.screenWidth / gameWidth;

            //int yPos = game.screenHeight / gameHeight;

            grappleableObjectList = new List <GameObject>();
            int y = -gameHeight + 8;

            while ((text = input.ReadLine()) != null)
            {
                int      x         = 0;
                string[] gamePiece = text.Split();
                foreach (string piece in gamePiece)
                {
                    if (piece == "w")
                    {
                        Platform block = new Platform(game.wallSprite, xPos * x + x, xPos * y + y, xPos, xPos);
                        drawList.Add(block);
                        colList.Add(block.rect);
                        platformList.Add(block);
                        grappleableObjectList.Add(block);
                    }
                    else if (piece == "c")
                    {
                        player = new Player(game.playerSprite, xPos * x + x, xPos * y + y, game.playerSprite.Width * 4, game.playerSprite.Height * 4, colList, game, this, enemy, block);
                    }
                    else if (piece == "f")
                    {
                        endGoal = new Goal(game.goalSprite, xPos * x + x, xPos * y + y, xPos, xPos, game, this);
                    }
                    else if (piece == "g")
                    {
                        gem = new Gold(game.gemSprite, xPos * x + 25, xPos * y + 35, game.gemSprite.Width, game.gemSprite.Height, this, game.coinS);
                        gemsList.Add(gem);
                    }
                    else if (piece == "e")
                    {
                        enemy = new Enemy(game.enemySprite, xPos * x, xPos * y + y, game.enemySprite.Width, game.enemySprite.Height, game, this, true, bulletList);
                        enemyList.Add(enemy);
                        bulletList.Add(enemy.MyBullet);
                    }
                    else if (piece == "t")
                    {
                        epe = new EnemyPathEnd(xPos * x + x, xPos * y + y, game.wallSprite.Width, 1, true, game);
                        enemyPathList.Add(epe);
                    }

                    // will add code later for all the other objects that are going to be shown

                    x++;
                }
                y++;
            }
            input.Close();
            input.Close();
            y--;
            lavaRect = new Rectangle(0, game.screenHeight - game.lavaBack.Height, game.screenWidth, game.lavaBack.Height);
        } // is not updated to current