entityjs 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. data/README.md +18 -14
  2. data/entityjs.gemspec +1 -0
  3. data/lib/entityjs/assets.rb +13 -163
  4. data/lib/entityjs/command.rb +5 -2
  5. data/lib/entityjs/commands/build.rb +63 -23
  6. data/lib/entityjs/commands/eunit.rb +44 -0
  7. data/lib/entityjs/commands/release.rb +1 -1
  8. data/lib/entityjs/commands/server.rb +19 -4
  9. data/lib/entityjs/compile.rb +152 -0
  10. data/lib/entityjs/config.rb +8 -0
  11. data/lib/entityjs/dirc.rb +70 -17
  12. data/lib/entityjs/page.rb +106 -0
  13. data/lib/entityjs/parsers/parse_coffee.rb +12 -0
  14. data/lib/entityjs/version.rb +1 -1
  15. data/lib/entityjs.rb +18 -4
  16. data/public/qunit/qunit.css +9 -3
  17. data/public/qunit/qunit.entity.js +113 -31
  18. data/public/qunit/qunit.js +296 -235
  19. data/public/qunit/qunit.mock.js +54 -2
  20. data/public/tests.html +0 -15
  21. data/spec/javascripts/src/cycle/tween_spec.js +59 -0
  22. data/spec/javascripts/src/display/screen_spec.js +0 -15
  23. data/spec/javascripts/src/display/text_spec.js +4 -0
  24. data/spec/javascripts/src/input/mouse_spec.js +18 -18
  25. data/spec/javascripts/src/input/preventdefault_spec.js +14 -0
  26. data/spec/javascripts/src/math/drag_spec.js +2 -2
  27. data/spec/javascripts/src/math/hit_spec.js +24 -0
  28. data/spec/javascripts/src/math/point_spec.js +3 -3
  29. data/spec/javascripts/src/math/tile_spec.js +1 -1
  30. data/spec/javascripts/src/media/sound_spec.js +1 -1
  31. data/spec/javascripts/src/pattern/automap_spec.js +3 -3
  32. data/spec/javascripts/src/pattern/flicker_spec.js +2 -1
  33. data/spec/javascripts/src/util/random_spec.js +17 -0
  34. data/spec/javascripts/src/util/scene_spec.js +15 -0
  35. data/spec/lib/entityjs/assets_spec.rb +2 -201
  36. data/spec/lib/entityjs/commands/build_spec.rb +18 -5
  37. data/spec/lib/entityjs/commands/eunit_spec.rb +18 -0
  38. data/spec/lib/entityjs/commands/release_spec.rb +2 -0
  39. data/spec/lib/entityjs/compile_spec.rb +204 -0
  40. data/spec/lib/entityjs/dirc_spec.rb +8 -4
  41. data/spec/lib/entityjs/page_spec.rb +59 -0
  42. data/spec/support/factories.rb +0 -2
  43. data/src/core/entity.js +4 -18
  44. data/src/core/query.js +1 -1
  45. data/src/core/re.js +6 -6
  46. data/src/core/system.js +17 -12
  47. data/src/cycle/tween.js +93 -31
  48. data/src/display/align.js +11 -6
  49. data/src/display/circle.js +5 -4
  50. data/src/display/imgtext.js +33 -22
  51. data/src/display/screen.js +0 -8
  52. data/src/display/text.js +37 -4
  53. data/src/input/keyboard.js +15 -5
  54. data/src/input/mouse.js +15 -25
  55. data/src/input/preventdefault.js +11 -0
  56. data/src/math/body.js +35 -16
  57. data/src/math/drag.js +2 -2
  58. data/src/math/force.js +2 -2
  59. data/src/math/hit.js +15 -6
  60. data/src/math/hitmap.js +6 -6
  61. data/src/math/point.js +1 -1
  62. data/src/math/tile.js +22 -17
  63. data/src/media/sound.js +1 -1
  64. data/src/pattern/automap.js +16 -27
  65. data/src/pattern/flicker.js +9 -5
  66. data/src/util/random.js +4 -0
  67. data/src/util/scene.js +2 -6
  68. data/templates/arrow_keys/scripts/{display → displays}/arrow.js +0 -0
  69. data/templates/arrow_keys/scripts/{input → inputs}/controls.js +0 -0
  70. data/templates/arrow_keys/tests/{display → displays}/arrow_test.js +1 -1
  71. data/templates/arrow_keys/tests/{input → inputs}/controls_test.js +0 -0
  72. data/templates/arrow_keys/tests/scenes/load_test.js +2 -0
  73. data/templates/{blank → circle}/config.yml +0 -0
  74. data/templates/{blank → circle}/readme.txt +0 -0
  75. data/templates/circle/scripts/init.js +7 -0
  76. data/templates/circle/scripts/scenes/home.js +62 -0
  77. data/templates/circle/scripts/scenes/load.js +11 -0
  78. data/templates/circle/tests/scenes/home_test.js +29 -0
  79. data/templates/circle/tests/scenes/load_test.js +15 -0
  80. data/templates/platform/config.yml +2 -1
  81. data/templates/platform/readme.txt +15 -16
  82. data/templates/platform/scripts/{display → displays}/bit.js +0 -0
  83. data/templates/platform/scripts/{display → displays}/hero.js +0 -0
  84. data/templates/platform/scripts/{display → displays}/tile.js +0 -0
  85. data/templates/platform/scripts/{display → displays}/tsprite.js +0 -0
  86. data/templates/platform/{assets → scripts}/levels/level1.tmx +0 -0
  87. data/templates/platform/scripts/{util → utils}/counter.js +0 -0
  88. data/templates/platform/scripts/{util → utils}/level.js +0 -0
  89. data/templates/platform/tests/{display → displays}/bit_test.js +1 -1
  90. data/templates/platform/tests/displays/hero_test.js +73 -0
  91. data/templates/platform/tests/{display → displays}/tile_test.js +1 -1
  92. data/templates/platform/tests/displays/tsprite_test.js +8 -0
  93. data/templates/platform/tests/items/coin_test.js +10 -10
  94. data/templates/platform/tests/items/item_test.js +9 -9
  95. data/templates/platform/tests/items/spring_test.js +3 -3
  96. data/templates/platform/tests/scenes/load_test.js +2 -1
  97. data/templates/platform/tests/{util → utils}/counter_test.js +2 -2
  98. data/templates/platform/tests/{util → utils}/level_test.js +3 -0
  99. data/templates/pong/config.yml +22 -0
  100. data/templates/pong/readme.txt +3 -0
  101. data/templates/pong/scripts/controls/ai.js +30 -0
  102. data/templates/pong/scripts/controls/arena.js +33 -0
  103. data/templates/pong/scripts/controls/hitmap.js +54 -0
  104. data/templates/pong/scripts/controls/player.js +24 -0
  105. data/templates/pong/scripts/controls/twoarena.js +14 -0
  106. data/templates/pong/scripts/displays/ball.js +29 -0
  107. data/templates/pong/scripts/displays/counter.js +22 -0
  108. data/templates/pong/scripts/displays/paddle.js +22 -0
  109. data/templates/pong/scripts/init.js +9 -0
  110. data/templates/pong/scripts/scenes/game.js +61 -0
  111. data/templates/pong/scripts/scenes/home.js +55 -0
  112. data/templates/pong/scripts/scenes/over.js +29 -0
  113. data/templates/pong/tests/controls/ai_test.js +34 -0
  114. data/templates/pong/tests/controls/arena_test.js +20 -0
  115. data/templates/pong/tests/controls/hitmap_test.js +89 -0
  116. data/templates/pong/tests/controls/player_test.js +25 -0
  117. data/templates/pong/tests/controls/twoarena_test.js +7 -0
  118. data/templates/pong/tests/displays/ball_test.js +10 -0
  119. data/templates/pong/tests/displays/counter_test.js +13 -0
  120. data/templates/pong/tests/displays/paddle_test.js +17 -0
  121. data/templates/pong/tests/scenes/game_test.js +16 -0
  122. data/templates/pong/tests/scenes/home_test.js +30 -0
  123. data/templates/pong/tests/scenes/over_test.js +16 -0
  124. data/templates/tiltmaze/config.yml +25 -0
  125. data/templates/tiltmaze/readme.txt +79 -0
  126. data/templates/tiltmaze/scripts/displays/ball.js +78 -0
  127. data/templates/tiltmaze/scripts/displays/target.js +13 -0
  128. data/templates/tiltmaze/scripts/displays/tile.js +2 -0
  129. data/templates/tiltmaze/scripts/init.js +7 -0
  130. data/templates/tiltmaze/scripts/levels/level1.json +14 -0
  131. data/templates/tiltmaze/scripts/levels/level2.json +14 -0
  132. data/templates/tiltmaze/scripts/levels/level3.json +14 -0
  133. data/templates/tiltmaze/scripts/levels/level4.json +15 -0
  134. data/templates/tiltmaze/scripts/levels/level5.json +18 -0
  135. data/templates/tiltmaze/scripts/scenes/game.js +56 -0
  136. data/templates/tiltmaze/scripts/scenes/home.js +24 -0
  137. data/templates/tiltmaze/scripts/structs/level.js +82 -0
  138. data/templates/tiltmaze/scripts/tiles/walltile.js +147 -0
  139. data/templates/tiltmaze/tests/displays/ball_test.js +67 -0
  140. data/templates/tiltmaze/tests/displays/target_test.js +8 -0
  141. data/templates/tiltmaze/tests/factories.js +38 -0
  142. data/templates/tiltmaze/tests/scenes/game_test.js +59 -0
  143. data/templates/tiltmaze/tests/scenes/home_test.js +7 -0
  144. data/templates/tiltmaze/tests/structs/level_test.js +44 -0
  145. data/templates/tiltmaze/tests/tiles/walltile_test.js +36 -0
  146. metadata +106 -33
  147. data/templates/platform/tests/display/hero_test.js +0 -73
  148. data/templates/platform/tests/display/tsprite_test.js +0 -8
