Example #1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatchPlus(GraphicsDevice);
            Texture2D plainText = new Texture2D(GraphicsDevice, 1, 1);

            plainText.SetData(new[] { Color.White });
            spriteBatch.setDefaultTexture(plainText);
            //currentTime = 0;
            //goalTime = 35;
            Keys[] MenuControlList = { Keys.Escape, Keys.Enter, Keys.W, Keys.S, Keys.Up, Keys.Down };
            MenuControls = new MenuControls(MenuControlList);

            Keys[] playControlList = { Keys.Escape, Keys.W, Keys.A, Keys.S, Keys.D, Keys.Left, Keys.Right, Keys.Up, Keys.Down, Keys.Space };
            PlayControls = new PlayControls(playControlList);



            //Creates Test Room

            /*GSprite[] roomSprites = { new NSprite(new Rectangle(0, 0, WIDTH, HEIGHT), Color.Gray),
             *  new NSprite(new Rectangle(100, 100, WIDTH - 200, HEIGHT - 200), Color.LightGray)};
             * rm = new Room(roomSprites);
             *
             * //rm.addObject(new Entity(new Vector2(500, 500), new NSprite(new Rectangle(500, 500, 50, 50), Color.Wheat)));*/


            //Imports Font
            mfont   = Content.Load <SpriteFont>("main");
            sfont   = Content.Load <SpriteFont>("second");
            guiFont = Content.Load <SpriteFont>("guiFont");
            int mHeight = (int)mfont.MeasureString("M").Y;
            int sHeight = (int)sfont.MeasureString("M").Y;


            //Score tracking system setup
            highscoresSprites  = new SSprite[10];
            achievementSprites = new SSprite[3];

            loadedHighscores   = new int[10];
            loadedAchievements = new int[3];

            for (int i = 0; i < 10; i++)
            {
                loadedHighscores[i] = -1;
            }
            for (int i = 0; i < 3; i++)
            {
                loadedAchievements[i] = -2;
            }

            string input = "-1";

            try
            {
                StreamReader sr = new StreamReader("sts.txt");
                for (int i = 0; i < 10; i++)
                {
                    input = sr.ReadLine();
                    int.TryParse(input, out loadedHighscores[i]);
                }

                for (int i = 0; i < 3; i++)
                {
                    input = sr.ReadLine();
                    int.TryParse(input, out loadedAchievements[i]);
                }
                sr.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
            }

            for (int i = 0; i < 10; i++)
            {
                highscoresSprites[i] = new SSprite(i + 1 + ". " + loadedHighscores[i], sfont, new Vector2(50, mHeight * 2 + 10 + i * (sHeight + 10)), Color.Azure);
            }
            achievementSprites[0] = new SSprite("Levels Completed: " + loadedAchievements[0], sfont, new Vector2(400, mHeight * 2 + 10 + 0 * (sHeight + 10)), Color.Azure);
            achievementSprites[1] = new SSprite("Chargers Killed: " + loadedAchievements[1], sfont, new Vector2(400, mHeight * 2 + 10 + 1 * (sHeight + 10)), Color.Azure);
            achievementSprites[2] = new SSprite("Rangers Killed: " + loadedAchievements[2], sfont, new Vector2(400, mHeight * 2 + 10 + 2 * (sHeight + 10)), Color.Azure);



            //Creates Main Menu
            GSprite[] gs = { new NSprite(new Rectangle(0,     0, WIDTH,          HEIGHT),      Color.SandyBrown),
                             new NSprite(new Rectangle(0,     0, WIDTH,          mHeight * 2), Color.SaddleBrown),
                             new SSprite("Maze Crawler",  mfont, new Vector2(25, mHeight / 2), Color.Azure) };

            MenuOption[] mo = { new MenuOption(new SSprite("Start Game",                  sfont, new Vector2(50, mHeight * 2 + sHeight),     Color.Azure)),
                                new MenuOption(new SSprite("Highscores and Achievements", sfont, new Vector2(50, mHeight * 2 + sHeight * 3), Color.Azure)),
                                new MenuOption(new SSprite("Quit Game",                   sfont, new Vector2(50, mHeight * 2 + sHeight * 5), Color.Azure)) };

            mainMenu = new GGUI(gs, mo, Color.Azure);



            //Creates Pause Menu
            GSprite[] pgs = { new NSprite(new Rectangle(WIDTH / 4, HEIGHT / 8, WIDTH / 2,                                                       HEIGHT / 2),               Color.SandyBrown),
                              new NSprite(new Rectangle(WIDTH / 4, HEIGHT / 8, WIDTH / 2,                                                       mHeight * 2),              Color.SaddleBrown),
                              new SSprite("Pause Menu",            mfont,      new Vector2(WIDTH / 2 - mfont.MeasureString("Pause Menu").X / 2, HEIGHT / 8 + mHeight / 2), Color.Azure) };

            MenuOption[] pmo = { new MenuOption(new SSprite("Resume", sfont, new Vector2(WIDTH / 2 - mfont.MeasureString("Pause Menu").X / 4, HEIGHT / 8 + mHeight * 2 + sHeight / 2), Color.Azure)),
                                 new MenuOption(new SSprite("Quit",   sfont, new Vector2(WIDTH / 2 - mfont.MeasureString("Pause Menu").X / 4, HEIGHT / 8 + mHeight * 2 + sHeight * 2), Color.Azure)) };

            pauseMenu = new GGUI(pgs, pmo, Color.Azure);

            //Creates Shop Menu
            GSprite[] sgs = { new NSprite(new Rectangle(WIDTH / 4, HEIGHT / 8, WIDTH / 2,                                                          HEIGHT * 2 / 3),           Color.SandyBrown),
                              new NSprite(new Rectangle(WIDTH / 4, HEIGHT / 8, WIDTH / 2,                                                          mHeight * 2),              Color.SaddleBrown),
                              new SSprite("Ye Old Shope",          mfont,      new Vector2(WIDTH / 2 - mfont.MeasureString("Ye Old Shoppe").X / 2, HEIGHT / 8 + mHeight / 2), Color.Azure) };

            MenuOption[] smo = { new MenuOption(new SSprite("Weapon Damage (10C)", sfont, new Vector2(WIDTH / 2 - mfont.MeasureString("Ye Old Shope").X / 4, HEIGHT / 8 + mHeight * 2 + sHeight / 2),    Color.Azure)),
                                 new MenuOption(new SSprite("Max Health (10C)",    sfont, new Vector2(WIDTH / 2 - mfont.MeasureString("Ye Old Shope").X / 4, HEIGHT / 8 + mHeight * 2 + sHeight * 2),    Color.Azure)),
                                 new MenuOption(new SSprite("Quit",                sfont, new Vector2(WIDTH / 2 - mfont.MeasureString("Ye Old Shope").X / 4, HEIGHT / 8 + mHeight * 2 + sHeight * 3.5f), Color.Azure)) };


            shopMenu = new GGUI(sgs, smo, Color.Azure);

            //Creates Death Menu

            deathMenuScore = new SSprite("Your Score: ", sfont, new Vector2(WIDTH / 2 - mfont.MeasureString("You Died").X / 4, HEIGHT / 8 + mHeight * 2 + sHeight * 3.5f), Color.Azure);

            GSprite[] dgs = { new NSprite(new Rectangle(WIDTH / 4, HEIGHT / 8, WIDTH / 2,                                                     HEIGHT / 2),               Color.SandyBrown),
                              new NSprite(new Rectangle(WIDTH / 4, HEIGHT / 8, WIDTH / 2,                                                     mHeight * 2),              Color.SaddleBrown),
                              new SSprite("You Died",              mfont,      new Vector2(WIDTH / 2 - mfont.MeasureString("You Died").X / 2, HEIGHT / 8 + mHeight / 2), Color.Azure),
                              deathMenuScore };

            MenuOption[] dmo = { new MenuOption(new SSprite("Main Menu", sfont, new Vector2(WIDTH / 2 - mfont.MeasureString("You Died").X / 4, HEIGHT / 8 + mHeight * 2 + sHeight / 2), Color.Azure)),
                                 new MenuOption(new SSprite("Quit",      sfont, new Vector2(WIDTH / 2 - mfont.MeasureString("You Died").X / 4, HEIGHT / 8 + mHeight * 2 + sHeight * 2), Color.Azure)) };

            deathMenu = new GGUI(dgs, dmo, Color.Azure);

            //Creates Leaderboard plus AH system

            GSprite[] scoregs = new GSprite[16];
            scoregs[0] = new NSprite(new Rectangle(0, 0, WIDTH, HEIGHT), Color.SandyBrown);
            scoregs[1] = new NSprite(new Rectangle(0, 0, WIDTH, mHeight * 2), Color.SaddleBrown);
            scoregs[2] = new SSprite("Highscores and Acheivements", mfont, new Vector2(25, mHeight / 2), Color.Azure);
            for (int i = 0; i < 10; i++)
            {
                scoregs[3 + i] = highscoresSprites[i];
            }
            for (int i = 0; i < 3; i++)
            {
                scoregs[13 + i] = achievementSprites[i];
            }

            MenuOption[] scoremo = { new MenuOption(new SSprite("Return", sfont, new Vector2(50, HEIGHT - sHeight * 2), Color.Azure)) };

            scoreMenu = new GGUI(scoregs, scoremo, Color.Azure);


            // TODO: use this.Content to load your game content here
        }
