Example #1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            gameState = GameState.Menu;

            // Set the previous keyboard state variable to what the current keyboard state is (which is nothing)
            _prevKbState = Keyboard.GetState();

            _Extraction = new GamePiece(400, 560, 256, 256);

            // Set the button state to hightlight the "Play Button"
            buttonState = Highlighted.Play;

            // Create height and width varibles that can be used throughout the class
            gameHeight = graphics.PreferredBackBufferHeight;
            gameWidth = graphics.PreferredBackBufferWidth;

            // Set all of the Human values:
            _p = new Player(GameVariables.playerStartX, GameVariables.playerStartY, GameVariables.spriteWidth, GameVariables.spriteHeight);    // The actual Player
            humanStep = GameVariables.stepSpeed;                                                           // The rate at which the player will take a step

            zombieStep = GameVariables.stepSpeed;
            //The HUD rectangle object
            _h = new GamePiece(-9, -1, 480, 110);
            scoreTimer = 0;
            // Create the map objects (It is important to note that the first digit is the Y value, while the second is the X)
            mt00 = new MapTile(3, 1, gameWidth, gameHeight, this.Content.Load<Texture2D>("00"));
            mt01 = new MapTile(1, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("01"));
            mt02 = new MapTile(1, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("02"));
            mt03 = new MapTile(1, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("03"));
            mt04 = new MapTile(1, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("04"));
            mt05 = new MapTile(1, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("05"));
            mt06 = new MapTile(1, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("06"));
            mt07 = new MapTile(1, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("07"));

            //mt02 = new MapTile(2, 1, gameWidth, gameHeight, this.Content.Load<Texture2D>("grass"));
            //mt03 = new MapTile(5, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("grass"));
            mt10 = new MapTile(2, 1, gameWidth, gameHeight, this.Content.Load<Texture2D>("10"));
            mt11 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("11"));
            mt12 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("12"));
            mt13 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("13"));
            mt14 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("14"));
            mt15 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("15"));
            mt16 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("16"));
            mt17 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("17"));

            //mt12 = new MapTile(0, 2, gameWidth, gameHeight, this.Content.Load<Texture2D>("road"));
            mt20 = new MapTile(2, 1, gameWidth, gameHeight, this.Content.Load<Texture2D>("20"));
            mt21 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("21"));
            mt22 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("22"));
            mt23 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("23"));
            mt24 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("24"));
            mt25 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("25"));
            mt26 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("26"));
            mt27 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("27"));

            mt30 = new MapTile(2, 1, gameWidth, gameHeight, this.Content.Load<Texture2D>("30"));
            mt31 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("31"));
            mt32 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("32"));
            mt33 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("33"));
            mt34 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("34"));
            mt35 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("35"));
            mt36 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("36"));
            mt37 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("37"));

            mt40 = new MapTile(2, 1, gameWidth, gameHeight, this.Content.Load<Texture2D>("40"));
            mt41 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("41"));
            mt42 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("42"));
            mt43 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("43"));
            mt44 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("44"));
            mt45 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("45"));
            mt46 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("46"));
            mt47 = new MapTile(3, 0, gameWidth, gameHeight, this.Content.Load<Texture2D>("47"));

            // Then add them to the list to reference by number
            listofMaptiles = new List<MapTile>();
            listofMaptiles.Add(mt00);
            listofMaptiles.Add(mt01);
            listofMaptiles.Add(mt02);
            listofMaptiles.Add(mt03);
            listofMaptiles.Add(mt04);
            listofMaptiles.Add(mt05);
            listofMaptiles.Add(mt06);
            listofMaptiles.Add(mt07);

            //listofMaptiles.Add(mt03);

            listofMaptiles.Add(mt10);
            listofMaptiles.Add(mt11);
            listofMaptiles.Add(mt12);
            listofMaptiles.Add(mt13);
            listofMaptiles.Add(mt14);
            listofMaptiles.Add(mt15);
            listofMaptiles.Add(mt16);
            listofMaptiles.Add(mt17);

            listofMaptiles.Add(mt20);
            listofMaptiles.Add(mt21);
            listofMaptiles.Add(mt22);
            listofMaptiles.Add(mt23);
            listofMaptiles.Add(mt24);
            listofMaptiles.Add(mt25);
            listofMaptiles.Add(mt26);
            listofMaptiles.Add(mt27);

            listofMaptiles.Add(mt30);
            listofMaptiles.Add(mt31);
            listofMaptiles.Add(mt32);
            listofMaptiles.Add(mt33);
            listofMaptiles.Add(mt34);
            listofMaptiles.Add(mt35);
            listofMaptiles.Add(mt36);
            listofMaptiles.Add(mt37);

            listofMaptiles.Add(mt40);
            listofMaptiles.Add(mt41);
            listofMaptiles.Add(mt42);
            listofMaptiles.Add(mt43);
            listofMaptiles.Add(mt44);
            listofMaptiles.Add(mt45);
            listofMaptiles.Add(mt46);
            listofMaptiles.Add(mt47);
            // And also to a dictionary for reference by name for their number that references which
            // Maptile its connected to
            dictionaryofMaptiles = new Dictionary<MapTile, int>();
            for (int i = 0; i < listofMaptiles.Count; i++)
            {
                dictionaryofMaptiles.Add(listofMaptiles[i], i);
            }

            // Set the current maptile
            currentMaptile = listofMaptiles[0];

            // Method where you can connect all of the barriers to a map tile
            SetUpBarrierConnections();

            //making the lsit of zombies
            _zs = new List<Zombie>();
            foreach (Zombie z in currentMaptile.GetSetZombieList)
            {
                _zs.Add(z);
            }

            //Bullet stuffs
            listBullet = new List<Bullet>();
            _b = new Bullet();
            bulletTimer = GameVariables.bTimer;

            //changing how much ammo
            ammo = 20;

            dcs = new List<DartCollectible>();
            foreach (DartCollectible dc in currentMaptile.GetSetDartCollectibles)
            {
                dcs.Add(dc);
            }

            //making the start score 0
            score = 0;
            //CheckExternal();
            base.Initialize();
        }
