Add formatting to frontend (#27)
This commit is contained in:
1 parent
f3143c7b88
commit
d4bb9b195f
14 files changed
+169
-82
No files matched your search
@@ -1 +1,2 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
|
.vscode
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"singleQuote": false,
|
||||||
|
"semi": true,
|
||||||
|
"endOfLine": "auto"
|
||||||
|
}
|
||||||
@@ -1,10 +1,21 @@
|
|||||||
// @ts-check
|
// @ts-check
|
||||||
|
|
||||||
import eslint from '@eslint/js';
|
import eslint from "@eslint/js";
|
||||||
import { defineConfig } from 'eslint/config';
|
import { defineConfig } from "eslint/config";
|
||||||
import tseslint from 'typescript-eslint';
|
import tseslint from "typescript-eslint";
|
||||||
|
import prettierConfig from "eslint-config-prettier";
|
||||||
|
import prettierPlugin from "eslint-plugin-prettier";
|
||||||
|
|
||||||
export default defineConfig(
|
export default defineConfig(
|
||||||
eslint.configs.recommended,
|
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",
|
||||||
|
},
|
||||||
|
},
|
||||||
);
|
);
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<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>
|
<title>Auto Beer Pong</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<script type="module" src="/src/main.ts"></script>
|
<script type="module" src="/src/main.ts"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Generated
+6
-6
@@ -13,9 +13,9 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^9.39.1",
|
"@eslint/js": "^9.39.1",
|
||||||
"eslint": "^9.39.1",
|
"eslint": "^9.39.1",
|
||||||
"eslint-config-prettier": "^10.1.2",
|
"eslint-config-prettier": "^10.1.8",
|
||||||
"eslint-plugin-prettier": "^5.2.6",
|
"eslint-plugin-prettier": "^5.5.4",
|
||||||
"prettier": "^3.5.3",
|
"prettier": "^3.7.4",
|
||||||
"typescript": "~5.7.3",
|
"typescript": "~5.7.3",
|
||||||
"typescript-eslint": "^8.48.0",
|
"typescript-eslint": "^8.48.0",
|
||||||
"vite": "^6.2.0"
|
"vite": "^6.2.0"
|
||||||
@@ -2135,9 +2135,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/prettier": {
|
"node_modules/prettier": {
|
||||||
"version": "3.6.2",
|
"version": "3.7.4",
|
||||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.6.2.tgz",
|
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.7.4.tgz",
|
||||||
"integrity": "sha512-I7AIg5boAr5R0FFtJ6rCfD+LFsWHp81dolrFD8S79U9tb8Az2nGrJncnMSnys+bpQJfRUzqs9hnA81OAA3hCuQ==",
|
"integrity": "sha512-v6UNi1+3hSlVvv8fSaoUbggEM5VErKmmpGA7Pl3HF8V6uKY7rvClBOJlH6yNwQtfTueNkGVpOv/mtWL9L4bgRA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
"start": "npm run dev",
|
"start": "npm run dev",
|
||||||
"build": "npm run lint && tsc && vite build",
|
"build": "npm run lint && tsc && vite build",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
|
"lint:fix": "eslint . --fix",
|
||||||
|
"format": "prettier . --write",
|
||||||
"dev": "vite"
|
"dev": "vite"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -15,9 +17,9 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^9.39.1",
|
"@eslint/js": "^9.39.1",
|
||||||
"eslint": "^9.39.1",
|
"eslint": "^9.39.1",
|
||||||
"eslint-config-prettier": "^10.1.2",
|
"eslint-config-prettier": "^10.1.8",
|
||||||
"eslint-plugin-prettier": "^5.2.6",
|
"eslint-plugin-prettier": "^5.5.4",
|
||||||
"prettier": "^3.5.3",
|
"prettier": "^3.7.4",
|
||||||
"typescript": "~5.7.3",
|
"typescript": "~5.7.3",
|
||||||
"typescript-eslint": "^8.48.0",
|
"typescript-eslint": "^8.48.0",
|
||||||
"vite": "^6.2.0"
|
"vite": "^6.2.0"
|
||||||
|
|||||||
@@ -1,12 +1,22 @@
|
|||||||
|
import {
|
||||||
import { Actor, ActorArgs, Circle, Color, Engine, Graphic, GraphicsGroup, Random, vec, Vector } from "excalibur";
|
Actor,
|
||||||
|
ActorArgs,
|
||||||
|
Circle,
|
||||||
|
Color,
|
||||||
|
Engine,
|
||||||
|
Graphic,
|
||||||
|
GraphicsGroup,
|
||||||
|
Random,
|
||||||
|
vec,
|
||||||
|
Vector,
|
||||||
|
} from "excalibur";
|
||||||
import { assertNotNull, assertNull } from "../utils/assertUtils";
|
import { assertNotNull, assertNull } from "../utils/assertUtils";
|
||||||
import { gravitationalConstant, groundHeight } from "../utils/physicsConstant";
|
import { gravitationalConstant, groundHeight } from "../utils/physicsConstant";
|
||||||
|
|
||||||
export const defaultBallConfiguration: BallConfiguration = {
|
export const defaultBallConfiguration: BallConfiguration = {
|
||||||
color: Color.Orange,
|
color: Color.Orange,
|
||||||
radius: 5,
|
radius: 5,
|
||||||
}
|
};
|
||||||
|
|
||||||
export interface BallConfiguration {
|
export interface BallConfiguration {
|
||||||
readonly color: Color;
|
readonly color: Color;
|
||||||
@@ -19,11 +29,13 @@ export class Ball extends Actor {
|
|||||||
private _graphic: Graphic = null!;
|
private _graphic: Graphic = null!;
|
||||||
private _animation: BallAnimation = new BallAnimation(this);
|
private _animation: BallAnimation = new BallAnimation(this);
|
||||||
|
|
||||||
constructor(actorArgs: ActorArgs, public readonly configuration: BallConfiguration) {
|
constructor(
|
||||||
|
actorArgs: ActorArgs,
|
||||||
|
public readonly configuration: BallConfiguration,
|
||||||
|
) {
|
||||||
super(actorArgs);
|
super(actorArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
onInitialize(engine: Engine): void {
|
onInitialize(engine: Engine): void {
|
||||||
const { configuration } = this;
|
const { configuration } = this;
|
||||||
const { radius } = configuration;
|
const { radius } = configuration;
|
||||||
@@ -40,10 +52,10 @@ export class Ball extends Actor {
|
|||||||
|
|
||||||
this._graphic = new GraphicsGroup({
|
this._graphic = new GraphicsGroup({
|
||||||
members: [
|
members: [
|
||||||
{ graphic: ballGraphic, offset: vec(0, 0)},
|
{ graphic: ballGraphic, offset: vec(0, 0) },
|
||||||
{ graphic:specularGraphic, offset: vec(radius / 2, radius / 2)}
|
{ graphic: specularGraphic, offset: vec(radius / 2, radius / 2) },
|
||||||
],
|
],
|
||||||
})
|
});
|
||||||
|
|
||||||
this.graphics.add(this._graphic);
|
this.graphics.add(this._graphic);
|
||||||
|
|
||||||
@@ -51,12 +63,14 @@ export class Ball extends Actor {
|
|||||||
this.pos = start;
|
this.pos = start;
|
||||||
|
|
||||||
engine.input.pointers.primary.on("down", () => {
|
engine.input.pointers.primary.on("down", () => {
|
||||||
const randomVelocity = vec(random.integer(100, 400), random.integer(0, -400));
|
const randomVelocity = vec(
|
||||||
|
random.integer(100, 400),
|
||||||
|
random.integer(0, -400),
|
||||||
|
);
|
||||||
this.startParabolaAnimation(new Parabola(start, randomVelocity));
|
this.startParabolaAnimation(new Parabola(start, randomVelocity));
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public update(engine: Engine, elapsed: number): void {
|
public update(engine: Engine, elapsed: number): void {
|
||||||
super.update(engine, elapsed);
|
super.update(engine, elapsed);
|
||||||
this._animation.update(elapsed);
|
this._animation.update(elapsed);
|
||||||
@@ -72,9 +86,7 @@ class BallAnimation {
|
|||||||
private _parabola: Parabola | null = null;
|
private _parabola: Parabola | null = null;
|
||||||
private _elapsedTime: number | null = null;
|
private _elapsedTime: number | null = null;
|
||||||
|
|
||||||
constructor(private _ball: Ball) {
|
constructor(private _ball: Ball) {}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
get running(): boolean {
|
get running(): boolean {
|
||||||
return this._running;
|
return this._running;
|
||||||
@@ -116,23 +128,23 @@ class BallAnimation {
|
|||||||
|
|
||||||
this._ball.pos = newPosition;
|
this._ball.pos = newPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Parabola {
|
export class Parabola {
|
||||||
constructor(
|
constructor(
|
||||||
readonly startPos: Vector,
|
readonly startPos: Vector,
|
||||||
readonly startVelocity: Vector
|
readonly startVelocity: Vector,
|
||||||
) { }
|
) {}
|
||||||
|
|
||||||
position(time: number): Vector {
|
position(time: number): Vector {
|
||||||
const timeSeconds = time / 1000;
|
const timeSeconds = time / 1000;
|
||||||
|
|
||||||
const x = this.startPos.x + this.startVelocity.x * timeSeconds;
|
const x = this.startPos.x + this.startVelocity.x * timeSeconds;
|
||||||
const y = this.startVelocity.y * timeSeconds + gravitationalConstant / 2 * timeSeconds ** 2 + this.startPos.y;
|
const y =
|
||||||
|
this.startVelocity.y * timeSeconds +
|
||||||
|
(gravitationalConstant / 2) * timeSeconds ** 2 +
|
||||||
|
this.startPos.y;
|
||||||
|
|
||||||
return new Vector(x, y);
|
return new Vector(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,4 +1,14 @@
|
|||||||
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 { pixelsPerMeter } from "../utils/physicsConstant";
|
||||||
import { jitterVector, randomInteger } from "../utils/randomUtils";
|
import { jitterVector, randomInteger } from "../utils/randomUtils";
|
||||||
|
|
||||||
@@ -61,19 +71,28 @@ export class Champion extends Actor {
|
|||||||
this.anchor = vec(0.5, 1);
|
this.anchor = vec(0.5, 1);
|
||||||
this._graphic = new GraphicsGroup({
|
this._graphic = new GraphicsGroup({
|
||||||
members: [
|
members: [
|
||||||
{ graphic: leftLeg , offset: vec(0, -waistHeight)},
|
{ graphic: leftLeg, offset: vec(0, -waistHeight) },
|
||||||
{ graphic: rightLeg , offset: vec(0, -waistHeight)},
|
{ graphic: rightLeg, offset: vec(0, -waistHeight) },
|
||||||
{ graphic: bodyGraphic, offset: vec(-width / 2, -height) },
|
{ 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: headGraphic,
|
||||||
{ graphic: smileEyeGraphic.clone(), offset: vec(headSize / 4, -height) },
|
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,
|
useAnchor: false,
|
||||||
})
|
});
|
||||||
|
|
||||||
this.graphics.add(this._graphic);
|
this.graphics.add(this._graphic);
|
||||||
|
|
||||||
this.rotation = Math.PI / 180 * 5;
|
this.rotation = (Math.PI / 180) * 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
update(_engine: Engine, elapsed: number): void {
|
update(_engine: Engine, elapsed: number): void {
|
||||||
@@ -84,9 +103,8 @@ export class Champion extends Actor {
|
|||||||
this._jiggleTimer += elapsed;
|
this._jiggleTimer += elapsed;
|
||||||
if (this._jiggleTimer > jiggleTime) {
|
if (this._jiggleTimer > jiggleTime) {
|
||||||
this._jiggleTimer -= jiggleTime;
|
this._jiggleTimer -= jiggleTime;
|
||||||
this.rotation = -this.rotation
|
this.rotation = -this.rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,9 +122,9 @@ const _crossEyeGraphic = new GraphicsGroup({
|
|||||||
end: vec(-5, 5),
|
end: vec(-5, 5),
|
||||||
color: Color.Black,
|
color: Color.Black,
|
||||||
thickness: 3,
|
thickness: 3,
|
||||||
})
|
}),
|
||||||
]
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
const smileEyeGraphic = new GraphicsGroup({
|
const smileEyeGraphic = new GraphicsGroup({
|
||||||
members: [
|
members: [
|
||||||
@@ -121,6 +139,6 @@ const smileEyeGraphic = new GraphicsGroup({
|
|||||||
end: vec(10, 5),
|
end: vec(10, 5),
|
||||||
color: Color.Black,
|
color: Color.Black,
|
||||||
thickness: 3,
|
thickness: 3,
|
||||||
})
|
}),
|
||||||
]
|
],
|
||||||
});
|
});
|
||||||
@@ -1,5 +1,14 @@
|
|||||||
|
import {
|
||||||
import { Actor, ActorArgs, Color, Engine, Graphic, GraphicsGroup, Line, Polygon,vec } from "excalibur";
|
Actor,
|
||||||
|
ActorArgs,
|
||||||
|
Color,
|
||||||
|
Engine,
|
||||||
|
Graphic,
|
||||||
|
GraphicsGroup,
|
||||||
|
Line,
|
||||||
|
Polygon,
|
||||||
|
vec,
|
||||||
|
} from "excalibur";
|
||||||
import { pixelsPerMeter } from "../utils/physicsConstant";
|
import { pixelsPerMeter } from "../utils/physicsConstant";
|
||||||
|
|
||||||
export const defaultCupConfiguration = {
|
export const defaultCupConfiguration = {
|
||||||
@@ -9,7 +18,7 @@ export const defaultCupConfiguration = {
|
|||||||
widthBottom: 0.12 * pixelsPerMeter,
|
widthBottom: 0.12 * pixelsPerMeter,
|
||||||
height: 0.2 * pixelsPerMeter,
|
height: 0.2 * pixelsPerMeter,
|
||||||
rimThickness: 0.02 * pixelsPerMeter,
|
rimThickness: 0.02 * pixelsPerMeter,
|
||||||
}
|
};
|
||||||
|
|
||||||
export interface CupConfiguration {
|
export interface CupConfiguration {
|
||||||
readonly cupColor: Color;
|
readonly cupColor: Color;
|
||||||
@@ -23,15 +32,17 @@ export interface CupConfiguration {
|
|||||||
export class Cup extends Actor {
|
export class Cup extends Actor {
|
||||||
private _graphic: Graphic = null!;
|
private _graphic: Graphic = null!;
|
||||||
|
|
||||||
constructor(actorArgs: ActorArgs, public readonly configuration: CupConfiguration) {
|
constructor(
|
||||||
|
actorArgs: ActorArgs,
|
||||||
|
public readonly configuration: CupConfiguration,
|
||||||
|
) {
|
||||||
super(actorArgs);
|
super(actorArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
onInitialize(_engine: Engine): void {
|
onInitialize(_engine: Engine): void {
|
||||||
const { configuration } = this;
|
const { configuration } = this;
|
||||||
const { height, widthRim, widthBottom, } = configuration;
|
const { height, widthRim, widthBottom } = configuration;
|
||||||
const halfWidthBottom = widthBottom / 2;
|
const halfWidthBottom = widthBottom / 2;
|
||||||
const halfWidthRim = widthRim / 2;
|
const halfWidthRim = widthRim / 2;
|
||||||
|
|
||||||
|
|||||||
@@ -7,13 +7,13 @@ export class Ground extends Actor {
|
|||||||
private _graphic: Graphic = null!;
|
private _graphic: Graphic = null!;
|
||||||
|
|
||||||
onInitialize(engine: Engine): void {
|
onInitialize(engine: Engine): void {
|
||||||
const { width, height} = engine.screen;
|
const { width, height } = engine.screen;
|
||||||
|
|
||||||
this._graphic = new Rectangle({
|
this._graphic = new Rectangle({
|
||||||
width,
|
width,
|
||||||
height: height / 2,
|
height: height / 2,
|
||||||
color: groundColor,
|
color: groundColor,
|
||||||
})
|
});
|
||||||
this.graphics.add(this._graphic);
|
this.graphics.add(this._graphic);
|
||||||
|
|
||||||
this.pos.setTo(0, groundHeight);
|
this.pos.setTo(0, groundHeight);
|
||||||
|
|||||||
@@ -1,4 +1,12 @@
|
|||||||
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";
|
import { pixelsPerMeter } from "../utils/physicsConstant";
|
||||||
|
|
||||||
export const defaultTableConfiguration = {
|
export const defaultTableConfiguration = {
|
||||||
@@ -8,7 +16,7 @@ export const defaultTableConfiguration = {
|
|||||||
thickness: 0.15 * pixelsPerMeter,
|
thickness: 0.15 * pixelsPerMeter,
|
||||||
legOffset: 0.15 * pixelsPerMeter,
|
legOffset: 0.15 * pixelsPerMeter,
|
||||||
legThickness: 0.15 * pixelsPerMeter,
|
legThickness: 0.15 * pixelsPerMeter,
|
||||||
}
|
};
|
||||||
|
|
||||||
export interface TableConfiguration {
|
export interface TableConfiguration {
|
||||||
readonly color: Color;
|
readonly color: Color;
|
||||||
@@ -22,13 +30,17 @@ export interface TableConfiguration {
|
|||||||
export class Table extends Actor {
|
export class Table extends Actor {
|
||||||
private _graphic: Graphic = null!;
|
private _graphic: Graphic = null!;
|
||||||
|
|
||||||
constructor(actorArgs: ActorArgs, public readonly configuration: TableConfiguration) {
|
constructor(
|
||||||
|
actorArgs: ActorArgs,
|
||||||
|
public readonly configuration: TableConfiguration,
|
||||||
|
) {
|
||||||
super(actorArgs);
|
super(actorArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
onInitialize(_engine: Engine): void {
|
onInitialize(_engine: Engine): void {
|
||||||
const { width, height, thickness, legOffset, legThickness } = this.configuration;
|
const { width, height, thickness, legOffset, legThickness } =
|
||||||
|
this.configuration;
|
||||||
const halfWidth = width / 2;
|
const halfWidth = width / 2;
|
||||||
|
|
||||||
const points = [
|
const points = [
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ export class GameScene extends GameStateScene {
|
|||||||
private _cups: Cup[] = [];
|
private _cups: Cup[] = [];
|
||||||
private _champions: Champion[] = [];
|
private _champions: Champion[] = [];
|
||||||
|
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
constructor(private _connection: Connection) {
|
constructor(private _connection: Connection) {
|
||||||
super();
|
super();
|
||||||
@@ -31,33 +30,41 @@ export class GameScene extends GameStateScene {
|
|||||||
this._ground = new Ground();
|
this._ground = new Ground();
|
||||||
this.add(this._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);
|
this.add(this._table);
|
||||||
|
|
||||||
const tableHalfWidth = this._table.configuration.width / 2;
|
const tableHalfWidth = this._table.configuration.width / 2;
|
||||||
const tableHeight = this._table.configuration.height;
|
const tableHeight = this._table.configuration.height;
|
||||||
|
|
||||||
const cupPositions = [
|
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 => {
|
cupPositions.forEach((offsetX) => {
|
||||||
const cup = new Cup({
|
const cup = new Cup(
|
||||||
|
{
|
||||||
pos: vec(offsetX, groundHeight - tableHeight),
|
pos: vec(offsetX, groundHeight - tableHeight),
|
||||||
color: Color.Red,
|
color: Color.Red,
|
||||||
}, defaultCupConfiguration)
|
},
|
||||||
|
defaultCupConfiguration,
|
||||||
|
);
|
||||||
|
|
||||||
this.add(cup);
|
this.add(cup);
|
||||||
this._cups.push(cup);
|
this._cups.push(cup);
|
||||||
});
|
});
|
||||||
|
|
||||||
const championPositions = [
|
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 => {
|
championPositions.forEach((offsetX) => {
|
||||||
|
const champion = new Champion({
|
||||||
const champion = new Champion({color: randomNonGroundColor(), pos: vec(offsetX, groundHeight)});
|
color: randomNonGroundColor(),
|
||||||
|
pos: vec(offsetX, groundHeight),
|
||||||
|
});
|
||||||
this.add(champion);
|
this.add(champion);
|
||||||
this._champions.push(champion);
|
this._champions.push(champion);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import { Color } from "excalibur";
|
import { Color } from "excalibur";
|
||||||
|
|
||||||
export function colorDistance(color1: Color, color2: Color): number {
|
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)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,11 @@ import { Color, Random, vec, Vector } from "excalibur";
|
|||||||
const rand = new Random();
|
const rand = new Random();
|
||||||
|
|
||||||
export function randomColor(): Color {
|
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] */
|
/** Jitter given vector by at most the given magnitude. The random offset is [-magnitude / 2, magnitude / 2] */
|
||||||
@@ -13,6 +17,6 @@ export function jitterVector(v: Vector, magnitude: number): Vector {
|
|||||||
return vec(x, y);
|
return vec(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function randomInteger(min: number, max:number): number {
|
export function randomInteger(min: number, max: number): number {
|
||||||
return rand.integer(min, max -1);
|
return rand.integer(min, max - 1);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user