protected override void Update(GameTime gameTime) { if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } else if (Keyboard.GetState().IsKeyDown(Keys.Space) && !ball.gameRun) { ball.gameRun = true; } else if (Keyboard.GetState().IsKeyDown(Keys.R) && ball.gameRun) { ball.gameRun = false; ball.Reetball(); } player1.posY = Mouse.GetState().Y; player2.posY = Mouse.GetState().Y; //bollen går till spelare nm2 if (ball.dirX > 0) { if (ball.posY >= player2.posY && ball.posY + ballSize < player2.posY + racketH && ball.posX + ballSize >= player2.posX) { ball.dirX = -ball.dirX; } else if (ball.posX >= GraphicsDevice.Viewport.Width - ballSize) { score1++; ball.gameRun = false; ball.Reetball(); } } //bollen går till spelare nm1 else if (ball.dirX < 0) { if (ball.posY >= player1.posY && ball.posY + ballSize <= player1.posY + racketH && ball.posX <= player1.posX + racketW) { ball.dirX = -ball.dirX; } else if (ball.posX <= 0) { score2++; ball.gameRun = false; ball.Reetball(); } } base.Update(gameTime); }
protected override void LoadContent() { scorefont = Content.Load <SpriteFont>("scorefont"); spriteBatch = new SpriteBatch(GraphicsDevice); ball = new ClassBall(GraphicsDevice, spriteBatch, this, ballSize); player1 = new ClassRacket(GraphicsDevice, spriteBatch, this, racketW, racketH, 10, GraphicsDevice.Viewport.Height / 2 - racketH / 2); player2 = new ClassRacket(GraphicsDevice, spriteBatch, this, racketW, racketH, GraphicsDevice.Viewport.Width - racketH, GraphicsDevice.Viewport.Height / 2 - racketH / 2); Components.Add(player1); Components.Add(player2); Components.Add(ball); ball.Reetball(); }