Permalink
Browse files

skills refactored

  • Loading branch information...
1 parent d9363f3 commit 9db310e059694650b6e41f117abf1cff8f9513e0 @hugeen committed Nov 18, 2012
Showing with 47 additions and 32 deletions.
  1. +16 −3 app/models/skill.js
  2. +17 −14 game/components/cooldown.js
  3. +9 −10 game/components/skill.js
  4. +5 −5 game/scenes/level.js
View
@@ -1,10 +1,23 @@
define([
- 'backbone'
-], function(Backbone) {
+ 'backbone',
+ 'crafty'
+], function(Backbone, Crafty) {
var Skill = Backbone.Model.extend({
defaults: {},
- initialize: function() {}
+ addEntity: function() {
+
+ return Crafty.e("Skill").skill({
+ cooldown: 0.5
+ }).bind("SkillTriggered", function() {
+ console.log("skill triggered")
+ //AttackEntity.create(player);
+ });
+
+ },
+ fire: function() {
+
+ }
});
return Skill;
@@ -6,38 +6,41 @@ define([
Crafty.c("Cooldown", {
init: function() {
- var cooldown = {
+ var options = {
value: 1,
start: 0,
ready: true,
initialized: false
};
- this.initCooldown = function(value) {
- cooldown.value = value;
- cooldown.initialized = true;
+ this.cooldown = function(value) {
+ _.extend(options, {
+ value: value,
+ initialized: true
+ });
+
this.bind("EnterFrame", function() {
- if(!cooldown.ready) {
+ if(!options.ready) {
var now = new Date().getTime();
- var finishAt = cooldown.start+(cooldown.value*1000);
+ var finishAt = options.start+(options.value*1000);
if(finishAt > now) {
- this.trigger("CooldownOn", now, finishAt, cooldown);
+ this.trigger("CooldownOn", now, finishAt, options);
} else {
- cooldown.ready = true;
- this.trigger("CooldownEnded", now, finishAt, cooldown);
+ options.ready = true;
+ this.trigger("CooldownEnded", now, finishAt, options);
}
}
});
};
this.startCooldown = function() {
- if(cooldown.initialized && cooldown.ready) {
- cooldown.start = new Date().getTime();
- cooldown.ready = false;
- this.trigger("CooldownStarted", cooldown);
+ if(options.initialized && options.ready) {
+ options.start = new Date().getTime();
+ options.ready = false;
+ this.trigger("CooldownStarted", options);
return true;
} else {
- this.trigger("CooldownNotReady", cooldown);
+ this.trigger("CooldownNotReady", options);
return false;
}
};
@@ -11,27 +11,26 @@ define([
key: "A",
cooldown: 1
};
-
- this.initSkill = function(_options) {
- _.extend(options, _options);
- this.initCooldown(options.cooldown);
+
+ this.skill = function(custom) {
+ _.extend(options, custom);
+ this.cooldown(options.cooldown);
};
this.bind("CooldownEnded", function() {
-
+ this.trigger("SkillReady");
});
this.bind("CooldownOn", function() {
-
+ this.trigger("SkillLocked");
});
this.bind("CooldownStarted", function(cooldown) {
this.trigger("SkillTriggered");
});
- this.bind("KeyDown", function() {
- if(this.isDown(options.key)) {
- this.startCooldown();
- }
+
+ this.bind("SkillCastingAttempt", function() {
+ this.startCooldown();
});
}
View
@@ -40,16 +40,16 @@ define([
//var monster = MonsterEntity.create("Octocat", 3);
Crafty.e("Wires");
- $("body").on("click", "#wrapper", function() {
- AttackEntity.create(player);
- });
-
var attackSkill = Crafty.e("Skill");
- attackSkill.initSkill({ key: "D", cooldown: 0.5 });
+ attackSkill.skill({ cooldown: 0.5 });
attackSkill.bind("SkillTriggered", function() {
AttackEntity.create(player);
});
+ $("body").on("click", "#wrapper", function() {
+ attackSkill.trigger("SkillCastingAttempt");
+ });
+
},
uninit: function() {
$("body").off("click", "#wrapper")

0 comments on commit 9db310e

Please sign in to comment.