Skip to content

Commit

Permalink
Lesson 28-29. Hive Whale and Drone enemy class
Browse files Browse the repository at this point in the history
  • Loading branch information
Зелёный Андрей Сергеевич committed Jan 8, 2024
1 parent 270dd10 commit 1a8eae7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/Enemies/Drone.js
@@ -0,0 +1,15 @@
class Drone extends Enemy {
constructor(game, x, y) {
super(game);
this.width = 115;
this.height = 95;
this.x = x;
this.y = y;
this.image = document.getElementById('drone');
this.frameY = Math.floor(Math.random() * 2);
this.lives = 3;
this.score = this.lives;
this.type = 'drone';
this.speedX = Math.random() * -4.2 - 0.5;
}
}
14 changes: 14 additions & 0 deletions src/Enemies/HiveWhale.js
@@ -0,0 +1,14 @@
class HiveWhale extends Enemy {
constructor(game) {
super(game);
this.width = 400;
this.height = 227;
this.y = Math.random() * (this.game.height * 0.95 - this.height);
this.image = document.getElementById('hivewhale');
this.frameY = 0;
this.lives = 20;
this.score = this.lives;
this.type = 'hive';
this.speedX = Math.random() * -1.2 - 0.2;
}
}
15 changes: 13 additions & 2 deletions src/Game.js
Expand Up @@ -57,7 +57,17 @@ class Game {
projectile.markedForDeletion = true; // удаляем пулю
// Проверяем, если у врага не осталось жизней
if (enemy.lives <= 0) {
enemy.markedForDeletion = true; // удаляем врага
enemy.markedForDeletion = true; // удаляем врага
// Если мы уничтожили большого врага (тип hive)
if (enemy.type === 'hive') {
for (let i = 0; i < 5; i++) {
// создаем массив из 5-ти дронов
this.enemies.push(new Drone(this,
enemy.x + Math.random() * enemy.width, enemy.y + Math.random() *
enemy.height * 0.5));
}

};
if (!this.gameOver) this.score += enemy.score; // увеличиваем количество очков игрока
if (this.isWin()) this.gameOver = true; // проверяем условие победы
}
Expand Down Expand Up @@ -88,7 +98,8 @@ class Game {
const randomize = Math.random();
if (randomize < 0.3) this.enemies.push(new Angler1(this));
else if (randomize < 0.6) this.enemies.push(new Angler2(this));
else this.enemies.push(new LuckyFish(this)); // добавляем Рыбку-Удачу
else if (randomize < 0.7) this.enemies.push(new HiveWhale(this));
else this.enemies.push(new LuckyFish(this));
}

addParticles(number, enemy) {
Expand Down

0 comments on commit 1a8eae7

Please sign in to comment.