Beispiel #1
0
        private void OnClick(GameTime gt, cButton button)
        {
            canTick = true;

            if (canTick)
            {
                clickTimer += gt.ElapsedGameTime.Milliseconds;
            }

            if (clickTimer > 100)
            {
                CurrentGameState = button.Destination;
                button.isClicked = false;
                canTick          = false;
                clickTimer       = 0;
            }

            if (button.Destination == GameState.ConfirmQuiting)
            {
                Exit();
            }
            else
            {
                CurrentGameState = button.Destination;
            }
        }
Beispiel #2
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 LoadContent(ContentManager Content, Game1 game)
        {
            this.game = game;
            mainMenu  = new MainMenu();
            mainMenu.LoadContent(Content);
            btnPlay          = new cButton(Content.Load <Texture2D>("Menu/Buttons/playButton"));
            backToGameButton = new cButton(Content.Load <Texture2D>("Menu/Buttons/playButton"));
            exitButton       = new cButton(Content.Load <Texture2D>("Menu/Buttons/exitButton"));
            restartButton    = new cButton(Content.Load <Texture2D>("Menu/Buttons/restartButton"));
            font             = Content.Load <SpriteFont>("healthsFont");
            switch (AnalyticsInfo.VersionInfo.DeviceFamily)
            {
            case "Windows.Mobile":
                device = CurrentDevice.Phone;
                break;

            default:
                device = CurrentDevice.Desktop;
                break;
            }
        }
Beispiel #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()
        {
            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));
        }
Beispiel #5
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 SpriteBatch(GraphicsDevice);



            IsMouseVisible = true;

            Content.Load <Texture2D>("Background/MapBackground");

            BtnPlay           = new cButton(Content.Load <Texture2D>("Buttons/PlayButtonAgile"), screenWidth, screenHeight, 120, GameState.Playing);
            BtnQuiting        = new cButton(Content.Load <Texture2D>("Buttons/QuitButton"), screenWidth, screenHeight, 80, GameState.Quiting);
            BtnConfirmQuiting = new cButton(Content.Load <Texture2D>("Buttons/QuitButton"), screenWidth, screenHeight, 40, GameState.ConfirmQuiting);

            mainMenuButtons.Add(BtnPlay);
            mainMenuButtons.Add(BtnQuiting);

            quitButtons.Add(new cButton(Content.Load <Texture2D>("Buttons/QuitButton"), screenWidth, screenHeight, 120, GameState.ConfirmQuiting));
            quitButtons.Add(new cButton(Content.Load <Texture2D>("Buttons/BackToMenu"), screenWidth, screenHeight, 40, GameState.MainMenu));

            MapTiles.Content = Content;

            map.Generate(mapGrid, size);

            for (int x = 0; x < mapGrid.GetLength(1); x++)
            {
                for (int y = 0; y < mapGrid.GetLength(0); y++)
                {
                    int current = mapGrid[y, x];
                }
            }

            //Player
            playerTex = Content.Load <Texture2D>("Player/CharacterSpriteSheetp");
            player    = new Player(Content, new Vector2(1000, 700), 1, 12, 100);

            //Bullet
            bulletTex = Content.Load <Texture2D>("Bullet/BulletM");

            //Armour Bar
            aBatch = new SpriteBatch(this.GraphicsDevice);

            //Arrow
            arrowTex = Content.Load <Texture2D>("MapAssets/Arrow");
            levels.Add(new Level(new Vector2(1150, 600), 50, Content));

            ContentManager aLoader = new ContentManager(this.Services);

            //HUD Elements
            weaponIcon  = Content.Load <Texture2D>("PickUps/WeaponPickUpSingle5");
            wpnIconPos  = new Vector2(GraphicsDevice.Viewport.X + 20, GraphicsDevice.Viewport.Height - 120);
            wpnIconRect = new Rectangle((int)wpnIconPos.X, (int)wpnIconPos.Y, 100, 100);

            for (int i = 0; i < 5; i++)
            {
                armourIcons.Add(Content.Load <Texture2D>("PickUps/armourIcon" + (i * 25)));
            }
            ;

            armIconPos  = new Vector2(GraphicsDevice.Viewport.X + 330, GraphicsDevice.Viewport.Y + 5);
            armIconRect = new Rectangle((int)armIconPos.X, (int)armIconPos.Y, 100, 100);


            aArmourBar = Content.Load <Texture2D>("PickUps/HealthBar") as Texture2D;

            //Pick Ups
            pickUps.Add(new PickUp(1, 8, Content, new Vector2(500, 600), 0));
            pickUps.Add(new PickUp(1, 8, Content, new Vector2(500, 80), 1));
            pickUps.Add(new PickUp(1, 8, Content, new Vector2(600, 400), 0));

            //Enemy
            enemies.Add(new Enemy(Content, new Vector2(300, 450), false, 100));
            enemies.Add(new Enemy(Content, new Vector2(575, 200), true, 150));
            enemies.Add(new Enemy(Content, new Vector2(1025, 650), false, 200));
            #region OldCode

            /*
             * _sprites = new List<Sprite>()
             * {
             *  new Sprite(animations)
             *  {
             *      Position = new Vector2(100,100),
             *      input = new Input()
             *      {
             *          Up = Keys.W,
             *          Down = Keys.S,
             *          Left = Keys.A,
             *          Right = Keys.D
             *
             *      },
             *  },
             * };
             */
            #endregion
        }