/// <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); //Load menu menu = Content.Load <Texture2D>("Ping_Pong_Menu"); //gamePlayMenu = Content.Load<Texture2D>("play-menu"); playMenu = Content.Load <Texture2D>("menu-play"); computerMenu = Content.Load <Texture2D>("menu-computer"); creditMenu = Content.Load <Texture2D>("menu-credits"); exitMenu = Content.Load <Texture2D>("menu-exit"); hoverPlay = Content.Load <Texture2D>("hover-play"); hoverDemo = Content.Load <Texture2D>("hover-computer"); hoverCredit = Content.Load <Texture2D>("hover-credit"); hoverExit = Content.Load <Texture2D>("hover-exit"); //End load menu //Load background background = Content.Load <Texture2D>("table"); // Load the SoundEffect resource ballHit = Content.Load <SoundEffect>("ballhit"); killShot = Content.Load <SoundEffect>("killshot"); miss = Content.Load <SoundEffect>("miss"); shotGunMenu = Content.Load <SoundEffect>("shotgun"); song = Content.Load <Song>("backgroundMusic"); MediaPlayer.Play(song); MediaPlayer.Volume = 10f; // Create a SoundEffect instance that can be manipulated later // seInstance.IsLooped = true; //Set font Font1 = Content.Load <SpriteFont>("Courier New"); // TODO: use this.Content to load your game content here //Draw ball ball = new clsSprite(Content.Load <Texture2D>("small_ball"), new Vector2(graphics.PreferredBackBufferHeight / 2, graphics.PreferredBackBufferWidth / 2), new Vector2(35f, 35f), graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); //Paddle for computer //Left hand side , position (0,height/2), size(10,height) computer = new paddle(Content.Load <Texture2D>("left_paddle"), new Vector2(50f, graphics.PreferredBackBufferHeight / 2), new Vector2(50f, 133f), graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); //Paddle for human //Righ hand side, position( width , height/2), size(10,height); human = new paddle(Content.Load <Texture2D>("right_paddle"), new Vector2(graphics.PreferredBackBufferWidth - 100f, graphics.PreferredBackBufferHeight / 2), new Vector2(50f, 133f), graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); rightComputer = new paddle(Content.Load <Texture2D>("right_paddle"), new Vector2(graphics.PreferredBackBufferWidth - 100f, graphics.PreferredBackBufferHeight / 2), new Vector2(50f, 133f), graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); // set the speed the sprites will move //Set random number between 0 and 10 ball.velocity = new Vector2(10.1f, 10.1f); computer.velocity = new Vector2(0, 5.1f); }
//Ball collide with player public int Player_Collide(paddle playerPaddle) { //Check for hit right paddle not in the surface up to down if (velocity.Y > 0 && position.X + size.X + velocity.X >= playerPaddle.position.X + playerPaddle.size.X / 2 && position.Y + size.Y + velocity.Y >= playerPaddle.position.Y + playerPaddle.velocity.Y && position.Y + velocity.Y <= playerPaddle.position.Y + playerPaddle.velocity.Y + playerPaddle.size.Y ) { Console.WriteLine("Hit not in the surface top"); return(-1);// Bounce toward the wall } else if (velocity.Y < 0 && position.X + size.X + velocity.X >= playerPaddle.position.X + playerPaddle.size.X / 2 && position.Y + velocity.Y <= playerPaddle.position.Y + playerPaddle.velocity.Y + playerPaddle.size.Y) { Console.WriteLine("Hit part 2"); return(-2); } //Dead hit upper part else if (velocity.Y > 0 && position.X + size.X + velocity.X >= playerPaddle.position.X && position.Y + size.Y + velocity.Y >= playerPaddle.position.Y && position.Y + size.Y + velocity.Y <= playerPaddle.position.Y + playerPaddle.size.Y / 2) { Console.WriteLine("Dead hit upper part"); return(3); } //Dead hit lower part else if (velocity.Y < 0 && this.position.X + this.size.X + velocity.X >= playerPaddle.position.X && this.position.Y >= playerPaddle.position.Y + playerPaddle.size.Y / 2 && this.position.Y <= playerPaddle.position.Y + playerPaddle.size.Y) { Console.WriteLine("Dead Hit lower part"); return(4); } //Check for go from top to bottom else if (velocity.Y > 0 && position.X + size.X + velocity.X >= playerPaddle.position.X && this.center.Y >= playerPaddle.position.Y && this.center.Y <= playerPaddle.position.Y + playerPaddle.size.Y) { Console.WriteLine("Up to bottom"); return(1); } //Check for go from bottom to top else if (velocity.Y < 0 && this.position.X + this.size.X + velocity.X >= playerPaddle.position.X && this.center.Y >= playerPaddle.position.Y && this.center.Y <= playerPaddle.position.Y + playerPaddle.size.Y) { Console.WriteLine("Bottom to Top"); return(2); } return(0); }
//Ball collide with computer public int Computer_Collide(paddle computerPaddle) { //Check for hit right paddle //Check for go from top to bottom //position.X + size.X + velocity.X>= playerPaddle.position.X && position.Y + size.Y >= playerPaddle.position.Y // && position.Y <= playerPaddle.position.Y if (velocity.Y > 0 && position.X + velocity.X <= computerPaddle.position.X + computerPaddle.size.X && this.center.Y >= computerPaddle.position.Y && this.center.Y <= computerPaddle.position.Y + computerPaddle.size.Y) { return(1); } //Check for go from bottom to top else if (velocity.Y < 0 && position.X + velocity.X <= computerPaddle.position.X + computerPaddle.size.X && this.center.Y >= computerPaddle.position.Y && this.center.Y <= computerPaddle.position.Y + computerPaddle.size.Y) { return(2); } return(0); }