diff --git a/.gitignore b/.gitignore
index e43b0f9..2608ec2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
.DS_Store
+.vscode
\ No newline at end of file
diff --git a/README.md b/README.md
index cd80ba9..8199221 100644
--- a/README.md
+++ b/README.md
@@ -2,4 +2,4 @@ A beer pong auto battler with stupid people.
## Frontend
-To run the front-end, go into `src/frontend` and run: `npm install && npm run dev`.
\ No newline at end of file
+To run the front-end, go into `src/frontend` and run: `npm install && npm run dev`.
diff --git a/src/frontend/.prettierrc b/src/frontend/.prettierrc
new file mode 100644
index 0000000..202ecff
--- /dev/null
+++ b/src/frontend/.prettierrc
@@ -0,0 +1,5 @@
+{
+ "singleQuote": false,
+ "semi": true,
+ "endOfLine": "auto"
+}
diff --git a/src/frontend/eslint.config.mjs b/src/frontend/eslint.config.mjs
index 7cd04f4..4222681 100644
--- a/src/frontend/eslint.config.mjs
+++ b/src/frontend/eslint.config.mjs
@@ -1,10 +1,21 @@
// @ts-check
-import eslint from '@eslint/js';
-import { defineConfig } from 'eslint/config';
-import tseslint from 'typescript-eslint';
+import eslint from "@eslint/js";
+import { defineConfig } from "eslint/config";
+import tseslint from "typescript-eslint";
+import prettierConfig from "eslint-config-prettier";
+import prettierPlugin from "eslint-plugin-prettier";
export default defineConfig(
eslint.configs.recommended,
- tseslint.configs.recommended,
-);
\ No newline at end of file
+ ...tseslint.configs.recommended,
+
+ // disables ESLint rules that conflict with Prettier (must be near the end)
+ prettierConfig,
+ {
+ plugins: { prettier: prettierPlugin },
+ rules: {
+ "prettier/prettier": "error",
+ },
+ },
+);
diff --git a/src/frontend/index.html b/src/frontend/index.html
index 520f0b7..d6c8c92 100644
--- a/src/frontend/index.html
+++ b/src/frontend/index.html
@@ -1,13 +1,13 @@
-
+
-
+
Auto Beer Pong
-
+
-
+
-
+
diff --git a/src/frontend/package-lock.json b/src/frontend/package-lock.json
index 1f093b8..8a34b51 100644
--- a/src/frontend/package-lock.json
+++ b/src/frontend/package-lock.json
@@ -13,9 +13,9 @@
"devDependencies": {
"@eslint/js": "^9.39.1",
"eslint": "^9.39.1",
- "eslint-config-prettier": "^10.1.2",
- "eslint-plugin-prettier": "^5.2.6",
- "prettier": "^3.5.3",
+ "eslint-config-prettier": "^10.1.8",
+ "eslint-plugin-prettier": "^5.5.4",
+ "prettier": "^3.7.4",
"typescript": "~5.7.3",
"typescript-eslint": "^8.48.0",
"vite": "^6.2.0"
@@ -2135,9 +2135,9 @@
}
},
"node_modules/prettier": {
- "version": "3.6.2",
- "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.6.2.tgz",
- "integrity": "sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ==",
+ "version": "3.7.4",
+ "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.7.4.tgz",
+ "integrity": "sha512-v6UNi1+3hSlVvv8fSaoUbggEM5VErKmmpGA7Pl3HF8V6uKY7rvClBOJlH6yNwQtfTueNkGVpOv/mtWL9L4bgRA==",
"dev": true,
"license": "MIT",
"bin": {
diff --git a/src/frontend/package.json b/src/frontend/package.json
index d270ea9..ba79b52 100644
--- a/src/frontend/package.json
+++ b/src/frontend/package.json
@@ -7,6 +7,8 @@
"start": "npm run dev",
"build": "npm run lint && tsc && vite build",
"lint": "eslint .",
+ "lint:fix": "eslint . --fix",
+ "format": "prettier . --write",
"dev": "vite"
},
"dependencies": {
@@ -15,9 +17,9 @@
"devDependencies": {
"@eslint/js": "^9.39.1",
"eslint": "^9.39.1",
- "eslint-config-prettier": "^10.1.2",
- "eslint-plugin-prettier": "^5.2.6",
- "prettier": "^3.5.3",
+ "eslint-config-prettier": "^10.1.8",
+ "eslint-plugin-prettier": "^5.5.4",
+ "prettier": "^3.7.4",
"typescript": "~5.7.3",
"typescript-eslint": "^8.48.0",
"vite": "^6.2.0"
diff --git a/src/frontend/public/style.css b/src/frontend/public/style.css
index aeff35c..f831dcc 100644
--- a/src/frontend/public/style.css
+++ b/src/frontend/public/style.css
@@ -1,6 +1,6 @@
body {
- margin: 0;
- padding: 0;
- color: rgba(255, 255, 255, 0.87);
- background-color: #000000;
+ margin: 0;
+ padding: 0;
+ color: rgba(255, 255, 255, 0.87);
+ background-color: #000000;
}
diff --git a/src/frontend/src/GameElements/Ball.ts b/src/frontend/src/GameElements/Ball.ts
index dbfb9e1..2ff1a4b 100644
--- a/src/frontend/src/GameElements/Ball.ts
+++ b/src/frontend/src/GameElements/Ball.ts
@@ -1,138 +1,150 @@
-
-import { Actor, ActorArgs, Circle, Color, Engine, Graphic, GraphicsGroup, Random, vec, Vector } from "excalibur";
+import {
+ Actor,
+ ActorArgs,
+ Circle,
+ Color,
+ Engine,
+ Graphic,
+ GraphicsGroup,
+ Random,
+ vec,
+ Vector,
+} from "excalibur";
import { assertNotNull, assertNull } from "../utils/assertUtils";
import { gravitationalConstant, groundHeight } from "../utils/physicsConstant";
export const defaultBallConfiguration: BallConfiguration = {
- color: Color.Orange,
- radius: 5,
-}
+ color: Color.Orange,
+ radius: 5,
+};
export interface BallConfiguration {
- readonly color: Color;
- readonly radius: number;
+ readonly color: Color;
+ readonly radius: number;
}
const random = new Random();
export class Ball extends Actor {
- private _graphic: Graphic = null!;
- private _animation: BallAnimation = new BallAnimation(this);
+ private _graphic: Graphic = null!;
+ private _animation: BallAnimation = new BallAnimation(this);
- constructor(actorArgs: ActorArgs, public readonly configuration: BallConfiguration) {
- super(actorArgs);
- }
+ constructor(
+ actorArgs: ActorArgs,
+ public readonly configuration: BallConfiguration,
+ ) {
+ super(actorArgs);
+ }
+ onInitialize(engine: Engine): void {
+ const { configuration } = this;
+ const { radius } = configuration;
- onInitialize(engine: Engine): void {
- const { configuration } = this;
- const { radius } = configuration;
+ const ballGraphic = new Circle({
+ radius: radius,
+ color: configuration.color,
+ });
- const ballGraphic = new Circle({
- radius: radius,
- color: configuration.color,
- });
+ const specularGraphic = new Circle({
+ radius: radius / 5,
+ color: Color.White,
+ });
- const specularGraphic = new Circle({
- radius: radius / 5,
- color: Color.White,
- });
+ this._graphic = new GraphicsGroup({
+ members: [
+ { graphic: ballGraphic, offset: vec(0, 0) },
+ { graphic: specularGraphic, offset: vec(radius / 2, radius / 2) },
+ ],
+ });
- this._graphic = new GraphicsGroup({
- members: [
- { graphic: ballGraphic, offset: vec(0, 0)},
- { graphic:specularGraphic, offset: vec(radius / 2, radius / 2)}
- ],
- })
+ this.graphics.add(this._graphic);
- this.graphics.add(this._graphic);
+ const start = vec(-150, -200);
+ this.pos = start;
- const start = vec(-150, -200);
- this.pos = start;
+ engine.input.pointers.primary.on("down", () => {
+ const randomVelocity = vec(
+ random.integer(100, 400),
+ random.integer(0, -400),
+ );
+ this.startParabolaAnimation(new Parabola(start, randomVelocity));
+ });
+ }
- engine.input.pointers.primary.on("down", () => {
- const randomVelocity = vec(random.integer(100, 400), random.integer(0, -400));
- this.startParabolaAnimation(new Parabola(start, randomVelocity));
- })
- }
+ public update(engine: Engine, elapsed: number): void {
+ super.update(engine, elapsed);
+ this._animation.update(elapsed);
+ }
-
- public update(engine: Engine, elapsed: number): void {
- super.update(engine, elapsed);
- this._animation.update(elapsed);
- }
-
- startParabolaAnimation(parabola: Parabola): void {
- this._animation.start(parabola);
- }
+ startParabolaAnimation(parabola: Parabola): void {
+ this._animation.start(parabola);
+ }
}
class BallAnimation {
- private _running: boolean = false;
- private _parabola: Parabola | null = null;
- private _elapsedTime: number | null = null;
+ private _running: boolean = false;
+ private _parabola: Parabola | null = null;
+ private _elapsedTime: number | null = null;
- constructor(private _ball: Ball) {
+ constructor(private _ball: Ball) {}
+ get running(): boolean {
+ return this._running;
+ }
+
+ start(parabola: Parabola): void {
+ this.reset();
+ this._parabola = parabola;
+ this._running = true;
+ }
+
+ reset(): void {
+ this._parabola = null;
+ this._running = false;
+ this._elapsedTime = null;
+
+ // TODO: Reset ball position?
+ }
+
+ update(elapsed: number): void {
+ if (!this.running) {
+ assertNull(this._parabola);
+ assertNull(this._elapsedTime);
+ return;
}
- get running(): boolean {
- return this._running;
+ assertNotNull(this._parabola);
+
+ if (this._elapsedTime == null) {
+ this._elapsedTime = 0;
}
+ this._elapsedTime += elapsed;
- start(parabola: Parabola): void {
- this.reset();
- this._parabola = parabola;
- this._running = true;
- }
+ const newPosition = this._parabola.position(this._elapsedTime);
- reset(): void {
- this._parabola = null;
- this._running = false;
- this._elapsedTime = null;
-
- // TODO: Reset ball position?
- }
-
- update(elapsed: number): void {
- if (!this.running) {
- assertNull(this._parabola);
- assertNull(this._elapsedTime);
- return;
- }
-
- assertNotNull(this._parabola);
-
- if (this._elapsedTime == null) {
- this._elapsedTime = 0;
- }
- this._elapsedTime += elapsed;
-
- const newPosition = this._parabola.position(this._elapsedTime);
-
- // Collide with ground
- const yMin = groundHeight - this._ball.configuration.radius;
- newPosition.y = Math.min(yMin, newPosition.y);
-
- this._ball.pos = newPosition;
- }
+ // Collide with ground
+ const yMin = groundHeight - this._ball.configuration.radius;
+ newPosition.y = Math.min(yMin, newPosition.y);
+ this._ball.pos = newPosition;
+ }
}
export class Parabola {
- constructor(
- readonly startPos: Vector,
- readonly startVelocity: Vector
- ) { }
+ constructor(
+ readonly startPos: Vector,
+ readonly startVelocity: Vector,
+ ) {}
- position(time: number): Vector {
- const timeSeconds = time / 1000;
-
- const x = this.startPos.x + this.startVelocity.x * timeSeconds;
- const y = this.startVelocity.y * timeSeconds + gravitationalConstant / 2 * timeSeconds ** 2 + this.startPos.y;
+ position(time: number): Vector {
+ const timeSeconds = time / 1000;
- return new Vector(x, y);
- }
+ const x = this.startPos.x + this.startVelocity.x * timeSeconds;
+ const y =
+ this.startVelocity.y * timeSeconds +
+ (gravitationalConstant / 2) * timeSeconds ** 2 +
+ this.startPos.y;
+ return new Vector(x, y);
+ }
}
-
diff --git a/src/frontend/src/GameElements/Champion.ts b/src/frontend/src/GameElements/Champion.ts
index 6d67cf9..1337df6 100644
--- a/src/frontend/src/GameElements/Champion.ts
+++ b/src/frontend/src/GameElements/Champion.ts
@@ -1,126 +1,144 @@
-import { Actor, ActorArgs, Color, Engine, Graphic, GraphicsGroup, Line, Polygon,vec } from "excalibur";
+import {
+ Actor,
+ ActorArgs,
+ Color,
+ Engine,
+ Graphic,
+ GraphicsGroup,
+ Line,
+ Polygon,
+ vec,
+} from "excalibur";
import { pixelsPerMeter } from "../utils/physicsConstant";
import { jitterVector, randomInteger } from "../utils/randomUtils";
const jiggleTime = 500;
export class Champion extends Actor {
- private _graphic: Graphic = null!;
+ private _graphic: Graphic = null!;
- private _jiggleTimer = randomInteger(0, 1000);
-
- constructor(actorArgs: ActorArgs) {
- super(actorArgs);
- }
-
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
- onInitialize(_engine: Engine): void {
- const height = 1.4 * pixelsPerMeter;
- const width = 0.4 * pixelsPerMeter;
- const waistHeight = 0.3 * pixelsPerMeter;
- const jitterMag = 0.1 * pixelsPerMeter;
- const headSize = 0.5 * pixelsPerMeter;
-
- const bodyPoints = [
- jitterVector(vec(-width / 2, waistHeight), jitterMag),
- jitterVector(vec(-width / 2, height), jitterMag),
- jitterVector(vec(width / 2, height), jitterMag),
- jitterVector(vec(width / 2, waistHeight), jitterMag),
- ];
-
- const bodyGraphic = new Polygon({
- points: bodyPoints,
- color: this.color,
- });
-
- const leftLeg = new Line({
- start: bodyPoints[0],
- end: vec(bodyPoints[0].x, 0),
- thickness: 5,
- color: Color.Black,
- });
-
- const rightLeg = new Line({
- start: bodyPoints[3],
- end: vec(bodyPoints[3].x, 0),
- thickness: 5,
- color: Color.Black,
- });
-
- const headPoints = [
- jitterVector(vec(-headSize / 2, 0), jitterMag),
- jitterVector(vec(-headSize / 2, headSize), jitterMag),
- jitterVector(vec(headSize / 2, headSize), jitterMag),
- jitterVector(vec(headSize / 2, 0), jitterMag),
- ];
- const headGraphic = new Polygon({
- points: headPoints,
- color: this.color,
- });
-
- this.anchor = vec(0.5, 1);
- this._graphic = new GraphicsGroup({
- members: [
- { graphic: leftLeg , offset: vec(0, -waistHeight)},
- { graphic: rightLeg , offset: vec(0, -waistHeight)},
- { graphic: bodyGraphic, offset: vec(-width / 2, -height) },
- { graphic: headGraphic, offset: vec(-headSize / 2, -height - headSize / 2) },
- { graphic: smileEyeGraphic.clone(), offset: vec(-headSize / 4, -height) },
- { graphic: smileEyeGraphic.clone(), offset: vec(headSize / 4, -height) },
- ],
- useAnchor: false,
- })
-
- this.graphics.add(this._graphic);
-
- this.rotation = Math.PI / 180 * 5;
- }
-
- update(_engine: Engine, elapsed: number): void {
- this._jiggle(elapsed);
- }
-
- private _jiggle(elapsed: number): void {
- this._jiggleTimer += elapsed;
- if (this._jiggleTimer > jiggleTime) {
- this._jiggleTimer -= jiggleTime;
- this.rotation = -this.rotation
- }
+ private _jiggleTimer = randomInteger(0, 1000);
+ constructor(actorArgs: ActorArgs) {
+ super(actorArgs);
+ }
+
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ onInitialize(_engine: Engine): void {
+ const height = 1.4 * pixelsPerMeter;
+ const width = 0.4 * pixelsPerMeter;
+ const waistHeight = 0.3 * pixelsPerMeter;
+ const jitterMag = 0.1 * pixelsPerMeter;
+ const headSize = 0.5 * pixelsPerMeter;
+
+ const bodyPoints = [
+ jitterVector(vec(-width / 2, waistHeight), jitterMag),
+ jitterVector(vec(-width / 2, height), jitterMag),
+ jitterVector(vec(width / 2, height), jitterMag),
+ jitterVector(vec(width / 2, waistHeight), jitterMag),
+ ];
+
+ const bodyGraphic = new Polygon({
+ points: bodyPoints,
+ color: this.color,
+ });
+
+ const leftLeg = new Line({
+ start: bodyPoints[0],
+ end: vec(bodyPoints[0].x, 0),
+ thickness: 5,
+ color: Color.Black,
+ });
+
+ const rightLeg = new Line({
+ start: bodyPoints[3],
+ end: vec(bodyPoints[3].x, 0),
+ thickness: 5,
+ color: Color.Black,
+ });
+
+ const headPoints = [
+ jitterVector(vec(-headSize / 2, 0), jitterMag),
+ jitterVector(vec(-headSize / 2, headSize), jitterMag),
+ jitterVector(vec(headSize / 2, headSize), jitterMag),
+ jitterVector(vec(headSize / 2, 0), jitterMag),
+ ];
+ const headGraphic = new Polygon({
+ points: headPoints,
+ color: this.color,
+ });
+
+ this.anchor = vec(0.5, 1);
+ this._graphic = new GraphicsGroup({
+ members: [
+ { graphic: leftLeg, offset: vec(0, -waistHeight) },
+ { graphic: rightLeg, offset: vec(0, -waistHeight) },
+ { graphic: bodyGraphic, offset: vec(-width / 2, -height) },
+ {
+ graphic: headGraphic,
+ offset: vec(-headSize / 2, -height - headSize / 2),
+ },
+ {
+ graphic: smileEyeGraphic.clone(),
+ offset: vec(-headSize / 4, -height),
+ },
+ {
+ graphic: smileEyeGraphic.clone(),
+ offset: vec(headSize / 4, -height),
+ },
+ ],
+ useAnchor: false,
+ });
+
+ this.graphics.add(this._graphic);
+
+ this.rotation = (Math.PI / 180) * 5;
+ }
+
+ update(_engine: Engine, elapsed: number): void {
+ this._jiggle(elapsed);
+ }
+
+ private _jiggle(elapsed: number): void {
+ this._jiggleTimer += elapsed;
+ if (this._jiggleTimer > jiggleTime) {
+ this._jiggleTimer -= jiggleTime;
+ this.rotation = -this.rotation;
}
+ }
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _crossEyeGraphic = new GraphicsGroup({
- members: [
- new Line({
- start: vec(-5, -5),
- end: vec(5, 5),
- color: Color.Black,
- thickness: 3,
- }),
- new Line({
- start: vec(5, -5),
- end: vec(-5, 5),
- color: Color.Black,
- thickness: 3,
- })
- ]
- });
+ members: [
+ new Line({
+ start: vec(-5, -5),
+ end: vec(5, 5),
+ color: Color.Black,
+ thickness: 3,
+ }),
+ new Line({
+ start: vec(5, -5),
+ end: vec(-5, 5),
+ color: Color.Black,
+ thickness: 3,
+ }),
+ ],
+});
const smileEyeGraphic = new GraphicsGroup({
- members: [
- new Line({
- start: vec(-5, 5),
- end: vec(5, -5),
- color: Color.Black,
- thickness: 3,
- }),
- new Line({
- start: vec(5, -5),
- end: vec(10, 5),
- color: Color.Black,
- thickness: 3,
- })
- ]
- });
\ No newline at end of file
+ members: [
+ new Line({
+ start: vec(-5, 5),
+ end: vec(5, -5),
+ color: Color.Black,
+ thickness: 3,
+ }),
+ new Line({
+ start: vec(5, -5),
+ end: vec(10, 5),
+ color: Color.Black,
+ thickness: 3,
+ }),
+ ],
+});
diff --git a/src/frontend/src/GameElements/Cups.ts b/src/frontend/src/GameElements/Cups.ts
index a730c6a..e35d3b6 100644
--- a/src/frontend/src/GameElements/Cups.ts
+++ b/src/frontend/src/GameElements/Cups.ts
@@ -1,67 +1,78 @@
-
-import { Actor, ActorArgs, Color, Engine, Graphic, GraphicsGroup, Line, Polygon,vec } from "excalibur";
+import {
+ Actor,
+ ActorArgs,
+ Color,
+ Engine,
+ Graphic,
+ GraphicsGroup,
+ Line,
+ Polygon,
+ vec,
+} from "excalibur";
import { pixelsPerMeter } from "../utils/physicsConstant";
export const defaultCupConfiguration = {
- cupColor: Color.Red,
- rimColor: Color.White,
- widthRim: 0.18 * pixelsPerMeter,
- widthBottom: 0.12 * pixelsPerMeter,
- height: 0.2 * pixelsPerMeter,
- rimThickness: 0.02 * pixelsPerMeter,
-}
+ cupColor: Color.Red,
+ rimColor: Color.White,
+ widthRim: 0.18 * pixelsPerMeter,
+ widthBottom: 0.12 * pixelsPerMeter,
+ height: 0.2 * pixelsPerMeter,
+ rimThickness: 0.02 * pixelsPerMeter,
+};
export interface CupConfiguration {
- readonly cupColor: Color;
- readonly rimColor: Color;
- readonly widthRim: number;
- readonly widthBottom: number;
- readonly height: number;
- readonly rimThickness: number;
+ readonly cupColor: Color;
+ readonly rimColor: Color;
+ readonly widthRim: number;
+ readonly widthBottom: number;
+ readonly height: number;
+ readonly rimThickness: number;
}
export class Cup extends Actor {
- private _graphic: Graphic = null!;
+ private _graphic: Graphic = null!;
- constructor(actorArgs: ActorArgs, public readonly configuration: CupConfiguration) {
- super(actorArgs);
- }
+ constructor(
+ actorArgs: ActorArgs,
+ public readonly configuration: CupConfiguration,
+ ) {
+ super(actorArgs);
+ }
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ onInitialize(_engine: Engine): void {
+ const { configuration } = this;
+ const { height, widthRim, widthBottom } = configuration;
+ const halfWidthBottom = widthBottom / 2;
+ const halfWidthRim = widthRim / 2;
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
- onInitialize(_engine: Engine): void {
- const { configuration } = this;
- const { height, widthRim, widthBottom, } = configuration;
- const halfWidthBottom = widthBottom / 2;
- const halfWidthRim = widthRim / 2;
+ const points = [
+ vec(-halfWidthBottom, 0),
+ vec(-halfWidthRim, -height),
+ vec(halfWidthRim, -height),
+ vec(halfWidthBottom, 0),
+ ];
- const points = [
- vec(-halfWidthBottom, 0),
- vec(-halfWidthRim, -height),
- vec(halfWidthRim, -height),
- vec(halfWidthBottom, 0),
- ];
+ const cupBody = new Polygon({
+ points,
+ color: configuration.cupColor,
+ });
- const cupBody = new Polygon({
- points,
- color: configuration.cupColor,
- });
+ const cupRim = new Line({
+ start: vec(-halfWidthRim - 1, 0),
+ end: vec(halfWidthRim + 1, 0),
+ color: configuration.rimColor,
+ thickness: configuration.rimThickness,
+ });
- const cupRim = new Line({
- start: vec(-halfWidthRim - 1, 0),
- end: vec(halfWidthRim + 1, 0),
- color: configuration.rimColor,
- thickness: configuration.rimThickness,
- });
+ this._graphic = new GraphicsGroup({
+ members: [
+ { graphic: cupBody, offset: vec(-halfWidthRim, -height) },
+ { graphic: cupRim, offset: vec(0, -height) },
+ ],
+ useAnchor: false,
+ });
- this._graphic = new GraphicsGroup({
- members: [
- { graphic: cupBody, offset: vec(-halfWidthRim, -height) },
- { graphic: cupRim, offset: vec(0, -height) },
- ],
- useAnchor: false,
- });
-
- this.graphics.add(this._graphic);
- }
-}
\ No newline at end of file
+ this.graphics.add(this._graphic);
+ }
+}
diff --git a/src/frontend/src/GameElements/Ground.ts b/src/frontend/src/GameElements/Ground.ts
index 092a035..a9a1553 100644
--- a/src/frontend/src/GameElements/Ground.ts
+++ b/src/frontend/src/GameElements/Ground.ts
@@ -4,22 +4,22 @@ import { groundHeight } from "../utils/physicsConstant";
export const groundColor = Color.Gray;
export class Ground extends Actor {
- private _graphic: Graphic = null!;
+ private _graphic: Graphic = null!;
- onInitialize(engine: Engine): void {
- const { width, height} = engine.screen;
+ onInitialize(engine: Engine): void {
+ const { width, height } = engine.screen;
- this._graphic = new Rectangle({
- width,
- height: height / 2,
- color: groundColor,
- })
- this.graphics.add(this._graphic);
+ this._graphic = new Rectangle({
+ width,
+ height: height / 2,
+ color: groundColor,
+ });
+ this.graphics.add(this._graphic);
- this.pos.setTo(0, groundHeight);
- this.anchor.setTo(0.5, 0);
+ this.pos.setTo(0, groundHeight);
+ this.anchor.setTo(0.5, 0);
- this._graphic.width = 10000;
- this._graphic.height = 10000;
- }
-}
\ No newline at end of file
+ this._graphic.width = 10000;
+ this._graphic.height = 10000;
+ }
+}
diff --git a/src/frontend/src/GameElements/Table.ts b/src/frontend/src/GameElements/Table.ts
index f80404c..5c64675 100644
--- a/src/frontend/src/GameElements/Table.ts
+++ b/src/frontend/src/GameElements/Table.ts
@@ -1,59 +1,71 @@
-import { Actor, ActorArgs, Color, Engine, Graphic, Polygon,vec } from "excalibur";
+import {
+ Actor,
+ ActorArgs,
+ Color,
+ Engine,
+ Graphic,
+ Polygon,
+ vec,
+} from "excalibur";
import { pixelsPerMeter } from "../utils/physicsConstant";
export const defaultTableConfiguration = {
- color: Color.Brown,
- width: 2.44 * pixelsPerMeter,
- height: 0.7 * pixelsPerMeter,
- thickness: 0.15 * pixelsPerMeter,
- legOffset: 0.15 * pixelsPerMeter,
- legThickness: 0.15 * pixelsPerMeter,
-}
+ color: Color.Brown,
+ width: 2.44 * pixelsPerMeter,
+ height: 0.7 * pixelsPerMeter,
+ thickness: 0.15 * pixelsPerMeter,
+ legOffset: 0.15 * pixelsPerMeter,
+ legThickness: 0.15 * pixelsPerMeter,
+};
export interface TableConfiguration {
- readonly color: Color;
- readonly width: number;
- readonly height: number;
- readonly thickness: number;
- readonly legOffset: number;
- readonly legThickness: number;
+ readonly color: Color;
+ readonly width: number;
+ readonly height: number;
+ readonly thickness: number;
+ readonly legOffset: number;
+ readonly legThickness: number;
}
export class Table extends Actor {
- private _graphic: Graphic = null!;
+ private _graphic: Graphic = null!;
- constructor(actorArgs: ActorArgs, public readonly configuration: TableConfiguration) {
- super(actorArgs);
- }
+ constructor(
+ actorArgs: ActorArgs,
+ public readonly configuration: TableConfiguration,
+ ) {
+ super(actorArgs);
+ }
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
- onInitialize(_engine: Engine): void {
- const { width, height, thickness, legOffset, legThickness } = this.configuration;
- const halfWidth = width / 2;
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ onInitialize(_engine: Engine): void {
+ const { width, height, thickness, legOffset, legThickness } =
+ this.configuration;
+ const halfWidth = width / 2;
- const points = [
- vec(halfWidth, -height),
- vec(halfWidth, thickness - height),
- vec(halfWidth - legOffset, thickness - height),
- vec(halfWidth - legOffset, 0),
- vec(halfWidth - legOffset - legThickness, 0),
- vec(halfWidth - legOffset - legThickness, thickness - height),
+ const points = [
+ vec(halfWidth, -height),
+ vec(halfWidth, thickness - height),
+ vec(halfWidth - legOffset, thickness - height),
+ vec(halfWidth - legOffset, 0),
+ vec(halfWidth - legOffset - legThickness, 0),
+ vec(halfWidth - legOffset - legThickness, thickness - height),
- vec(-halfWidth + legOffset + legThickness, thickness - height),
- vec(-halfWidth + legOffset + legThickness, 0),
- vec(-halfWidth + legOffset, 0),
- vec(-halfWidth + legOffset, thickness - height),
- vec(-halfWidth, thickness - height),
- vec(-halfWidth, -height),
- ];
+ vec(-halfWidth + legOffset + legThickness, thickness - height),
+ vec(-halfWidth + legOffset + legThickness, 0),
+ vec(-halfWidth + legOffset, 0),
+ vec(-halfWidth + legOffset, thickness - height),
+ vec(-halfWidth, thickness - height),
+ vec(-halfWidth, -height),
+ ];
- this._graphic = new Polygon({
- points,
- color: this.configuration.color,
- });
+ this._graphic = new Polygon({
+ points,
+ color: this.configuration.color,
+ });
- this.graphics.add(this._graphic);
+ this.graphics.add(this._graphic);
- this.anchor.setTo(0.5, 1);
- }
-}
\ No newline at end of file
+ this.anchor.setTo(0.5, 1);
+ }
+}
diff --git a/src/frontend/src/Scenes/GameScene.ts b/src/frontend/src/Scenes/GameScene.ts
index 3f1c4c7..73f2120 100644
--- a/src/frontend/src/Scenes/GameScene.ts
+++ b/src/frontend/src/Scenes/GameScene.ts
@@ -18,7 +18,6 @@ export class GameScene extends GameStateScene {
private _cups: Cup[] = [];
private _champions: Champion[] = [];
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
constructor(private _connection: Connection) {
super();
@@ -31,33 +30,41 @@ export class GameScene extends GameStateScene {
this._ground = new Ground();
this.add(this._ground);
- this._table = new Table({pos: vec(0, groundHeight)}, defaultTableConfiguration);
+ this._table = new Table(
+ { pos: vec(0, groundHeight) },
+ defaultTableConfiguration,
+ );
this.add(this._table);
const tableHalfWidth = this._table.configuration.width / 2;
const tableHeight = this._table.configuration.height;
const cupPositions = [
- ...[10, 32, 54].map(v => v - tableHalfWidth),
- ...[10, 32, 54].map(v => -v + tableHalfWidth),
+ ...[10, 32, 54].map((v) => v - tableHalfWidth),
+ ...[10, 32, 54].map((v) => -v + tableHalfWidth),
];
- cupPositions.forEach(offsetX => {
- const cup = new Cup({
- pos: vec(offsetX, groundHeight - tableHeight),
- color: Color.Red,
- }, defaultCupConfiguration)
+ cupPositions.forEach((offsetX) => {
+ const cup = new Cup(
+ {
+ pos: vec(offsetX, groundHeight - tableHeight),
+ color: Color.Red,
+ },
+ defaultCupConfiguration,
+ );
- this.add(cup);
- this._cups.push(cup);
+ this.add(cup);
+ this._cups.push(cup);
});
const championPositions = [
- ...[50, 150, 250].map(v => -v - tableHalfWidth),
- ...[50, 150, 250].map(v => v + tableHalfWidth)
+ ...[50, 150, 250].map((v) => -v - tableHalfWidth),
+ ...[50, 150, 250].map((v) => v + tableHalfWidth),
];
- championPositions.forEach(offsetX => {
-
- const champion = new Champion({color: randomNonGroundColor(), pos: vec(offsetX, groundHeight)});
+ championPositions.forEach((offsetX) => {
+ const champion = new Champion({
+ color: randomNonGroundColor(),
+ pos: vec(offsetX, groundHeight),
+ });
this.add(champion);
this._champions.push(champion);
});
@@ -74,4 +81,4 @@ function randomNonGroundColor(): Color {
} while (colorDistance(color, groundColor) < 100);
return color;
-}
\ No newline at end of file
+}
diff --git a/src/frontend/src/utils/assertUtils.ts b/src/frontend/src/utils/assertUtils.ts
index 1cbcbfd..0598d2f 100644
--- a/src/frontend/src/utils/assertUtils.ts
+++ b/src/frontend/src/utils/assertUtils.ts
@@ -1,17 +1,17 @@
export function assert(condition: boolean, message?: string): void {
- if (!condition) {
- throw new Error(message || "Assertion failed");
- }
+ if (!condition) {
+ throw new Error(message || "Assertion failed");
+ }
}
export function assertNull(obj: T | null): asserts obj is null {
- if (obj != null) {
- throw new Error("Assertion failed");
- }
+ if (obj != null) {
+ throw new Error("Assertion failed");
+ }
}
export function assertNotNull(obj: T | null): asserts obj is T {
- if (obj == null) {
- throw new Error("Assertion failed");
- }
-}
\ No newline at end of file
+ if (obj == null) {
+ throw new Error("Assertion failed");
+ }
+}
diff --git a/src/frontend/src/utils/colorUtils.ts b/src/frontend/src/utils/colorUtils.ts
index b6eaabb..17c1789 100644
--- a/src/frontend/src/utils/colorUtils.ts
+++ b/src/frontend/src/utils/colorUtils.ts
@@ -1,5 +1,9 @@
import { Color } from "excalibur";
export function colorDistance(color1: Color, color2: Color): number {
- return Math.abs(color1.r - color2.r) + Math.abs(color1.g - color2.g) + Math.abs(color1.b - color2.b);
-}
\ No newline at end of file
+ return (
+ Math.abs(color1.r - color2.r) +
+ Math.abs(color1.g - color2.g) +
+ Math.abs(color1.b - color2.b)
+ );
+}
diff --git a/src/frontend/src/utils/physicsConstant.ts b/src/frontend/src/utils/physicsConstant.ts
index 765fe90..fca0e41 100644
--- a/src/frontend/src/utils/physicsConstant.ts
+++ b/src/frontend/src/utils/physicsConstant.ts
@@ -1,3 +1,3 @@
export const pixelsPerMeter = 100;
export const gravitationalConstant = 9.81 * pixelsPerMeter;
-export const groundHeight = 0;
\ No newline at end of file
+export const groundHeight = 0;
diff --git a/src/frontend/src/utils/randomUtils.ts b/src/frontend/src/utils/randomUtils.ts
index 9729601..e6dd1f5 100644
--- a/src/frontend/src/utils/randomUtils.ts
+++ b/src/frontend/src/utils/randomUtils.ts
@@ -3,16 +3,20 @@ import { Color, Random, vec, Vector } from "excalibur";
const rand = new Random();
export function randomColor(): Color {
- return new Color(rand.integer(0, 255), rand.integer(0, 255), rand.integer(0, 255));
+ return new Color(
+ rand.integer(0, 255),
+ rand.integer(0, 255),
+ rand.integer(0, 255),
+ );
}
/** Jitter given vector by at most the given magnitude. The random offset is [-magnitude / 2, magnitude / 2] */
export function jitterVector(v: Vector, magnitude: number): Vector {
- const x = v.x + rand.next() * magnitude - magnitude / 2;
- const y = v.y + rand.next() * magnitude - magnitude / 2;
- return vec(x, y);
+ const x = v.x + rand.next() * magnitude - magnitude / 2;
+ const y = v.y + rand.next() * magnitude - magnitude / 2;
+ return vec(x, y);
}
-export function randomInteger(min: number, max:number): number {
- return rand.integer(min, max -1);
-}
\ No newline at end of file
+export function randomInteger(min: number, max: number): number {
+ return rand.integer(min, max - 1);
+}