Example #2
0
        /// <summary>
        /// This will warp the game object from the top to the bottom of the screen and vice versa, from the left to the right of the screed and vice versa
        /// </summary>
        /// <param name="go">The Gampiece object you wish to have the screenwrap affect</param>
        public void ScreenWrap()
        {
            // If the object moves up and collides with the top barrier & has its own unique number that's not the default
            if (_p.CheckCollision(currentMaptile.GetSetBarrierUp0) == true && currentMaptile.GetSetBarrierUp0.GetSetMaptileNumber != 100)
            {
                // It moves to the bottom of the screen minus the height of the object and the barrier
                _p.YValue = gameHeight - (currentMaptile.GetSetBarrierDown2._Rectangle.Height + _p._Rectangle.Height);

                // Change the current maptile to this maptile's new maptile
                currentMaptile = listofMaptiles[currentMaptile.GetSetBarrierUp0.GetSetMaptileNumber];

                // Clear the current list of zombies and input the new maptile's list into it
                _zs.Clear();
                foreach (Zombie z in currentMaptile.GetSetZombieList)
                {
                    _zs.Add(z);
                }
            }

            // If the object moves right and collides with the right barrier
            if (_p.CheckCollision(currentMaptile.GetSetBarrierRight1) == true && currentMaptile.GetSetBarrierRight1.GetSetMaptileNumber != 100)
            {
                // It moves to the left of the screen plus the width of the barrier
                _p.XValue = currentMaptile.GetSetBarrierLeft3._Rectangle.Width;

                // Change the current maptile to this maptile's new maptile
                currentMaptile = listofMaptiles[currentMaptile.GetSetBarrierRight1.GetSetMaptileNumber];

                // Clear the current list of zombies and input the new maptile's list into it
                _zs.Clear();
                foreach (Zombie z in currentMaptile.GetSetZombieList)
                {
                    _zs.Add(z);
                }
            }

            // If the object moves down and collides with the bottom barrier
            if (_p.CheckCollision(currentMaptile.GetSetBarrierDown2) == true && currentMaptile.GetSetBarrierDown2.GetSetMaptileNumber != 100)
            {
                // It moves to the top of the screen plus the height of the barrier
                _p.YValue = currentMaptile.GetSetBarrierUp0._Rectangle.Height;

                // Change the current maptile to this maptile's new maptile
                currentMaptile = listofMaptiles[currentMaptile.GetSetBarrierDown2.GetSetMaptileNumber];

                // Clear the current list of zombies and input the new maptile's list into it
                _zs.Clear();
                foreach (Zombie z in currentMaptile.GetSetZombieList)
                {
                    _zs.Add(z);
                }
            }

            // If the object moves left and collides with the left barrier
            if (_p.CheckCollision(currentMaptile.GetSetBarrierLeft3) == true && currentMaptile.GetSetBarrierLeft3.GetSetMaptileNumber != 100)
            {
                // It moves to the right of the screen minus the width of the object and the barrier
                _p.XValue = gameWidth - (currentMaptile.GetSetBarrierRight1._Rectangle.Width + _p._Rectangle.Width);

                // Change the current maptile to this maptile's new maptile
                currentMaptile = listofMaptiles[currentMaptile.GetSetBarrierLeft3.GetSetMaptileNumber];

                // Clear the current list of zombies and input the new maptile's list into it
                _zs.Clear();
                foreach (Zombie z in currentMaptile.GetSetZombieList)
                {
                    _zs.Add(z);
                }
            }

            dcs.Clear();
            foreach (DartCollectible dc in currentMaptile.GetSetDartCollectibles)
            {
                dcs.Add(dc);
            }
        }