Création des bars de vie et de bouclier. Ajout animation de tir. Les robots changent automatiquement de cible quand celle-ci meure. Les robots choisissent pour cible le robot le plus proche d'eux. Si deux robots sont à la meme distance, c'est aléatoire.
parent
58863ea587
commit
f0ea863610
After Width: | Height: | Size: 37 KiB |
File diff suppressed because one or more lines are too long
@ -0,0 +1,68 @@
|
|||||||
|
class HealthBar {
|
||||||
|
constructor(scene, width, height, x, y, valueMax, color) {
|
||||||
|
this.bar = new Phaser.GameObjects.Graphics(scene);
|
||||||
|
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
this.valueMax = valueMax;
|
||||||
|
this.value = valueMax;
|
||||||
|
this.color = color;
|
||||||
|
|
||||||
|
this.draw();
|
||||||
|
|
||||||
|
this.setX(x);
|
||||||
|
this.setY(y);
|
||||||
|
scene.add.existing(this.bar);
|
||||||
|
}
|
||||||
|
|
||||||
|
decrease(amount) {
|
||||||
|
this.value -= amount;
|
||||||
|
|
||||||
|
let diff = 0;
|
||||||
|
if (this.value < 0) {
|
||||||
|
diff = -this.value;
|
||||||
|
this.value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.draw();
|
||||||
|
|
||||||
|
return diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
setX(x) {
|
||||||
|
this.bar.setX(x - this.width / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
setY(y) {
|
||||||
|
this.bar.setY(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
draw() {
|
||||||
|
this.bar.clear();
|
||||||
|
|
||||||
|
// BG
|
||||||
|
this.bar.fillStyle(0x000000);
|
||||||
|
this.bar.fillRect(0, 0, this.width, this.height);
|
||||||
|
|
||||||
|
// Health
|
||||||
|
|
||||||
|
this.bar.fillStyle(0xffffff);
|
||||||
|
this.bar.fillRect(2, 2, this.width - 4, this.height - 4);
|
||||||
|
|
||||||
|
let percent = this.value / this.valueMax;
|
||||||
|
|
||||||
|
if (percent < 0.3) {
|
||||||
|
this.bar.fillStyle(0xff0000);
|
||||||
|
} else {
|
||||||
|
this.bar.fillStyle(this.color);
|
||||||
|
}
|
||||||
|
|
||||||
|
let d = Math.floor(percent * (this.width - 4));
|
||||||
|
|
||||||
|
this.bar.fillRect(2, 2, d, this.height - 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
destroy() {
|
||||||
|
this.bar.destroy();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
class Missile extends Phaser.GameObjects.Image {
|
||||||
|
|
||||||
|
constructor(scene, frame, width, height) {
|
||||||
|
super(scene, 0, 0, frame);
|
||||||
|
this.visible = false;
|
||||||
|
this.setOrigin(0.5, 0.5);
|
||||||
|
this.setScale(0.02);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue