restart on failure

This commit is contained in:
Daniel Bulant 2021-04-09 08:27:13 +02:00
parent 235c69d18f
commit 05c41d003b
2 changed files with 12 additions and 1 deletions

View file

@ -6,6 +6,11 @@ import { dialog } from "../stores/dialog.js";
const textureWidth = 100;
var stepNum;
steps.subscribe(t => {
stepNum = t;
});
export class GameScene extends Phaser.Scene {
constructor(map) {
super({
@ -61,6 +66,7 @@ export class GameScene extends Phaser.Scene {
createMap() {
console.log(this.map);
steps.set(this.map.steps);
this.container = this.add.container();
this.container.width = this.map.size.x * this.map.px + this.map.offset.x * 2;
this.container.height = this.map.size.y * this.map.px + this.map.offset.y * 2;
@ -196,6 +202,11 @@ export class GameScene extends Phaser.Scene {
if(this.items[toX + moveX][toY + moveY] && this.items[toX + moveX][toY + moveY].type !== "wind") return;
this.move(toX, toY, toX + moveX, toY + moveY);
}
if(stepNum <= 0) {
this.unload();
this.createMap();
return;
}
this.canMove = false;
if(!fromWind) {
steps.update(t => --t);

View file

@ -50,7 +50,7 @@ export function setMap(newmap) {
mapname = newmap;
map = maps[mapname];
if(gs) {
// gs.unload();
gs.unload();
gs.map = map;
gs.createMap();
}