public void Collision(ref Ball ball, ref RacketComputer racketComputer) { if (racketComputer.rectangle.Intersects(ball.rectangle)) { var coordinate = ball.rectangle.X + ball.texture.Width; if ((racketComputer.rectangle.X <= coordinate + 5) && (racketComputer.rectangle.X >= coordinate - 5) && (ball.rectangle.X < racketComputer.rectangle.X)) { ball.speedVector2.X = -ball.speedVector2.X; ball.speedVector2.Y = -ball.speedVector2.Y; } else if ((racketComputer.rectangle.X + racketComputer.texture.Width <= ball.rectangle.X + 5) && (racketComputer.rectangle.X + racketComputer.texture.Width >= ball.rectangle.X - 5)) { ball.speedVector2.X = -ball.speedVector2.X; ball.speedVector2.Y = -ball.speedVector2.Y; } else { ball.speedVector2.Y = -ball.speedVector2.Y; } } }
void NewGame() { displayWidth = graphics.PreferredBackBufferWidth; displayHeight = graphics.PreferredBackBufferHeight; var displayCentreX = displayWidth / 2; var displayCentreY = displayHeight / 2; ball = new Ball(Content.Load<Texture2D>("round"), new Rectangle(displayCentreX - 250, displayCentreY, 50, 50), displayWidth, displayHeight, 6); racket1 = new Racket(Content.Load<Texture2D>("palka"), new Rectangle(displayCentreX, displayHeight - 20, 250, 20), displayWidth, displayHeight, 5); racketComputer = new RacketComputer(Content.Load<Texture2D>("palka2"), new Rectangle(displayCentreX, 0, 250, 20), displayWidth, displayHeight, 5); action = new Action(); }