aboutsummaryrefslogtreecommitdiffstats
path: root/src/Ball.ts
diff options
context:
space:
mode:
authorMaksymilian Jopek <maks@jopek.eu>2022-03-16 22:34:43 +0100
committerMaksymilian Jopek <maks@jopek.eu>2022-03-16 22:34:43 +0100
commitf8c006414aec99c90558587dbe08cf1705ed44f7 (patch)
tree2f52ea7f071f91e5e53e4dfdde9cdd2b8d7cd4dc /src/Ball.ts
downloadboules-f8c006414aec99c90558587dbe08cf1705ed44f7.tar.gz
boules-f8c006414aec99c90558587dbe08cf1705ed44f7.tar.zst
boules-f8c006414aec99c90558587dbe08cf1705ed44f7.zip
Initial commit w/ v0.0.1
Diffstat (limited to 'src/Ball.ts')
-rw-r--r--src/Ball.ts27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/Ball.ts b/src/Ball.ts
new file mode 100644
index 0000000..c520cb8
--- /dev/null
+++ b/src/Ball.ts
@@ -0,0 +1,27 @@
+import { START_NO_OF_BALLS, MAP_WIDTH, MAP_HEIGHT, COLORS, TD_SIZE, CIRCLE_SIZE } from "./consts";
+import { getRandomInt, getRandomEl } from "./utils";
+
+export default class Ball {
+ x: number;
+ y: number;
+ color: string;
+
+ constructor(x: number, y: number, color: string) {
+ this.x = x;
+ this.y = y;
+ this.color = color;
+ }
+ onclick(el: PointerEvent) {
+ }
+ static generateStartBalls(): Array<Ball> {
+ const out = <Ball[]>[];
+ for (let i = 0; i < START_NO_OF_BALLS; i++) {
+ let x: number, y: number, color: string;
+ do {
+ [x, y, color] = [getRandomInt(0, MAP_HEIGHT), getRandomInt(0, MAP_WIDTH), getRandomEl(COLORS)];
+ } while (out.filter(b => b.x === x && b.y === y).length !== 0)
+ out.push(new Ball(x, y, color));
+ }
+ return out;
+ }
+}