示例#1
0
		public void Update(Window window, Bar bar1, Bar bar2, Ball ball)
		{
			//Disegno parte superiore del Ring
			this.DrawRectFilled (window, 10, 10, 255, 255, 255, window.width-20, 10);
			//Disegno parte inferiore del Ring
			this.DrawRectFilled (window, 10, window.height-20, 255, 255, 255, window.width-20, 10);
			//Disegno righe tratteggiate che separano il ring
			int k = 20;
			while(k < window.height-20)
			{
				this.DrawRectFilled(window, window.width/2, k, 255, 255, 255, 7, 30);
				k += 40;
			}
			//Disegno la Palla
			//this.DrawRectFilled (window, ball.GetX(), ball.GetY(), ball.GetR(), ball.GetG(), ball.GetB(), ball.GetWidht(), ball.GetHeight());
			this.DrawCircle(window, ball.GetX(), ball.GetY(), ball.GetRaggio(), 255, 255, 255);
			//Disegno la barra del Player 1
			this.DrawRectFilled (window, bar1.GetX(), bar1.GetY(), 255, 0, 0, bar1.GetWidht(), bar1.GetHeight());
			//Disegno la Barra del Player 2
			this.DrawRectFilled (window, bar2.GetX(), bar2.GetY(), 0, 255, 0, bar2.GetWidht(), bar2.GetHeight());
			//Movimeto barra del Player 1
			bar1.Move (window, ball);
			//Movimeto barra del Player 2
			bar2.Move2 (window, ball, window.height);
			//Movimeto della Palla
			ball.Update (window.height, window.width);

			numb1.CurrentResultDec (window, bar1.GetPoints());

			numb2.CurrentResult (window, bar1.GetPoints());

			numb3.CurrentResultDec (window, bar2.GetPoints());

			numb4.CurrentResult (window, bar2.GetPoints());
		}
示例#2
0
		public void Move(Window window, Ball ball, int h)
		{
			if (window.GetKey (KeyCode.Up)) {
				this.y -= this.speed;
			}

			if (window.GetKey (KeyCode.Down)) {
				this.y += this.speed;
			}

			if (this.y <= 14)
				this.y += this.speed;

			if (this.y >= h - this.height - 15)
				this.y -= this.speed;

			if ((ball.GetX () == this.x - 15) && (ball.GetY () >= this.y) && (ball.GetY () <= this.y + this.height)) {
				ball.SetDirezioneX (ball.GetDirezioneX () * -1);

				if ((ball.GetY () < this.y + (height / 5)))
					ball.SetDirezioneY (-2);
				else if ((ball.GetY () < (this.y + (height / 5) * 2)))
					ball.SetDirezioneY (-1);
				else if ((ball.GetY () < (this.y + (height / 5) * 3)))
					ball.SetDirezioneY (0);
				else if ((ball.GetY () < (this.y + (height / 5) * 4)))
					ball.SetDirezioneY (1);
				else
					ball.SetDirezioneY (2);
			}
		}
示例#3
0
        public void Move(Window window, Ball ball, int h)
        {
            if (window.GetKey(KeyCode.Up))
            {
                this.y -= this.speed;
            }

            if (window.GetKey(KeyCode.Down))
            {
                this.y += this.speed;
            }

            if (this.y <= 14)
            {
                this.y += this.speed;
            }

            if (this.y >= h - this.height - 15)
            {
                this.y -= this.speed;
            }

            if ((ball.GetX() == this.x - 15) && (ball.GetY() >= this.y) && (ball.GetY() <= this.y + this.height))
            {
                ball.SetDirezioneX(ball.GetDirezioneX() * -1);

                if ((ball.GetY() < this.y + (height / 5)))
                {
                    ball.SetDirezioneY(-2);
                }
                else if ((ball.GetY() < (this.y + (height / 5) * 2)))
                {
                    ball.SetDirezioneY(-1);
                }
                else if ((ball.GetY() < (this.y + (height / 5) * 3)))
                {
                    ball.SetDirezioneY(0);
                }
                else if ((ball.GetY() < (this.y + (height / 5) * 4)))
                {
                    ball.SetDirezioneY(1);
                }
                else
                {
                    ball.SetDirezioneY(2);
                }
            }
        }
