/// 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(); }
/// 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; } } } } }
/// Update Method: /// The main game logic is located in this method or the update methods in the classes called in this method. /// The majority of user input is registered i.e. button/key pressing is registered here. protected override void Update(GameTime gameTime) { state = GamePad.GetState(PlayerIndex.One); // creates a state for gamepads // EXIT GAME VIA ESCAPE KEY if (state.Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); // the game closes } InterfaceUpdate(); mainID.update(gameTime, mainPlayer, mainHUD, areaInt, mainLG, state); if (mainID.Init == true) { Initialize(); // reinitialise game } // PAUSE SCREEN if (mainID.GameError == false && mainID.RegisterStartPress == true && mainID.ShowTitleScreen == false && mainID.GameOver == false && mainID.GameComplete == false) { bool ExitGame = false; mainPS.update(state, mainID, mainLG, mainPlayer, mainHUD, ref ExitGame); if (ExitGame == true) { Exit(); // close game } } // if (mainID.GameError == false && mainID.GamePaused == false && mainID.GameComplete == false) { if (mainID.GameOver == false) { if (mainID.ShowLoadScreen == true) { mainLS.update(state, mainID, mainLG, mainPlayer, mainHUD, areaInt); } // IN GAME CLOCK SYSTEM - Prints an in game clock on the HUD. if (mainID.ShowFirstDay == false && mainID.ShowTitleScreen == false && mainID.ShowFinalDay == false && mainID.ShowLoadScreen == false && mainID.GameOver == false) { mainHUD.update(gameTime, mainPlayer, mainID); } if ((areaInt.ChangeSec == true) && mainID.AllowSectionChangeReset == true) { // Generate structure for area i.e. read text file and load to array, then draw if (mainPlayer.InOverworld == true) { mainOWM.GenerateStructure((int)mainPlayer.CurrentOWSec.X, (int)mainPlayer.CurrentOWSec.Y); mainOWM.GenerateRectangleCollisions(); } if (mainPlayer.InDungeon == true) { mainDM.GenerateStructure(mainPlayer.CurrentDungeonNumber, (int)mainPlayer.CurrentDUNSec.X, (int)mainPlayer.CurrentDUNSec.Y); mainPlayer.CurrentBLNumber = mainPlayer.CurrentDungeonNumber; mainDM.GenerateRectangleCollisions(); } if (mainPlayer.InBossLevel == true) { mainBLM.SetBossLevelNumber(mainPlayer.CurrentBLNumber); mainBLM.GenerateStructure(); mainDM.GenerateRectangleCollisions(); } if (areaInt.EnemyList != null) { areaInt.EnemyList.Clear(); // clear the area's enemy list } if (areaInt.ItemList != null) { areaInt.ItemList.Clear(); // clear the area's item list mainID.NewItemList = true; } mainID.AllowSectionChangeReset = false; } if (areaInt.ChangeSec == false) { mainID.AllowSectionChangeReset = true; } // reset change section areaInt.update(); // ENEMY, WEAPON AND ITEM UPDATE AND LIST GENERATION if (areaInt.ChangeSec == false && mainID.GameOver == false) { Rectangle WeaponRectangle = new Rectangle(0, 0, 0, 0); // default rectangle mainPlayer.PlayerWeapon.SetRectangle(); WeaponRectangle = mainPlayer.PlayerWeapon.GetWeaponRect(); // sets the weapon rectangle to the dimentions and position of the sword. FalseBool = false; // a bool that will be set to false everytime update is called. if (mainPlayer.HasChangedArea == true) { mainID.NewEnemyList = true; mainID.EraseList = true; mainPlayer.HasChangedArea = false; } areaInt.GenerateEnemies(mainPlayer.Rect(), mainID); areaInt.GenerateItems(mainPlayer, areaInt, mainID); if (areaInt.EnemyList != null) // check to see if enemy list is empty { if (areaInt.EnemyList.Count > 0) { mainEM.Update(gameTime, areaInt, mainPlayer, mainID); // Update the enemy manager } } } } // PLAYER UPDATE AND MOVEMENT if (mainPlayer.AllowEntityMovement == true && areaInt.ChangeSec == false) { bool trueBool = true; mainPlayer.Update(gameTime, state, areaInt, mainID); // If the player changes area type, then reaload the interface, content and enemies if (mainPlayer.InOverworld == true && mainPlayer.HasChangedArea == true) { mainOWM.GenerateStructure((int)mainPlayer.CurrentOWSec.X, (int)mainPlayer.CurrentOWSec.Y); mainOWM.GenerateEnemies(mainPlayer.Rect(), mainID); areaInt.GenerateRectangleCollisions(); } if (mainPlayer.InDungeon == true && mainPlayer.HasChangedArea == true) { InterfaceUpdate(); areaInt.GenerateStructure(mainPlayer.CurrentDungeonNumber, 2, 3); areaInt.GenerateRectangleCollisions(); mainPlayer.CurrentBLNumber = mainPlayer.CurrentDungeonNumber; areaInt.GenerateEnemies(mainPlayer.Rect(), mainID); } if (mainPlayer.InBossLevel == true && mainPlayer.HasChangedArea == true) { InterfaceUpdate(); areaInt.SetBossLevelNumber(mainPlayer.CurrentBLNumber); areaInt.GenerateStructure(); areaInt.GenerateRectangleCollisions(); areaInt.GenerateEnemies(mainPlayer.Rect(), mainID); } // ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- } // ITEM UPDATE if (areaInt.ChangeSec == false) { mainIM.update(areaInt, mainPlayer); } } base.Update(gameTime); }