public void Update(KeyboardState keyboardState, GameTime gameTime, IEnumerable <ICollidable> collidables) { MouseState mouseState = Mouse.GetState(); Hitbox = new Rectangle((int)Position.X - 16, (int)Position.Y - 16, 32, 32); rectangle = new Rectangle((int)Position.X, (int)Position.Y, Texture.Width, Texture.Height); // W // Move up if (keyboardState.IsKeyDown(Keys.W)) { Vector2 newPosiiton = new Vector2(Position.X, Position.Y - playerSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds); Rectangle newRectangle = new Rectangle((int)newPosiiton.X - 16, (int)newPosiiton.Y - 16, 32, 32); bool movementPossible = true; foreach (var item in collidables) { if (item.Hitbox.Intersects(newRectangle) && item.IsSolid) { movementPossible = false; return; } } if (movementPossible) { Position.Y -= playerSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; isMoving = true; } } // S // Move down if (keyboardState.IsKeyDown(Keys.S)) { Vector2 newPosiiton = new Vector2(Position.X, Position.Y + playerSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds); Rectangle newRectangle = new Rectangle((int)newPosiiton.X - 16, (int)newPosiiton.Y - 16, 32, 32); bool movementPossible = true; foreach (var item in collidables) { if (item.Hitbox.Intersects(newRectangle) && item.IsSolid) { movementPossible = false; return; } } if (movementPossible) { Position.Y += playerSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; isMoving = true; } } // A // Move left if (keyboardState.IsKeyDown(Keys.A)) { Vector2 newPosiiton = new Vector2(Position.X - playerSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds, Position.Y); Rectangle newRectangle = new Rectangle((int)newPosiiton.X - 16, (int)newPosiiton.Y - 16, 32, 32); bool movementPossible = true; foreach (var item in collidables) { if (item.Hitbox.Intersects(newRectangle) && item.IsSolid) { movementPossible = false; return; } } if (movementPossible) { Position.X -= playerSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; isMoving = true; } } // D // Move right if (keyboardState.IsKeyDown(Keys.D)) { Vector2 newPosiiton = new Vector2(Position.X + playerSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds, Position.Y); Rectangle newRectangle = new Rectangle((int)newPosiiton.X - 16, (int)newPosiiton.Y - 16, 32, 32); bool movementPossible = true; foreach (var item in collidables) { if (item.Hitbox.Intersects(newRectangle) && item.IsSolid) { movementPossible = false; return; } } if (movementPossible) { Position.X += playerSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; isMoving = true; } } // LMB // Shoot if (mouseState.LeftButton == ButtonState.Pressed) { Shoot(Position, mouseState.Position.ToVector2(), GameState.mapObjects, GameState.entities); } // 1 // Change gun to 0 if (keyboardState.IsKeyDown(Keys.D1)) { CurrentGun = 0; } // 2 // Change gun to 1 if (keyboardState.IsKeyDown(Keys.D2)) { CurrentGun = 1; } // 3 // Change gun to 2 if (keyboardState.IsKeyDown(Keys.D3)) { CurrentGun = 2; } // 4 // Change gun to 3 if (keyboardState.IsKeyDown(Keys.D4)) { CurrentGun = 3; } // No keys // Reset movement if (keyboardState.GetPressedKeyCount() == 0) { isMoving = false; } //Hitmarks remove if (HM.Count > 15) { HM.Dequeue(); } currentFrame++; if (currentFrame == totalFrames) { currentFrame = 0; } GunCooldown++; }