protected override void Update(GameTime gameTime) { MouseState mState = Mouse.GetState(); KeyboardState kState = Keyboard.GetState(); if (kState.IsKeyDown(Keys.C) && _lastKeyState.IsKeyUp(Keys.C)) { _alphaPolyType++; if (_alphaPolyType == 4) { _alphaPolyType = 0; } _polygonAlpha = PolyTypes.CreateDefaultPolygon(_alphaPolyType, pos: _polygonAlpha.GetPosition(), rotation: _polygonAlpha.GetRotation(), scale: _polygonAlpha.GetScale()); _alphaDrawer = new PolyDrawer(GraphicsDevice, _spriteBatch, _pixel, _polygonAlpha); _polygonAlphaProjection = PolyTypes.CreateDefaultPolygon(_alphaPolyType, pos: _polygonAlpha.GetPosition(), rotation: _polygonAlpha.GetRotation(), scale: _polygonAlpha.GetScale()); _alphaProjectionDrawer = new PolyDrawer(GraphicsDevice, _spriteBatch, _pixel, _polygonAlphaProjection); } if (kState.IsKeyDown(Keys.V) && _lastKeyState.IsKeyUp(Keys.V)) { _betaPolyType++; if (_betaPolyType == 4) { _betaPolyType = 0; } _polygonBeta = PolyTypes.CreateDefaultPolygon(_betaPolyType, pos: _polygonBeta.GetPosition(), rotation: _polygonBeta.GetRotation(), scale: _polygonBeta.GetScale()); _betaDrawer = new PolyDrawer(GraphicsDevice, _spriteBatch, _pixel, _polygonBeta); } if (kState.IsKeyDown(Keys.Z)) { UsesBoundingSquares = false; } else if (kState.IsKeyDown(Keys.X)) { UsesBoundingSquares = true; } if (mState.LeftButton == ButtonState.Pressed) { _polygonAlpha.SetPosition(new Vector2D(mState.Position.X, mState.Position.Y)); } else if (mState.RightButton == ButtonState.Pressed) { _polygonBeta.SetPosition(new Vector2D(mState.Position.X, mState.Position.Y)); } if (kState.IsKeyDown(Keys.Q)) { _polygonAlpha.Rotate(MathD.PIOVER2 * gameTime.ElapsedGameTime.TotalSeconds); } else if (kState.IsKeyDown(Keys.W)) { _polygonAlpha.Rotate(-MathD.PIOVER2 * gameTime.ElapsedGameTime.TotalSeconds); } if (kState.IsKeyDown(Keys.A)) { _polygonBeta.Rotate(MathD.PIOVER2 * gameTime.ElapsedGameTime.TotalSeconds); } else if (kState.IsKeyDown(Keys.S)) { _polygonBeta.Rotate(-MathD.PIOVER2 * gameTime.ElapsedGameTime.TotalSeconds); } if (kState.IsKeyDown(Keys.E)) { _polygonAlpha.AddScale(gameTime.ElapsedGameTime.TotalSeconds * 100); } else if (kState.IsKeyDown(Keys.R)) { _polygonAlpha.AddScale(-gameTime.ElapsedGameTime.TotalSeconds * 100); } if (kState.IsKeyDown(Keys.D)) { _polygonBeta.AddScale(gameTime.ElapsedGameTime.TotalSeconds * 100); } else if (kState.IsKeyDown(Keys.F)) { _polygonBeta.AddScale(-gameTime.ElapsedGameTime.TotalSeconds * 100); } _broadphaseColliding = false; _colliding = false; if (!UsesBoundingSquares) { _alphaBounds = _polygonAlpha.GetBoundingBox(); _betaBounds = _polygonBeta.GetBoundingBox(); } else { _alphaBounds = _polygonAlpha.GetBoundingSquare(); _betaBounds = _polygonBeta.GetBoundingSquare(); } if (_alphaBounds.Overlaps(_betaBounds)) { _broadphaseColliding = true; } _minimumTranslationVector = Collision.CheckCollisionAndRespond(_polygonAlpha, _polygonBeta); if (_minimumTranslationVector != Vector2D.Zero) { _colliding = true; _polygonAlphaProjection.SetPosition(_polygonAlpha.GetPosition() + _minimumTranslationVector); _polygonAlphaProjection.SetRotation(_polygonAlpha.GetRotation()); _polygonAlphaProjection.SetScale(_polygonAlpha.GetScale()); } //if (_colliding && !_broadphaseColliding) // throw new Exception("Broadphase did not collide when SAT did!"); _lastKeyState = kState; base.Update(gameTime); }