HTML and CSS Reference
In-Depth Information
Listing 13-10: The Enemy, Fountain and Loot classes
Q.Enemy = Q.Sprite.extend({
init: function(props) {
this._super(_({
sheet: 'characters',
z: 10,
health: 10,
maxHealth: 10,
damage: 5,
xp: 100
}).extend(props));
this.add('tiled, transition');
this.bind('interact',this,'interact');
this.hide();
},
interact: function(data) {
this.p.health -= data.damage;
if(this.p.health <= 0) {
this.destroy();
data.source.trigger('xp',this.p.xp);
} else {
var damage = Math.round(Math.random() * this.p.damage);
data.source.trigger('interact',
{ source: this, damage: damage });
}
this.trigger('health',this);
}
});
Q.Fountain= Q.Sprite.extend({
init: function(props) {
this._super(_({
sheet: 'tiles',
frame: 71,
z: 10,
power: 10
}).extend(props));
this.add('tiled');
this.bind('interact',this,'interact');
this.hide();
},
interact: function(data) {
data.source.trigger('heal',{ amount: this.p.power });
}
 
Search WWH ::




Custom Search