From 7d84f51d914aa1fe9aec9e3a2e9e696b494a191d Mon Sep 17 00:00:00 2001 From: s-prechtl Date: Tue, 13 Dec 2022 08:33:37 +0100 Subject: [PATCH] code review --- frontend/models/Obstacle.ts | 6 +++--- frontend/models/Pipe.ts | 1 - frontend/models/Raspberry.ts | 14 ++++++-------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/frontend/models/Obstacle.ts b/frontend/models/Obstacle.ts index 4070801..b75be4a 100644 --- a/frontend/models/Obstacle.ts +++ b/frontend/models/Obstacle.ts @@ -1,9 +1,9 @@ class Obstacle extends Entity { private pipeTop: Pipe; private pipeBottom: Pipe; - private distanceBetweenPipes: number; - private padding: number = 300; - private speed: number = 8; + private readonly distanceBetweenPipes: number; + private readonly padding: number = 300; + private readonly speed: number = 8; private static startX: number; diff --git a/frontend/models/Pipe.ts b/frontend/models/Pipe.ts index 4ed0b46..2099e63 100644 --- a/frontend/models/Pipe.ts +++ b/frontend/models/Pipe.ts @@ -18,7 +18,6 @@ class Pipe extends Entity { public update(): void {} public draw(): void { - // @ts-ignore image(this.image, this.position.x, this.position.y, this.width, this.height); noFill(); rect( diff --git a/frontend/models/Raspberry.ts b/frontend/models/Raspberry.ts index 9a5b873..0116c9f 100644 --- a/frontend/models/Raspberry.ts +++ b/frontend/models/Raspberry.ts @@ -1,9 +1,9 @@ class Raspberry extends Entity { - private lift: number = -10; - private gravity: number = 1; + private readonly lift: number = -10; + private readonly gravity: number = 1; private _velocity: number = 0; private _image: any; - private static maxVelocity: number = 5; + private static readonly maxVelocity: number = 5; constructor() { super(new Position(width / 6, height / 2), 180, 70, 0); @@ -17,7 +17,7 @@ class Raspberry extends Entity { set velocity(value: number) { this._velocity = (this.velocity > Raspberry.maxVelocity) ? Raspberry.maxVelocity : value; } - + get image(): any { return this._image; } @@ -34,9 +34,7 @@ class Raspberry extends Entity { } private applyGravity(): void { - if (this.position.y - this.height > 0) { - this.velocity += this.gravity; - } + this.velocity += this.gravity; } private forceBoundaries(): void { @@ -54,7 +52,7 @@ class Raspberry extends Entity { public boost(): void { this.velocity += this.lift; } - + public draw(): void { image(this.image, this.position.x, this.position.y, this.width, this.height); noFill();