add a reset button!

This commit is contained in:
Elizabeth Hunt 2025-03-01 13:10:21 -07:00
parent 8dacee8f73
commit 309ed20627
Signed by: simponic
GPG Key ID: 2909B9A7FF6213EE
3 changed files with 14 additions and 5 deletions

View File

@ -27,6 +27,8 @@ export namespace KeyConstants {
" ": Action.INTERACT,
enter: Action.INTERACT,
r: Action.RESET,
};
// value -> [key] from KeyActions

View File

@ -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<Level>(SystemNames.Level).reset(game);
}
game.forEachEntityWithComponent(ComponentNames.Control, (entity) =>
this.handleMovement(entity, game),
);

View File

@ -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<string>;
private currentLevel: LevelType | null;
private unlockedLevels: Set<string> = new Set();
private currentLevel: LevelType | null = null;
private moveToLevel: string | null;
private levelMap: Map<string, LevelType>;
@ -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;