Example #2
0
        public void GenerateMap()
        {
            r      = new Random();
            player = new Entity(new NSprite(new Rectangle(500, 500, 50, 50), Color.Wheat));

            int count;
            int x, y;

            do
            {
                //Generates first room in a random place on map
                x = r.Next(0, size);
                y = r.Next(0, size);
                _rooms[x + size * y] = new Room();
                _currRoom            = _rooms[x + size * y];

                //Creates stack used for recursize alg
                Stack <Room> _stack = new Stack <Room>();
                _stack.Push(_rooms[x + size * y]);
                _roomRec(_stack, x, y);// Generates map layout recursively

                count = 0;
                for (int i = 0; i < size * size; i++)
                {
                    if (_rooms[i] != null)
                    {
                        count++;
                    }
                }
                if (count < roomRejectionSize || count > roomUpperBound)
                {
                    if (!muteConsole)
                    {
                        Console.Out.WriteLine("Retry Generation /////////////////");
                    }
                    for (int i = 0; i < size * size; i++)
                    {
                        _rooms[i] = null;
                    }
                }
            } while (count < roomRejectionSize || count > roomUpperBound);

            _currRoom.addObject(player);//Puts player in first room

            //
            //Used for constructing minimap, can be ignorned
            List <GSprite> gs = new List <GSprite>();

            gs.Add(new NSprite(new Rectangle(0, 0, 10 + 100 * size, 10 + 100 * size), Color.Black));

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    if (_rooms[i + size * j] != null)
                    {
                        if (i == x && j == y)
                        {
                            gs.Add(new NSprite(new Rectangle(10 + (100) * i, 10 + 100 * j, 90, 90), Color.Red));
                        }
                        else
                        {
                            gs.Add(new NSprite(new Rectangle(10 + (100) * i, 10 + 100 * j, 90, 90), Color.Azure));
                        }
                    }
                }
            }

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    if (_rooms[i + size * j] != null)
                    {
                        if (_rooms[i + size * j].right != null)
                        {
                            gs.Add(new NSprite(new Rectangle(100 + (100) * i, 50 + 100 * j, 10, 10), Color.Gray));
                        }
                        if (_rooms[i + size * j].down != null)
                        {
                            gs.Add(new NSprite(new Rectangle(50 + (100) * i, 100 + 100 * j, 10, 10), Color.Gray));
                        }
                    }
                }
            }
            miniMap = new GGUI(gs.ToArray(), null, Color.Beige);
            if (!muteConsole)
            {
                Console.Out.WriteLine("Complete");
            }
            //End minimap section
            //
        }
