Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2016
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace WindowsFormsApplication1
  12. {
  13. public partial class Form1 : Form
  14. {
  15. bool right;
  16. bool left;
  17. bool up;
  18. bool down;
  19. bool fire;
  20.  
  21.  
  22. public Form1()
  23. {
  24. InitializeComponent();
  25. }
  26.  
  27.  
  28.  
  29. private void timer1_Tick(object sender, EventArgs e)
  30. {
  31. /* move */
  32. if (right == true) { player.Left += 5; }
  33. if (left == true) { player.Left -= 5; }
  34. if (up == true) { player.Top -= 5; }
  35. if (down == true) { player.Top += 5; }
  36.  
  37.  
  38. /* boards */
  39. if (player.Top + player.Height >= screen.Height) { player.Top = screen.Height - player.Height; }
  40. if (player.Top <= 0) { player.Top = 0; }
  41. if (player.Width + player.Left >= screen.Width) { player.Left = screen.Width - player.Width; }
  42. if (player.Left <= 0) { player.Left = 0; }
  43.  
  44.  
  45. /* fire*/
  46. if (fire == true)
  47. {
  48.  
  49. bullet1.Location = new Point(player.Location.X + 18, player.Location.Y - 10);
  50. bullet1.Visible = true;
  51.  
  52. int i = 0;
  53. do
  54. {
  55. bullet1.Top -= 1;
  56. i++;
  57. System.Threading.Thread.Sleep(1);
  58. } while (i < 400);
  59.  
  60. }
  61. }
  62.  
  63. private void Form1_KeyDown(object sender, KeyEventArgs e)
  64. {
  65. if (e.KeyCode == Keys.Right) { right = true; }
  66. if (e.KeyCode == Keys.Left) { left = true; }
  67. if (e.KeyCode == Keys.Up) { up = true; }
  68. if (e.KeyCode == Keys.Down) { down = true; }
  69. //move
  70.  
  71. /* fire*/
  72. if (e.KeyCode == Keys.Z) { fire = true; }
  73. }
  74.  
  75. private void Form1_KeyUp(object sender, KeyEventArgs e)
  76. {
  77. if (e.KeyCode == Keys.Right) { right = false; }
  78. if (e.KeyCode == Keys.Left) { left = false; }
  79. if (e.KeyCode == Keys.Up) { up = false; }
  80. if (e.KeyCode == Keys.Down) { down = false; }
  81. //move
  82.  
  83. /* fire*/
  84. if (e.KeyCode == Keys.Z) { fire = false; }
  85. }
  86.  
  87. private void screen_Paint(object sender, PaintEventArgs e)
  88. {
  89.  
  90. }
  91.  
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement