From ad68174c60c27f2115f516c447f3b5bd961d730f Mon Sep 17 00:00:00 2001 From: Daniel Bulant Date: Fri, 11 Jun 2021 18:19:25 +0200 Subject: [PATCH] level3 but broken cloud destroying --- src/game/gameScene.js | 76 ++++++++++++++++++++++++++++--------------- src/game/maps.js | 27 ++++++++++++++- src/stores/dialog.js | 1 + 3 files changed, 77 insertions(+), 27 deletions(-) diff --git a/src/game/gameScene.js b/src/game/gameScene.js index 880370d..f167742 100644 --- a/src/game/gameScene.js +++ b/src/game/gameScene.js @@ -77,7 +77,7 @@ export class GameScene extends Phaser.Scene { } calculateScale() { - const maxWidth = innerWidth * 0.8 - (document.body.clientHeight / 1080 * 615 * 1.1); + const maxWidth = innerWidth * 0.8 - (document.body.clientHeight / 1080 * 615 * 1.15); const maxHeight = innerHeight * 0.8; const targetWidth = this.originalWidth + this.map.offset.x * 2; const targetHeight = this.originalHeight + this.map.offset.y * 2; @@ -130,7 +130,10 @@ export class GameScene extends Phaser.Scene { x = parseInt(x); if(item.type !== "barrier") { var type = item.type; - if(type === "angel") type = this.map.sprite; + if(type === "angel") { + type = this.map.sprite; + item.texture = type; + } if(this.textures.get(type).frameTotal > 1) { var sprite = this.add.sprite(x * this.map.px, y * this.map.px); item.animated = true; @@ -149,17 +152,17 @@ export class GameScene extends Phaser.Scene { var sprite = this.add.sprite(x * this.map.px, y * this.map.px, type); item.animated = false; } + sprite.scale = this.map.px / 100; sprite.setRotation(item.direction * Math.PI / 2); this.grid.add(sprite); item.sprite = sprite; - if(type !== item.type) { - item.texture = type; - } if(item.type === "spawn") { + /** @type {{ x: number, y: number, hasKey: boolean }} */ this.player = item; this.player.x = x; this.player.y = y; + this.player.hasKey = false; } if(item.type === "angel") { this.angel = item; @@ -226,36 +229,57 @@ export class GameScene extends Phaser.Scene { return this.isWindActive(x-mov.x, y-mov.y); } + tryDestroy(toX, toY) { + if(this.items[toX][toY].destroyable) { + this.items[toX][toY].sprite.alpha = 0; + this.items[toX][toY].sprite.destroy(); + console.log("Destroyed", this.items[toX][toY].sprite); + this.items[toX][toY] = null; + this.canMove = false; + setTimeout(() => { + this.canMove = true; + }, 400); + return true; + } + } + movePlayer(moveX, moveY, fromWind = false) { if(!this.canMove) return; var toX = this.player.x + moveX; var toY = this.player.y + moveY; if(toX > this.map.size.x - 1 || toX < 0 || toY > this.map.size.y - 1 || toY < 0) return; if(this.items[toX][toY]) { - if(fromWind) return; - if(this.items[toX][toY].type !== "lyre") { - if(this.items[toX][toY].destroyable) { - this.items[toX][toY].sprite.destroy(); - this.items[toX][toY] = null; - this.canMove = false; - setTimeout(() => { - this.canMove = true; - }, 400); + if(this.items[toX][toY].type === "key") { + this.items[toX][toY].sprite.destroy(); + this.items[toX][toY] = null; + this.player.hasKey = true; + } else if(fromWind) return; + else if(this.items[toX][toY].type === "lock") { + if(!this.player.hasKey) return; + this.items[toX][toY].sprite.destroy(); + this.items[toX][toY] = null; + } else if(this.items[toX][toY].type !== "lyre" && this.tryDestroy(toX, toY)) { + steps.update(t => --t); + if(stepNum <= 0) { + this.unload(); + this.createMap(); + return; } return; - } - if(toX + moveX > this.map.size.x - 1|| toX + moveX < 0 || toY + moveY > this.map.size.y - 1 || toY + moveY < 0) return; - if(this.items[toX + moveX][toY + moveY] && this.items[toX + moveX][toY + moveY].type !== "wind") return; - if(stepNum <= 0) { - this.unload(); - this.createMap(); + } else if(this.items[toX][toY].type === "lyre" && !this.items[toX + moveX][toY + moveY]) { + if(toX + moveX > this.map.size.x - 1|| toX + moveX < 0 || toY + moveY > this.map.size.y - 1 || toY + moveY < 0) return; + if(this.items[toX + moveX][toY + moveY] && this.items[toX + moveX][toY + moveY].type !== "wind") return; + if(stepNum <= 0) { + this.unload(); + this.createMap(); + return; + } + this.canMove = false; + this.move(toX, toY, toX + moveX, toY + moveY, () => { + this.canMove = true; + }); return; - } - this.canMove = false; - this.move(toX, toY, toX + moveX, toY + moveY, () => { - this.canMove = true; - }); - return; + } else return; } if(stepNum <= 0) { this.unload(); diff --git a/src/game/maps.js b/src/game/maps.js index 66bb37b..8491700 100644 --- a/src/game/maps.js +++ b/src/game/maps.js @@ -75,11 +75,36 @@ export const maps = { ["barrier" , "barrier" , "barrier" , cloud , cloud , cloud , cloud , cloud , cloud , cloud , cloud ], ["barrier" , "barrier" , "barrier" , cloud , "barrier" , "barrier" , "barrier" , "barrier" , "barrier" , "pillar" , cloud ], [cloud , cloud , cloud , cloud , "barrier" , "barrier" , "barrier" , "barrier" , "barrier" , "pillar" , cloud ], - [cloud , "barrier" , "barrier" , "barrier" , "barrier" , "barrier" , "barrier" , "barrier" , null , "angel" , cloud ], + [cloud , "barrier" , "barrier" , "barrier" , "barrier" , "barrier" , "barrier" , "barrier" , "barrier" , "angel" , cloud ], [cloud , null , "lyre" , null , null , null , null , "lyre" , null , null , "barrier" ], [null , null , null , "lyre" , "lyre" , null , "lyre" , null , "lyre" , "lyre" , null ], ["spawn" , null , "lyre" , null , null , "lyre" , null , "lyre" , null , null , "barrier" ], ["barrier" , "barrier" , null , "lyre" , null , null , "lyre" , "barrier" , "barrier" , "barrier" , "barrier" ] ] + }, + uziel: { + background: "level3", + sprite: "uziel", + next: "uziel_start", + size: { + x: 7, + y: 8 + }, + offset: { + x: 0, + y: 100 + }, + px: 80, + steps: 26, + map: [ + ["barrier" , "barrier" , "barrier" , "barrier" , "angel" , "barrier" ], + [wind(4) , wind(4) , wind(4) , wind(4) , wind(3) , "barrier" ], + [null , cloud , null , "lyre" , "lock" , "barrier" ], + ["barrier" , null , "lyre" , null , null , "barrier" ], + ["barrier" , cloud , "lyre" , null , null , "barrier" , "barrier" ], + ["spawn" , null , null , wind(2) , cloud , "lyre" , "key" ], + ["barrier" , "barrier" , wind(2) , "lyre" ], + [null , "barrier" , null , null , null , "barrier" , "barrier" ] + ] } }; \ No newline at end of file diff --git a/src/stores/dialog.js b/src/stores/dialog.js index cb540d6..f17e4e7 100644 --- a/src/stores/dialog.js +++ b/src/stores/dialog.js @@ -143,6 +143,7 @@ export const dialog = [{ background: "/sprite/backg.webp", character: "Uziel", chapterStart: "uziel", + map: "uziel", text: "(she appear out of nowhere and suddenly approaches you.)", buttons: [{ text: "oh, you're approaching me? Had you heard of my harem proposal.",