Skip to content

Commit

Permalink
feat: increasing ball speed
Browse files Browse the repository at this point in the history
  • Loading branch information
GuiMartinelli committed Jul 12, 2023
1 parent ded161c commit 42f2645
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion backend/src/game/game.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class GameService {
public PADDLE_HEIGHT: number;
private MAX_SCORE = 10;
private BALL_SPEED = 6;
private BALL_ACCELERATION = 1.1;

updateBallPosition(gameDto: GameDto) {
gameDto.ball.x += gameDto.ball.dx;
Expand All @@ -28,7 +29,11 @@ export class GameService {
}

private calculateBallCollision(gameDto: GameDto) {
if (this.isPlayerCollision(gameDto)) gameDto.ball.dx *= -1;
if (this.isPlayerCollision(gameDto)) {
gameDto.ball.dx *= -1;
gameDto.ball.dx *= this.BALL_ACCELERATION;
gameDto.ball.dy *= this.BALL_ACCELERATION;
}
}

private isPlayerCollision(gameDto: GameDto): boolean {
Expand Down

0 comments on commit 42f2645

Please sign in to comment.