protected override void Initialize() { gamestate = Vars_Func.GameState.StartMenu; hexagonSideLength = 1; //dont change mapDrawWidth = 10; //dont go over 15 planeLength = 50; //need an even number! minimapSize = 5 * planeLength; //in pixel frameTimeCounter = 0; frames = 0; drawFrame = 0; updateTimeCounter = 0; updates = 0; drawUpdates = 0; showIngameMenu = false; buttonIsPressed = false; reinitializeDone = false; timeCounter = 0.0f; minDelayTime = 100.0f; Vars_Func.loadContent(Content); map = new Map(planeLength, Logic.Vars_Func.HexTyp.Sand, true, hexagonSideLength); Mapgenerator.generateMap(map, planeLength, (int)(planeLength / 10), (int)(planeLength / 5), false); //cameraposition HQ.X * 1.5, HQ.Y * 1.75 camera = new Camera(new Vector3((map.HQPosition.X * 1.5f) + 1, (map.HQPosition.Y * 1.75f) - 10 + 0.875f, 11), new Vector3((map.HQPosition.X * 1.5f) + 1, (map.HQPosition.Y * 1.75f) + 0.875f, 0), Vector3.UnitZ, GraphicsDevice.Viewport.AspectRatio, 0.5f, 1000.0f, planeLength, hexagonSideLength); view = camera.View; projection = camera.Projection; keyboard = Keyboard.GetState(); mouseState = Mouse.GetState(); mousePosition = Vars_Func.mousepos(GraphicsDevice, mouseState, projection, view); minimap = new Minimap(map, new Vector2(graphics.PreferredBackBufferWidth - minimapSize, 0), new Vector2(minimapSize, minimapSize)); BasicGUI.createGUI(); StartMenu_GUI.createGUI(); MainMenu_GUI.createGUI(); Highscore_GUI.createGUI(); Setting_GUI.createGUI(); IngameMenu_GUI.createGUI(); Confirm_GUI.createGUI(); GameOver_GUI.createGUI(); IntroMenu_GUI.createGUI(); //InsertNameGUI.createGUI(); base.Initialize(); Interaction.Game = this; reinitializeDone = true; }
protected override void Update(GameTime gameTime) { timeCounter += gameTime.ElapsedGameTime.Milliseconds; // updates per second updateTimeCounter += gameTime.ElapsedGameTime.Milliseconds; ++updates; if (updateTimeCounter >= 1000) { drawUpdates = updates; updates = 0; updateTimeCounter -= 1000; } //// DON'T TOUCH THIS//// keyboard = Keyboard.GetState(); lastMouseState = mouseState; mouseState = Mouse.GetState(); //mousePosition = Vars_Func.mousepos(GraphicsDevice, mouseState, projection, view); //camera.Update(gameTime, gameTime.ElapsedGameTime.Milliseconds, mouseState); //view = camera.View; //map.update(gameTime, gameTime.ElapsedGameTime.Milliseconds); ////// DON'T TOUCH THIS//// //indexOfMiddleHexagon = Vars_Func.gridColision(camera.Target, planeLength, hexagonSideLength); //Vector2 mouseover = Vars_Func.gridColision(mousePosition, planeLength, hexagonSideLength); //Vars_Func.resetHexagonColors(map); //wavecontroller.update(gameTime, map); //Interaction.Update(gameTime, map, mouseover, mouseState, lastMouseState, keyboard); //GUI.update(gameTime, map, mouseState); if (Interaction.GameState == Vars_Func.GameState.GameOver) { gamestate = Vars_Func.GameState.GameOver; } switch (gamestate) { #region Startmenu case Vars_Func.GameState.StartMenu: StartMenu_GUI.update(gameTime, mouseState, keyboard); if (timeCounter > minDelayTime) { if (StartMenu_GUI.getGUI_Button() != null && StartMenu_GUI.getGUI_Button().Typ == Vars_Func.GUI_Typ.StartButton) { gamestate = Vars_Func.GameState.MainMenu; timeCounter = 0; } } break; #endregion #region Mainmenu case Vars_Func.GameState.MainMenu: MainMenu_GUI.update(gameTime, mouseState, keyboard); Highscore_GUI.restGUI(); Setting_GUI.restGUI(); GameOver_GUI.restGUI(); IntroMenu_GUI.restGUI(); showIngameMenu = false; if (MainMenu_GUI.getGUI_Button() != null) { if (timeCounter > minDelayTime) { switch (MainMenu_GUI.getGUI_Button().Typ) { case Vars_Func.GUI_Typ.NewGameButton: reinitialize(); //gamestate = Vars_Func.GameState.Ingame; gamestate = Vars_Func.GameState.Intro; timeCounter = 0; //MainMenu_GUI.restGUI(); break; case Vars_Func.GUI_Typ.SettingsButton: gamestate = Vars_Func.GameState.Settings; timeCounter = 0; break; case Vars_Func.GUI_Typ.HighScoreButton: gamestate = Vars_Func.GameState.Highscore; timeCounter = 0; break; case Vars_Func.GUI_Typ.QuitButton: timeCounter = 0; this.Exit(); break; default: break; } } } break; #endregion #region Ingame case Vars_Func.GameState.Ingame: MainMenu_GUI.restGUI(); Setting_GUI.restGUI(); Highscore_GUI.restGUI(); Confirm_GUI.restGUI(); GameOver_GUI.restGUI(); IntroMenu_GUI.restGUI(); if (keyboard.IsKeyDown(Keys.Tab) && !buttonIsPressed) { buttonIsPressed = true; showIngameMenu = !showIngameMenu; } if (!keyboard.IsKeyDown(Keys.Tab) && buttonIsPressed) { buttonIsPressed = false; } // Add ingame menu if (showIngameMenu) { IngameMenu_GUI.update(gameTime, mouseState, keyboard); if (IngameMenu_GUI.getGUI_Button() != null) { switch (IngameMenu_GUI.getGUI_Button().Typ) { case Vars_Func.GUI_Typ.NewGameButton: showIngameMenu = false; IngameMenu_GUI.restGUI(); break; case Vars_Func.GUI_Typ.SettingsButton: gamestate = Vars_Func.GameState.Settings; break; case Vars_Func.GUI_Typ.HighScoreButton: gamestate = Vars_Func.GameState.Highscore; break; case Vars_Func.GUI_Typ.StartButton: //Player.saveScore(); //reinitialize(); gamestate = Vars_Func.GameState.Confirm; break; default: break; } } } else { mousePosition = Vars_Func.mousepos(GraphicsDevice, mouseState, projection, view); camera.Update(gameTime, gameTime.ElapsedGameTime.Milliseconds, mouseState); view = camera.View; map.update(gameTime, gameTime.ElapsedGameTime.Milliseconds, this); //// DON'T TOUCH THIS//// indexOfMiddleHexagon = Vars_Func.gridColision(camera.Target, planeLength, hexagonSideLength); Vector2 mouseover = Vars_Func.gridColision(mousePosition, planeLength, hexagonSideLength); Vars_Func.resetHexagonColors(map); WaveController.update(gameTime, map); BasicGUI.update(gameTime, map, mouseState); Interaction.Update(gameTime, map, mouseover, mouseState, lastMouseState, keyboard); } break; #endregion #region Highscore case Vars_Func.GameState.Highscore: Highscore_GUI.update(gameTime, mouseState, keyboard); if (showIngameMenu) { IngameMenu_GUI.restGUI(); if (timeCounter > minDelayTime) { if (Highscore_GUI.getGUI_Button() != null && Highscore_GUI.getGUI_Button().Typ == Vars_Func.GUI_Typ.StartButton) { gamestate = Vars_Func.GameState.Ingame; timeCounter = 0; } } } else { MainMenu_GUI.restGUI(); if (timeCounter > minDelayTime) { if (Highscore_GUI.getGUI_Button() != null && Highscore_GUI.getGUI_Button().Typ == Vars_Func.GUI_Typ.StartButton) { gamestate = Vars_Func.GameState.MainMenu; timeCounter = 0; } } } break; #endregion #region Settings case Vars_Func.GameState.Settings: Setting_GUI.update(gameTime, mouseState, lastMouseState, keyboard); if (showIngameMenu) { IngameMenu_GUI.restGUI(); if (timeCounter > minDelayTime) { if (Setting_GUI.getGUI_Button() != null && Setting_GUI.getGUI_Button().Typ == Vars_Func.GUI_Typ.StartButton) { gamestate = Vars_Func.GameState.Ingame; timeCounter = 0; } } } else { MainMenu_GUI.restGUI(); if (timeCounter > minDelayTime) { if (Setting_GUI.getGUI_Button() != null && Setting_GUI.getGUI_Button().Typ == Vars_Func.GUI_Typ.StartButton) { gamestate = Vars_Func.GameState.MainMenu; timeCounter = 0; } } } break; #endregion #region Confirm case Vars_Func.GameState.Confirm: Confirm_GUI.update(gameTime, mouseState, keyboard); if (timeCounter > minDelayTime) { if (Confirm_GUI.getGUI_Button() != null && Confirm_GUI.getGUI_Button().Typ == Vars_Func.GUI_Typ.NewGameButton) { showIngameMenu = false; IngameMenu_GUI.restGUI(); gamestate = Vars_Func.GameState.Ingame; //showIngameMenu = false; //IngameMenu_GUI.restGUI(); //gamestate = Vars_Func.GameState.GameOver; timeCounter = 0; } if (Confirm_GUI.getGUI_Button() != null && Confirm_GUI.getGUI_Button().Typ == Vars_Func.GUI_Typ.QuitButton) { Player.saveScore(); reinitialize(); IntroMenu_GUI.createGUI(); MainMenu_GUI.createGUI(); Highscore_GUI.createGUI(); gamestate = Vars_Func.GameState.MainMenu; //gamestate = Vars_Func.GameState.InsertNameConfirm; //showIngameMenu = false; //IngameMenu_GUI.restGUI(); //gamestate = Vars_Func.GameState.Ingame; timeCounter = 0; } } break; #endregion #region GameOver case Vars_Func.GameState.GameOver: GameOver_GUI.update(gameTime, mouseState, keyboard); if (timeCounter > minDelayTime) { if (GameOver_GUI.getGUI_Button() != null && GameOver_GUI.getGUI_Button().Typ == Vars_Func.GUI_Typ.NewGameButton) { showIngameMenu = false; Player.saveScore(); reinitialize(); MainMenu_GUI.createGUI(); IngameMenu_GUI.restGUI(); Highscore_GUI.createGUI(); gamestate = Vars_Func.GameState.Ingame; //gamestate = Vars_Func.GameState.InserNameReset; //timeCounter = 0; } if (GameOver_GUI.getGUI_Button() != null && GameOver_GUI.getGUI_Button().Typ == Vars_Func.GUI_Typ.QuitButton) { Player.saveScore(); this.Exit(); //gamestate = Vars_Func.GameState.InserNameQuit; //timeCounter = 0; } } break; #endregion #region Intro case Vars_Func.GameState.Intro: IntroMenu_GUI.update(gameTime, mouseState, keyboard); if (timeCounter > minDelayTime) { if (IntroMenu_GUI.getGUI_Button() != null && IntroMenu_GUI.getGUI_Button().Typ == Vars_Func.GUI_Typ.NewGameButton) { MainMenu_GUI.restGUI(); reinitialize(); Setting_GUI.ShowHelp = true; gamestate = Vars_Func.GameState.Ingame; timeCounter = 0; } if (IntroMenu_GUI.getGUI_Button() != null && IntroMenu_GUI.getGUI_Button().Typ == Vars_Func.GUI_Typ.QuitButton) { MainMenu_GUI.restGUI(); reinitialize(); Setting_GUI.ShowHelp = false; gamestate = Vars_Func.GameState.Ingame; timeCounter = 0; } } break; #endregion #region Insert Name After Confirm case Vars_Func.GameState.InsertNameConfirm: InsertNameGUI.update(gameTime, mouseState, keyboard); if (timeCounter > minDelayTime) { if (InsertNameGUI.getGUI_Button() != null && InsertNameGUI.getGUI_Button().Typ == Vars_Func.GUI_Typ.QuitButton) { //Retrun the player name string PlayerName = InsertNameGUI.getPlayerName(); //TODO: pass on to the Player class Player.saveScore(); reinitialize(); IntroMenu_GUI.createGUI(); MainMenu_GUI.createGUI(); gamestate = Vars_Func.GameState.MainMenu; timeCounter = 0; } } break; #endregion #region Insert Name Before Reset case Vars_Func.GameState.InserNameReset: InsertNameGUI.update(gameTime, mouseState, keyboard); if (timeCounter > minDelayTime) { if (InsertNameGUI.getGUI_Button() != null && InsertNameGUI.getGUI_Button().Typ == Vars_Func.GUI_Typ.QuitButton) { //Retrun the player name string PlayerName = InsertNameGUI.getPlayerName(); //TODO: pass on to the Player class showIngameMenu = false; Player.saveScore(); reinitialize(); MainMenu_GUI.createGUI(); IngameMenu_GUI.restGUI(); gamestate = Vars_Func.GameState.Ingame; timeCounter = 0; } } break; #endregion #region Insert Name Before Quit case Vars_Func.GameState.InserNameQuit: InsertNameGUI.update(gameTime, mouseState, keyboard); if (timeCounter > minDelayTime) { if (InsertNameGUI.getGUI_Button() != null && InsertNameGUI.getGUI_Button().Typ == Vars_Func.GUI_Typ.QuitButton) { timeCounter = 0; //Retrun the player name string PlayerName = InsertNameGUI.getPlayerName(); //TODO: pass on to the Player class Player.saveScore(); this.Exit(); } } break; #endregion default: break; } base.Update(gameTime); }