public bool Collide(Rectangle rectangle) { RotatedRectangle rotateRectangle = new RotatedRectangle( null, new Vector2(rectangle.X, rectangle.Y), new Vector2(0, 0), rectangle.Width, rectangle.Height); rotateRectangle.Update(); return(Collide(rotateRectangle)); }
protected override void Update(GameTime gameTime) { Window.Title = "Monogame Sat System @mmbelkiman"; //Move rectangle 1 with keyboard KeyboardState state = Keyboard.GetState(); Vector2 rotate1Position = rotatedRectangle1.Position; if (state.IsKeyDown(Keys.Left)) { rotate1Position.X -= 2.5f; } if (state.IsKeyDown(Keys.Right)) { rotate1Position.X += 2.5f; } if (state.IsKeyDown(Keys.Up)) { rotate1Position.Y -= 2.5f; } if (state.IsKeyDown(Keys.Down)) { rotate1Position.Y += 2.5f; } rotatedRectangle1.Position = rotate1Position; rotatedRectangle1.Update(); rotatedRectangle2.Update(); rotatedRectangle1.Rotation -= 0.01f; rotatedRectangle2.Rotation += 0.01f; //Check collisions if (rotatedRectangle1.Collide(rotatedRectangle2) || rotatedRectangle1.Collide(rectangleNormal)) { rotatedRectangle1.SetColor(new Color(100, 50, 50, 200)); } else { rotatedRectangle1.SetColor(new Color(50, 100, 50, 200)); } if (circle1.Collide(circle2)) { circle1.SetColor(new Color(100, 50, 50, 200)); circle2.SetColor(new Color(100, 50, 50, 200)); } else { circle1.SetColor(new Color(150, 255, 180, 255)); circle2.SetColor(new Color(150, 255, 180, 255)); } if (circle2MoveUp) { circle2.Position = new Vector2(circle2.Position.X, circle2.Y -= 2); } else { circle2.Position = new Vector2(circle2.Position.X, circle2.Y += 2); } if (circle2.Position.Y > 430) { circle2MoveUp = true; } else if (circle2.Position.Y < 180) { circle2MoveUp = false; } base.Update(gameTime); }