From 123f73ff4909838edc85707d0e4959083b66d094 Mon Sep 17 00:00:00 2001 From: dhain Date: Tue, 29 Nov 2022 11:21:45 +0100 Subject: [PATCH] added `Obstacle.ts` * resetPosition maby done * update done ig --- frontend/models/Obstacle.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 frontend/models/Obstacle.ts diff --git a/frontend/models/Obstacle.ts b/frontend/models/Obstacle.ts new file mode 100644 index 0000000..ebbe0f9 --- /dev/null +++ b/frontend/models/Obstacle.ts @@ -0,0 +1,23 @@ +class Obstacle { + private pipeTop: Entity; + private pipeBottom: Entity; + private distanceBetweenPipes: number; + private padding: number; + private speed: number; + private static startX: number; + + private resetPosition(){ + let randomY = Math.random() * (height - this.padding) + this.padding; + + this.pipeTop.height = randomY - this.distanceBetweenPipes / 2; + this.pipeTop.position.x = Obstacle.startX; + + this.pipeBottom.height = randomY + this.distanceBetweenPipes / 2; + this.pipeBottom.position.x = Obstacle.startX; + } + + public update(){ + this.pipeTop.position.x -= this.speed; + this.pipeBottom.position.x -= this.speed; + } +} \ No newline at end of file