Skip to content
Snippets Groups Projects
Commit ef12c91e authored by Paolo.Brasolin's avatar Paolo.Brasolin
Browse files

feat: #fe move foes w/ physics instead of tweens

parent 360a6c9d
No related branches found
No related tags found
No related merge requests found
let enemies = ["bear", "wolf", "deer", "boar"]; let SPECIES = ["bear", "wolf", "deer", "boar"];
let enemiesSpeed = 50000;
class Foe { class Foe {
constructor(scene, word) { constructor(scene, word) {
...@@ -7,7 +6,7 @@ class Foe { ...@@ -7,7 +6,7 @@ class Foe {
this.scene.foes.push(this); this.scene.foes.push(this);
this.word = word; this.word = word;
this.addClue(); this.addClue();
this.run(); this.addAnimal();
} }
addClue() { addClue() {
...@@ -20,64 +19,42 @@ class Foe { ...@@ -20,64 +19,42 @@ class Foe {
} }
addClueSprite() { addClueSprite() {
this.scene.add.sprite(400, 300, this.word.id); // TODO: position
this.clueSprite = this.scene.add.sprite(400, 300, this.word.id);
} }
run() { addAnimal() {
let me = this; this.species = SPECIES[Math.floor(Math.random() * SPECIES.length)];
let randomEnemyType = enemies[Math.floor(Math.random() * 4 + 0)];
let scale = 2; let scale = 2;
if (randomEnemyType === "deer") { if (this.species === "deer") {
scale = 2.5; scale = 2.5;
} else if (randomEnemyType === "bear") { } else if (this.species === "bear") {
scale = 3; scale = 3;
} }
let enemy = this.scene.physics.add this.animalSprite = this.scene.physics.add
.sprite(-100, this.scene.cameras.main.height - 100, randomEnemyType) .sprite(-100, this.scene.cameras.main.height - 100, this.species)
.setScale(scale) .setScale(-1 * scale, scale)
.setInteractive(); .setInteractive();
this.sprite = enemy; this.scene.physics.add.collider(this.animalSprite, this.scene.ground);
enemy.typeName = randomEnemyType; setAnimation(this.animalSprite, this.species + "_walk");
this.scene.physics.add.collider(enemy, this.scene.ground);
enemy.flipX = true;
setAnimation(enemy, enemy.typeName + "_walk");
// TODO: bring animal below grass // TODO: bring animal below grass
enemy.movement = this.scene.tweens.add({ this.animalSprite.body.setVelocity(100, 0);
targets: enemy,
x: this.scene.cameras.main.width + 300,
duration: enemiesSpeed,
onComplete: function () {
enemy.destroy();
callback(me);
},
onStop: function () {},
});
// here to implement health // here to implement health
this.scene.physics.add.overlap(this.scene.player, enemy, (p, nemico) => { this.scene.physics.add.overlap(
nemico.disableInteractive(); this.scene.player,
nemico.body.enable = false; this.animalSprite,
nemico.movement.pause(); (player, nemico) => {
nemico.play(nemico.typeName + "_idle"); nemico.play(this.species + "_run");
setTimeout(() => { this.animalSprite.body.setVelocity(300, 0);
nemico.play(nemico.typeName + "_run"); setTimeout(() => nemico.destroy(), 2000);
nemico.movement.stop(); },
this.scene.tweens.add({ );
targets: nemico,
x: this.scene.cameras.main.width + 100,
duration: 2000,
onComplete: function () {
nemico.destroy();
},
});
}, 3000);
});
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment