Advertisement
Guest User

Untitled

a guest
Oct 20th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. namespace Pong
  2. {
  3. public partial class GameArea : Form
  4. {
  5. public Timer gameTime;
  6. const int screenWidth = 1248;
  7. const int screenHeight = 720;
  8. int gameTimeInterval=1;
  9. public Player player;
  10. public AI ai;
  11. public Ball ball;
  12. public GameController controller;
  13. public GameArea()
  14. {
  15.  
  16. InitializeComponent();
  17. this.Height= screenHeight;
  18. this.Width=screenWidth;
  19. this.StartPosition=FormStartPosition.CenterScreen;
  20. controller = new GameController(this);
  21.  
  22. player = new Player(this);
  23. player.Size=new Size(20,50);
  24. player.Location = new Point(player.Width / 2, ClientSize.Height/2-player.Height/2);
  25. player.BackColor = Color.Aquamarine;
  26.  
  27. ai = new AI(this);
  28. ai.Size = new Size(20, 50);
  29. ai.Location = new Point(ClientSize.Width-(ai.Width+ai.Width / 2), ClientSize.Height / 2 - ai.Height / 2);
  30. ai.BackColor = Color.Blue;
  31. //player.BackColor = Color.Black; THIS LINE WILL CHANGE THE COLOR OF THE AI, WHY??
  32. }
  33.  
  34.  
  35.  
  36.  
  37. namespace Pong
  38. {
  39. public class Movable
  40. {
  41. static
  42. private PictureBox pictureBox { get; set; }
  43. protected Form mainForm;
  44. public int Height { get
  45. {return pictureBox.Size.Height;}
  46. }
  47. public int Width
  48. {
  49. get{ return pictureBox.Size.Width;}
  50. }
  51. public Size Size
  52. {
  53. get
  54. { return pictureBox.Size; }
  55. set
  56. {
  57. if (value.Height > 0 && value.Width > 0)
  58. {
  59. pictureBox.Size = value;
  60. }
  61.  
  62. }
  63.  
  64.  
  65. }
  66. public Point Location
  67. {
  68. get
  69. { return pictureBox.Location; }
  70. set
  71. { pictureBox.Location = value; }
  72.  
  73.  
  74. }
  75. public Color BackColor
  76. {
  77. get
  78. { return
  79. pictureBox.BackColor; }
  80. set
  81. { pictureBox.BackColor = value; }
  82. }
  83. public Movable(Form form)
  84. {
  85. mainForm = form;
  86. pictureBox = new PictureBox();
  87. form.Controls.Add(pictureBox);
  88. }
  89. }
  90. }
  91.  
  92.  
  93. namespace Pong
  94. {
  95. public class Player : Movable
  96. {
  97. public Point move()
  98. {
  99. if ( base.mainForm.PointToClient(Control.MousePosition).Y >= Height/2 && mainForm.PointToClient(Control.MousePosition).Y <= mainForm.Height-Height/2)
  100. {
  101. int playerX = Width / 2;
  102. int playerY = mainForm.PointToClient(Control.MousePosition).Y - Height / 2;
  103. return new Point(playerX, playerY);
  104. }
  105. return new Point(-1, -1);
  106. }
  107. public Player(Form form): base(form)
  108. {
  109.  
  110. }
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement