Permalink
Browse files

Skills logic refactored

  • Loading branch information...
1 parent 9db310e commit f9d1a73541e3b1be74b1fe20fd62114e0601eef7 @hugeen committed Nov 18, 2012
Showing with 21 additions and 24 deletions.
  1. +3 −15 game/components/skills/attack.js
  2. +7 −4 game/entities/player.js
  3. +11 −5 game/scenes/level.js
@@ -1,26 +1,14 @@
define([
- 'underscore',
- 'crafty',
- 'game/mouse'
-], function(_, Crafty, mouse) {
+ 'crafty'
+], function(Crafty) {
Crafty.c("Attack", {
init : function() {
this.addComponent("Bullet, axe, Collision");
this.speed = 15;
- this.attack = function(player) {
-
- var from = {
- x: player.x,
- y: player.y
- }
-
- var to = {
- x: mouse.position.relative.x,
- y: mouse.position.relative.y
- }
+ this.attack = function(from, to) {
this.origin("center");
@@ -2,12 +2,15 @@ define([
'underscore',
'crafty'
], function(_, Crafty) {
-
+
+ var player;
+
return {
create: function() {
-
- var player = Crafty.e("PlayableCharacter, PlayerMove, Wolf")
-
+ player = Crafty.e("PlayableCharacter, PlayerMove, Wolf");
+ return player;
+ },
+ get: function() {
return player;
}
};
View
@@ -9,8 +9,8 @@ define([
'collections/skills',
'text!templates/game_ui/skills.html',
'text!templates/game_ui/skill.html',
- 'mouseTrap'
-], function($, Crafty, Burst, PlayerEntity, MonsterEntity, AttackEntity, keyboard, skills, _skills, _skill, Mousetrap) {
+ 'game/mouse'
+], function($, Crafty, Burst, PlayerEntity, MonsterEntity, AttackEntity, keyboard, skills, _skills, _skill, mouse) {
return {
name: "level",
@@ -21,9 +21,9 @@ define([
skills.each(function(skill) {
var keybind = keyboard.keybinds.AZERTY[skill.get("name")]
- Mousetrap.bind(keybind, function() {
+ /*Mousetrap.bind(keybind, function() {
console.log(skill.get("name"));
- });
+ });*/
var compiledTemplate = _.template(_skill, {
key: keybind,
@@ -43,7 +43,13 @@ define([
var attackSkill = Crafty.e("Skill");
attackSkill.skill({ cooldown: 0.5 });
attackSkill.bind("SkillTriggered", function() {
- AttackEntity.create(player);
+ Crafty.e("Attack").attack({
+ x: player.x,
+ y: player.y
+ }, {
+ x: mouse.position.relative.x,
+ y: mouse.position.relative.y
+ });
});
$("body").on("click", "#wrapper", function() {

0 comments on commit f9d1a73

Please sign in to comment.