Skip to content

Commit

Permalink
Randomize ball speedY
Browse files Browse the repository at this point in the history
  • Loading branch information
devfacet committed Mar 18, 2024
1 parent 1b18299 commit 0feca62
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/lib/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class Game {
x: this.canvas.width / 4,
y: randomNumber(Game.cellSize, this.canvas.height - Game.cellSize),
speedX: Game.ballSpeed,
speedY: Game.ballSpeed,
speedY: Math.random() < 0.5 ? Game.ballSpeed : -Game.ballSpeed,
radius: Game.cellSize / 2,
color: Game.colorDarkSideBall,
}))
Expand All @@ -136,7 +136,7 @@ export class Game {
x: this.canvas.width / 4 * 3,
y: randomNumber(Game.cellSize, this.canvas.height - Game.cellSize),
speedX: -Game.ballSpeed,
speedY: -Game.ballSpeed,
speedY: Math.random() < 0.5 ? Game.ballSpeed : -Game.ballSpeed,
radius: Game.cellSize / 2,
color: Game.colorLightSideBall,
}))
Expand Down Expand Up @@ -271,6 +271,7 @@ export class Game {
for (const ball of this.balls) {
ball.reset()
ball.setY(randomNumber(Game.cellSize, this.canvas.height - Game.cellSize))
ball.setSpeedY(Math.random() < 0.5 ? Game.ballSpeed : -Game.ballSpeed)
}

// Clear the canvas
Expand Down

0 comments on commit 0feca62

Please sign in to comment.