From 769800045f1cd70f764f18a00e83df434d57962c Mon Sep 17 00:00:00 2001 From: Michael Peters Date: Sat, 3 Aug 2024 20:14:33 -0700 Subject: [PATCH] configuration for steps before delay in engine constructor --- src/components/snake/canvas.ts | 4 ++-- src/components/snake/game-engine.ts | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/components/snake/canvas.ts b/src/components/snake/canvas.ts index ff8c117..3ba7001 100644 --- a/src/components/snake/canvas.ts +++ b/src/components/snake/canvas.ts @@ -89,7 +89,7 @@ function shallowCopySGS(state: SnakeGameState): SnakeGameState { return { dead: state.dead, snake: [...state.snake], - apple: state.apple.copy(), + apple: state.apple, }; } @@ -106,7 +106,7 @@ function getSnakeNextSquare(snake: Snake, dir: Vec2) { export default function runCanvas(canvas: HTMLCanvasElement) { const ui = new UI(canvas); const keys = new Keys(); - const engine = new Engine({ updateDelay: 0 }); + const engine = new Engine({ stepsBeforeDelay: 5, updateDelay: 0 }); // game logic -------------------------------------------------------------- diff --git a/src/components/snake/game-engine.ts b/src/components/snake/game-engine.ts index d3f4588..ac78e88 100644 --- a/src/components/snake/game-engine.ts +++ b/src/components/snake/game-engine.ts @@ -191,7 +191,8 @@ export class Engine { stepsBeforeDelay: number = 1; updateDelay: number; - constructor({ updateDelay }: { updateDelay: number }) { + constructor({ stepsBeforeDelay, updateDelay }: { stepsBeforeDelay: number; updateDelay: number }) { + this.stepsBeforeDelay = stepsBeforeDelay; this.updateDelay = updateDelay; }