From 309ed20627ed798c464a9f97d9c32ceb1a314595 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sat, 1 Mar 2025 13:10:21 -0700 Subject: add a reset button! --- src/engine/config/constants.ts | 2 ++ src/engine/systems/Input.ts | 6 +++++- src/engine/systems/Level.ts | 11 +++++++---- 3 files changed, 14 insertions(+), 5 deletions(-) (limited to 'src/engine') diff --git a/src/engine/config/constants.ts b/src/engine/config/constants.ts index 89f7e92..5303ab5 100644 --- a/src/engine/config/constants.ts +++ b/src/engine/config/constants.ts @@ -27,6 +27,8 @@ export namespace KeyConstants { " ": Action.INTERACT, enter: Action.INTERACT, + + r: Action.RESET, }; // value -> [key] from KeyActions diff --git a/src/engine/systems/Input.ts b/src/engine/systems/Input.ts index c527f29..b11ba84 100644 --- a/src/engine/systems/Input.ts +++ b/src/engine/systems/Input.ts @@ -1,4 +1,4 @@ -import { Grid as GridSystem, SystemNames, System } from "."; +import { Grid as GridSystem, SystemNames, System, Level } from "."; import { Game } from ".."; import { ComponentNames, Grid, Interactable } from "../components"; import { Control } from "../components/Control"; @@ -31,6 +31,10 @@ export class Input extends System { } public update(_dt: number, game: Game) { + if (this.hasSomeKey(KeyConstants.ActionKeys.get(Action.RESET))) { + game.getSystem(SystemNames.Level).reset(game); + } + game.forEachEntityWithComponent(ComponentNames.Control, (entity) => this.handleMovement(entity, game), ); diff --git a/src/engine/systems/Level.ts b/src/engine/systems/Level.ts index 87e12a5..824895d 100644 --- a/src/engine/systems/Level.ts +++ b/src/engine/systems/Level.ts @@ -3,8 +3,8 @@ import { Game } from ".."; import { type Level as LevelType, LEVELS, LEVEL_PROGRESSION } from "../levels"; export class Level extends System { - private unlockedLevels: Set; - private currentLevel: LevelType | null; + private unlockedLevels: Set = new Set(); + private currentLevel: LevelType | null = null; private moveToLevel: string | null; private levelMap: Map; @@ -16,15 +16,18 @@ export class Level extends System { this.levelMap.set(level.name, level); }); - this.currentLevel = null; this.moveToLevel = initialLevel; - this.unlockedLevels = new Set(); } public setLevel(level: string) { this.moveToLevel = level; } + public reset(game: Game) { + game.resetState(); + this.currentLevel?.init(game); + } + public update(_dt: number, game: Game) { if (this.moveToLevel === this.currentLevel?.name || !this.moveToLevel) { return; -- cgit v1.2.3-70-g09d2