/// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { timeElapsed += (float)gameTime.ElapsedGameTime.Milliseconds; if (this.IsActive) { if (prevmousestate != mousestate) { prevmousestate = mousestate; } mousestate = Mouse.GetState(); if (prevkeystate != keystate) { prevkeystate = keystate; } keystate = Keyboard.GetState(); switch (gameState) { case GameState.Start: { #region MOve if (keystate.IsKeyDown(Keys.D) && !keystate.IsKeyDown(Keys.A)) { character.Move(10, 0); if (timeElapsed >= character.Interval) { character.Animation(Orientation.Right); timeElapsed = 0; } } if (keystate.IsKeyDown(Keys.A) && !keystate.IsKeyDown(Keys.D)) { character.Move(-10, 0); if (timeElapsed >= character.Interval) { character.Animation(Orientation.Left); timeElapsed = 0; } } if (keystate.IsKeyDown(Keys.W) && !keystate.IsKeyDown(Keys.S)) { character.Move(0, -10); if (timeElapsed >= character.Interval) { character.Animation(Orientation.Up); timeElapsed = 0; } } if (keystate.IsKeyDown(Keys.S) && !keystate.IsKeyDown(Keys.W)) { character.Move(0, 10); if (timeElapsed >= character.Interval) { character.Animation(Orientation.Down); timeElapsed = 0; } } #endregion break; } case GameState.Play: { break; } case GameState.Stop: { break; } case GameState.Base: { #region MOve if (keystate.IsKeyDown(Keys.D) && !keystate.IsKeyDown(Keys.A)) { character.Move(10, 0); if (timeElapsed >= character.Interval) { character.Animation(Orientation.Right); timeElapsed = 0; } } if (keystate.IsKeyDown(Keys.A) && !keystate.IsKeyDown(Keys.D)) { character.Move(-10, 0); if (timeElapsed >= character.Interval) { character.Animation(Orientation.Left); timeElapsed = 0; } } if (keystate.IsKeyDown(Keys.W) && !keystate.IsKeyDown(Keys.S)) { character.Move(0, -10); if (timeElapsed >= character.Interval) { character.Animation(Orientation.Up); timeElapsed = 0; } } if (keystate.IsKeyDown(Keys.S) && !keystate.IsKeyDown(Keys.W)) { character.Move(0, 10); if (timeElapsed >= character.Interval) { character.Animation(Orientation.Down); timeElapsed = 0; } } #endregion break; } default: { break; } } #region Menu switch (menuState) { case MenuState.Start: { buttons.Clear(); background = Content.Load <Texture2D>("bg_menu"); buttons.Add(new Button(100, 100, Content.Load <Texture2D>("bt_newgame"), null)); buttons.Add(new Button(100, 200, Content.Load <Texture2D>("bt_newgame"), null)); buttons.Add(new Button(100, 300, Content.Load <Texture2D>("bt_exit"), null)); if (buttons[0].LeftClick(mousestate, prevmousestate)) { menuState = MenuState.Newgame; } else if (buttons[1].LeftClick(mousestate, prevmousestate)) { menuState = MenuState.Load; } else if (buttons[2].LeftClick(mousestate, prevmousestate)) { Exit(); } break; } case MenuState.Newgame: { buttons.Clear(); background = Content.Load <Texture2D>("bg_newgame"); buttons.Add(new Button(450, 200, Content.Load <Texture2D>("bt_newcharacter"), null)); buttons.Add(new Button(100, 200, Content.Load <Texture2D>("bt_Back"), null)); buttons.Add(new Button(150, 300, Content.Load <Texture2D>("alian1"), null)); buttons.Add(new Button(300, 300, Content.Load <Texture2D>("alian2"), null)); buttons.Add(new Button(450, 300, Content.Load <Texture2D>("alian3"), null)); if (buttons[0].LeftClick(mousestate, prevmousestate)) { gameState = GameState.Base; playState = PlayState.Player; menuState = MenuState.Game; } if (buttons[1].LeftClick(mousestate, prevmousestate)) { menuState = MenuState.Start; } break; } case MenuState.Load: { buttons.Clear(); buttons.Add(new Button(100, 100, Content.Load <Texture2D>("bt_play"), null)); buttons.Add(new Button(110, 200, Content.Load <Texture2D>("bt_play"), null)); buttons.Add(new Button(120, 300, Content.Load <Texture2D>("bt_play"), null)); buttons.Add(new Button(100, 400, Content.Load <Texture2D>("bt_Back"), null)); if (buttons[0].LeftClick(mousestate, prevmousestate) || buttons[1].LeftClick(mousestate, prevmousestate) || buttons[2].LeftClick(mousestate, prevmousestate)) { playState = PlayState.Player; } if (buttons[3].LeftClick(mousestate, prevmousestate)) { menuState = MenuState.Start; } break; } case MenuState.Game: { buttons.Clear(); buttons.Add(new Button(100, 100, Content.Load <Texture2D>("bt_newgame"), null)); buttons.Add(new Button(300, 100, Content.Load <Texture2D>("bt_newgame"), null)); buttons.Add(new Button(500, 100, Content.Load <Texture2D>("bt_exit"), null)); // if (character.Position == buttons[0].) { // karaktert mozgását levizsgálni h belelép a kockákba akkor lépjen tovább x-y helyre } break; } default: { break; } } #endregion switch (playState) { case PlayState.Default: { break; } case PlayState.Player: { buttons.Clear(); gameState = GameState.Base; background = Content.Load <Texture2D>("bg_newgame"); if (keystate.IsKeyDown(Keys.Escape)) { playState = PlayState.Pause; gameState = GameState.Stop; } break; } case PlayState.Enemy: { break; } case PlayState.Pause: { buttons.Clear(); buttons.Add(new Button(100, 100, Content.Load <Texture2D>("bt_play"), null)); buttons.Add(new Button(100, 200, Content.Load <Texture2D>("bt_back"), null)); if (buttons[0].LeftClick(mousestate, prevmousestate)) { playState = PlayState.Player; } if (buttons[1].LeftClick(mousestate, prevmousestate)) { menuState = MenuState.Start; playState = PlayState.Enemy; } break; } default: { break; } } } base.Update(gameTime); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { timeElapsed += (float)gameTime.ElapsedGameTime.Milliseconds; if (this.IsActive) { if (prevms != ms) { prevms = ms; } ms = Mouse.GetState(); if (prevks != ks) { prevks = ks; } ks = Keyboard.GetState(); switch (gameState) { case GameState.Start: { if (ks.IsKeyDown(Keys.D) && !ks.IsKeyDown(Keys.A)) { character.Move(10, 0); if (timeElapsed >= character.Interval) { character.Animation(Orientation.Right); timeElapsed = 0; } } if (ks.IsKeyDown(Keys.A) && !ks.IsKeyDown(Keys.D)) { character.Move(-10, 0); if (timeElapsed >= character.Interval) { character.Animation(Orientation.Left); timeElapsed = 0; } } if (ks.IsKeyDown(Keys.W) && !ks.IsKeyDown(Keys.S)) { character.Move(0, -10); if (timeElapsed >= character.Interval) { character.Animation(Orientation.Up); timeElapsed = 0; } } if (ks.IsKeyDown(Keys.S) && !ks.IsKeyDown(Keys.W)) { character.Move(0, 10); if (timeElapsed >= character.Interval) { character.Animation(Orientation.Down); timeElapsed = 0; } } break; } case GameState.Play: { break; } case GameState.Stop: { break; } default: { break; } } #region Menu switch (menuState) { case MenuState.Start: { buttons.Clear(); background = Content.Load <Texture2D>("bg_menu"); buttons.Add(new Button(100, 100, Content.Load <Texture2D>("bt_newgame"), null)); buttons.Add(new Button(100, 150, Content.Load <Texture2D>("bt_newgame"), null)); buttons.Add(new Button(100, 200, Content.Load <Texture2D>("bt_exit"), null)); if (buttons[0].LeftClick(ms, prevms)) { menuState = MenuState.Newgame; } else if (buttons[1].LeftClick(ms, prevms)) { menuState = MenuState.Load; } else if (buttons[2].LeftClick(ms, prevms)) { Exit(); } break; } case MenuState.Newgame: { buttons.Clear(); buttons.Add(new Button(450, 200, Content.Load <Texture2D>("bt_newcharacter"), null)); buttons.Add(new Button(100, 200, Content.Load <Texture2D>("bt_Back"), null)); buttons.Add(new Button(150, 300, Content.Load <Texture2D>("alian1"), null)); buttons.Add(new Button(300, 300, Content.Load <Texture2D>("alian2"), null)); buttons.Add(new Button(450, 300, Content.Load <Texture2D>("alian3"), null)); if (buttons[0].LeftClick(ms, prevms)) { gameState = GameState.Play; playState = PlayState.Player; menuState = MenuState.Game; } if (buttons[1].LeftClick(ms, prevms)) { menuState = MenuState.Start; } break; } case MenuState.Load: { buttons.Clear(); buttons.Add(new Button(100, 100, Content.Load <Texture2D>("bt_play"), null)); buttons.Add(new Button(110, 200, Content.Load <Texture2D>("bt_play"), null)); buttons.Add(new Button(120, 300, Content.Load <Texture2D>("bt_play"), null)); buttons.Add(new Button(100, 400, Content.Load <Texture2D>("bt_Back"), null)); if (buttons[0].LeftClick(ms, prevms) || buttons[1].LeftClick(ms, prevms) || buttons[2].LeftClick(ms, prevms)) { gameState = GameState.Start; menuState = MenuState.Game; } if (buttons[3].LeftClick(ms, prevms)) { menuState = MenuState.Start; } break; } case MenuState.Game: { break; } default: { break; } } #endregion switch (playState) { case PlayState.Default: { break; } case PlayState.Player: { buttons.Clear(); background = Content.Load <Texture2D>("bg_horde"); buttons.Clear(); if (ks.IsKeyDown(Keys.Escape)) { playState = PlayState.Pause; } break; } case PlayState.Enemy: { break; } case PlayState.Pause: { buttons.Clear(); buttons.Add(new Button(100, 100, Content.Load <Texture2D>("bt_play"), null)); buttons.Add(new Button(100, 200, Content.Load <Texture2D>("bt_back"), null)); if (buttons[0].LeftClick(ms, prevms)) { playState = PlayState.Player; } if (buttons[1].LeftClick(ms, prevms)) { menuState = MenuState.Start; playState = PlayState.Enemy; } break; } default: { break; } } } base.Update(gameTime); }