/// <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); font = Content.Load<SpriteFont>("Font"); font_big = Content.Load<SpriteFont>("font_big"); t_wall = new Texture2D(GraphicsDevice,1,1); t_wall.SetData(new Color[] {Color.Black}); t_goal = new Texture2D(GraphicsDevice, 1, 1); t_goal.SetData(new Color[] { Color.Pink }); Dictionary<Keys, Command> p1Dict = new Dictionary<Keys, Command>(); player1 = new Player(Content.Load<Texture2D>(@"png/bar"), new Vector2(0, 0), 1,p1Dict); player1.Position = new Vector2(boundingBoxLeft.Width, boundingBoxTop.Y + boundingBoxTop.Height); //player1.Position = new Vector2(boundingBoxLeft.Width, boundingBoxTop.Y + boundingBoxTop.Height + HEIGHT / 2 - player1.BoundingBox.Height); p1Dict.Add(Keys.W, new MoveUpCommand(player1)); p1Dict.Add(Keys.S, new MoveDownCommand(player1)); Dictionary<Keys, Command> p2Dict = new Dictionary<Keys, Command>(); player2 = new Player(Content.Load<Texture2D>(@"png/bar"), new Vector2(0, 0), 2, p2Dict); player2.Position = new Vector2(WIDTH - boundingBoxRight.Width - player2.BoundingBox.Width, boundingBoxTop.Y + boundingBoxTop.Height); // player2.Position = new Vector2(WIDTH-boundingBoxRight.Width-player2.BoundingBox.Width, boundingBoxTop.Y + boundingBoxTop.Height + HEIGHT/2 - player2.BoundingBox.Height ); p2Dict.Add(Keys.Up, new MoveUpCommand(player2)); p2Dict.Add(Keys.Down, new MoveDownCommand(player2)); ball = new Ball(Content.Load<Texture2D>(@"png/ball"),new Vector2(300, boundingBoxTop.Y + boundingBoxTop.Height + player1.BoundingBox.Height/2 - 10),300f); ball.setToStartPosition(player1); }
private void goalShotBy(Player scorer) { scorer.Score++; ball.setToStartPosition(scorer); if (!this.WAITFORENTER == true) { _waitingforenter = true; } }
private void hitPaddleFrom(Player player) { float relIntersY = (int)((player.Position.Y + player.BoundingBox.Height / 2) - (ball.Position.Y + ball.BoundingBox.Height / 2)); float normalizedInters = relIntersY / player.BoundingBox.Height / 2; float bounceangle = (normalizedInters * ((5 * MathHelper.Pi) / 12)); // 75 Grad float newspeed = ball.Speed + 0.1f * ball.Startspeed ; // Increase Ball Speed by 20 % TODO: Maybe not exponential growth if (newspeed/60 < player1.BoundingBox.Width) // Prevents Ball from Jumping over Player { ball.Speed += SPEEDGROWTH * ball.Startspeed; } if (player.Id == 1) { ball.Velocity = new Vector2((float) (ball.Speed*Math.Cos(bounceangle)), (float) (-ball.Speed*Math.Sin(bounceangle))); } else { ball.Velocity = new Vector2((float)(-ball.Speed * Math.Cos(bounceangle)), (float)(-ball.Speed * Math.Sin(bounceangle))); } }
public MoveUpCommand(Player actor) : base(actor) { }
public MoveDownCommand(Player actor) : base(actor) { }
public Command(Player actor) { _actor = actor; }
public void setToStartPosition(Player scorer) { this.Speed = this._startspeed; //this.Position = new Vector2(Game1.WIDTH/2-BoundingBox.Width/2,Game1.HEIGHT/2-BoundingBox.Height/2); if(scorer.Id == 1) { this.Velocity = new Vector2(-1*Speed, 0); } else { this.Velocity = new Vector2(Speed, 0); } }