added alternate game mode "movingWalls"
This commit is contained in:
@@ -3,28 +3,68 @@ import * as c from "../constants.js"
|
||||
import * as en from "../../shared_js/enums.js"
|
||||
import { Vector, VectorInteger } from "../../shared_js/class/Vector.js";
|
||||
import { TextElem, TextNumericValue } from "./Text.js";
|
||||
import { RectangleClient, RacketClient, BallClient, Line } from "./RectangleClient.js";
|
||||
import { RectangleClient, MovingRectangleClient, RacketClient, BallClient, Line } from "./RectangleClient.js";
|
||||
import { GameComponents } from "../../shared_js/class/GameComponents.js";
|
||||
import { assertMovingRectangle } from "../utils.js";
|
||||
|
||||
class GameComponentsExtensionForClient extends GameComponents {
|
||||
wallTop: RectangleClient;
|
||||
wallBottom: RectangleClient;
|
||||
wallTop: RectangleClient | MovingRectangleClient;
|
||||
wallBottom: RectangleClient | MovingRectangleClient;
|
||||
playerLeft: RacketClient;
|
||||
playerRight: RacketClient;
|
||||
ballsArr: BallClient[];
|
||||
constructor(options: en.MatchOptions, ctx: CanvasRenderingContext2D)
|
||||
{
|
||||
super(options);
|
||||
this.wallTop = new RectangleClient(this.wallTop.pos, this.wallTop.width, this.wallTop.height, ctx, "grey");
|
||||
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");
|
||||
|
||||
// Rackets
|
||||
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");
|
||||
|
||||
// Balls
|
||||
const newBallsArr: BallClient[] = [];
|
||||
this.ballsArr.forEach((ball) => {
|
||||
newBallsArr.push(new BallClient(ball.pos, ball.width, ball.baseSpeed, ball.speedIncrease, ctx, "white"));
|
||||
newBallsArr.push(new BallClient(
|
||||
ball.pos, ball.width, ball.baseSpeed, ball.speedIncrease,
|
||||
ctx, "white")
|
||||
);
|
||||
});
|
||||
this.ballsArr = newBallsArr;
|
||||
|
||||
// Walls
|
||||
if (options & en.MatchOptions.movingWalls)
|
||||
{
|
||||
const dir = new Vector;
|
||||
|
||||
assertMovingRectangle(this.wallTop);
|
||||
dir.assign(this.wallTop.dir.x, this.wallTop.dir.y);
|
||||
this.wallTop = new MovingRectangleClient(
|
||||
this.wallTop.pos, this.wallTop.width, this.wallTop.height,
|
||||
this.wallTop.baseSpeed,
|
||||
ctx, "grey");
|
||||
(<MovingRectangleClient>this.wallTop).dir.assign(dir.x, dir.y);
|
||||
|
||||
assertMovingRectangle(this.wallBottom);
|
||||
dir.assign(this.wallBottom.dir.x, this.wallBottom.dir.y);
|
||||
this.wallBottom = new MovingRectangleClient(
|
||||
this.wallBottom.pos, this.wallBottom.width, this.wallBottom.height,
|
||||
this.wallBottom.baseSpeed,
|
||||
ctx, "grey");
|
||||
(<MovingRectangleClient>this.wallBottom).dir.assign(dir.x, dir.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.wallTop = new RectangleClient(
|
||||
this.wallTop.pos, this.wallTop.width, this.wallTop.height,
|
||||
ctx, "grey");
|
||||
this.wallBottom = new RectangleClient(
|
||||
this.wallBottom.pos, this.wallBottom.width, this.wallBottom.height,
|
||||
ctx, "grey");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user