Пример #1
0
 /// RegularSettings
 /// If the player reloads a saved game the following variables will ve set to the speicfied values.
 public void RegularSettings(Player mainPlayer, InformationDisplay mainID)
 {
     mainID.ShowFirstDay            = false;
     mainID.ShowHUD                 = true;
     mainPlayer.AllowEntityMovement = true;
     mainPlayer.AllowWeaponFire     = true;
     mainID.ShowPlayer              = true;
     mainID.ShowEnemies             = true;
     mainID.ShowItems               = true;
     mainID.EraseList               = false;
     mainID.GraphicShowTime         = 0;
 }
Пример #2
0
        /// DefaultSettings
        /// If the player starts a new game the variables will be set to the values specified in the function.
        public void DefaultSettings(Player mainPlayer, InformationDisplay mainID, AreaInterface areaInt)
        {
            int STARTX = 2;             // inital starting section of overworld is 2,4
            int STARTY = 4;

            int STARTDUNNUM = 1;             // set default dungeon number

            mainID.ShowFirstDay = true;      // show the first day information screen on loading of game file.
            // Set variables for player object
            mainPlayer.CurrentOWSec         = new Vector2(STARTX, STARTY);
            mainPlayer.EntityPos            = new Vector2(144, 432);  // 144,432
            mainPlayer.CurrentDungeonNumber = STARTDUNNUM;
            mainPlayer.CurrentBLNumber      = STARTDUNNUM;

            areaInt.GenerateStructure(STARTX, STARTY);
            areaInt.GenerateRectangleCollisions();
        }
Пример #3
0
        /// DRAW
        public void Draw(SpriteBatch spriteBatch, Player mainPlayer, InformationDisplay mainID, SpriteFont font)
        {
            spriteBatch.Draw(HUDBack, new Vector2(0, 0));

            spriteBatch.DrawString(font, "HEALTH", new Vector2(20, 10), Color.White);
            spriteBatch.Draw(HeartIcon, new Vector2(22, 45));

            if (mainPlayer.Health > 20)
            {
                spriteBatch.DrawString(font, (mainPlayer.Health.ToString()), new Vector2(65, 55), Color.White);                 // current player health levels displayed
            }
            else
            {
                spriteBatch.DrawString(font, (mainPlayer.Health.ToString()), new Vector2(65, 55), Color.Red);                 // current player health levels displayed
            }

            // A and B button icons on the HUD
            spriteBatch.Draw(HUD_B_Button, new Vector2(160, 6));
            spriteBatch.Draw(HUD_A_Button, new Vector2(240, 6));
            spriteBatch.Draw(HUD_ItemHolder, new Vector2(320, 6));

            spriteBatch.Draw(Coin_Icon, new Vector2(344, 18));
            spriteBatch.DrawString(font, _CoinAmountString, new Vector2(338, 60), Color.White);             // current player coin amount displayed


            if (_FinalCountdownBool == false)
            {
                spriteBatch.DrawString(font, _CurrentTime, new Vector2(632, 55), Color.White);
            }
            else
            {
                // Final hour string drawn as red font.
                spriteBatch.DrawString(font, "FINAL HOUR: " + _FinalCountdown, new Vector2(580, 55), Color.Red);
            }

            if (_Dawn == true && DawnGraphic != null)
            {
                spriteBatch.Draw(DawnGraphic, new Vector2(618, 16));
            }
            if (_Dusk == true && DuskGraphic != null && DuskChanger != null)
            {
                spriteBatch.Draw(DuskGraphic, new Vector2(618, 16));                 // Transparent layer darkens the game to give night effect.s
                spriteBatch.Draw(DuskChanger, new Vector2(0, 96));
            }
        }
Пример #4
0
        /// Draw
        public override void Draw(SpriteBatch spriteBatch, Player mainPlayer, InformationDisplay mainID)
        {
            spriteBatch.Draw(BossLevelBack, new Vector2(0, 96));

            // Draw structure of BossLevel, go through for nested loop in coordinate increments of 48 to set structure.
            int x = 0;
            int y;

            for (int row = 0; row < 16; row++)
            {
                y = 96;
                for (int column = 0; column < 13; column++)
                {
                    if (_Structure[row, column] == true)                     // brick is present at coordinate so draw.
                    {
                        spriteBatch.Draw(Brick, new Vector2(x, y));
                    }
                    y += 48;
                }
                x += 48;
            }
        }
Пример #5
0
        /// GenerateEnemies
        /// Uses values gained previously from the text file and adds them to the enemyList.
        /// Still uses list structure although there is only one boss for continuity with the rest of the program.
        public override void GenerateEnemies(Rectangle playerRect, InformationDisplay mainID)
        {
            if (mainID.EraseList == true)
            {
                _enemyList.Clear();
                mainID.EraseList = false;
            }
            if (_EnemyAmount > 0)
            {
                if (mainID.NewEnemyList == true)
                {
                    _enemyList.Clear();

                    Random R = new Random();
                    int    a = R.Next(_EnemyAmount, _EnemyAmount + 1);


                    _enemyList.Add(new Boss());
                    _enemyList[0].EnemyTextureName = "Boss" + (_BossLevelNumber);                     // set texture name.

                    _enemyList[0].Health    = (200);
                    _enemyList[0].HealthMax = (200);

                    _enemyList[0].Orientation = 'D';                     // default facing direction.


                    // Set random coordinates within bounds
                    Vector2 coordinates = _enemyList[0].EnemyGenCoordinate(_enemyList[0].Width, _enemyList[0].Height, playerRect, _collisionRects, ref _enemyRects);
                    _enemyList[0].EnemyCoordinates = (coordinates);


                    mainID.NewEnemyList = false;

                    _BossGenerated = true;
                }
            }
        }
        /// GenerateItems
        /// Uses information gained previously from the text file, adds items to itemList through a for loop.
        public override void GenerateItems(Player mainPlayer, AreaInterface areaInt, InformationDisplay mainID)
        {
            if (mainID.EraseList == true)
            {
                _itemList.Clear();
                _itemRects.Clear();
                mainID.EraseList = false;
            }


            if (_ItemTypeA != null || _ItemTypeB != null && _ItemAAmount > 0)
            {
                if (_ItemTypeA != null)
                {
                    if (mainID.NewItemList == true)
                    {
                        for (int i = 0; i <= _ItemAAmount; i++)
                        {
                            if (_ItemTypeA == "Coin")
                            {
                                if (mainPlayer.VisitedOWSections[(int)mainPlayer.CurrentOWSec.X, (int)mainPlayer.CurrentOWSec.Y] == false) // if section has not been visited
                                {
                                    _itemList.Add(new Coin());                                                                             // add Coin object to list
                                }
                                else
                                {
                                    _ItemTypeA   = null;
                                    _ItemAAmount = 0;
                                }
                            }

                            if (_ItemTypeA == "Heart")
                            {
                                _itemList.Add(new Heart());                                 // add Heart object to list
                            }

                            if (_ItemTypeA != null)
                            {
                                _itemList[i].DrawItem = true;
                            }
                        }

                        for (int i = 0; i < _itemList.Count; i++)
                        {
                            // Generate random coordinate in bounds.
                            Vector2 coordinates = _itemList[i].ItemGenCoordinate(i, mainPlayer, areaInt);

                            _itemList[i].ItemCoordinates = coordinates;
                        }
                    }
                }

                if (_ItemTypeB != null)
                {
                    if (mainID.NewItemList == true)
                    {
                        for (int i = 0; i <= _ItemBAmount; i++)
                        {
                            if (_ItemTypeB == "Coin")
                            {
                                if (mainPlayer.VisitedOWSections[(int)mainPlayer.CurrentOWSec.X, (int)mainPlayer.CurrentOWSec.Y] == false) // if section has not been visited
                                {
                                    _itemList.Add(new Coin());                                                                             // add Coin object to list
                                }
                                else
                                {
                                    _ItemTypeB   = null;
                                    _ItemBAmount = 0;
                                }
                            }

                            if (_ItemTypeB == "Heart")
                            {
                                _itemList.Add(new Heart());                                 // add Heart object to list
                            }

                            if (_ItemTypeB != null)
                            {
                                _itemList[i].DrawItem = true;
                            }
                        }

                        for (int i = 0; i < _itemList.Count; i++)
                        {
                            // Generate random coordinate in bounds.
                            Vector2 coordinates = _itemList[i].ItemGenCoordinate(i, mainPlayer, areaInt);

                            _itemList[i].ItemCoordinates = (coordinates);
                        }
                    }
                }

                mainID.NewItemList = false;
            }
        }
Пример #7
0
        /// Draw
        public override void Draw(SpriteBatch spriteBatch, Player mainPlayer, InformationDisplay mainID)
        {
            if (_changeSec == true)
            {
                mainPlayer.DrawWeapon = false;
                mainID.NewEnemyList   = true;
                mainID.EraseList      = true;


                if (_changeDirection == 'R')                                                          // If the player is walking into a right section
                {
                    spriteBatch.Draw(PreDungeonBack, new Vector2(_DefaultPos.X, _DefaultPos.Y));      // draw the previous dungeon section
                    spriteBatch.Draw(DungeonBack, new Vector2(_DefaultNewPosR.X, _DefaultNewPosR.Y)); // draw the new dungeon section
                }

                if (_changeDirection == 'L')                 // If the player is walking into a left section
                {
                    spriteBatch.Draw(PreDungeonBack, new Vector2(_DefaultPos.X, _DefaultPos.Y));
                    spriteBatch.Draw(DungeonBack, new Vector2(_DefaultNewPosL.X, _DefaultNewPosL.Y));
                }

                if (_changeDirection == 'U')                 // If the player is walking into a upwards section
                {
                    spriteBatch.Draw(PreDungeonBack, new Vector2(_DefaultPos.X, _DefaultPos.Y));
                    spriteBatch.Draw(DungeonBack, new Vector2(_DefaultNewPosU.X, _DefaultNewPosU.Y));
                }

                if (_changeDirection == 'D')                 // If the player is walking into a downwards section
                {
                    spriteBatch.Draw(PreDungeonBack, new Vector2(_DefaultPos.X, _DefaultPos.Y));
                    spriteBatch.Draw(DungeonBack, new Vector2(_DefaultNewPosD.X, _DefaultNewPosD.Y));
                }


                // SLIDING ANIMATION
                // When the player moves into a new section, the new section will slide into place in the opposite direction the player is travelling.

                int x = 0;

                // Set default X values.
                if (_changeDirection == 'U')
                {
                    x = (int)_DefaultNewPosU.X;
                }

                if (_changeDirection == 'D')
                {
                    x = (int)_DefaultNewPosD.X;
                }

                if (_changeDirection == 'L')
                {
                    x = (int)_DefaultNewPosL.X;
                }

                if (_changeDirection == 'R')
                {
                    x = (int)_DefaultNewPosR.X;
                }

                int y = 0;

                // For loop to go through structure array, if part of array is true then draw.
                for (int row = 0; row < 16; row++)
                {
                    // Set default Y values.
                    if (_changeDirection == 'U')
                    {
                        y = (int)_DefaultNewPosU.Y;
                    }

                    if (_changeDirection == 'D')
                    {
                        y = (int)_DefaultNewPosD.Y;
                    }

                    if (_changeDirection == 'L')
                    {
                        y = (int)_DefaultNewPosL.Y;
                    }

                    if (_changeDirection == 'R')
                    {
                        y = (int)_DefaultNewPosR.Y;
                    }

                    for (int column = 0; column < 13; column++)
                    {
                        if (_Structure[row, column] == true)
                        {
                            spriteBatch.Draw(Brick, new Vector2(x, y));
                        }
                        y += 48;
                    }
                    x += 48;
                }


                // Draw the position of the old section, works in the same manner as the new section animation.
                x = (int)_DefaultPos.X;

                y = 0;

                for (int row = 0; row < 16; row++)
                {
                    y = (int)_DefaultPos.Y;

                    for (int column = 0; column < 13; column++)
                    {
                        if (_PreviousStructure[row, column] == true)
                        {
                            spriteBatch.Draw(Brick, new Vector2(x, y));
                        }
                        y += 48;
                    }

                    x += 48;
                }
            }

            // Draw dungeon section while slide animation is not running
            else
            {
                spriteBatch.Draw(DungeonBack, new Vector2(0, 96));

                int x = 0;
                int y;

                for (int row = 0; row < 16; row++)
                {
                    y = 96;
                    for (int column = 0; column < 13; column++)
                    {
                        if (_Structure[row, column] == true)
                        {
                            spriteBatch.Draw(Brick, new Vector2(x, y));
                        }
                        y += 48;
                    }

                    x += 48;
                }
            }
        }
Пример #8
0
        /// SaveGameFile
        /// Writes current information into the text file of the GameSave selected on the LoadScreen.
        public void SaveGameFile(Player mainPlayer, HUD mainHUD, InformationDisplay mainID)
        {
            // New arrays to store information from text file
            bool[,] InternalVisitedOWSecs   = mainPlayer.VisitedOWSections;
            bool[,] InternalVisitedDUN1Secs = mainPlayer.VisitedDUN1Sections;
            bool[,] InternalVisitedDUN2Secs = mainPlayer.VisitedDUN2Sections;
            bool[,] InternalVisitedDUN3Secs = mainPlayer.VisitedDUN3Sections;

            InternalVisitedOWSecs[(int)mainPlayer.CurrentOWSec.X, (int)mainPlayer.CurrentOWSec.Y] = true;             // must have visited the section they last saved in.

            // Sets the dungeon section the player saved in to visited status i.e. true.
            if (mainPlayer.CurrentDungeonNumber == 1 && mainPlayer.InDungeon == true)
            {
                InternalVisitedDUN1Secs[(int)mainPlayer.CurrentDUNSec.X, (int)mainPlayer.CurrentDUNSec.Y] = true;
            }

            if (mainPlayer.CurrentDungeonNumber == 2 && mainPlayer.InDungeon == true)
            {
                InternalVisitedDUN2Secs[(int)mainPlayer.CurrentDUNSec.X, (int)mainPlayer.CurrentDUNSec.Y] = true;
            }

            if (mainPlayer.CurrentDungeonNumber == 3 && mainPlayer.InDungeon == true)
            {
                InternalVisitedDUN3Secs[(int)mainPlayer.CurrentDUNSec.X, (int)mainPlayer.CurrentDUNSec.Y] = true;
            }

            int SaveFileNumber = mainID.SaveFileNumber;

            string FileName = "GameSave" + SaveFileNumber + ".txt";

            using (var Writer = new StreamWriter(FileName)){
                // Begin writing data to relevent text file in same layout as the reading version
                Writer.WriteLine("Active");                 // save file is active
                Writer.WriteLine(mainPlayer.CompletedDungeons[0]);
                Writer.WriteLine(mainPlayer.CompletedDungeons[1]);
                Writer.WriteLine(mainPlayer.CompletedDungeons[2]);
                Writer.WriteLine("{0}{1}", (int)mainPlayer.CurrentOWSec.X, (int)mainPlayer.CurrentOWSec.Y);
                Writer.WriteLine(mainPlayer.CoinCount);
                Writer.WriteLine(mainHUD.TotalTime);
                Writer.WriteLine(mainHUD.CurrentHour);
                Writer.WriteLine(mainHUD.CurrentMin);


                // Reversed version of reading visited sections, writes a 1 or 0 depending on array value; through a nested for loop.
                for (int Column = 0; Column < 5; Column++)
                {
                    for (int Row = 0; Row < 5; Row++)
                    {
                        if (InternalVisitedOWSecs[Row, Column] == true)
                        {
                            Writer.Write("1");
                        }
                        else
                        {
                            Writer.Write("0");
                        }
                    }

                    Writer.WriteLine();
                }


                for (int Column = 0; Column < 4; Column++)
                {
                    for (int Row = 0; Row < 4; Row++)
                    {
                        if (InternalVisitedDUN1Secs[Row, Column] == true)
                        {
                            Writer.Write("1");
                        }
                        else
                        {
                            Writer.Write("0");
                        }
                    }
                    Writer.WriteLine();
                }

                for (int Column = 0; Column < 4; Column++)
                {
                    for (int Row = 0; Row < 4; Row++)
                    {
                        if (InternalVisitedDUN2Secs[Row, Column] == true)
                        {
                            Writer.Write("1");
                        }
                        else
                        {
                            Writer.Write("0");
                        }
                    }
                    Writer.WriteLine();
                }

                for (int Column = 0; Column < 4; Column++)
                {
                    for (int Row = 0; Row < 4; Row++)
                    {
                        if (InternalVisitedDUN3Secs[Row, Column] == true)
                        {
                            Writer.Write("1");
                        }
                        else
                        {
                            Writer.Write("0");
                        }
                    }
                    Writer.WriteLine();
                }

                Writer.Close();
            }
        }
