/
octocat.js
44 lines (31 loc) · 1.18 KB
/
octocat.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
define([
'underscore',
'crafty'
], function(_, Crafty) {
Crafty.c("Octocat", {
init : function() {
this.addComponent("SpriteAnimation, SpriteColor, octocat, Collision");
this.attr({
w : 90,
h : 90
});
this.life = 300;
this.collision(new Crafty.polygon([29,17],[23,41],[34,54],[42,75],[61,74],[45,45],[74,25]));
this.walkSpeed = 0.65;
this.animate("walk", 0, 0, 7);
this.animate("walk", 45, -1);
this.walk();
this.onHit("Bullet", function(others) {
others[0].obj.destroy();
var damages = Math.round(Crafty.math.randomNumber(30,70));
this.takeDamages(damages);
this.git({x: 35, y: 45});
Crafty.e("Damages").display(damages, { x: this._x, y: this._y });
});
this.bind("Death", function() {
this.git({x: 35, y: 45});
this.destroy();
});
}
});
});