public void Update() { if (Input.GetKeyDown(KeyCode.Space)) { if (m_scoreDisplayVisible) { m_scoreDisplay.Hide(); } else { m_scoreDisplay.Show(); } m_scoreDisplayVisible = !m_scoreDisplayVisible; } if (Input.GetKeyDown(KeyCode.R)) { Main.Instance.ModifyScore(PlayerData.PlayerId.PLAYER_2, 100); } if (Input.GetKeyDown(KeyCode.P)) { m_timerDisplay.m_timeLeft = 0; } }
private void timerTick(object sender, EventArgs e) { var cheerTimer = new Timer(); cheerTimer.Interval = 3000; cheerTimer.Tick += (s, trigger) => { ScoreDisplay.Hide(); cheerTimer.Stop(); }; if (playerScore < 10) { playerScoreboard.Text = "0" + playerScore; } else { playerScoreboard.Text = "" + playerScore; } if (cpuScore < 10) { cpuScoreboard.Text = "0" + cpuScore; } else { cpuScoreboard.Text = "" + cpuScore; } ball.Top -= ballY; ball.Left -= ballX; cpu.Top += cpuSpeed; if (cpu.Top < 0 || cpu.Top + cpu.Height > ClientSize.Height) { cpuSpeed = -cpuSpeed; } if (goUp && player.Top > 0 && !goDown) { player.Top -= 8; } if (goDown && player.Top + player.Height < ClientSize.Height && !goUp) { player.Top += 8; } if (ball.Top < 0 || ball.Top + ball.Height > ClientSize.Height) { ballY = -ballY; } if (ball.Left < 0) { ball.Left = this.Width / 2; ballX = -ballX; //ballX -= 2; playerScore++; ScoreDisplay.Text = "Player scores!"; if (ScoreDisplay.Visible == true) { cheerTimer.Stop(); } else { ScoreDisplay.Show(); } cheerTimer.Start(); } if (ball.Left > ClientSize.Width) { ball.Left = ClientSize.Width / 2; ballX = -ballX; //ballX += 2; cpuScore++; ScoreDisplay.Text = "CPU scores!"; if (ScoreDisplay.Visible == true) { cheerTimer.Stop(); } else { ScoreDisplay.Show(); } cheerTimer.Start(); } if (ball.Bounds.IntersectsWith(player.Bounds) || ball.Bounds.IntersectsWith(cpu.Bounds)) { ballX = -ballX; } if (playerScore >= 10) { gameTimer.Stop(); MessageBox.Show("Player wins"); } }