Example #3
0
        public void GenerateMap()
        {
            for (int i = 0; i < size * size; i++)
            {
                _rooms[i] = null;
            }
            r = new Random();
            int count;
            int x, y;

            do
            {
                //Generates first room in a random place on map
                x = r.Next(0, size);
                y = r.Next(0, size);
                _rooms[x + size * y] = new ShopRoom();
                _currRoom            = _rooms[x + size * y];

                //Creates stack used for recursize alg
                Stack <Room> _stack = new Stack <Room>();
                _stack.Push(_rooms[x + size * y]);
                _roomRec(_stack, x, y);// Generates map layout recursively

                count = 0;
                for (int i = 0; i < size * size; i++)
                {
                    if (_rooms[i] != null)
                    {
                        count++;
                    }
                }
                if (count < roomRejectionSize || count > roomUpperBound)
                {
                    if (!muteConsole)
                    {
                        Console.Out.WriteLine("Retry Generation /////////////////");
                    }
                    for (int i = 0; i < size * size; i++)
                    {
                        _rooms[i] = null;
                    }
                }
            } while (count < roomRejectionSize || count > roomUpperBound);

            _currRoom.addObject(player);//Puts player in first room

            Room crawler = _currRoom;

            do
            {
                for (int i = 0; i < 100; i++)
                {
                    List <Room> direction = new List <Room>();
                    if (crawler.left != null)
                    {
                        direction.Add(crawler.left);
                    }
                    if (crawler.up != null)
                    {
                        direction.Add(crawler.up);
                    }
                    if (crawler.right != null)
                    {
                        direction.Add(crawler.right);
                    }
                    if (crawler.down != null)
                    {
                        direction.Add(crawler.down);
                    }

                    crawler = direction.ElementAt(r.Next(direction.Count));
                }
            } while (crawler == _currRoom);

            Room temp = new EndRoom();

            if (crawler.left != null)
            {
                crawler.left.right = temp;
                temp.left          = crawler.left;
            }
            if (crawler.up != null)
            {
                crawler.up.down = temp;
                temp.up         = crawler.up;
            }
            if (crawler.right != null)
            {
                crawler.right.left = temp;
                temp.right         = crawler.right;
            }
            if (crawler.down != null)
            {
                crawler.down.up = temp;
                temp.down       = crawler.down;
            }

            for (int i = 0; i < _rooms.Length; i++)
            {
                if (_rooms[i] == crawler)
                {
                    _rooms[i] = temp;
                }
            }


            //
            //Used for constructing minimap, can be ignorned
            List <GSprite> gs = new List <GSprite>();

            gs.Add(new NSprite(new Rectangle(0, 0, 10 + 100 * size, 10 + 100 * size), Color.Black));

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    if (_rooms[i + size * j] != null)
                    {
                        if (i == x && j == y)
                        {
                            gs.Add(new NSprite(new Rectangle(10 + (100) * i, 10 + 100 * j, 90, 90), Color.Red));
                        }
                        else if (_rooms[i + size * j] is EndRoom)
                        {
                            gs.Add(new NSprite(new Rectangle(10 + (100) * i, 10 + 100 * j, 90, 90), Color.Purple));
                        }
                        else
                        {
                            gs.Add(new NSprite(new Rectangle(10 + (100) * i, 10 + 100 * j, 90, 90), Color.Azure));
                        }
                    }
                }
            }

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    if (_rooms[i + size * j] != null)
                    {
                        if (_rooms[i + size * j].right != null)
                        {
                            gs.Add(new NSprite(new Rectangle(100 + (100) * i, 50 + 100 * j, 10, 10), Color.Gray));
                        }
                        if (_rooms[i + size * j].down != null)
                        {
                            gs.Add(new NSprite(new Rectangle(50 + (100) * i, 100 + 100 * j, 10, 10), Color.Gray));
                        }
                    }
                }
            }
            miniMap = new GGUI(gs.ToArray(), null, Color.Beige);
            if (!muteConsole)
            {
                Console.Out.WriteLine("Complete");
            }
            //End minimap section
            //
        }
