multiBalls refactoring with ballsArr[]

This commit is contained in:
LuckyLaszlo
2022-12-01 17:48:34 +01:00
parent c8c3111ed4
commit f73932c131
9 changed files with 97 additions and 121 deletions

View File

@@ -11,9 +11,7 @@ class GameComponentsExtensionForClient extends GameComponents {
wallBottom: RectangleClient;
playerLeft: RacketClient;
playerRight: RacketClient;
ball: BallClient;
ball2?: BallClient;
ball3?: BallClient;
ballsArr: BallClient[];
constructor(options: en.MatchOptions, ctx: CanvasRenderingContext2D)
{
super(options);
@@ -21,12 +19,12 @@ class GameComponentsExtensionForClient extends GameComponents {
this.wallBottom = new RectangleClient(this.wallBottom.pos, this.wallBottom.width, this.wallBottom.height, ctx, "grey");
this.playerLeft = new RacketClient(this.playerLeft.pos, this.playerLeft.width, this.playerLeft.height, this.playerLeft.baseSpeed, ctx, "white");
this.playerRight = new RacketClient(this.playerRight.pos, this.playerRight.width, this.playerRight.height, this.playerRight.baseSpeed, ctx, "white");
this.ball = new BallClient(this.ball.pos, this.ball.width, this.ball.baseSpeed, this.ball.speedIncrease, ctx, "white");
if (options & en.MatchOptions.multiBalls)
{ // ALTERNATIVE POSSIBLE, Array of balls
this.ball2 = new BallClient(this.ball2.pos, this.ball2.width, this.ball2.baseSpeed, this.ball2.speedIncrease, ctx, "white");
this.ball3 = new BallClient(this.ball3.pos, this.ball3.width, this.ball3.baseSpeed, this.ball3.speedIncrease, ctx, "white");
}
const newBallsArr: BallClient[] = [];
this.ballsArr.forEach((ball) => {
newBallsArr.push(new BallClient(ball.pos, ball.width, ball.baseSpeed, ball.speedIncrease, ctx, "white"));
});
this.ballsArr = newBallsArr;
}
}