Пример #9
0
        /// LoadGameFile
        /// A method used to load the game save file information from a text file.
        /// This method will check to see if the text file is valid in certain points and will set variables according to denoted structure.
        public void LoadGameFile(InformationDisplay mainID, Player mainPlayer, HUD mainHUD, int SaveFileNumber)
        {
            try
            {             // If an error occurs when loading the game information then go to catch.
                string line;
                string FileName = "GameSave" + SaveFileNumber + ".txt";

                int Count = 0;

                int Row    = 0;
                int Column = 0;

                StreamReader Reader = new StreamReader(FileName);                 // Setup a file reader

                while ((line = Reader.ReadLine()) != null)
                {
                    // Count represents current line of text file
                    if (Count == 1)
                    {
                        if (line != "True" && line != "False")                 // Check to see if valid
                        {
                            throw new Exception();                             // an error is in the text file so go to catch
                        }

                        if (line == "True")                         // Has the player completed the first dungeon
                        {
                            mainPlayer.CompletedDungeons[0] = true;
                        }
                    }

                    if (Count == 2)
                    {
                        if (line != "True" && line != "False")                         // Check to see if valid
                        {
                            throw new Exception();
                        }

                        if (line == "True")                         // Has the player completed the second dungeon
                        {
                            mainPlayer.CompletedDungeons[1] = true;
                        }
                    }

                    if (Count == 3)
                    {
                        if (line != "True" && line != "False")                         // Check to see if valid
                        {
                            throw new Exception();
                        }

                        if (line == "True")                         // Has the player completed the third dungeon
                        {
                            mainPlayer.CompletedDungeons[2] = true;
                        }
                    }

                    if (Count == 4)
                    {
                        // Fourth line contains where the player last saved in the overworld, even if in a dungeon.
                        mainPlayer.CurrentOWSec = new Vector2(Convert.ToInt32(line[0]) - 48, Convert.ToInt32(line[1]) - 48);
                    }

                    if (Count == 5)
                    {
                        // Fith line contains how many coins the player has.
                        mainPlayer.CoinCount = Convert.ToInt32(line);
                    }


                    if (Count == 6)
                    {
                        // Sixth line for how many hours the player has remaining.
                        mainHUD.TotalTime = Convert.ToInt32(line);
                    }

                    // Seventh and Eigth lines denote information for the HUD clock.
                    if (Count == 7)
                    {
                        mainHUD.CurrentHour = Convert.ToInt32(line);
                    }
                    if (Count == 8)
                    {
                        mainHUD.CurrentMin = Convert.ToInt32(line);
                    }

                    // Nested for loops used to go through text data and use boolean information to construct a 2D array.
                    // File lines 9-14 contain binary information for an array structure denoting where in the overworld the player has already been.
                    if (Count >= 9 && Count < 14)
                    {
                        for (int i = 0; i < line.Length; i++)
                        {
                            if (line[i] != '1' && line[i] != '0')
                            {
                                throw new Exception();                                 // Must be binary data otherwise erronious.
                            }

                            if (line[i] == '1')
                            {
                                mainPlayer.VisitedOWSections[Row, Column] = true;
                            }
                            if (line[i] == '0')
                            {
                                mainPlayer.VisitedOWSections[Row, Column] = false;
                            }
                            Row++;
                        }
                        Row = 0;
                        Column++;
                    }

                    if (Count == 14)
                    {
                        Column = 0;
                    }                                                    // Reset Column, Row has already been reset.

                    // File lines 14-18 contain binary information for an array structure denoting where in Dungeon1 the player has already been.
                    if (Count >= 14 && Count < 18)
                    {
                        for (int i = 0; i < line.Length; i++)
                        {
                            if (line[i] != '1' && line[i] != '0')
                            {
                                throw new Exception();
                            }

                            if (line[i] == '1')
                            {
                                mainPlayer.VisitedDUN1Sections[Row, Column] = true;
                            }
                            if (line[i] == '0')
                            {
                                mainPlayer.VisitedDUN1Sections[Row, Column] = false;
                            }
                            Row++;
                        }

                        Row = 0;
                        Column++;
                    }

                    if (Count == 18)
                    {
                        Column = 0;
                    }                                                    // Reset Column, Row has already been reset.

                    // File lines 18-22 contain binary information for an array structure denoting where in Dungeon2 the player has already been.
                    if (Count >= 18 && Count < 22)
                    {
                        for (int i = 0; i < line.Length; i++)
                        {
                            if (line[i] != '1' && line[i] != '0')
                            {
                                throw new Exception();
                            }

                            if (line[i] == '1')
                            {
                                mainPlayer.VisitedDUN2Sections[Row, Column] = true;
                            }
                            if (line[i] == '0')
                            {
                                mainPlayer.VisitedDUN2Sections[Row, Column] = false;
                            }
                            Row++;
                        }

                        Row = 0;
                        Column++;
                    }

                    if (Count == 22)
                    {
                        Column = 0;
                    }                                                    // Reset Column, Row has already been reset.

                    // File lines 22-ENDOFFILE contain binary information for an array structure denoting where in Dungeon3 the player has already been.
                    if (Count >= 22)
                    {
                        for (int i = 0; i < line.Length; i++)
                        {
                            if (line[i] != '1' && line[i] != '0')
                            {
                                throw new Exception();
                            }

                            if (line[i] == '1')
                            {
                                mainPlayer.VisitedDUN3Sections[Row, Column] = true;
                            }
                            if (line[i] == '0')
                            {
                                mainPlayer.VisitedDUN3Sections[Row, Column] = false;
                            }
                            Row++;
                        }

                        Row = 0;
                        Column++;
                    }


                    Count++;
                }

                _hasLoadedGame = true;
                Reader.Close();                 // Close the reader
            }
            catch
            {
                mainID.GameError     = true;
                mainID.GameErrorCode = "GE0008LGF";                 // failed to load game file, streamreader error would cause this
            }
        }
Пример #10
0
        public void update(GamePadState state, InformationDisplay mainID, LoadGame mainLG, Player mainPlayer, HUD mainHUD, ref bool ExitGame)
        {
            if (mainID.GamePaused == false && mainID.ShowPlayer == true)                                                  // If the game is not paused allow the game to be paused as long as the player graphic is currently shown
            {
                if (state.Buttons.RightStick == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Enter) == true) // once start or enter pressed, close title screen.
                {
                    mainID.GamePaused          = true;                                                                    // pause game
                    mainID.RegisterStartPress  = false;
                    mainID.RegisterSelectPress = false;
                    OptionNumber = 1;                     // default option number to 1
                    ArrowPos     = new Vector2(250, 315); // default arrow position
                }
            }

            if (mainID.GamePaused == true)
            {
                if (mainID.RegisterSelectPress == true)
                {
                    if (state.Buttons.LeftStick == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.S) == true)
                    {
                        OptionNumber += 1;                         // Increment option number by 1 each time start or enter pressed

                        if (OptionNumber == 4)
                        {
                            OptionNumber = 1;
                        }                                                                    // options only go upto 3 so reset to 1

                        if (OptionNumber == 1)
                        {
                            ArrowPos = new Vector2(250, 315);                             // change arrow position when option changed
                        }

                        if (OptionNumber == 2)
                        {
                            ArrowPos = new Vector2(250, 392);
                        }

                        if (OptionNumber == 3)
                        {
                            ArrowPos = new Vector2(250, 469);
                        }

                        mainID.RegisterSelectPress = false;                         // Only allow one option to be changed per press of button
                    }
                }

                if (mainID.RegisterStartPress == true)
                {
                    if (state.Buttons.RightStick == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Enter) == true)                     // once start or enter pressed, close title screen.
                    {
                        if (OptionNumber == 1)
                        {
                            mainID.GamePaused = false;                             // resume the game
                        }

                        if (OptionNumber == 2)
                        {
                            mainLG.SaveGameFile(mainPlayer, mainHUD, mainID);                           // Save the game file selected when started
                        }

                        if (OptionNumber == 3)
                        {
                            ExitGame = true;                             // Close the game
                        }

                        mainID.RegisterStartPress = false;
                    }
                }
            }
        }
Пример #11
0
        /// Update
        public void update(GamePadState state, InformationDisplay mainID, LoadGame mainLG, Player mainPlayer, HUD mainHUD, AreaInterface areaInt)
        {
            mainLG.INIT(ref ActiveSaves, ref CompletedDungeons);             // initialise

            if (mainID.RegisterSelectPress == true)
            {
                if (DeleteMode == true)
                {
                    // DELETE MODE

                    // If conditions: so that program only registers one press of each specified button at a time.
                    if (state.Buttons.LeftStick == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.S) == true)
                    {
                        mainID.RegisterSelectPress = false;
                    }

                    if (mainID.RegisterBPress == true)                                                               // confirm the player wants to delete the save file
                    {
                        if (state.Buttons.A == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.B) == true) // player chooses not to delete
                        {
                            DeleteMode            = false;                                                           // exit delete mode
                            mainID.RegisterBPress = false;
                        }
                    }

                    // Player chooses to delete file
                    if (mainID.RegisterStartPress == true)                     // if start button can be pressed
                    {
                        if (state.Buttons.RightStick == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Enter) == true)
                        {
                            mainLG.DeleteGameFile(LoadOptionNumber);        // Delete file
                            DeleteMode = false;                             // exit delete mode
                            mainID.RegisterStartPress = false;
                        }
                    }
                }

                if (DeleteMode == false)                 // If not in delete mode
                {
                    // SWITCHING OPTIONS
                    if (state.Buttons.LeftStick == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.S) == true)
                    {
                        LoadOptionNumber += 1;

                        if (LoadOptionNumber >= 4)
                        {
                            LoadOptionNumber = 1;
                        }                                                                            // only allow upto 4 options

                        // Move the position of the arrow graphic in accordance to the option number
                        if (LoadOptionNumber == 1)
                        {
                            ArrowPos = new Vector2(40, 180);
                        }

                        if (LoadOptionNumber == 2)
                        {
                            ArrowPos = new Vector2(40, 340);
                        }

                        if (LoadOptionNumber == 3)
                        {
                            ArrowPos = new Vector2(40, 500);
                        }

                        mainID.RegisterSelectPress = false;
                    }

                    // CHECK TO SEE IF ENTERING DELETE MODE
                    if (mainID.RegisterBPress == true)
                    {
                        if (state.Buttons.A == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.B) == true)
                        {
                            if (ActiveSaves[LoadOptionNumber - 1] == true)         // -1 as option number minimum is 1 compared with Active saves which starts with 0.
                            {
                                DeleteMode = true;                                 // enter delete mode
                            }
                            mainID.RegisterBPress = false;
                        }
                    }

                    // LOAD GAME FILE AND SETUP, LoadOptionNumber 1 corresponds with file 0.
                    if (mainID.RegisterStartPress == true)
                    {
                        if (state.Buttons.RightStick == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Enter) == true)
                        {
                            if (ActiveSaves[LoadOptionNumber - 1] == true)                           // -1 as option number minimum is 1 compared with Active saves which starts with 0.
                            {
                                mainLG.LoadGameFile(mainID, mainPlayer, mainHUD, LoadOptionNumber);

                                areaInt.GenerateStructure((int)mainPlayer.CurrentOWSec.X, (int)mainPlayer.CurrentOWSec.Y);
                                areaInt.GenerateRectangleCollisions();
                                mainPlayer.PlayerGenCoordinate(areaInt);

                                RegularSettings(mainPlayer, mainID);
                            }
                            else
                            {
                                DefaultSettings(mainPlayer, mainID, areaInt);
                            }

                            mainID.ShowPlayer     = true;
                            mainID.SaveFileNumber = LoadOptionNumber;

                            mainID.ShowLoadScreen = false;

                            mainID.RegisterStartPress = false;
                        }
                    }
                }
            }
        }
Пример #12
0
 public virtual void GenerateItems(Player mainPlayer, AreaInterface areaInt, InformationDisplay mainID)
 {
 }
Пример #13
0
        /// GenerateEnemies
        /// Uses values gained previously from the text file and adds them to the enemyList.
        public virtual void GenerateEnemies(Rectangle playerRect, InformationDisplay mainID)
        {
            if (mainID.EraseList == true)
            {
                _enemyList.Clear();
                _itemRects.Clear();
                _enemyRects.Clear();
                mainID.EraseList = false;
            }

            if (_enemyAmount > 0)
            {
                if (mainID.NewEnemyList == true)
                {
                    _enemyList.Clear();
                    _itemRects.Clear();

                    Random R = new Random();
                    int    a = R.Next(_enemyAmount, _enemyAmount + 1);                  // random amount of enemies between that stated in the text file and +1.

                    for (int i = 0; i <= a; i++)
                    {
                        int orientationNum = R.Next(0, 3);                         // generate random number between 0 and 3.

                        if (_enemyType == "Leafen")
                        {
                            _enemyList.Add(new Leafen());                             // add new enemy to the enemyList.
                        }
                        if (_enemyType == "Firmeleon")
                        {
                            _enemyList.Add(new Firmeleon());
                        }

                        if (_enemyType == "Seafen")
                        {
                            _enemyList.Add(new Seafen());
                        }

                        // Random number generated denotes what direction the enemy will face.
                        if (orientationNum == 0)
                        {
                            _enemyList[i].Orientation = 'R';
                        }
                        if (orientationNum == 1)
                        {
                            _enemyList[i].Orientation = 'L';
                        }
                        if (orientationNum == 2)
                        {
                            _enemyList[i].Orientation = 'U';
                        }
                        if (orientationNum == 3)
                        {
                            _enemyList[i].Orientation = 'D';
                        }
                    }

                    for (int i = 0; i < _enemyList.Count; i++)
                    {
                        // Generate (within bounds) random coordinates for the enemy.
                        Vector2 coordinates = _enemyList[i].EnemyGenCoordinate(_enemyList[i].Width, _enemyList[i].Height, playerRect, _collisionRects, ref _itemRects);
                        _enemyList[i].EnemyCoordinates = coordinates;
                    }

                    mainID.NewEnemyList = false;
                }
            }
        }
Пример #14
0
        /// Draw
        public override void Draw(SpriteBatch spriteBatch, Player mainPlayer, InformationDisplay mainID)
        {
            if (_changeSec == true)
            {
                mainPlayer.DrawWeapon = false;
                mainID.NewEnemyList   = true;
                mainID.EraseList      = true;


                if (_changeDirection == 'R')                                                                  // If the player is walking into a right section
                {
                    spriteBatch.Draw(PreOverworldBackground, new Vector2(_DefaultPos.X, _DefaultPos.Y));      // draw the previous overworld section
                    spriteBatch.Draw(OverworldBackground, new Vector2(_DefaultNewPosR.X, _DefaultNewPosR.Y)); // draw the new overworld section
                }

                if (_changeDirection == 'L')                 // If the player is walking into a left section
                {
                    spriteBatch.Draw(PreOverworldBackground, new Vector2(_DefaultPos.X, _DefaultPos.Y));
                    spriteBatch.Draw(OverworldBackground, new Vector2(_DefaultNewPosL.X, _DefaultNewPosL.Y));
                }

                if (_changeDirection == 'U')                 // If the player is walking into a upwards section
                {
                    spriteBatch.Draw(PreOverworldBackground, new Vector2(_DefaultPos.X, _DefaultPos.Y));
                    spriteBatch.Draw(OverworldBackground, new Vector2(_DefaultNewPosU.X, _DefaultNewPosU.Y));
                }

                if (_changeDirection == 'D')                 // If the player is walking into a downwards section
                {
                    spriteBatch.Draw(PreOverworldBackground, new Vector2(_DefaultPos.X, _DefaultPos.Y));
                    spriteBatch.Draw(OverworldBackground, new Vector2(_DefaultNewPosD.X, _DefaultNewPosD.Y));
                }


                // SLIDING ANIMATION
                // When the player moves into a new section, the new section will slide into place in the opposite direction the player is travelling.

                int x = 0;

                // Set default X values.
                if (_changeDirection == 'U')
                {
                    x = (int)_DefaultNewPosU.X;
                }

                if (_changeDirection == 'D')
                {
                    x = (int)_DefaultNewPosD.X;
                }

                if (_changeDirection == 'L')
                {
                    x = (int)_DefaultNewPosL.X;
                }

                if (_changeDirection == 'R')
                {
                    x = (int)_DefaultNewPosR.X;
                }

                int y = 0;

                // For loop to go through structure array, if part of array is true then draw.
                for (int row = 0; row < 16; row++)
                {
                    // Set default Y values.
                    if (_changeDirection == 'U')
                    {
                        y = (int)_DefaultNewPosU.Y;
                    }

                    if (_changeDirection == 'D')
                    {
                        y = (int)_DefaultNewPosD.Y;
                    }

                    if (_changeDirection == 'L')
                    {
                        y = (int)_DefaultNewPosL.Y;
                    }

                    if (_changeDirection == 'R')
                    {
                        y = (int)_DefaultNewPosR.Y;
                    }

                    for (int column = 0; column < 13; column++)
                    {
                        if (_Structure[row, column] == true)
                        {
                            // Draw different graphic depending on section type.
                            if (_SectionType == "Forest" || _SectionType == "Riverside")
                            {
                                spriteBatch.Draw(Tree, new Vector2(x, y));
                            }

                            if (_SectionType == "DryForest")
                            {
                                spriteBatch.Draw(Tree_Brown, new Vector2(x, y));
                            }

                            if (_SectionType == "Desert")
                            {
                                spriteBatch.Draw(Desert_Plant, new Vector2(x, y));
                            }
                        }
                        y += 48;
                    }
                    x += 48;                     // each graphic size 48.
                }



                // Draw the position of the old section, works in the same manner as the new section animation.

                x = (int)_DefaultPos.X;

                y = 0;

                for (int row = 0; row < 16; row++)
                {
                    y = (int)_DefaultPos.Y;

                    for (int column = 0; column < 13; column++)
                    {
                        if (_PreviousStructure[row, column] == true)
                        {
                            if (_PreSectionType == "Forest" || _PreSectionType == "Riverside")
                            {
                                spriteBatch.Draw(Tree, new Vector2(x, y));
                            }

                            if (_PreSectionType == "DryForest")
                            {
                                spriteBatch.Draw(Tree_Brown, new Vector2(x, y));
                            }

                            if (_PreSectionType == "Desert")
                            {
                                spriteBatch.Draw(Desert_Plant, new Vector2(x, y));
                            }
                        }
                        y += 48;
                    }

                    x += 48;
                }
            }

            // Draw overworld section while slide animation is not running
            else
            {
                spriteBatch.Draw(OverworldBackground, new Vector2(0, 96));

                int x = 0;
                int y;

                for (int row = 0; row < 16; row++)
                {
                    y = 96;
                    for (int column = 0; column < 13; column++)
                    {
                        if (_Structure[row, column] == true)
                        {
                            if (_SectionType == "Forest" || _SectionType == "Riverside")
                            {
                                spriteBatch.Draw(Tree, new Vector2(x, y));
                            }

                            if (_SectionType == "DryForest")
                            {
                                spriteBatch.Draw(Tree_Brown, new Vector2(x, y));
                            }

                            if (_SectionType == "Desert")
                            {
                                spriteBatch.Draw(Desert_Plant, new Vector2(x, y));
                            }
                        }
                        y += 48;
                    }

                    x += 48;
                }

                if (_HasDungeonExterior == true)
                {
                    spriteBatch.Draw(DungeonExt, _DungeonExtPos);                     // draw dungeon exterior.
                }
            }
        }
Пример #15
0
        /// UPDATE
        public void update(GameTime gameTime, Player mainPlayer, InformationDisplay mainID)
        {
            /// COIN AMOUNT DISPLAY

            // Coin count always displayed as a 3 digit number.
            if (mainPlayer.CoinCount >= 0 && mainPlayer.CoinCount < 10)
            {
                _CoinAmountString = "x00" + mainPlayer.CoinCount.ToString();
            }
            if (mainPlayer.CoinCount >= 10 && mainPlayer.CoinCount < 100)
            {
                _CoinAmountString = "x0" + mainPlayer.CoinCount.ToString();
            }
            if (mainPlayer.CoinCount > 99)
            {
                _CoinAmountString = "x" + mainPlayer.CoinCount.ToString();
            }



            /// TIMING SYSTEM
            /// This ensures there are constraints in place for minutes, hours and days.
            _CurrentTimeAdder += gameTime.ElapsedGameTime.Milliseconds;

            int TimeInMs = 1800;             // 1800 is default value. Denotes speed of clock.

            if (_FinalCountdownBool == false)
            {
                if (_TotalTime == 1)
                {
                    // When the game time reaches the final hour
                    _CurrentTimeAdder   = 0;
                    _FinalCountdownBool = true;
                }

                if (_CurrentTimeAdder >= TimeInMs)
                {
                    // Add a minute eachtime gametime reaches 1800ms.
                    _CurrentMin      += 1;
                    _CurrentTimeAdder = 0;
                }

                if (_CurrentHour == 24)
                {
                    _CurrentHour = 0;
                }

                if (_CurrentMin >= 60)
                {
                    _CurrentMin   = 0;
                    _CurrentHour += 1;
                    _TotalTime   -= 1;
                }



                if ((_TotalTime <= 36 && _TotalTime > 24) || (_TotalTime <= 12 && _TotalTime >= 1))
                {
                    // Between 20:00-07:59 the time is dusk.
                    _Dusk = true;
                    _Dawn = false;
                }
                else
                {
                    _Dawn = true;
                    _Dusk = false;
                }

                if (_TotalTime == 24 && mainID.FinalDayShown == false)
                {
                    // Final day when only 24 hours remaining.
                    mainID.ShowFinalDay = true;
                }


                // Form a clock as a string
                // Depending on how many digits is in the current minute and hour.
                // Formats as a 24h clock.
                if (_CurrentHour < 10)
                {
                    _CurrentHourStr = "0" + _CurrentHour.ToString();
                }

                if (_CurrentMin < 10)
                {
                    _CurrentMinStr = "0" + _CurrentMin.ToString();
                }

                if (_CurrentHour >= 10)
                {
                    _CurrentHourStr = _CurrentHour.ToString();
                }

                if (_CurrentMin >= 10)
                {
                    _CurrentMinStr = _CurrentMin.ToString();
                }

                _CurrentTime = _CurrentHourStr + ":" + _CurrentMinStr;
            }
            else
            {
                // The game has reached the final hour

                if (_CurrentTimeAdder >= TimeInMs)
                {
                    _FinalCountdown  -= 1;
                    _CurrentTimeAdder = 0;
                }

                if (_FinalCountdown <= 0)
                {
                    // Game over when the timer has ran to 0 for the final hour.
                    _TotalTime      = 0;
                    mainID.GameOver = true;
                    _FinalCountdown = 0;
                }
            }
        }
Пример #16
0
        public void Update(GameTime gameTime, AreaInterface areaInt, Player mainPlayer, InformationDisplay mainID)
        {
            Random R = new Random();                          // Random generator

            for (int i = 0; i < areaInt.EnemyList.Count; i++) // goes through the EnemyList which has the objects of all the enimies in an area.
            {
                List <EnemyInterface> EnemyList = areaInt.EnemyList;

                Rectangle WeaponRect = EnemyList[i].EnemyWeapon.GetWeaponRect();


                /// Enemy Weapons

                if (EnemyList[i].EnemyWeapon.WeaponFireTimeMax != 0)                                                                           // maximum weapon fire time cannot be 0
                {
                    EnemyList[i].EnemyWeapon.WeaponFireTime = EnemyList[i].EnemyWeapon.WeaponFireTime + gameTime.ElapsedGameTime.Milliseconds; // Increment weapon fire time
                }

                if (areaInt.EnemyList[i].EnemyWeapon.WeaponFireTime > 0 && areaInt.EnemyList[i].EnemyWeapon.WeaponFireTime <= areaInt.EnemyList[i].EnemyWeapon.WeaponFireTimeMax)
                {
                    areaInt.EnemyList[i].DrawWeapon = true;                     // Draw the enemies weapon

                    // Set the weapon coordinates to the position of the enemy depending on direction.
                    if (EnemyList[i].EnemyWeapon.GetWeaponOrientation() == 'U')
                    {
                        EnemyList[i].EnemyWeapon.SetWeaponCoordinates(new Vector2(areaInt.EnemyList[i].EnemyWeapon.GetWeaponCoordinates().X, EnemyList[i].EnemyWeapon.GetWeaponCoordinates().Y - 7));
                    }

                    if (EnemyList[i].EnemyWeapon.GetWeaponOrientation() == 'D')
                    {
                        EnemyList[i].EnemyWeapon.SetWeaponCoordinates(new Vector2(EnemyList[i].EnemyWeapon.GetWeaponCoordinates().X, EnemyList[i].EnemyWeapon.GetWeaponCoordinates().Y + 7));
                    }

                    if (EnemyList[i].EnemyWeapon.GetWeaponOrientation() == 'L')
                    {
                        EnemyList[i].EnemyWeapon.SetWeaponCoordinates(new Vector2(EnemyList[i].EnemyWeapon.GetWeaponCoordinates().X - 7, EnemyList[i].EnemyWeapon.GetWeaponCoordinates().Y));
                    }

                    if (EnemyList[i].EnemyWeapon.GetWeaponOrientation() == 'R')
                    {
                        EnemyList[i].EnemyWeapon.SetWeaponCoordinates(new Vector2(EnemyList[i].EnemyWeapon.GetWeaponCoordinates().X + 7, EnemyList[i].EnemyWeapon.GetWeaponCoordinates().Y));
                    }
                }



                /// Enemy Out of bounds checker

                if (EnemyList[i].DrawCoordinates.X <= 0 && EnemyList[i].DrawCoordinates.X >= 768 && EnemyList[i].DrawCoordinates.Y <= 0 && EnemyList[i].DrawCoordinates.Y >= 720)
                {
                    EnemyList.RemoveAt(i);                     // remove the enemy if it is outside the parameters (coordiante range) of the area
                }


                EnemyList[i].IsMoving = true;                 // Set the enemy to moving status


                // Rectangles drawn around the possible coordinates and the draw coordinates of the enemy
                Rectangle EnemyRectangle     = new Rectangle((int)EnemyList[i].EnemyCoordinates.X, (int)EnemyList[i].EnemyCoordinates.Y, EnemyList[i].Width, EnemyList[i].Height);
                Rectangle EnemyDrawRectangle = new Rectangle((int)EnemyList[i].EnemyCoordinates.X, (int)EnemyList[i].DrawCoordinates.Y, EnemyList[i].Width, EnemyList[i].Height);

                Vector2 TempCoordinates = EnemyList[i].EnemyCoordinates;                 // allows new coordinates to be set in another class

                int eGameTime = EnemyList[i].EnemyHitTime;

                if (EnemyList[i].BeenHit == true)
                {
                    EnemyList[i].EnemyHitTime = (eGameTime + gameTime.ElapsedGameTime.Milliseconds);

                    if (eGameTime > 200)                     // Recovery time over
                    {
                        EnemyList[i].EnemyHitTime = 0;
                        eGameTime            = 0;
                        EnemyList[i].BeenHit = false;
                    }
                }



                /// Enemy Logic and Movement
                bool AllowDirectionChange = EnemyList[i].AllowDirChange;
                bool AllowMovement        = EnemyList[i].AllowMovement;

                // collision checker

                bool checkMove = false;                 // false for no collision


                checkMove = areaInt.checkMoveManager(EnemyRectangle);                 // check if enemy rectangle collides with area structure


                bool checkEnemyAndPlayerCollision = EnemyAndPlayerCollision(i, mainPlayer, areaInt);                 // check collision between enemy and player


                EnemyList[i].EnemyCoordinates = TempCoordinates;                 // Set the preliminary coordinates to the temporary coordinates (possible coordinates to use).

                if (checkMove == false && checkEnemyAndPlayerCollision == false)
                {
                    EnemyList[i].DrawCoordinates = EnemyList[i].EnemyCoordinates;
                }
                if ((checkMove == true || checkEnemyAndPlayerCollision == true) && EnemyList[i].AllowDirChange == true)
                {
                    EnemyList[i].entityReaction(); EnemyList[i].EnemyCoordinates = EnemyList[i].DrawCoordinates;
                }

                EnemyList[i].AllowDirChange = AllowDirectionChange;         // (Dis)Allow the enemy to change direction
                EnemyList[i].AllowMovement  = AllowMovement;                // (Dis)Allow the enemy to move


                EnemyList[i].EnemyGameTime = (EnemyList[i].EnemyGameTime + gameTime.ElapsedGameTime.Milliseconds);


                if (AllowDirectionChange == true)
                {
                    // Change direction at random time interval
                    if (EnemyList[i].EnemyGameTime >= R.Next(1200, 1500))
                    {
                        int orientationNum = R.Next(0, 4);
                        if (orientationNum == 0)
                        {
                            EnemyList[i].Orientation = 'R';
                        }
                        if (orientationNum == 1)
                        {
                            EnemyList[i].Orientation = 'L';
                        }
                        if (orientationNum == 2)
                        {
                            EnemyList[i].Orientation = 'U';
                        }
                        if (orientationNum == 3)
                        {
                            EnemyList[i].Orientation = 'D';
                        }

                        EnemyList[i].EnemyGameTime = 0;
                    }
                }



                EnemyList[i].Update(gameTime, R, checkMove, checkEnemyAndPlayerCollision, mainPlayer, eGameTime); // update each enemy in the list



                EnemyList[i].AllowDirChange = true;

                if (EnemyList[i].Health <= 0)                 // kill enemy if health <= 0
                {
                    mainID.EntityKilled   = true;
                    mainID.KilledLocation = EnemyList[i].DrawCoordinates; // show kill animation
                    EnemyList.RemoveAt(i);                                // remove enemy from list
                }
            }
        }