Example #4
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatchPlus(GraphicsDevice);
            Texture2D plainText = new Texture2D(GraphicsDevice, 1, 1);

            plainText.SetData(new[] { Color.White });
            spriteBatch.setDefaultTexture(plainText);
            //currentTime = 0;
            //goalTime = 35;
            Keys[] MenuControlList = { Keys.Escape, Keys.Enter, Keys.W, Keys.S, Keys.Up, Keys.Down };
            MenuControls = new MenuControls(MenuControlList);

            Keys[] playControlList = { Keys.Escape, Keys.W, Keys.A, Keys.S, Keys.D, Keys.Left, Keys.Right, Keys.Up, Keys.Down, Keys.Space };
            PlayControls = new PlayControls(playControlList);



            //Creates Test Room

            /*GSprite[] roomSprites = { new NSprite(new Rectangle(0, 0, WIDTH, HEIGHT), Color.Gray),
             *  new NSprite(new Rectangle(100, 100, WIDTH - 200, HEIGHT - 200), Color.LightGray)};
             * rm = new Room(roomSprites);
             *
             * //rm.addObject(new Entity(new Vector2(500, 500), new NSprite(new Rectangle(500, 500, 50, 50), Color.Wheat)));*/


            //Imports Font
            mfont = Content.Load <SpriteFont>("main");
            sfont = Content.Load <SpriteFont>("second");
            int mHeight = (int)mfont.MeasureString("M").Y;
            int sHeight = (int)sfont.MeasureString("M").Y;


            //Creates Main Menu
            GSprite[] gs = { new NSprite(new Rectangle(0,     0, WIDTH,          HEIGHT),      Color.SandyBrown),
                             new NSprite(new Rectangle(0,     0, WIDTH,          mHeight * 2), Color.SaddleBrown),
                             new SSprite("Maze Crawler",  mfont, new Vector2(25, mHeight / 2), Color.Azure) };

            MenuOption[] mo = { new MenuOption(new SSprite("Start Game", sfont, new Vector2(50, mHeight * 2 + sHeight),     Color.Azure)),
                                new MenuOption(new SSprite("Settings",   sfont, new Vector2(50, mHeight * 2 + sHeight * 3), Color.Azure)),
                                new MenuOption(new SSprite("Quit Game",  sfont, new Vector2(50, mHeight * 2 + sHeight * 5), Color.Azure)) };

            mainMenu = new GGUI(gs, mo, Color.Azure);



            //Creates Pause Menu
            GSprite[] pgs = { new NSprite(new Rectangle(WIDTH / 4, HEIGHT / 8, WIDTH / 2,                                                       HEIGHT / 2),               Color.SandyBrown),
                              new NSprite(new Rectangle(WIDTH / 4, HEIGHT / 8, WIDTH / 2,                                                       mHeight * 2),              Color.SaddleBrown),
                              new SSprite("Pause Menu",            mfont,      new Vector2(WIDTH / 2 - mfont.MeasureString("Pause Menu").X / 2, HEIGHT / 8 + mHeight / 2), Color.Azure) };

            MenuOption[] pmo = { new MenuOption(new SSprite("Resume",  sfont, new Vector2(WIDTH / 2 - mfont.MeasureString("Pause Menu").X / 4, HEIGHT / 8 + mHeight * 2 + sHeight / 2),    Color.Azure)),
                                 new MenuOption(new SSprite("Setting", sfont, new Vector2(WIDTH / 2 - mfont.MeasureString("Pause Menu").X / 4, HEIGHT / 8 + mHeight * 2 + sHeight * 2),    Color.Azure)),
                                 new MenuOption(new SSprite("Quit",    sfont, new Vector2(WIDTH / 2 - mfont.MeasureString("Pause Menu").X / 4, HEIGHT / 8 + mHeight * 2 + sHeight * 3.5f), Color.Azure)) };

            pauseMenu = new GGUI(pgs, pmo, Color.Azure);


            // TODO: use this.Content to load your game content here
        }