Example #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());
		}
Example #2
0
		public static void Main (string[] args)
		{
			Window window = new Window (1200, 700, "RingPong", PixelFormat.RGB);
			//Definizione : Ring, Finestra del programma, Palla, Barra Player 1, Barra Player 2
			Ring ring = new Ring (window);
			Ball ball = new Ball ();
			//Parametri Bar : Posizione X, Posizione Y, Comando per andare su, Comando per andare giù
			Bar bar1= new Bar (window.width-25, window.height/2, KeyCode.Up, KeyCode.Down);
			Bar bar2 = new Bar (10, window.height/2, KeyCode.W, KeyCode.S);

			//Inizio Gioco
			bool isGameRunning = true;
			while (isGameRunning) 
			{
				//Pulizia della Finestra
				ring.Clear(window, 0, 0, 0);

				ring.Update (window, bar1, bar2, ball);

				window.Blit();
				//Scrittura del punteggio 
				if (bar1.GetPoints () == 15)
				{
					Console.WriteLine ("Player 1 VINCE");
					isGameRunning = false;
				}
				else if (bar2.GetPoints () == 15)
				{
					Console.WriteLine ("Player 2 VINCE");
					isGameRunning = false;
				}

			}
		}
Example #3
0
        public void CheckHit(Bar playerBar, Bar cpuBar)
        {
            if(IsCollision(playerBar))
            {
                Swing(playerBar);
                BounceHorizontal();
                playerBar.PlaySound();

                playerBar.IncreaseMovementSpeed();

            }

            if(IsCollision(cpuBar)) {
                Swing(cpuBar);
                BounceHorizontal();
                cpuBar.PlaySound();

                cpuBar.IncreaseMovementSpeed();
            }
        }
Example #4
0
 private void Swing(Bar bar)
 {
     verticalMovement = OffCollision(bar);
     IncreasetHorizontalMovement();
 }
Example #5
0
 private int OffCollision(Bar bar)
 {
     // That's some interesting bit, how should the ball bounce when colliding with the bar??
     // Let's make it simple: the further away from the middle of the bar, the least horizontally the ball will go
     var diff = yPosition - bar.YCenterOfBar();
     var off = (diff) / 2;
     return off;
 }
Example #6
0
 private Boolean IsXcollision(Bar bar)
 {
     return xPosition <= bar.GetXposition() + BarWidth && xPosition >= bar.GetXposition();
 }
Example #7
0
 private Boolean IsCollision(Bar bar)
 {
     return IsXcollision(bar) && IsYcollision(bar);
 }
Example #8
0
 public Boolean IsYcollision(Bar bar)
 {
     return yPosition < bar.GetYposition() + BarHeight && yPosition > bar.GetYposition();
 }
Example #9
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            Content.RootDirectory = "Content";
            var barTexture = Content.Load<Texture2D>("PongBar");
            var ballTexture = Content.Load<Texture2D>("PongBall");

            var ballOutSound = Content.Load<SoundEffect>("ballOutSound");
            var ballCollideWithBarSound = Content.Load<SoundEffect>("ballBarCollision");
            var ballCollideWithEdgeSound = Content.Load<SoundEffect>("ballEdgeCollision");

            var music = Content.Load<SoundEffect>("music");
            SoundEffectInstance soundEffectInstance = music.CreateInstance();
            soundEffectInstance.IsLooped = true;
            soundEffectInstance.Play();

            var font = Content.Load<SpriteFont>("Score");

            playerBar = new Bar(barTexture, BarToEdgePadding, Height, ballCollideWithBarSound);
            cpuBar = new Bar(barTexture, Width - BarToEdgePadding, Height, ballCollideWithBarSound);

            var ball = new Ball(ballTexture, Width / 2, Width, Height, ballCollideWithEdgeSound);

            score = new Score(font);
            ballOutManager = new BallOutMananger(ball, Width, ballOutSound, score);

            cpuController = new CpuController(cpuBar, ball, Height);
        }
Example #10
0
 public CpuController(Bar cpuBar, Ball ball, int worldHeight)
 {
     this.cpuBar = cpuBar;
     this.ball = ball;
     this.worldHeight = worldHeight;
 }