data/src/math/drag.js CHANGED
@@ -24,9 +24,9 @@ re.c('drag')
24
24
  return this;
25
25
  },
26
26
 
27
- dragEnd:function(){
27
+ dragFinish:function(){
28
28
  this.dragging = false;
29
- return this.trigger('drag:end');
29
+ return this.trigger('drag:finish');
30
30
  },
31
31
 
32
32
  dragUpdate:function(x, y){
data/src/math/force.js CHANGED
@@ -85,11 +85,11 @@ re.force = re.c('force')
85
85
  this.posY = posy;
86
86
 
87
87
  if(hitx){
88
- this.velX = this.forceRes(this.velX, this.resX);
88
+ this.velX = this.forceRes(this.velX, this.resX);
89
89
  }
90
90
 
91
91
  if(hity){
92
- this.velY = this.forceRes(this.velY, this.resY);
92
+ this.velY = this.forceRes(this.velY, this.resY);
93
93
  }
94
94
 
95
95
  return this.trigger('aftermath', hitx, hity, tarx, tary);
data/src/math/hit.js CHANGED
@@ -11,21 +11,30 @@ re.c('hit')
11
11
  checks if the two targets intersect with each other.
12
12
 
13
13
  k.hit(x, y, width, height);
14
-
14
+ k.hit(entity);
15
+
15
16
  */
16
- hit:function(x, y, w, h){
17
+ hit:function(x, y, w, h, rx, ry){
17
18
  if(re.is(x, 'object')){
18
19
  y = x.posY || x.y;
19
20
  w = x.sizeX || x.w;
20
21
  h = x.sizeY || x.h;
22
+ rx = x.regX || 0;
23
+ ry = x.regY || 0;
21
24
  x = x.posX || x.x;
22
25
  }
26
+
27
+ rx = rx || 0;
28
+ ry = ry || 0;
29
+ var regX = this.regX || 0;
30
+ var regY = this.regY || 0;
31
+
23
32
  return !
24
33
  (
25
- x > this.posX + this.sizeX ||
26
- x + w < this.posX ||
27
- y > this.posY + this.sizeY ||
28
- y + h < this.posY
34
+ x - rx > this.posX + this.sizeX - regX ||
35
+ x + w - rx < this.posX - regX ||
36
+ y - ry > this.posY + this.sizeY - regY ||
37
+ y + h - ry < this.posY - regY
29
38
  );
30
39
  }
31
40
 
data/src/math/hitmap.js CHANGED
@@ -108,11 +108,11 @@ re.c('hitmap')
108
108
 
109
109
  for(ty = firsty; ty<lasty; ty++){
110
110
 
111
- if(this.map[ty]){
111
+ if(this._automap[ty]){
112
112
 
113
- this.trigger('hit', this.map[ty][tx], tx, ty);
113
+ this.trigger('hit', this._automap[ty][tx], tx, ty);
114
114
 
115
- if(this.checkAxisX(this.map[ty][tx], x, y, vx, vy)) {
115
+ if(this.checkAxisX(this._automap[ty][tx], x, y, vx, vy)) {
116
116
  res.hitX = true;
117
117
  res.posX = tx * t + offx - offsetx;
118
118
  res.tarX = tx * t;
@@ -142,11 +142,11 @@ re.c('hitmap')
142
142
 
143
143
  for(tx = firstx; tx<lastx; tx++) {
144
144
 
145
- if(this.map[ty]){
145
+ if(this._automap[ty]){
146
146
 
147
- this.trigger('hit', this.map[ty][tx], tx, ty);
147
+ this.trigger('hit', this._automap[ty][tx], tx, ty);
148
148
 
149
- if(this.checkAxisY(this.map[ty][tx], x, y, vx, vy)) {
149
+ if(this.checkAxisY(this._automap[ty][tx], x, y, vx, vy)) {
150
150
  res.hitY = true;
151
151
  res.posY = ty * t + offy - offsety;
152
152
  res.tarX = tx * t;
data/src/math/point.js CHANGED
@@ -25,7 +25,7 @@ re.c('point')
25
25
  return this;
26
26
  },
27
27
 
28
- distanceTo:function(x, y){
28
+ distance:function(x, y){
29
29
  if(re.is(x,'object')){
30
30
  y = x.posY || x.y;
31
31
  x = x.posX || x.x;
data/src/math/tile.js CHANGED
@@ -37,7 +37,7 @@ re.e('tile sprite tiles.png', map.length * map[0].length)
37
37
  });
38
38
 
39
39
  @warning moving to negative tiles will cause rounding issues.
40
- Its recommended you avoid negative maps
40
+ Its recommended you avoid negative tile values
41
41
 
42
42
  */
43
43
  re.tile = re.c('tile')
@@ -74,18 +74,17 @@ re.tile = re.c('tile')
74
74
 
75
75
  })
76
76
  .init(function(){
77
- this.def({
78
- sizeX:re.tile.sizeX,
79
- sizeY:re.tile.sizeY
80
- });
77
+ this.sizeX = re.tile.sizeX;
78
+ this.sizeY = re.tile.sizeY;
81
79
 
82
80
  })
83
81
  .defines({
84
82
 
85
83
  tile:function(x, y){
86
84
  if(re.is(x,'object')){
87
- y = x.posY || x.y;
88
- x = x.posX || x.x;
85
+ //will mess up if regX is not top right corner
86
+ y = x.y || re.tile.toTileY(x.posY);
87
+ x = x.x || re.tile.toTileX(x.posX);
89
88
  }
90
89
  this.tileX(x);
91
90
  this.tileY(y);
@@ -93,19 +92,25 @@ re.tile = re.c('tile')
93
92
  },
94
93
 
95
94
  tileX:function(v){
96
- if(re.is(v)){
97
- this.posX = v * this.sizeX;
98
- return this;
99
- }
100
- return re.tile.toTileX(this.posX, this.sizeX);
95
+ var s = this.sizeX || re.tile.sizeX;
96
+ var r = this.regX || 0;
97
+ if(re.is(v)){
98
+ this.posX = (v - r) * s;
99
+ return this;
100
+ }
101
+
102
+ return (this.posX - r) / s + 0.5 | 0;
101
103
  },
102
104
 
103
105
  tileY:function(v){
104
- if(re.is(v)){
105
- this.posY = v * this.sizeY;
106
- return this;
107
- }
108
- return re.tile.toTileY(this.posY, this.sizeY);
106
+ var s = this.sizeX || re.tile.sizeY;
107
+ var r = this.regY || 0;
108
+ if(re.is(v)){
109
+ this.posY = (v - r)* s;
110
+ return this;
111
+ }
112
+
113
+ return (this.posY - r) / s + 0.5 | 0;
109
114
  }
110
115
 
111
116
  });
data/src/media/sound.js CHANGED
@@ -56,7 +56,7 @@ re.sound = re.c('sound')
56
56
 
57
57
  ended:function(){
58
58
 
59
- this.trigger('sound:end');
59
+ this.trigger('sound:finish');
60
60
 
61
61
  }
62
62
 
@@ -36,10 +36,10 @@ map.lenY
36
36
  re.c('automap')
37
37
  .defaults({
38
38
  lenX:0,
39
- lenY:0
39
+ lenY:0,
40
+ automapDefault:0
40
41
  })
41
42
  .defines({
42
- value:0,
43
43
 
44
44
  automap:function(x, y, value){
45
45
  if(re.is(x, 'array')){
@@ -47,7 +47,7 @@ re.c('automap')
47
47
  if(y){
48
48
  //non-deep copy
49
49
 
50
- this.map = x;
50
+ this._automap = x;
51
51
 
52
52
  if(x.length > 0){
53
53
  this.lenX = x[0].length;
@@ -72,38 +72,38 @@ re.c('automap')
72
72
 
73
73
  if(!re.is(value)){
74
74
  if(this.within(x,y)){
75
- return this.map[y][x];
75
+ return this._automap[y][x];
76
76
  }
77
77
  return null;
78
78
  }
79
79
 
80
80
  //increate y length
81
- while(y >= this.map.length){
82
- var m = new Array(this.map[0]);
81
+ while(y >= this._automap.length){
82
+ var m = new Array(this._automap[0]);
83
83
 
84
84
  for(var l in m){
85
- m[l] = this.value;
85
+ m[l] = this.automapDefault;
86
86
  }
87
87
 
88
- this.map.push(m);
88
+ this._automap.push(m);
89
89
 
90
90
  }
91
91
 
92
92
  //increase x length
93
- while(x >= this.map[this.map.length-1].length){
93
+ while(x >= this._automap[this._automap.length-1].length){
94
94
 
95
- for(var k=0; k<this.map.length; k++){
96
- if(this.map[k].length <= x){
97
- this.map[k].push(this.value);
95
+ for(var k=0; k<this._automap.length; k++){
96
+ if(this._automap[k].length <= x){
97
+ this._automap[k].push(this.automapDefault);
98
98
  }
99
99
  }
100
100
 
101
101
  }
102
102
 
103
- this.lenX = this.map[y].length;
104
- this.lenY = this.map.length;
103
+ this.lenX = this._automap[y].length;
104
+ this.lenY = this._automap.length;
105
105
 
106
- this.map[y][x] = value;
106
+ this._automap[y][x] = value;
107
107
 
108
108
  return this;
109
109
  },
@@ -114,20 +114,9 @@ re.c('automap')
114
114
  return false;
115
115
  }
116
116
  return true;
117
- },
118
-
119
- copy:function(a){
120
-
121
- return this;
122
- },
123
-
124
- copyByRef:function(m){
125
-
126
-
127
- return this;
128
117
  }
129
118
 
130
119
  })
131
120
  .init(function(){
132
- this.map = [];
121
+ this._automap = [];
133
122
  });
@@ -27,7 +27,7 @@ re.c('flicker')
27
27
 
28
28
  this.off('update', this.flicker_update);
29
29
 
30
- return this.trigger('flicker:end', o);
30
+ return this.trigger('flicker:finish', o);
31
31
  },
32
32
 
33
33
  flicker_update:function(t){
@@ -69,7 +69,6 @@ re.c('flicker')
69
69
  if(re.is(id, 'object')){
70
70
 
71
71
  for(var i in id){
72
- if(!id.hasOwnProperty(i)) continue;
73
72
 
74
73
  //copy formed array and insert
75
74
  var c = id[i].slice();
@@ -101,7 +100,6 @@ re.c('flicker')
101
100
  if(re.is(id,'object')){
102
101
 
103
102
  for(var i in id){
104
- if(!id.hasOwnProperty(i)) continue;
105
103
 
106
104
  this.removeFlicker.call(this, id[i]);
107
105
  }
@@ -166,14 +164,20 @@ re.c('flicker')
166
164
  //copy from saved animation or newly given
167
165
  c.loops = (isNaN(loops))? r.loops : loops;
168
166
  c.duration = (isNaN(duration))? r.duration : duration;
167
+
168
+ //convert to seconds
169
+ if(c.duration >= 30){
170
+ c.duration /= 1000;
171
+ }
172
+
169
173
  c.frames = (re.is(frames,'object'))? frames : r.frames;
170
174
 
171
175
  //setup counter for loops
172
176
  this.flicker_loops = c.loops;
173
177
 
174
178
  this.stepProgress = 0;
175
- this.stepSize = c.duration / c.frames.length / 1000;
176
-
179
+ this.stepSize = c.duration / c.frames.length;
180
+
177
181
  //save old frames for upon completion
178
182
 
179
183
  this.flicker_frame = 0;
data/src/util/random.js CHANGED
@@ -5,9 +5,13 @@ The random component implements two helper methods for calculating random number
5
5
  re.random() // 0 - 1
6
6
  re.random(10) // 0 - 9
7
7
  re.random(10, 30) // 10 - 30
8
+ re.random([1, 10, 40]) // 1 or 10 or 40
8
9
 
9
10
  */
10
11
  re.random = function(max, min){
12
+ if(re.is(max, 'array')){
13
+ return max[Math.random() * max.length | 0];
14
+ }
11
15
  var r = Math.random();
12
16
  switch(arguments.length){
13
17
  case 0:
data/src/util/scene.js CHANGED
@@ -65,14 +65,14 @@ re.c('scene')
65
65
  if(!re.is(title, 'function')){
66
66
 
67
67
  if(re.scene.current)
68
- re.scene().exit(title);
68
+ re.scene().exit();
69
69
 
70
70
  //set current scene
71
71
  re.scene.current = this.sceneName
72
72
 
73
73
  if(this.scene_enter)
74
74
  this.scene_enter.apply(this, arguments);
75
- return this;
75
+
76
76
  } else {
77
77
  //set new enter method
78
78
  this.scene_enter = title;
@@ -86,10 +86,6 @@ re.c('scene')
86
86
 
87
87
  re.scene.current = '';
88
88
 
89
- if(re.is(this.scene_exit, 'function')){
90
- this.scene_exit.apply(this, arguments);
91
- }
92
-
93
89
  if(this.scene_exit)
94
90
  this.scene_exit.apply(this, arguments);
95
91
  } else {
@@ -14,7 +14,7 @@ test('keys move arrow', function(){
14
14
 
15
15
  //mock/stub methods in qunit/qunit.mock.js
16
16
  //expects 4 calls to frame
17
- expectCall(arrow, 'frame', 4);
17
+ expectCall(arrow, 'frame', null, 4);
18
18
 
19
19
  //simulate keypress / mouse clicks with qunit/qunit.input.js
20
20
  //dispatches a keydown on each key, calls the given method
@@ -13,4 +13,6 @@ test('load assets', function(){
13
13
  //the home scene should then call start()
14
14
  stop();
15
15
 
16
+ expect(0);
17
+
16
18
  });
File without changes
File without changes
@@ -0,0 +1,7 @@
1
+ re.ready(function(){
2
+
3
+ re.sys.init(re.canvas).start();
4
+
5
+ re.scene('load').enter();
6
+
7
+ });
@@ -0,0 +1,62 @@
1
+ re.scene('home')
2
+ .enter(function(){
3
+
4
+ //stop the browser from moving around
5
+ re.preventDefault('left right up down');
6
+
7
+ //create new circle on canvas
8
+ re.e('circle align update')
9
+ .attr({
10
+ radius:10,
11
+ speed:15,
12
+ color:'#ff0000'
13
+ })
14
+ //from align component
15
+ .alignHor()
16
+ .alignVer()
17
+ .on('update', function(){
18
+
19
+ //move on keypressed
20
+ if(re.pressed('a', 'left')) this.posX -= this.speed;
21
+ if(re.pressed('d', 'right')) this.posX += this.speed;
22
+
23
+ if(re.pressed('w', 'up')) this.posY -= this.speed;
24
+ if(re.pressed('s', 'down')) this.posY += this.speed;
25
+
26
+ });
27
+
28
+ //add help text
29
+ re.e('text align')
30
+ .text('Use WASD or arrow keys to move the circle')
31
+ .alignTop(5)
32
+ .alignLeft(5);
33
+
34
+ //stop the browser from moving around
35
+ re.preventDefault('left right up down');
36
+
37
+ //create new circle on canvas
38
+ re.e('circle align update')
39
+ .attr({
40
+ radius:10,
41
+ speed:15,
42
+ color:'#ff0000'
43
+ })
44
+ //from align component
45
+ .align()
46
+ .on('update', function(){
47
+
48
+ //move on keypressed
49
+ if(re.pressed('a', 'left')) this.posX -= this.speed;
50
+ if(re.pressed('d', 'right')) this.posX += this.speed;
51
+
52
+ if(re.pressed('w', 'up')) this.posY -= this.speed;
53
+ if(re.pressed('s', 'down')) this.posY += this.speed;
54
+
55
+ });
56
+
57
+ //add help text
58
+ re.e('text align')
59
+ .text('Use WASD or arrow keys to move the circle')
60
+ .alignTop(5)
61
+ .alignLeft(5);
62
+ });
@@ -0,0 +1,11 @@
1
+ re.scene('load')
2
+ .enter(function(){
3
+
4
+ re.load(re.assets)
5
+ .complete(function(){
6
+
7
+ re.scene('home').enter();
8
+
9
+ });
10
+
11
+ });
@@ -0,0 +1,29 @@
1
+ module('scenes/home', {
2
+ setup:function(){
3
+ re.scene('home').enter();
4
+ }
5
+ });
6
+
7
+ test('entities should exist', function(){
8
+
9
+ var circle = re('circle')[0];
10
+
11
+ is(circle);
12
+
13
+ //has update listener
14
+ expectEvent(circle, 'update');
15
+
16
+ var xBefore = circle.posX;
17
+
18
+ //moves upon keypress
19
+ keypress('a', function(){
20
+ //key is currently down, so call update method
21
+ circle.trigger('update');
22
+ });
23
+
24
+ //check if the circle moved
25
+ ok(xBefore != circle.posX);
26
+
27
+ //text exists
28
+ is(re('text')[0]);
29
+ });
@@ -0,0 +1,15 @@
1
+ module('scenes/load');
2
+
3
+ test('load stuff', function(){
4
+
5
+ stop();
6
+
7
+ stub(re.scene('home'), 'enter', function(){
8
+ start();
9
+ });
10
+
11
+ re.scene('load').enter();
12
+
13
+
14
+ expect(0);
15
+ });
@@ -9,6 +9,7 @@ scripts-ignore:
9
9
 
10
10
  #specify files to be loaded first in /scripts
11
11
  order:
12
+ .*\.js
12
13
 
13
14
  #components to ignore in the entityjs source
14
15
  #reduce file size by ignoring unused components
@@ -19,4 +20,4 @@ entity-ignore:
19
20
 
20
21
  #ignore tests in /tests
21
22
  tests-ignore:
22
-
23
+
@@ -9,34 +9,33 @@ Contains all sounds, images and data files. Place all sounds in the sounds direc
9
9
  and all the images in the images directory. These directories will be looked at
10
10
  and an asset array will be created for easy asset loading (see scripts/scenes/load.js)
11
11
 
12
- Creating any other directory or placing files in the levels directory will be seen
13
- as data files and will be read and automatically put in js files.
12
+ ## /builds
14
13
 
15
- For example, if I have a directory like /assets/animations/monster.json.
14
+ Contains assets and minified code for the game.
16
15
 
17
- The file will automatically be read upon calling 'entityjs refresh' and will be turned into this:
16
+ ## /scripts
18
17
 
19
- re.e('monster.json animation')
20
- .attr(**Animation JSON here**);
18
+ Contains javascripts and coffeescripts for the game.
21
19
 
22
- Which means you can edit files in different programs and not worry about copying and pasting
23
- the contents. Just run entityjs refresh.
24
20
 
25
- At the moment only JSON is supported but in the future, XML, YAML, CSV and TMX will be supported.
26
- TMX is a special XML format for a tile map editor.
21
+ Data files such as xml, json or tmx will be read and automatically compiled into js files.
27
22
 
28
- ## /builds
23
+ For example, if I have a directory like /scripts/animations/monster.json.
29
24
 
30
- Contains assets and minified code for the game.
25
+ The file will be turned into this:
31
26
 
32
- ## /scripts
27
+ re.e('monster.json animation')
28
+ .attr(**Animation JSON here**);
33
29
 
34
- Contains javascripts for the game.
30
+ Which means you can edit files in different programs and not worry about copying and pasting
31
+ the contents.
32
+
33
+ TMX is a special XML format for a tile map editor.
35
34
 
36
35
  ## /tests
37
36
 
38
37
  Contains tests for the game. It is good practice to keep this structured exactly the same as the scripts
39
- directory.
38
+ directory. Tests can also be in coffeescript.
40
39
 
41
40
  ## /tmp
42
41
 
@@ -84,4 +83,4 @@ entityjs refresh
84
83
  or
85
84
  entityjs r
86
85
 
87
- Creates a file called game.debug.js inside /tmp
86
+ Creates a file called game.debug.js inside /tmp
File without changes
@@ -2,6 +2,6 @@ module('bit', lazy('bit'));
2
2
 
3
3
  test('valid', function(){
4
4
 
5
- ok(e.has('bit.png align'));
5
+ ok(bit.has('bit.png align'));
6
6
 
7
7
  });