Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Pong
- {
- public partial class GameArea : Form
- {
- public Timer gameTime;
- const int screenWidth = 1248;
- const int screenHeight = 720;
- int gameTimeInterval=1;
- public Player player;
- public AI ai;
- public Ball ball;
- public GameController controller;
- public GameArea()
- {
- InitializeComponent();
- this.Height= screenHeight;
- this.Width=screenWidth;
- this.StartPosition=FormStartPosition.CenterScreen;
- controller = new GameController(this);
- player = new Player(this);
- player.Size=new Size(20,50);
- player.Location = new Point(player.Width / 2, ClientSize.Height/2-player.Height/2);
- player.BackColor = Color.Aquamarine;
- ai = new AI(this);
- ai.Size = new Size(20, 50);
- ai.Location = new Point(ClientSize.Width-(ai.Width+ai.Width / 2), ClientSize.Height / 2 - ai.Height / 2);
- ai.BackColor = Color.Blue;
- //player.BackColor = Color.Black; THIS LINE WILL CHANGE THE COLOR OF THE AI, WHY??
- }
- namespace Pong
- {
- public class Movable
- {
- static
- private PictureBox pictureBox { get; set; }
- protected Form mainForm;
- public int Height { get
- {return pictureBox.Size.Height;}
- }
- public int Width
- {
- get{ return pictureBox.Size.Width;}
- }
- public Size Size
- {
- get
- { return pictureBox.Size; }
- set
- {
- if (value.Height > 0 && value.Width > 0)
- {
- pictureBox.Size = value;
- }
- }
- }
- public Point Location
- {
- get
- { return pictureBox.Location; }
- set
- { pictureBox.Location = value; }
- }
- public Color BackColor
- {
- get
- { return
- pictureBox.BackColor; }
- set
- { pictureBox.BackColor = value; }
- }
- public Movable(Form form)
- {
- mainForm = form;
- pictureBox = new PictureBox();
- form.Controls.Add(pictureBox);
- }
- }
- }
- namespace Pong
- {
- public class Player : Movable
- {
- public Point move()
- {
- if ( base.mainForm.PointToClient(Control.MousePosition).Y >= Height/2 && mainForm.PointToClient(Control.MousePosition).Y <= mainForm.Height-Height/2)
- {
- int playerX = Width / 2;
- int playerY = mainForm.PointToClient(Control.MousePosition).Y - Height / 2;
- return new Point(playerX, playerY);
- }
- return new Point(-1, -1);
- }
- public Player(Form form): base(form)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement