From 9b3c5fcc299f2ad0eca7bcd32835886a440da42d Mon Sep 17 00:00:00 2001 From: ColorFilter Date: Wed, 24 Jan 2024 18:55:56 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix(game.js):=20pass=20speed=20a?= =?UTF-8?q?nd=20defaultBottom=20options=20to=20ObstacleManager=20construct?= =?UTF-8?q?or=20to=20ensure=20proper=20initialization=20=F0=9F=94=A7=20fix?= =?UTF-8?q?(obstacle.js):=20add=20constructor=20to=20ObstacleManager=20to?= =?UTF-8?q?=20receive=20options=20and=20store=20them=20for=20later=20use?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/game.js | 2 +- src/obstacle.js | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/game.js b/src/game.js index 087f3b1..eba2fd4 100644 --- a/src/game.js +++ b/src/game.js @@ -20,7 +20,7 @@ class Game { constructor({ speed, defaultBottom }) { this.mario = new Mario({ defaultBottom }); this.background = new Background({ speed }); - this.obstacles = new ObstacleManager(); + this.obstacles = new ObstacleManager({ speed, defaultBottom }); this.score = new Score(); this.eventHandler = new EventHandler(this); diff --git a/src/obstacle.js b/src/obstacle.js index 44ade2d..dc29e20 100644 --- a/src/obstacle.js +++ b/src/obstacle.js @@ -5,10 +5,15 @@ class ObstacleManager { frameId = null; isMonitoring = false; + constructor(options) { + this.defaultOptions = options; + } + add() { - const obstacle = new Obstacle(); - this.list.add(obstacle); + const obstacle = new Obstacle(this.defaultOptions); DomManager.gameArea.appendChild(obstacle.element); + + this.list.add(obstacle); obstacle.move(); }