//Stopping Movement Timers private void MoveTimersStop() { MoveUpTimer.Stop(); MoveDownTimer.Stop(); MoveLeftTimer.Stop(); MoveRightTimer.Stop(); }
//KeyUp Event Handler private void SpaceForm_KeyUp(object sender, KeyEventArgs e) { MoveRigthTimer.Stop(); MoveLeftTimer.Stop(); MoveDownTimer.Stop(); MoveTopTimer.Stop(); if (e.KeyCode == Keys.Space) { if (!gameIsOver) { if (pause) { StartTimers(); Text_lbl.Visible = false; GameSong.controls.play();; pause = false; } else { Text_lbl.Location = new Point(20, 150); Text_lbl.Text = "GAME PAUSED"; Text_lbl.Visible = true; GameSong.controls.pause(); StopTimers(); pause = true; } } } }
//Key Detection private void Form1_KeyDown(object sender, KeyEventArgs e) { if (lost == false) { if (pause == false) { if (e.KeyCode == Keys.W) { MoveUpTimer.Start(); MoveDownTimer.Stop(); MoveLeftTimer.Stop(); MoveRightTimer.Stop(); } if (e.KeyCode == Keys.A) { MoveLeftTimer.Start(); MoveUpTimer.Stop(); MoveDownTimer.Stop(); MoveRightTimer.Stop(); } if (e.KeyCode == Keys.S) { MoveDownTimer.Start(); MoveUpTimer.Stop(); MoveLeftTimer.Stop(); MoveRightTimer.Stop(); } if (e.KeyCode == Keys.D) { MoveRightTimer.Start(); MoveUpTimer.Stop(); MoveDownTimer.Stop(); MoveLeftTimer.Stop(); } } } }