/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); switch (CurrentGameState) { case GameState.InGame: InGame.Draw(_spriteBatch); break; case GameState.MainMenu: Main.Draw(_spriteBatch); break; case GameState.Exit: break; case GameState.HighScore: HighScore.Draw(_spriteBatch); break; default: throw new ArgumentOutOfRangeException(); } base.Draw(gameTime); }
private void GetMovement(GameTime gameTime) { // Update keyboard state _currentKeyboardState = Keyboard.GetState(); // Reset displacement Vector2 displacement = Vector2.Zero; // Get input if (_currentKeyboardState.IsKeyDown(_controlScheme.MoveUp)) { displacement.Y -= speed * gameTime.ElapsedGameTime.Milliseconds; _animationSet.AnimationDirection = AnimationDirections.Up; } if (_currentKeyboardState.IsKeyDown(_controlScheme.MoveLeft)) { displacement.X -= speed * gameTime.ElapsedGameTime.Milliseconds; _animationSet.AnimationDirection = AnimationDirections.Left; } if (_currentKeyboardState.IsKeyDown(_controlScheme.MoveRight)) { displacement.X += speed * gameTime.ElapsedGameTime.Milliseconds; _animationSet.AnimationDirection = AnimationDirections.Right; } if (_currentKeyboardState.IsKeyDown(_controlScheme.MoveDown)) { displacement.Y += speed * gameTime.ElapsedGameTime.Milliseconds; _animationSet.AnimationDirection = AnimationDirections.Down; } // if nothing happened set _animationState to Idle and return. if (displacement == Vector2.Zero) { _animationSet.AnimationState = AnimationStates.Idle; return; } // if something happened set _animationState to Walk _animationSet.AnimationState = AnimationStates.Walk; // Limit distance from other player // If the new distance is greater than MaxChainLength if (Vector2.Distance(CollidableObject.Position + displacement, InGame.GetOtherPlayerPosition(CollidableObject.Position)) > MaxChainLength) { // DonĀ“t add displacement to position return; // TODO: make the remaining length used too } // Add displacement to position AddToPosition(displacement); }
/// <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) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.End) || Keyboard.GetState().IsKeyDown(Keys.Escape)) { this.Exit(); } // If console is opened, skip updating game if (_console.Opened) { base.Update(gameTime); return; } //Fullscreen if (Keyboard.GetState().IsKeyDown(Keys.F)) { _graphics.IsFullScreen = !_graphics.IsFullScreen; _graphics.ApplyChanges(); } switch (CurrentGameState) { case GameState.InGame: if (IsMouseVisible == true) { IsMouseVisible = false; } InGame.Update(gameTime); break; case GameState.MainMenu: Main.Update(); break; case GameState.HighScore: HighScore.Update(); break; case GameState.Exit: this.Exit(); break; default: throw new ArgumentOutOfRangeException(); } base.Update(gameTime); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. _spriteBatch = new SpriteBatch(GraphicsDevice); Services.AddService(typeof(SpriteBatch), _spriteBatch); GameConsoleOptions consoleOptions = new GameConsoleOptions() { ToggleKey = Keys.Insert, Padding = 10, OpenOnWrite = true, }; IConsoleCommand[] commands = new IConsoleCommand[] { new BeepCommand() }; _console = new GameConsole(this, _spriteBatch, commands, consoleOptions); InGame.LoadContent(Content, GraphicsDevice); Main.LoadContent(Content, GraphicsDevice.Viewport); HighScore.LoadContent(Content, GraphicsDevice.Viewport); #if DEBUG DebugFont = Content.Load <SpriteFont>(@"Fonts/DebugFont"); #endif }