Пример #17
0
 public virtual void Draw(SpriteBatch spriteBatch, Player mainPlayer, InformationDisplay mainID)
 {
 }
Пример #18
0
        // NOTE: PLAYER ITEM COLLISION IS IN THE ITEM MANAGER - instantiated as mainIM in Game1 class.



        // MAIN FUNCTIONS


        public void Update(GameTime gameTime, GamePadState state, AreaInterface areaPoly, InformationDisplay mainID)
        {
            int playerSpeed = 4;             // player speed set

            if (_hasAnimationReset == true)
            {
                timeSinceLastFrame = 0;                 // resets animation
            }


            // CHECK MOVE MANAGER FUNCTIONS RETURN WHETHER THE PLAYER CAN MOVE IN THE DIRECTION THEY ARE FACING
            bool checkMove = false;


            checkMove = areaPoly.checkMoveManager(Rect());             // check whether the move is valid



            // CHECK EXIT MANAGER FUNCTIONS RETURN WHETHER THE PLAYER WILL MOVE INTO ANOTHER SECTION OF THE OVERWORLD OR DUNGEON
            string checkExit = "";

            if (mainID.EnergyBarrierStatus == false)             // CHANGE THIS TO JUST FALSE
            {
                if (_inOverworld == true)
                {
                    checkExit = areaPoly.checkExitManager(Rect(), CurrentOWSec);                     // checks to see if the player is near an exit
                }
                else
                {
                    checkExit = areaPoly.checkExitManager(Rect(), CurrentDUNSec);                     // checks to see if the player is near an exit
                }
            }


            // COLLISION WITH ENEMY ENTITIES
            bool checkEnemyCollision = false;

            if (areaPoly.EnemyList != null)
            {
                if (areaPoly.EnemyList.Count > 0)
                {
                    checkEnemyCollision = PlayerEnemyCollision(areaPoly);

                    PlayerEnemyWeaponCollision(areaPoly);                     // collisions with enemy weapons
                }
            }



            if (checkMove == false && checkEnemyCollision == false)
            {
                _drawPos = _entityPos;
            }                                                                                              // set draw coordaintes to equal the entity coordinates as they are valid.
            if ((checkMove == true || checkEnemyCollision == true) && _allowEntityDirChange == true)
            {
                _entityPos = _drawPos;
            }                                                                                                                               // Opposite to previous comment as they are not valid.


            // If statements and logic for the player traveling between areas

            if (_inOverworld == true)                                                                                             // if the player is in the overworld
            {
                bool checkDunEntrance = areaPoly.checkDunEntranceManager(_entityPos, _Height, _Width, ref _currentDungeonNumber); // check if the player has gone through dungeon entrance

                if (checkDunEntrance == true)
                {
                    if (areaPoly.EnemyList != null)
                    {
                        areaPoly.EnemyList.Clear();                         // clear the enemy list
                    }

                    _inDungeon      = true;                // enter the dungeon
                    _inOverworld    = false;
                    _inBossLevel    = false;
                    _hasChangedArea = true;

                    // default perameters/values for dungeons

                    _currentDUNSec  = new Vector2(2, 3);
                    _previousDUNSec = new Vector2(2, 3);

                    if (_currentDungeonNumber == 1)
                    {
                        _entityPos = new Vector2(288 - _Width, 650);
                        _drawPos   = _entityPos;
                    }

                    if (_currentDungeonNumber == 2)
                    {
                        _entityPos = new Vector2(288 - _Width, 650);
                        _drawPos   = _entityPos;
                    }

                    if (_currentDungeonNumber == 3)
                    {
                        _entityPos = new Vector2(288 - _Width, 650);
                        _drawPos   = _entityPos;
                    }
                }
            }


            if (_inDungeon == true)                                       // if the player is in a dungeon
            {
                bool checkDunExit = areaPoly.checkDunExitManager(Rect()); // check to see if player has collided with dungeon exit

                if (checkDunExit == true)
                {
                    if (areaPoly.EnemyList != null)
                    {
                        areaPoly.EnemyList.Clear();                         // clear the enemy list
                    }

                    // change area to overworld
                    _inDungeon      = false;
                    _inOverworld    = true;
                    _inBossLevel    = false;
                    _hasChangedArea = true;


                    // Set default entity position for overworld section to avoid collisions with structure
                    if ((int)_currentOWSec.X == 4 && (int)_currentOWSec.Y == 2)
                    {
                        _entityPos = new Vector2(366, 496);
                    }

                    if ((int)_currentOWSec.X == 1 && (int)_currentOWSec.Y == 0)
                    {
                        _entityPos = new Vector2(366, 496);
                    }

                    if ((int)_currentOWSec.X == 0 && (int)_currentOWSec.Y == 4)
                    {
                        _entityPos = new Vector2(510, 544);
                    }

                    _drawPos = _entityPos;
                }


                bool checkBossLevelEntrance = areaPoly.checkBossLevelEntranceManager(Rect());                 // check if player rectangle collides with BossLevel entrance

                if (checkBossLevelEntrance == true && mainID.EnergyBarrierStatus == false)
                {
                    // Change area to BossLevel
                    _inDungeon      = false;
                    _inOverworld    = false;
                    _inBossLevel    = true;
                    _hasChangedArea = true;

                    _entityPos = new Vector2(((720 / 2) - _Width), 520);                     // Default position when entering a boss level
                }
            }

            if (_inBossLevel == true)                         // player is located in BosLevel
            {
                if (areaPoly.CheckCompletedDungeon() == true) // check to see if dungeon has been completed
                {
                    _completedDungeons[areaPoly.GetBossLevelNumber() - 1] = true;
                    _justCompletedDungeon = true;

                    if (areaPoly.EnemyList != null)
                    {
                        areaPoly.EnemyList.Clear();                         // clear the enemy list
                    }

                    // Change location to the Overworld
                    _inDungeon      = false;
                    _inOverworld    = true;
                    _inBossLevel    = false;
                    _hasChangedArea = true;


                    // Default values when exiting BossLevel
                    if ((int)_currentOWSec.X == 4 && (int)_currentOWSec.Y == 2)
                    {
                        _entityPos = new Vector2(366, 496);
                    }

                    if ((int)_currentOWSec.X == 1 && (int)_currentOWSec.Y == 0)
                    {
                        _entityPos = new Vector2(366, 496);
                    }

                    if ((int)_currentOWSec.X == 0 && (int)_currentOWSec.Y == 4)
                    {
                        _entityPos = new Vector2(510, 544);
                    }

                    _drawPos = _entityPos;
                }
            }


            // Player weapon hit detection
            if (_playerHit == true)
            {
                if (_hitTime < 1)
                {
                    _Health -= 10;                     // deduct 10 health from the player

                    if (_Health <= 0)
                    {
                        _Health         = 0;
                        mainID.GameOver = true;                         // health is 0 so GameOver.
                    }
                }

                // Animation for player hit
                _hitTime           += gameTime.ElapsedGameTime.Milliseconds; // add time to variable
                timeSinceLastFrame += gameTime.ElapsedGameTime.Milliseconds; // add time to variable
                Animation(gameTime, ref timeSinceLastFrame);                 // animate through the sprite sheet when moving

                // Check recovery
                if (_hitTime >= _recoveryTime)
                {
                    _playerHit = false;
                    _hitTime   = 0;
                }
            }



            // Switch Player Weapons
            if (_allowEntityMovement == true && mainID.RegisterSelectPress == true && _playerWeaponFiring == false)
            {
                if (state.Buttons.LeftStick == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.S) == true)
                {
                    WeaponOptNum++;                     // increase weapon option by 1

                    while (true)
                    {
                        if (WeaponOptNum > 4 || WeaponOptNum < 1)
                        {
                            WeaponOptNum = 1;                             // Reset Weapon Option Number to 1
                        }

                        // Change player weapon based on Weapon Option Number (Changed when player uses S key or SELECT button)
                        if (WeaponOptNum == 1)                         // Default weapon, accessible by all players
                        {
                            _currentWeapon = "Sword";
                            break;
                        }
                        // For the next weapons, they are only avaliable on the condition that a specific dungeon has been completed.
                        if (WeaponOptNum == 2 && CompletedDungeons[0] == true)
                        {
                            _currentWeapon = "Seed";
                            break;
                        }
                        if (WeaponOptNum == 3 && CompletedDungeons[1] == true)
                        {
                            _currentWeapon = "FireBall";
                            break;
                        }
                        if (WeaponOptNum == 4 && CompletedDungeons[2] == true)
                        {
                            _currentWeapon = "WaterBall";
                            break;
                        }

                        WeaponOptNum++;                         // increment the option by one, go back through loop.
                    }

                    ChangeWeapon();                     // Change the weapon and set objects
                    mainID.RegisterSelectPress = false; // Only allow one press of select or S key/button at a time.
                }
            }



            /// Player Movement and Overworld/Dungeon Section Exits

            if (_allowEntityDirChange == true && _allowEntityMovement == true && _entityPos == _drawPos)
            {             // If movement is allowed and player's coordinates are valid.
                if (state.IsButtonDown(Buttons.LeftThumbstickUp) || Keyboard.GetState().IsKeyDown(Keys.Up) || state.IsButtonDown(Buttons.LeftThumbstickDown) || Keyboard.GetState().IsKeyDown(Keys.Down) ||
                    state.IsButtonDown(Buttons.LeftThumbstickLeft) || Keyboard.GetState().IsKeyDown(Keys.Left) || state.IsButtonDown(Buttons.LeftThumbstickRight) ||
                    Keyboard.GetState().IsKeyDown(Keys.Right))
                {                                                                // If any movement key is currently being pressed
                    timeSinceLastFrame += gameTime.ElapsedGameTime.Milliseconds; // add time to time since last frame
                    Animation(gameTime, ref timeSinceLastFrame);                 // Call animation function

                    // use information from CheckExit function if a value was returned
                    if (checkExit == "EXIT U" || checkExit == "EXIT D" || checkExit == "EXIT L" || checkExit == "EXIT R")
                    {
                        if (_inOverworld == true)
                        {
                            _previousOWSec     = new Vector2((int)_currentOWSec.X, (int)_currentOWSec.Y); // set previous overworld section
                            areaPoly.ChangeSec = true;                                                    // changing section
                            areaPoly.GeneratePreStructure((int)_previousOWSec.X, (int)_previousOWSec.Y);  // Generate the structure of the previous section
                            _visitedOWSections[(int)_previousOWSec.X, (int)_previousOWSec.Y] = true;      // the player has now visited the section
                        }

                        if (_inDungeon == true)
                        {
                            _previousDUNSec    = new Vector2((int)_currentDUNSec.X, (int)_currentDUNSec.Y); // set previous dungeon section
                            areaPoly.ChangeSec = true;                                                      // changing section
                            areaPoly.GeneratePreStructure((int)_previousDUNSec.X, (int)_previousDUNSec.Y);  // Generate the structure of the previous section
                            // the player has now visited the section, check which dungeon number section is in.
                            if (_currentDungeonNumber == 1)
                            {
                                _visitedDUN1Sections[(int)_previousDUNSec.X, (int)_previousDUNSec.Y] = true;
                            }
                            if (_currentDungeonNumber == 2)
                            {
                                _visitedDUN2Sections[(int)_previousDUNSec.X, (int)_previousDUNSec.Y] = true;
                            }
                            if (_currentDungeonNumber == 3)
                            {
                                _visitedDUN3Sections[(int)_previousDUNSec.X, (int)_previousDUNSec.Y] = true;
                            }
                        }
                    }
                }


                // MOVING BETWEEN SECTIONS OF THE OVERWORLD OR DUNGEONS

                // Direction depending on button pressed.

                if (state.IsButtonDown(Buttons.LeftThumbstickUp) || Keyboard.GetState().IsKeyDown(Keys.Up)) // this is the d-pad on some controllers
                {
                    _orientation = 'U';                                                                     // player is facing upwards

                    if (checkExit == "EXIT U")                                                              // player exits the overworld section up
                    {
                        if (_inOverworld == true)
                        {
                            _currentOWSec = new Vector2((int)_currentOWSec.X, (int)_currentOWSec.Y - 1);                             // move upwards by a section
                        }

                        if (_inDungeon == true)
                        {
                            _currentDUNSec = new Vector2((int)_currentDUNSec.X, (int)_currentDUNSec.Y - 1);                             // move upwards by a section
                        }

                        _entityPos = new Vector2(_entityPos.X, 670 - _Height);  // Set location player will spawn in the new section

                        areaPoly.ChangeDirection = 'U';                         // which direction is the new section in.
                    }

                    if (checkMove == false && checkEnemyCollision == false && mainID.GameOver == false)
                    {
                        _entityPos = new Vector2(_entityPos.X, _entityPos.Y - playerSpeed);                         // allow the player to move upwards 3 pixels at a time for each call of function
                    }
                }


                else if (state.IsButtonDown(Buttons.LeftThumbstickDown) || Keyboard.GetState().IsKeyDown(Keys.Down))
                {
                    _orientation = 'D';

                    if (checkExit == "EXIT D")                     // player exits the overworld section down
                    {
                        if (_inOverworld == true)
                        {
                            _currentOWSec = new Vector2((int)_currentOWSec.X, (int)_currentOWSec.Y + 1);                             // move downwards by a section
                        }

                        if (_inDungeon == true)
                        {
                            _currentDUNSec = new Vector2((int)_currentDUNSec.X, (int)_currentDUNSec.Y + 1);                             // move downwards by a section
                        }

                        _entityPos = new Vector2(_entityPos.X, 126);                         // Set location player will spawn in the new section
                        areaPoly.ChangeDirection = 'D';
                    }

                    if (checkMove == false && checkEnemyCollision == false && mainID.GameOver == false)
                    {
                        _entityPos = new Vector2(_entityPos.X, _entityPos.Y + playerSpeed);
                    }
                }

                else if (state.IsButtonDown(Buttons.LeftThumbstickLeft) || Keyboard.GetState().IsKeyDown(Keys.Left))
                {
                    _orientation = 'L';

                    if (checkExit == "EXIT L")                     // player exits the overworld section left
                    {
                        if (_inOverworld == true)
                        {
                            _currentOWSec = new Vector2((int)_currentOWSec.X - 1, (int)_currentOWSec.Y);                             // move left by a section
                        }

                        if (_inDungeon == true)
                        {
                            _currentDUNSec = new Vector2((int)_currentDUNSec.X - 1, (int)_currentDUNSec.Y);                             // move left by a section
                        }

                        _entityPos = new Vector2(680, _entityPos.Y);                         // Set location player will spawn in the new section
                        areaPoly.ChangeDirection = 'L';
                    }


                    if (checkMove == false && checkEnemyCollision == false && mainID.GameOver == false)
                    {
                        _entityPos = new Vector2(_entityPos.X - playerSpeed, _entityPos.Y);
                    }
                }

                else if (state.IsButtonDown(Buttons.LeftThumbstickRight) || Keyboard.GetState().IsKeyDown(Keys.Right))
                {
                    _orientation = 'R';

                    if (checkExit == "EXIT R")                     // player exits the overworld section right
                    {
                        if (_inOverworld == true)
                        {
                            _currentOWSec = new Vector2((int)_currentOWSec.X + 1, (int)_currentOWSec.Y);                             // move right by a section
                        }

                        if (_inDungeon == true)
                        {
                            _currentDUNSec = new Vector2((int)_currentDUNSec.X + 1, (int)_currentDUNSec.Y);                             // move right by a section
                        }

                        _entityPos = new Vector2(30, _entityPos.Y);                         // Set location player will spawn in the new section
                        areaPoly.ChangeDirection = 'R';
                    }

                    if (checkMove == false && checkEnemyCollision == false && mainID.GameOver == false)
                    {
                        _entityPos = new Vector2(_entityPos.X + playerSpeed, _entityPos.Y);
                    }
                }
            }

            _allowEntityDirChange = true;

            /// END OF PLAYER MOVEMENT AND SECTION EXITS



            // PLAYER WEAPON FIRE

            if (_allowWeaponFire == true && areaPoly.ChangeSec == false && mainID.GameOver == false)
            {
                _timeSincePlayerWeaponFire += gameTime.ElapsedGameTime.TotalMilliseconds;                 // add time to player weapon fire


                if (state.IsButtonDown(Buttons.A) || Keyboard.GetState().IsKeyDown(Keys.B))                 // A button is Keys.B on controller used for development
                {
                    if (_newPlayerWeaponFire == true)
                    {
                        _timeSincePlayerWeaponFire = 0;                         // reset timer
                        _playerWeaponFiring        = true;
                        _drawWeapon = true;
                        if (_currentWeapon == "Sword")
                        {
                            _playerWeapon.SetWeaponCoordinates(_entityPos);                             // set the weapons coordinates to fire from the players location
                            _playerWeapon.SetWeaponOrientation(_orientation);                           // Set the weapon ordientation in the direction the player is facing
                        }

                        if (_currentWeapon == "Seed")
                        {
                            _playerWeapon.SetWeaponCoordinates(_entityPos);                             // set the weapons coordinates to fire from the players location
                            _playerWeapon.SetWeaponOrientation(_orientation);                           // Set the weapon ordientation in the direction the player is facing
                        }

                        if (_currentWeapon == "FireBall")
                        {
                            _playerWeapon.SetWeaponCoordinates(_entityPos);                             // set the weapons coordinates to fire from the players location
                            _playerWeapon.SetWeaponOrientation(_orientation);                           // Set the weapon ordientation in the direction the player is facing
                        }

                        if (_currentWeapon == "WaterBall")
                        {
                            _playerWeapon.SetWeaponCoordinates(_entityPos);                             // set the weapons coordinates to fire from the players location
                            _playerWeapon.SetWeaponOrientation(_orientation);                           // Set the weapon ordientation in the direction the player is facing
                        }
                    }
                }


                // Fire Player Weapon
                if (_timeSincePlayerWeaponFire <= 410 && _playerWeaponFiring == true)
                {
                    _newPlayerWeaponFire = false;

                    _playerWeapon.FireWeapon();                     // Fire the weapon

                    // Set coordinates of player weapon based on direction
                    if (_playerWeapon.GetWeaponOrientation() == 'U')
                    {
                        _playerWeapon.SetWeaponCoordinates(new Vector2(_playerWeapon.GetWeaponCoordinates().X, _playerWeapon.GetWeaponCoordinates().Y - 7));
                    }

                    if (_playerWeapon.GetWeaponOrientation() == 'D')
                    {
                        _playerWeapon.SetWeaponCoordinates(new Vector2(_playerWeapon.GetWeaponCoordinates().X, _playerWeapon.GetWeaponCoordinates().Y + 7));
                    }

                    if (_playerWeapon.GetWeaponOrientation() == 'L')
                    {
                        _playerWeapon.SetWeaponCoordinates(new Vector2(_playerWeapon.GetWeaponCoordinates().X - 7, _playerWeapon.GetWeaponCoordinates().Y));
                    }

                    if (_playerWeapon.GetWeaponOrientation() == 'R')
                    {
                        _playerWeapon.SetWeaponCoordinates(new Vector2(_playerWeapon.GetWeaponCoordinates().X + 7, _playerWeapon.GetWeaponCoordinates().Y));
                    }
                }
                if (_timeSincePlayerWeaponFire > 400 && _timeSincePlayerWeaponFire <= 450 && _playerWeaponFiring == true)                 // stop displaying and firing weapon
                {
                    _playerWeaponFiring = false;
                    _drawWeapon         = false;
                }
                if (_timeSincePlayerWeaponFire > 500 && _playerWeaponFiring == false) // weapon cooldown
                {
                    _timeSincePlayerWeaponFire = 0;                                   // reset
                    _newPlayerWeaponFire       = true;
                }
            }
        }
