diff --git a/src/game-entry.js b/src/game-entry.js new file mode 100644 index 0000000..d4e971a --- /dev/null +++ b/src/game-entry.js @@ -0,0 +1,28 @@ +import Phaser from 'phaser'; + +const originalRestart = Phaser.Scenes.ScenePlugin.prototype.restart; +Phaser.Scenes.ScenePlugin.prototype.restart = function restartWithFreshRunState(data) { + const scene = this.scene; + + if (scene?.sys?.settings?.key === 'game') { + scene.playerSpeed = 0; + scene.playerHull = 100; + scene.gameState = 'playing'; + scene.lastPlayerShot = 0; + scene.wave = 1; + scene.defeated = 0; + } + + return originalRestart.call(this, data); +}; + +const originalSetData = Phaser.GameObjects.GameObject.prototype.setData; +Phaser.GameObjects.GameObject.prototype.setData = function setBalancedDamage(key, value) { + if (key === 'damage' && this.texture?.key === 'pirate-shot') { + value = Math.min(Number(value) || 0, 4); + } + + return originalSetData.call(this, key, value); +}; + +await import('./game-v4.js');