-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenemyPokemon.js
More file actions
62 lines (58 loc) · 1.64 KB
/
enemyPokemon.js
File metadata and controls
62 lines (58 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class EnemyPokemon extends Pokemon {
constructor(ctx, game, x, y, img, lifePoints, attackPoints, atkImg) {
super(ctx, game, x, y, img, lifePoints, attackPoints, atkImg)
this.width = 70;
this.height = 50;
this.xFrame = 0;
this.frames = 3;
this.speed = 5;
this.fireballSpeed = -10;
}
moveRandom() {
const maxLimit = 700;
const minLimit = 10;
const random = Math.floor(Math.random() * 100);
if (this.game.counter % 10 === 0) {
if(this.y < minLimit) {
this.moveDown();
this.moveDown();
this.moveDown();
this.moveDown();
this.moveDown();
}else if (this.y + this.height > maxLimit) {
this.moveUp();
this.moveUp();
this.moveUp();
this.moveUp();
this.moveUp();
} else if (random < 50) {
this.moveUp();
}
else {
this.moveDown();
}
}
}
clearFireBalls() {
this.fireBalls = this.fireBalls.filter(fireBall => {
return fireBall.x > 0;
});
}
addFireBall() {
const fireBall = new FireBall(
this.ctx,
this.game,
this.x -100,
this.y + this.height / 2,
this.atkImg,
this.fireballSpeed,
);
this.fireBalls.push(fireBall);
}
attackRandom() {
const random = Math.floor(Math.random() * 100);
if (random < 0.3) {
this.addFireBall();
}
}
}