Add formatting to frontend (#27)

This commit is contained in:
lucas authored and GitHub committed 2026-01-05 19:25:41 +01:00
1 parent f3143c7b88
commit d4bb9b195f
18 files changed
+469 -382

No files matched your search

+1
View File
@@ -1 +1,2 @@
.DS_Store
.vscode
+1 -1
View File
@@ -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`.
To run the front-end, go into `src/frontend` and run: `npm install && npm run dev`.
+5
View File
@@ -0,0 +1,5 @@
{
"singleQuote": false,
"semi": true,
"endOfLine": "auto"
}
+16 -5
View File
@@ -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,
);
...tseslint.configs.recommended,
// disables ESLint rules that conflict with Prettier (must be near the end)
prettierConfig,
{
plugins: { prettier: prettierPlugin },
rules: {
"prettier/prettier": "error",
},
},
);
+5 -5
View File
@@ -1,13 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="/style.css">
<link rel="stylesheet" href="/style.css" />
<title>Auto Beer Pong</title>
</head>
</head>
<body>
<body>
<script type="module" src="/src/main.ts"></script>
</body>
</body>
</html>
+6 -6
View File
@@ -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": {
+5 -3
View File
@@ -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"
+4 -4
View File
@@ -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;
}
+111 -99
View File
@@ -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);
}
}
+129 -111
View File
@@ -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,
})
]
});
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,
}),
],
});
+63 -52
View File
@@ -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);
}
}
this.graphics.add(this._graphic);
}
}
+15 -15
View File
@@ -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;
}
}
this._graphic.width = 10000;
this._graphic.height = 10000;
}
}
+56 -44
View File
@@ -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);
}
}
this.anchor.setTo(0.5, 1);
}
}
+24 -17
View File
@@ -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;
}
}
+10 -10
View File
@@ -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<T>(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<T>(obj: T | null): asserts obj is T {
if (obj == null) {
throw new Error("Assertion failed");
}
}
if (obj == null) {
throw new Error("Assertion failed");
}
}
+6 -2
View File
@@ -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);
}
return (
Math.abs(color1.r - color2.r) +
Math.abs(color1.g - color2.g) +
Math.abs(color1.b - color2.b)
);
}
+1 -1
View File
@@ -1,3 +1,3 @@
export const pixelsPerMeter = 100;
export const gravitationalConstant = 9.81 * pixelsPerMeter;
export const groundHeight = 0;
export const groundHeight = 0;
+11 -7
View File
@@ -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);
}
export function randomInteger(min: number, max: number): number {
return rand.integer(min, max - 1);
}