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.
- data/README.md +18 -14
- data/entityjs.gemspec +1 -0
- data/lib/entityjs/assets.rb +13 -163
- data/lib/entityjs/command.rb +5 -2
- data/lib/entityjs/commands/build.rb +63 -23
- data/lib/entityjs/commands/eunit.rb +44 -0
- data/lib/entityjs/commands/release.rb +1 -1
- data/lib/entityjs/commands/server.rb +19 -4
- data/lib/entityjs/compile.rb +152 -0
- data/lib/entityjs/config.rb +8 -0
- data/lib/entityjs/dirc.rb +70 -17
- data/lib/entityjs/page.rb +106 -0
- data/lib/entityjs/parsers/parse_coffee.rb +12 -0
- data/lib/entityjs/version.rb +1 -1
- data/lib/entityjs.rb +18 -4
- data/public/qunit/qunit.css +9 -3
- data/public/qunit/qunit.entity.js +113 -31
- data/public/qunit/qunit.js +296 -235
- data/public/qunit/qunit.mock.js +54 -2
- data/public/tests.html +0 -15
- data/spec/javascripts/src/cycle/tween_spec.js +59 -0
- data/spec/javascripts/src/display/screen_spec.js +0 -15
- data/spec/javascripts/src/display/text_spec.js +4 -0
- data/spec/javascripts/src/input/mouse_spec.js +18 -18
- data/spec/javascripts/src/input/preventdefault_spec.js +14 -0
- data/spec/javascripts/src/math/drag_spec.js +2 -2
- data/spec/javascripts/src/math/hit_spec.js +24 -0
- data/spec/javascripts/src/math/point_spec.js +3 -3
- data/spec/javascripts/src/math/tile_spec.js +1 -1
- data/spec/javascripts/src/media/sound_spec.js +1 -1
- data/spec/javascripts/src/pattern/automap_spec.js +3 -3
- data/spec/javascripts/src/pattern/flicker_spec.js +2 -1
- data/spec/javascripts/src/util/random_spec.js +17 -0
- data/spec/javascripts/src/util/scene_spec.js +15 -0
- data/spec/lib/entityjs/assets_spec.rb +2 -201
- data/spec/lib/entityjs/commands/build_spec.rb +18 -5
- data/spec/lib/entityjs/commands/eunit_spec.rb +18 -0
- data/spec/lib/entityjs/commands/release_spec.rb +2 -0
- data/spec/lib/entityjs/compile_spec.rb +204 -0
- data/spec/lib/entityjs/dirc_spec.rb +8 -4
- data/spec/lib/entityjs/page_spec.rb +59 -0
- data/spec/support/factories.rb +0 -2
- data/src/core/entity.js +4 -18
- data/src/core/query.js +1 -1
- data/src/core/re.js +6 -6
- data/src/core/system.js +17 -12
- data/src/cycle/tween.js +93 -31
- data/src/display/align.js +11 -6
- data/src/display/circle.js +5 -4
- data/src/display/imgtext.js +33 -22
- data/src/display/screen.js +0 -8
- data/src/display/text.js +37 -4
- data/src/input/keyboard.js +15 -5
- data/src/input/mouse.js +15 -25
- data/src/input/preventdefault.js +11 -0
- data/src/math/body.js +35 -16
- data/src/math/drag.js +2 -2
- data/src/math/force.js +2 -2
- data/src/math/hit.js +15 -6
- data/src/math/hitmap.js +6 -6
- data/src/math/point.js +1 -1
- data/src/math/tile.js +22 -17
- data/src/media/sound.js +1 -1
- data/src/pattern/automap.js +16 -27
- data/src/pattern/flicker.js +9 -5
- data/src/util/random.js +4 -0
- data/src/util/scene.js +2 -6
- data/templates/arrow_keys/scripts/{display → displays}/arrow.js +0 -0
- data/templates/arrow_keys/scripts/{input → inputs}/controls.js +0 -0
- data/templates/arrow_keys/tests/{display → displays}/arrow_test.js +1 -1
- data/templates/arrow_keys/tests/{input → inputs}/controls_test.js +0 -0
- data/templates/arrow_keys/tests/scenes/load_test.js +2 -0
- data/templates/{blank → circle}/config.yml +0 -0
- data/templates/{blank → circle}/readme.txt +0 -0
- data/templates/circle/scripts/init.js +7 -0
- data/templates/circle/scripts/scenes/home.js +62 -0
- data/templates/circle/scripts/scenes/load.js +11 -0
- data/templates/circle/tests/scenes/home_test.js +29 -0
- data/templates/circle/tests/scenes/load_test.js +15 -0
- data/templates/platform/config.yml +2 -1
- data/templates/platform/readme.txt +15 -16
- data/templates/platform/scripts/{display → displays}/bit.js +0 -0
- data/templates/platform/scripts/{display → displays}/hero.js +0 -0
- data/templates/platform/scripts/{display → displays}/tile.js +0 -0
- data/templates/platform/scripts/{display → displays}/tsprite.js +0 -0
- data/templates/platform/{assets → scripts}/levels/level1.tmx +0 -0
- data/templates/platform/scripts/{util → utils}/counter.js +0 -0
- data/templates/platform/scripts/{util → utils}/level.js +0 -0
- data/templates/platform/tests/{display → displays}/bit_test.js +1 -1
- data/templates/platform/tests/displays/hero_test.js +73 -0
- data/templates/platform/tests/{display → displays}/tile_test.js +1 -1
- data/templates/platform/tests/displays/tsprite_test.js +8 -0
- data/templates/platform/tests/items/coin_test.js +10 -10
- data/templates/platform/tests/items/item_test.js +9 -9
- data/templates/platform/tests/items/spring_test.js +3 -3
- data/templates/platform/tests/scenes/load_test.js +2 -1
- data/templates/platform/tests/{util → utils}/counter_test.js +2 -2
- data/templates/platform/tests/{util → utils}/level_test.js +3 -0
- data/templates/pong/config.yml +22 -0
- data/templates/pong/readme.txt +3 -0
- data/templates/pong/scripts/controls/ai.js +30 -0
- data/templates/pong/scripts/controls/arena.js +33 -0
- data/templates/pong/scripts/controls/hitmap.js +54 -0
- data/templates/pong/scripts/controls/player.js +24 -0
- data/templates/pong/scripts/controls/twoarena.js +14 -0
- data/templates/pong/scripts/displays/ball.js +29 -0
- data/templates/pong/scripts/displays/counter.js +22 -0
- data/templates/pong/scripts/displays/paddle.js +22 -0
- data/templates/pong/scripts/init.js +9 -0
- data/templates/pong/scripts/scenes/game.js +61 -0
- data/templates/pong/scripts/scenes/home.js +55 -0
- data/templates/pong/scripts/scenes/over.js +29 -0
- data/templates/pong/tests/controls/ai_test.js +34 -0
- data/templates/pong/tests/controls/arena_test.js +20 -0
- data/templates/pong/tests/controls/hitmap_test.js +89 -0
- data/templates/pong/tests/controls/player_test.js +25 -0
- data/templates/pong/tests/controls/twoarena_test.js +7 -0
- data/templates/pong/tests/displays/ball_test.js +10 -0
- data/templates/pong/tests/displays/counter_test.js +13 -0
- data/templates/pong/tests/displays/paddle_test.js +17 -0
- data/templates/pong/tests/scenes/game_test.js +16 -0
- data/templates/pong/tests/scenes/home_test.js +30 -0
- data/templates/pong/tests/scenes/over_test.js +16 -0
- data/templates/tiltmaze/config.yml +25 -0
- data/templates/tiltmaze/readme.txt +79 -0
- data/templates/tiltmaze/scripts/displays/ball.js +78 -0
- data/templates/tiltmaze/scripts/displays/target.js +13 -0
- data/templates/tiltmaze/scripts/displays/tile.js +2 -0
- data/templates/tiltmaze/scripts/init.js +7 -0
- data/templates/tiltmaze/scripts/levels/level1.json +14 -0
- data/templates/tiltmaze/scripts/levels/level2.json +14 -0
- data/templates/tiltmaze/scripts/levels/level3.json +14 -0
- data/templates/tiltmaze/scripts/levels/level4.json +15 -0
- data/templates/tiltmaze/scripts/levels/level5.json +18 -0
- data/templates/tiltmaze/scripts/scenes/game.js +56 -0
- data/templates/tiltmaze/scripts/scenes/home.js +24 -0
- data/templates/tiltmaze/scripts/structs/level.js +82 -0
- data/templates/tiltmaze/scripts/tiles/walltile.js +147 -0
- data/templates/tiltmaze/tests/displays/ball_test.js +67 -0
- data/templates/tiltmaze/tests/displays/target_test.js +8 -0
- data/templates/tiltmaze/tests/factories.js +38 -0
- data/templates/tiltmaze/tests/scenes/game_test.js +59 -0
- data/templates/tiltmaze/tests/scenes/home_test.js +7 -0
- data/templates/tiltmaze/tests/structs/level_test.js +44 -0
- data/templates/tiltmaze/tests/tiles/walltile_test.js +36 -0
- metadata +106 -33
- data/templates/platform/tests/display/hero_test.js +0 -73
- data/templates/platform/tests/display/tsprite_test.js +0 -8
data/src/math/drag.js
CHANGED
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
|
-
|
|
88
|
+
this.velX = this.forceRes(this.velX, this.resX);
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
if(hity){
|
|
92
|
-
|
|
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.
|
|
111
|
+
if(this._automap[ty]){
|
|
112
112
|
|
|
113
|
-
this.trigger('hit', this.
|
|
113
|
+
this.trigger('hit', this._automap[ty][tx], tx, ty);
|
|
114
114
|
|
|
115
|
-
if(this.checkAxisX(this.
|
|
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.
|
|
145
|
+
if(this._automap[ty]){
|
|
146
146
|
|
|
147
|
-
this.trigger('hit', this.
|
|
147
|
+
this.trigger('hit', this._automap[ty][tx], tx, ty);
|
|
148
148
|
|
|
149
|
-
if(this.checkAxisY(this.
|
|
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
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
|
|
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.
|
|
78
|
-
|
|
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
|
-
|
|
88
|
-
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return
|
|
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
data/src/pattern/automap.js
CHANGED
|
@@ -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.
|
|
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.
|
|
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.
|
|
82
|
-
var m = new Array(this.
|
|
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.
|
|
85
|
+
m[l] = this.automapDefault;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
this.
|
|
88
|
+
this._automap.push(m);
|
|
89
89
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
//increase x length
|
|
93
|
-
while(x >= this.
|
|
93
|
+
while(x >= this._automap[this._automap.length-1].length){
|
|
94
94
|
|
|
95
|
-
for(var k=0; k<this.
|
|
96
|
-
if(this.
|
|
97
|
-
this.
|
|
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.
|
|
104
|
-
this.lenY = this.
|
|
103
|
+
this.lenX = this._automap[y].length;
|
|
104
|
+
this.lenY = this._automap.length;
|
|
105
105
|
|
|
106
|
-
this.
|
|
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.
|
|
121
|
+
this._automap = [];
|
|
133
122
|
});
|
data/src/pattern/flicker.js
CHANGED
|
@@ -27,7 +27,7 @@ re.c('flicker')
|
|
|
27
27
|
|
|
28
28
|
this.off('update', this.flicker_update);
|
|
29
29
|
|
|
30
|
-
return this.trigger('flicker:
|
|
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
|
|
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(
|
|
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
|
-
|
|
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 {
|
|
File without changes
|
|
File without changes
|
|
@@ -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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -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,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
|
+
});
|
|
@@ -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
|
-
|
|
13
|
-
as data files and will be read and automatically put in js files.
|
|
12
|
+
## /builds
|
|
14
13
|
|
|
15
|
-
|
|
14
|
+
Contains assets and minified code for the game.
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
## /scripts
|
|
18
17
|
|
|
19
|
-
|
|
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
|
-
|
|
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
|
-
|
|
23
|
+
For example, if I have a directory like /scripts/animations/monster.json.
|
|
29
24
|
|
|
30
|
-
|
|
25
|
+
The file will be turned into this:
|
|
31
26
|
|
|
32
|
-
|
|
27
|
+
re.e('monster.json animation')
|
|
28
|
+
.attr(**Animation JSON here**);
|
|
33
29
|
|
|
34
|
-
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|