Skip to content

Commit

Permalink
🔧 fix(game.js): pass speed and defaultBottom options to ObstacleManag…
Browse files Browse the repository at this point in the history
…er constructor to ensure proper initialization

🔧 fix(obstacle.js): add constructor to ObstacleManager to receive options and store them for later use
  • Loading branch information
romantech committed Jan 24, 2024
1 parent b262ef0 commit 9b3c5fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
9 changes: 7 additions & 2 deletions src/obstacle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit 9b3c5fc

Please sign in to comment.