Permalink
Browse files

Wave component created

  • Loading branch information...
1 parent bf77f7c commit c1e4af91628f4b76d91523981b8730c72e902dfe @hugeen committed Nov 20, 2012
Showing with 58 additions and 10 deletions.
  1. +2 −1 game/components.js
  2. +45 −0 game/components/wave.js
  3. +6 −6 game/levels.js
  4. +5 −3 game/scenes/level.js
View
@@ -19,7 +19,8 @@ define([
'game/components/player_move',
'game/components/skill',
'game/components/skills/attack',
- 'game/components/state'
+ 'game/components/state',
+ 'game/components/wave'
],function() {
return true;
View
@@ -0,0 +1,45 @@
+define([
+ 'underscore',
+ 'crafty',
+ 'game/utils',
+ 'game/entities/monster'
+], function(_, Crafty, utils, Monster) {
+
+ Crafty.c("Wave", {
+ init: function() {
+
+ this.addComponent("Delay");
+
+ this.start = function(waveLines, speed) {
+ _.extend(this, {
+ waveLines: waveLines,
+ steps: waveLines[1].length,
+ step: 0,
+ speed: speed || 1
+ });
+ this.next();
+ };
+
+ this.next = function() {
+
+ _.each(this.waveLines, function(line, lineNumber) {
+ var monsterCode = line[this.step];
+ if(monsterCode !== "*") {
+ Monster.create("Octocat", lineNumber);
+ }
+ }, this);
+
+ this.step++;
+
+ if(this.step < this.steps) {
+ this.delay(function() {
+ this.next();
+ }, 1000/this.speed);
+ }
+
+ };
+
+ }
+ });
+
+});
View
@@ -4,12 +4,12 @@ define(function() {
id: 1,
speed: 1,
waves: [{
- "1": "**********p*************************************************",
- "2": "******p*****************************************************",
- "3": "*p**********************************************************",
- "4": "****p*******************************************************",
- "5": "************************************************************",
- "6": "************************************************************"
+ "1": "*****",
+ "2": "*****",
+ "3": "*p***",
+ "4": "***p*",
+ "5": "*****",
+ "6": "*****"
}]
}, {
id: 2
View
@@ -15,9 +15,11 @@ define([
return {
name: "level",
- init: function(options) {
-
+ init: function(options) {
var waves = options.level.get("waves");
+ Crafty.e("Wave").start(waves[0]);
+ /*
+
function Wave(wave) {
var timer = false
var stepsCount = wave[1].length;
@@ -43,7 +45,7 @@ define([
}
var wave = new Wave(waves[0]);
wave.start();
-
+ */
$("#wrapper").append(_.template(_skills));
var player = PlayerEntity.create();

0 comments on commit c1e4af9

Please sign in to comment.