Esempio n. 1
0
        protected override void LoadContent()
        {
            names = System.IO.File.ReadAllLines("names.txt");    // reads in the file and stores the text in a linear array
            Array.Sort(names);                                   // sorts the array alphabetically
            Random rng = new Random();                           // create a random number generator

            name        = names[rng.Next(0, names.Length)];      // sets player name to be a random name chosen from the array
            reset       = false;                                 // sets reset to false.
            spriteBatch = new SpriteBatch(GraphicsDevice);       // calls a new insatnce forsprite batch so that the program can draw images

            playerfont = Content.Load <SpriteFont>("health");    //loads ina spritetext file to be used for outputing text to an array
            Title      = Content.Load <Texture2D>("Quarterra");  // loads in the title image from the content folder
            background = Content.Load <Texture2D>("background"); //loads the background image in from the foler for the game

            graphics.PreferredBackBufferHeight = screenHeight;   // sets the screen height to the value provided in the variable
            graphics.PreferredBackBufferWidth  = screenWidth;    // sets the screen width to the value provided in the variable
            graphics.ApplyChanges();                             // applys new screen resolution

            IsMouseVisible = true;                               // allows the mouse cursor to be visible when inside the window

            effect = Content.Load <SoundEffect>("Run");

            backbounds = new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); // sets a bounding box of the game to be that of the screen size
            btnplay    = new cButton(Content.Load <Texture2D>("Button1"), graphics.GraphicsDevice);          // creates a new start button with the image loaded from the content folder and using the graphics device as a bounding box
            btnplay.setPosition(new Vector2(350, 300));                                                      // changes the position of the button to the centre of the screen

            camera   = new Camera(GraphicsDevice.Viewport);                                                  // creates a new camera instance so that the camera can scroll until the player reaches the end of the map
            worldmap = System.IO.File.ReadAllLines("world.txt");                                             // reads a file and stores all the map data to an array
            data     = System.IO.File.ReadAllLines("save.txt");                                              //loads the player data from a file and stores it in an array

            mapgen = new int[worldmap.Length, worldmap[0].Length];                                           // creates a 2d array so that it can be passed into a the map gen class
            for (int j = 0; j < worldmap.Length; j++)
            {
                for (int i = 0; i < worldmap[j].Length; i++)
                {
                    try { mapgen[j, i] = int.Parse(worldmap[j].Substring(i, 1)); } catch { } // attempts to split up the old array into a 2d array so that the world can be generated
                }
            }

            Blocks.Content = Content;        // sets the load section of blocks to the content foler

            map.GenerateMap(mapgen, 50);     // generates the map using the data in the array
            p1.Load(Content, data);          // loads the player using the content data

            enemyM.Load(Content, map.Width); //loads the enemy using the content data
        }
        public void DrawMainMenu(SpriteBatch spriteBatch)
        {
            Vector2 position = getXYtoDrawMenu();

            mainMenu.Draw(spriteBatch, position);
            switch (device)
            {
                #region DrawMainMenu Desktop
            case CurrentDevice.Desktop:
                btnPlay.setPosition(new Vector2(330 + (int)position.Y, 255 + (int)position.X));
                btnPlay.Draw(spriteBatch);
                break;

                #endregion
                #region DrawMainMenu Phone
            case CurrentDevice.Phone:
                spriteBatch.DrawString(font, startGame, new Vector2(270 + (int)position.Y, 240 + (int)position.X), Color.Black * transparency);
                break;
                #endregion
            }
        }
Esempio n. 3
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            // Create a new SpriteBatch, which can be used to draw textures.

            Marcel_Basis.LoadContent(GlobalVars, this);
            Marco_Basis.LoadContent(GlobalVars, this);
            Marc_Basis.LoadContent(GlobalVars, this);
            Paul_Basis.LoadContent(GlobalVars, this);
            Eljakim_Basis.LoadContent(GlobalVars, this);

            /*
             * TODO: use this.Content to load your game content here
             */
            graphics.PreferredBackBufferWidth  = screenWidth;
            graphics.PreferredBackBufferHeight = screenHeight;
            graphics.ApplyChanges();
            IsMouseVisible = true;

            btnPlay = new cButton(Content.Load <Texture2D>("button"), graphics.GraphicsDevice);
            btnPlay.setPosition(new Vector2(600, 0));
        }
        public void DrawPause(SpriteBatch spriteBatch)
        {
            Vector2 position = getXYtoDrawMenu();

            switch (device)
            {
                #region DrawPause Desktop
            case CurrentDevice.Desktop:
                backToGameButton.setPosition(new Vector2(330 + (int)position.Y, 300 + (int)position.X));
                backToGameButton.Draw(spriteBatch);

                exitButton.setPosition(new Vector2(330 + (int)position.Y, 350 + (int)position.X));
                exitButton.Draw(spriteBatch);
                break;

                #endregion
                #region DrawPause Phone
            case CurrentDevice.Phone:
                spriteBatch.DrawString(font, backToGame, new Vector2(300 + (int)position.Y, 240 + (int)position.X), Color.Black * transparency);
                spriteBatch.DrawString(font, quitGame, new Vector2(300 + (int)position.Y, 270 + (int)position.X), Color.Black * transparency);
                break;
                #endregion
            }
        }