Пример #19
0
        /// Initialize method:
        /// The following method will instantiate objects used throughout the program and set up default values for variables.

        protected override void Initialize()
        {
            try
            {
                mainID           = new InformationDisplay();
                mainID.GameError = false;
            }
            catch
            {
                Console.WriteLine("[WARNING] A game error has occurred! " + "GE0000MID");
            }

            try
            {
                Window.Title = "Chevron Shards";

                // WINDOW SIZE
                graphics.PreferredBackBufferWidth  = 768;
                graphics.PreferredBackBufferHeight = 720;
                graphics.ApplyChanges();
            }
            catch
            {
                // IF AN ERROR OCCURS WHILE LOADING A TEXTURE
                mainID.GameErrorCode = "GE0006WIN";
                Console.WriteLine("[WARNING] A game error has occurred! " + mainID.GameErrorCode);
                mainID.GameError = true;
            }

            try{
                Console.WriteLine("Game is Initialising...");

                // TITLE SCREEN
                mainID.ShowTitleScreen = true;
                mainID.ShowLoadScreen  = false;
                mainID.ShowHUD         = false;

                //mainLG = new LoadGame();
                mainLG     = new LoadGame();
                mainPS     = new PauseScreen();
                mainLS     = new LoadScreen();
                mainHUD    = new HUD();
                mainPlayer = new Player();
                mainOWM    = new OverworldManager();        // OWM stands for OverWorldManager
                mainDM     = new DungeonManager();          // DM stands for DungeonManager
                mainBLM    = new BossLevelManager();        // BLM stands for BossLevelManager
                mainEM     = new EnemyManager();            // EM stands for EnemyManager
                mainIM     = new ItemManager();             // IM stands for ItemManager

                mainID.SplashScreenTime = 0;

                mainHUD.Initialise();

                mainPlayer.InOverworld = true;                 // set player location to overworld
                mainPlayer.InDungeon   = false;
                mainPlayer.InBossLevel = false;

                InterfaceUpdate();

                areaInt.ChangeSec = false;

                mainID.GamePaused = false;

                mainPlayer.AllowEntityMovement = false;
                mainPlayer.AllowWeaponFire     = false;
                mainPlayer.PlayerWeaponFiring  = false;
                mainPlayer.NewPlayerWeaponFire = true;
                mainPlayer.DrawWeapon          = false;

                mainPlayer.AllowEntityDirChange = true;
                mainPlayer.Orientation          = 'R';
                mainPlayer.CurrentWeapon        = "Sword";
                mainPlayer.ChangeWeapon();

                mainID.ShowPlayer   = false;
                mainID.NewEnemyList = true;

                mainID.ShowItems     = false;
                mainID.NewItemList   = true;
                mainID.EraseItemList = false;

                mainID.EnergyBarrierStatus = false;

                mainID.GameOver             = false;
                mainID.GameOverAniCompleted = false;
                mainID.GameOverTime         = 0;
                mainID.GameOverStoryTime    = 0;


                mainID.ElapsedTime = 0f;

                mainID.CurrentFrame = new Point(0, 0);

                mainID.EntityKilled       = false;
                mainID.KillAnimationTimer = 0;
            }
            catch
            {
                mainID.GameErrorCode = "GE0007INI";
                Console.WriteLine("[WARNING] A game error has occurred! " + mainID.GameErrorCode);
                mainID.GameError = true;
            }

            base.Initialize();             // THIS MUST BE LAST
        }