/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { game = this; // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here mainMenuScreen = new MainMenuScreen(game); cursor = new Cursor(game); table = new Table(game); puck = new Puck(game); paddle = new Paddle(game); }
public static void MovingPuckCollision(Paddle paddle, Puck puck) { MovingPaddleCollision(paddle, puck, 10); }
public static float DistanceBetweenPaddle(Point startingDistance, Paddle currentPosition) { double distanceX = Math.Pow((double)currentPosition.CenterX - (double)startingDistance.X, 2); double distanceY = Math.Pow((double)currentPosition.CenterY - (double)startingDistance.Y, 2); double dblDistance = Math.Round(Math.Sqrt(distanceX + distanceY), 2); float returnDistance = (float)Math.Abs(dblDistance); if (returnDistance > 150) { return 2.0f; } else if (returnDistance > 100 && returnDistance <= 150) { return 2.5f; } else if (returnDistance >= 50 && returnDistance <= 100) { return 3.0f; } else if (returnDistance < 50 && returnDistance > 30) { return 4.0f; } else if (returnDistance <= 30 && returnDistance > 15) { return 5.0f; } else { return 7.0f; } }
//public static Point PaddlePuckCollisionDest(Paddle paddle, Puck puck) //{ // Point point = new Point(); // //Standing puck, Moving paddle // double dblCollisionDist = Math.Sqrt(Math.Pow(puck.CenterX - paddle.CenterX, 2) + Math.Pow(puck.CenterY - paddle.CenterY, 2)); // double n_x = (puck.CenterX - paddle.X) / dblCollisionDist; // double n_Y = (puck.CenterY - paddle.Y) / dblCollisionDist; // double p = 2 * (paddle.StartCenterX * n_x + paddle.StartCenterY * n_Y) / (paddle.Mass + puck.Mass); //Division is for the mass of an object // double w_x = paddle.StartCenterX - p * paddle.Mass * n_x - p * paddle.CenterX * n_x; // double w_y = paddle.StartCenterY - p * paddle.Mass * n_Y - p * paddle.CenterY * n_Y; // //puck.Speed = (float)(Math.Abs(p) / 20); // point.X = (int)w_x; // point.Y = (int)w_y; // return point; //} public static void MovingPaddleCollision(Paddle paddle, Puck puck, float force) { //lower the force number the faster the puck goes float DirX = (paddle.CenterX - puck.CenterX) / force; float DirY = (paddle.CenterY - puck.CenterY) / force; DirX = DirX * -1; DirY = DirY * -1; puck.SpeedX = DirX; puck.SpeedY = DirY; }