From 1bb33d6fb1677ef53b5aa5abbc8a992156f0bda3 Mon Sep 17 00:00:00 2001 From: s-prechtl Date: Tue, 10 Jan 2023 09:39:34 +0100 Subject: [PATCH] More refactor more comments --- frontend/game.ts | 1 + frontend/model/Entity.ts | 6 ++++++ frontend/model/Obstacle.ts | 17 ++++++++--------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/frontend/game.ts b/frontend/game.ts index c63d86c..117fc7d 100644 --- a/frontend/game.ts +++ b/frontend/game.ts @@ -19,6 +19,7 @@ function setup() { createCanvas(2000, 1000); obstacleOffset = width / 3; Obstacle.distanceBetweenPipes = height / 2.5 + Obstacle.startX = width; textSize(150); textFont("resources/PressStart2P-Regular.ttf"); diff --git a/frontend/model/Entity.ts b/frontend/model/Entity.ts index 745f71a..07d8c95 100644 --- a/frontend/model/Entity.ts +++ b/frontend/model/Entity.ts @@ -54,8 +54,14 @@ abstract class Entity { this._showHitbox = false; } + /** + * Updates the entity. + */ public abstract update(): void; + /** + * Draws the entity. + */ public draw(): void { push(); fill(this.fill); diff --git a/frontend/model/Obstacle.ts b/frontend/model/Obstacle.ts index 44560d1..8c6fc07 100644 --- a/frontend/model/Obstacle.ts +++ b/frontend/model/Obstacle.ts @@ -5,7 +5,11 @@ class Obstacle extends Entity implements Collidable { private readonly padding: number = 150; private readonly speed: number = 3; - private static startX: number; + private static _startX: number; + + static set startX(value: number) { + this._startX = value; + } static set distanceBetweenPipes(value: number) { this._distanceBetweenPipes = value; @@ -25,9 +29,7 @@ class Obstacle extends Entity implements Collidable { this.pipeBottom = new Pipe(position.x, obstacleWidth, obstacleHeight); this.pipeTop.image = pipeImagePath; this.pipeBottom.image = pipeImagePath; - - //TODO: Put into setupGame() - Obstacle.startX = width; + this.pipeTop.position.y = 0; } /** @@ -36,9 +38,8 @@ class Obstacle extends Entity implements Collidable { */ public resetPosition(): void { this.randomizeHeight(); - - this.pipeBottom.position.x = Obstacle.startX; - this.pipeTop.position.x = Obstacle.startX; + this.pipeBottom.position.x = Obstacle._startX; + this.pipeTop.position.x = Obstacle._startX; } /** @@ -46,8 +47,6 @@ class Obstacle extends Entity implements Collidable { */ public randomizeHeight(): void { this.pipeTop.height = this.randomRange(this.padding, height - this.padding - Obstacle._distanceBetweenPipes); - //TODO: Soi des do sei? - this.pipeTop.position.y = 0; this.pipeBottom.position.y = this.pipeTop.height + Obstacle._distanceBetweenPipes; this.pipeBottom.height = height - this.pipeTop.height - this.padding; }