-
Notifications
You must be signed in to change notification settings - Fork 11
/
Egg.js
52 lines (42 loc) · 987 Bytes
/
Egg.js
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
class Egg extends Animatable {
constructor(canvas) {
super(canvas, 180);
const egg = new Sprite('images/Egg.png', 900, 120, 5, 1);
this.animations = {
egg: egg.get(0),
}
this.bounce = this.bounce.bind(this);
this.break = this.break.bind(this);
this.hatch = this.hatch.bind(this);
}
bounce(max) {
const frame = this.frame(this.animations.egg);
function* animation() {
while (max > 0) {
yield* frame(2);
yield* frame(3);
yield* frame(4);
yield* frame(3);
yield* frame(2);
max--;
}
};
return animation.call(this);
}
break() {
const frame = this.frame(this.animations.egg);
function* animation() {
yield* frame(2);
yield* frame(1);
yield* frame(0);
};
return animation.call(this);
}
hatch() {
function* animation() {
yield* this.bounce(3);
yield* this.break();
};
return animation.call(this);
}
}