diff --git a/frontend/src/js/fight_scene.js b/frontend/src/js/fight_scene.js index b8f3c8b60c4b3c319f70ef4abda3862d6f9d02e8..d301a88ee8a789e973328007c11c3de1bae1a108 100644 --- a/frontend/src/js/fight_scene.js +++ b/frontend/src/js/fight_scene.js @@ -367,20 +367,7 @@ function gameStart(scene) { function dispatchEnemy(scene) { backend.post("GetImage", {}).then(function (response) { - let e = new Foe(scene, response.data); - - scene.textures.addBase64(`WORD-${response.data.id}`, response.data.image); - scene.textures.once( - "addtexture", - function () { - e.run((v) => { - setTimeout(() => { - dispatchEnemy(scene); - }, Math.floor(Math.random() * 10000 + 3000)); - }); - }, - scene, - ); + new Foe(scene, response.data); }); } diff --git a/frontend/src/js/foe.js b/frontend/src/js/foe.js index ea8619f6e07ba34b6237d3b9d7fd92ba496a4265..a45872b6c8f96734246ffe69478cd1072f6cba97 100644 --- a/frontend/src/js/foe.js +++ b/frontend/src/js/foe.js @@ -6,9 +6,24 @@ class Foe { this.scene = scene; this.scene.foes.push(this); this.word = word; + this.addClue(); + this.run(); } - run(callback) { + addClue() { + this.scene.textures.addBase64(this.word.id, this.word.image); + this.scene.textures.once( + "addtexture", + this.addClueSprite.bind(this), + this.scene, + ); + } + + addClueSprite() { + this.scene.add.sprite(400, 300, this.word.id); + } + + run() { let me = this; let randomEnemyType = enemies[Math.floor(Math.random() * 4 + 0)]; @@ -19,7 +34,6 @@ class Foe { scale = 3; } - let flag = this.scene.add.sprite(400, 300, `WORD-${this.word.id}`); let enemy = this.scene.physics.add .sprite(-100, this.scene.cameras.main.height - 100, randomEnemyType) .setScale(scale) @@ -60,7 +74,6 @@ class Foe { duration: 2000, onComplete: function () { nemico.destroy(); - callback(me); }, }); }, 3000);