Skip to content

Randomize initial serve direction in Pong game#64

Closed
Copilot wants to merge 2 commits into61-ai-opponent-integrationfrom
copilot/sub-pr-63
Closed

Randomize initial serve direction in Pong game#64
Copilot wants to merge 2 commits into61-ai-opponent-integrationfrom
copilot/sub-pr-63

Conversation

Copy link

Copilot AI commented Feb 3, 2026

The ball always started moving right (towards AI), giving the human player first serve every time.

Changes

  • Randomized serve initialization: 50/50 chance for either player to serve first
  • Aligned ball velocity: Initial velocity now matches randomly selected serve direction
// Before: always served right
this.serve = 1;
this.ball = new Ball(
  new Vector2(this.width / 2, this.height / 2),
  new Vector2(5, 0),  // always positive X
  ...
);

// After: random serve direction
this.serve = Math.random() < 0.5 ? 1 : -1;
this.ball = new Ball(
  new Vector2(this.width / 2, this.height / 2),
  new Vector2(5 * this.serve, 0),  // matches serve direction
  ...
);

The existing serve alternation logic (paddle hits, post-score resets) remains unchanged.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: lisambet <148557838+lisambet@users.noreply.github.com>
Copilot AI changed the title [WIP] Integrate first AI opponent into the game Randomize initial serve direction in Pong game Feb 3, 2026
Copilot AI requested a review from lisambet February 3, 2026 14:31
@lisambet lisambet closed this Feb 3, 2026
@lisambet lisambet deleted the copilot/sub-pr-63 branch February 3, 2026 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments