private void tick_game_Tick(object sender, EventArgs e) { lbl_fps.Text = "FPS: " + CalculateFrameRate().ToString(); p1_Head.Location = new Point(p1.Location.X + (p1_Head.Width / 2), p1.Location.Y - p1_Head.Height); p2_Head.Location = new Point(p2.Location.X + (p2_Head.Width / 2), p2.Location.Y - p2_Head.Height); if (p1_HP <= 0 || p2_HP <= 0) { tick_game.Enabled = false; string str_MessageGO = ""; if (p1_HP <= 0 && p2_HP <= 0) { str_MessageGO = "Tie!"; } else { if (p1_HP <= 0) { str_MessageGO = "Player 2 WINS!"; p2_Score++; lbl_p2score.Text = "Score: " + p2_Score.ToString(); } else if (p2_HP <= 0) { str_MessageGO = "Player 1 WINS!"; p1_Score++; lbl_p1score.Text = "Score: " + p1_Score.ToString(); } } frm_winner Winner = new frm_winner(str_MessageGO); DialogResult DR_WINNER = Winner.ShowDialog(); if (DR_WINNER == DialogResult.Retry) { Retry(); } else if (DR_WINNER == DialogResult.Cancel) { frm_mainmenu frm_mainmenu = new frm_mainmenu(); frm_mainmenu.Show(); Close(); } } MoveP1(); MoveP2(); }
private void frm_main_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Escape) { frm_mainmenu frm_mainmenu = new frm_mainmenu(); frm_mainmenu.Show(); Close(); } if (e.KeyCode == Keys.A) { p1_MovingL = true; if (p1_ActiveBullet == false) { p1_DIR = SHOOTDIR.LEFT; } } else if (e.KeyCode == Keys.D) { p1_MovingR = true; if (p1_ActiveBullet == false) { p1_DIR = SHOOTDIR.RIGHT; } } else if (e.KeyCode == Keys.W) { p1_Jump = true; p1_Collide = false; } else if (e.KeyCode == Keys.G && p1_ActiveBullet == false) { if (p1_DIR == SHOOTDIR.LEFT) { p1_Bullet.Location = new Point(p1.Location.X - p1_Bullet.Width, p1.Location.Y + (p1.Height / 2)); } else if (p1_DIR == SHOOTDIR.RIGHT) { p1_Bullet.Location = new Point(p1.Location.X + p1.Width, p1.Location.Y + (p1.Height / 2)); } p1_ActiveBullet = true; } if (e.KeyCode == Keys.Left) { p2_MovingL = true; if (p2_ActiveBullet == false) { p2_DIR = SHOOTDIR.LEFT; } } else if (e.KeyCode == Keys.Right) { p2_MovingR = true; if (p2_ActiveBullet == false) { p2_DIR = SHOOTDIR.RIGHT; } } else if (e.KeyCode == Keys.Up) { p2_Jump = true; p2_Collide = false; } else if (e.KeyCode == Keys.P && p2_ActiveBullet == false) { if (p2_DIR == SHOOTDIR.LEFT) { p2_Bullet.Location = new Point(p2.Location.X - p2_Bullet.Width, p2.Location.Y + (p2.Height / 2)); } else if (p2_DIR == SHOOTDIR.RIGHT) { p2_Bullet.Location = new Point(p2.Location.X + p2.Width, p2.Location.Y + (p2.Height / 2)); } p2_ActiveBullet = true; } }