示例#4
0
        public void Update(Window window, Bar bar1, Bar bar2, Ball ball)
        {
            //Disegno parte superiore del Ring
            this.DrawRectFilled(window, 10, 10, 255, 255, 255, window.width - 20, 10);
            //Disegno parte inferiore del Ring
            this.DrawRectFilled(window, 10, window.height - 20, 255, 255, 255, window.width - 20, 10);
            //Disegno righe tratteggiate che separano il ring
            int k = 20;

            while (k < window.height - 20)
            {
                this.DrawRectFilled(window, window.width / 2, k, 255, 255, 255, 7, 30);
                k += 40;
            }
            //Disegno la Palla
            //this.DrawRectFilled (window, ball.GetX(), ball.GetY(), ball.GetR(), ball.GetG(), ball.GetB(), ball.GetWidht(), ball.GetHeight());
            this.DrawCircle(window, ball.GetX(), ball.GetY(), ball.GetRaggio(), 255, 255, 255);
            //Disegno la barra del Player 1
            this.DrawRectFilled(window, bar1.GetX(), bar1.GetY(), 255, 0, 0, bar1.GetWidht(), bar1.GetHeight());
            //Disegno la Barra del Player 2
            this.DrawRectFilled(window, bar2.GetX(), bar2.GetY(), 0, 255, 0, bar2.GetWidht(), bar2.GetHeight());
            //Movimeto barra del Player 1
            bar1.Move(window, ball);
            //Movimeto barra del Player 2
            bar2.Move2(window, ball, window.height);
            //Movimeto della Palla
            ball.Update(window.height, window.width);

            numb1.CurrentResultDec(window, bar1.GetPoints());

            numb2.CurrentResult(window, bar1.GetPoints());

            numb3.CurrentResultDec(window, bar2.GetPoints());

            numb4.CurrentResult(window, bar2.GetPoints());
        }
示例#5
0
        //In questo metodo facciamo gli UPDATE della barra del player 1
        public void Move(Window window, Ball ball)
        {
            if (window.GetKey(this.up))
            {
                this.y -= this.speed;
            }

            if (window.GetKey(this.down))
            {
                this.y += this.speed;
            }

            //Controllo pe non superare il bordo superiore
            if (this.y <= 14)
            {
                this.y = 20;
            }
            //Controllo per non superare il bordo inferiore
            if (this.y >= window.height - this.height - 17)
            {
                this.y = window.height - this.height - 20;
            }

            //int distance = (int)(ball.GetRaggio() *  26.67)/100;

            //Controllo il punto della barra in cui è avvenuto il contatto con la pallina per far cambiare l'angolazione del tiro
            if ((ball.GetX() + ball.GetRaggio() - 17 >= this.x - 15) && (ball.GetY() >= this.y) && (ball.GetY() <= this.y + this.height))
            {
                ball.SetDirezioneX(ball.GetDirezioneX() * -1);
                ball.SetR(255);
                ball.SetG(0);
                ball.SetB(0);
                if ((ball.GetY() < this.y + (height / 5)))
                {
                    ball.SetDirezioneY(-2);
                }
                else if ((ball.GetY() < (this.y + (height / 5) * 2)))
                {
                    ball.SetDirezioneY(-1);
                }
                else if ((ball.GetY() < (this.y + (height / 5) * 3)))
                {
                    ball.SetDirezioneY(0);
                }
                else if ((ball.GetY() < (this.y + (height / 5) * 4)))
                {
                    ball.SetDirezioneY(1);
                }
                else
                {
                    ball.SetDirezioneY(2);
                }
            }
            else if (ball.GetX() > window.width)
            {
                points++;
                ball.SetX(window.width / 2);
                ball.SetY(window.height / 2);
                if (RandomGenerator.GetRandom(0, 1) == 0)
                {
                    ball.SetDirezioneX(-1);
                }
                else
                {
                    ball.SetDirezioneX(1);
                }
                ball.SetDirezioneY(RandomGenerator.GetRandom(-2, 2));
            }
        }
示例#6
0
文件: Bar.cs 项目: DrTonyChopper/Pong
		//In questo metodo facciamo gli UPDATE della barra del player 1
		public void Move(Window window, Ball ball)
		{
			if(window.GetKey(this.up))
			{
				this.y -= this.speed;
			}

			if(window.GetKey(this.down))
			{
				this.y += this.speed;
			}

			//Controllo pe non superare il bordo superiore
			if (this.y <= 14)
				this.y = 20;
			//Controllo per non superare il bordo inferiore
			if (this.y >= window.height-this.height-17)
				this.y = window.height - this.height-20;

			//int distance = (int)(ball.GetRaggio() *  26.67)/100;

			//Controllo il punto della barra in cui è avvenuto il contatto con la pallina per far cambiare l'angolazione del tiro 
			if ((ball.GetX () + ball.GetRaggio()-17 >= this.x - 15) && (ball.GetY () >= this.y) && (ball.GetY () <= this.y + this.height)) 
			{
				ball.SetDirezioneX (ball.GetDirezioneX () * -1);
				ball.SetR(255);
				ball.SetG(0);
				ball.SetB(0);
				if ((ball.GetY () < this.y + (height / 5)))
					ball.SetDirezioneY (-2);
				else if ((ball.GetY () < (this.y + (height / 5) * 2)))
					ball.SetDirezioneY (-1);
				else if ((ball.GetY () < (this.y + (height / 5) * 3)))
					ball.SetDirezioneY (0);
				else if ((ball.GetY () < (this.y + (height / 5) * 4)))
					ball.SetDirezioneY (1);
				else
					ball.SetDirezioneY (2);
			} 
			else if (ball.GetX () > window.width) 
			{
				points++;
				ball.SetX (window.width/2);
				ball.SetY (window.height/2);
				if (RandomGenerator.GetRandom (0, 1) == 0)
					ball.SetDirezioneX (-1);
				else ball.SetDirezioneX (1);
				ball.SetDirezioneY (RandomGenerator.GetRandom (-2, 2));

			}
				

		 }