public GameScreen() { playerPaddle = new Paddle(new Vector2(20, 275), 8, true); watsonPaddle = new Paddle(new Vector2(780, 275), 8, false); ball = new Ball(6); screenState = GameScreenState.Playing; }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here ScreenWidth = GraphicsDevice.Viewport.Width; ScreenHeight = GraphicsDevice.Viewport.Height; player1 = new Player(); player2 = new Player(); ball = new Ball(); base.Initialize(); }
public void Update(Ball ball) { velocity = Vector2.Zero; if (controller == Controller.Player) { if (ScreenManager.keyboard.Up) { velocity.Y = speed * -1; } else if (ScreenManager.keyboard.Down) { velocity.Y = speed; } position += velocity; } else //if (controller == Controller.Watson) { if (ball.Velocity.X > 0) { float distance = position.Y + 25 - ball.Position.Y; if (distance > 15) { velocity.Y = speed * -1; } else if (distance < -15) { velocity.Y = speed; } position += velocity; } } #region Check Position if (position.Y < 10) { position.Y = 10; } else if (position.Y > 540) { position.Y = 540; } #endregion Boundary = new Rectangle((int)position.X, (int)position.Y, 10, 50); }
public override void UpdatePosition(Ball ball) { if (ball.GetDirection() > 1.5 * Math.PI || ball.GetDirection() < 0.5 * Math.PI) { if (ball.GetPosition().Y - 5 > GetPosition().Y + GetSize().Height / 2) { MoveDown(); } else if (ball.GetPosition().Y == GetPosition().Y + GetSize().Height / 2) { } else if (ball.GetPosition().Y + 5 < GetPosition().Y + GetSize().Height / 2) { MoveUp(); } } base.UpdatePosition(ball); }
public static bool CheckPaddleBallCollision(Player player, Ball ball) { if (player.Bounds.Intersects(ball.Bounds)) return true; return false; }
public virtual void UpdatePosition(Ball ball) { size.X = (int)position.X; size.Y = (int)position.Y; }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here screenWidth = 800; screenHeight = 600; menu = new Menu(); gamestate = GameStates.Menu; resetTimer = 0; resetTimerInUse = true; lastScored = false; graphics.PreferredBackBufferWidth = screenWidth; graphics.PreferredBackBufferHeight = screenHeight; graphics.ApplyChanges(); input = new Input(); SetUpMulti(); ball = new Ball(Content, new Vector2(screenWidth, screenHeight)); base.Initialize(); }