entityjs 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -6
- data/.rspec +2 -0
- data/README.md +170 -49
- data/Rakefile +9 -0
- data/bin/entityjs +24 -14
- data/entityjs.gemspec +15 -9
- data/lib/entityjs/assets.rb +167 -0
- data/lib/entityjs/command.rb +52 -27
- data/lib/entityjs/commands/build.rb +128 -0
- data/lib/entityjs/commands/comp.rb +74 -0
- data/lib/entityjs/commands/font.rb +73 -0
- data/lib/entityjs/commands/new.rb +59 -0
- data/lib/entityjs/commands/server.rb +54 -0
- data/lib/entityjs/commands/templates.rb +28 -0
- data/lib/entityjs/commands/test.rb +69 -0
- data/lib/entityjs/config.rb +130 -0
- data/lib/entityjs/dirc.rb +184 -0
- data/lib/entityjs/parsers/parse_tmx.rb +41 -0
- data/lib/entityjs/parsers/parse_xml.rb +39 -0
- data/lib/entityjs/version.rb +1 -1
- data/lib/entityjs.rb +53 -0
- data/license.txt +1 -1
- data/public/play.html +122 -0
- data/public/qunit/qunit.css +226 -0
- data/public/qunit/qunit.entity.js +190 -0
- data/public/qunit/qunit.input.js +200 -0
- data/public/qunit/qunit.js +1598 -0
- data/public/qunit/qunit.mock.js +97 -0
- data/public/tests.html +45 -0
- data/spec/javascripts/helpers/accept.png +0 -0
- data/spec/javascripts/helpers/alligator.mp3 +0 -0
- data/spec/javascripts/helpers/alligator.ogg +0 -0
- data/spec/javascripts/helpers/canvas.js +15 -0
- data/spec/javascripts/helpers/entityunit.js +50 -0
- data/spec/javascripts/helpers/factories.js +11 -0
- data/spec/javascripts/helpers/jquery-1.7.1.min.js +4 -0
- data/spec/javascripts/src/core/comp_spec.js +145 -0
- data/spec/javascripts/src/core/entity_spec.js +324 -0
- data/spec/javascripts/src/core/load_spec.js +71 -0
- data/spec/javascripts/src/core/query_spec.js +157 -0
- data/spec/javascripts/src/core/re_spec.js +61 -0
- data/spec/javascripts/src/core/system_spec.js +41 -0
- data/spec/javascripts/src/cycle/draw_spec.js +106 -0
- data/spec/javascripts/src/cycle/tick_spec.js +20 -0
- data/spec/javascripts/src/cycle/update_spec.js +86 -0
- data/spec/javascripts/src/display/align_spec.js +43 -0
- data/spec/javascripts/src/display/circle_spec.js +26 -0
- data/spec/javascripts/src/display/group_spec.js +7 -0
- data/spec/javascripts/src/display/image_spec.js +32 -0
- data/spec/javascripts/src/display/imgtext_spec.js +32 -0
- data/spec/javascripts/src/display/rect_spec.js +13 -0
- data/spec/javascripts/src/display/screen_spec.js +47 -0
- data/spec/javascripts/src/display/sprite_spec.js +28 -0
- data/spec/javascripts/src/display/text_spec.js +30 -0
- data/spec/javascripts/src/input/keyboard_spec.js +67 -0
- data/spec/javascripts/src/input/mouse_spec.js +133 -0
- data/spec/javascripts/src/input/pressed_spec.js +31 -0
- data/spec/javascripts/src/math/bisect_spec.js +59 -0
- data/spec/javascripts/src/math/body_spec.js +30 -0
- data/spec/javascripts/src/math/drag_spec.js +38 -0
- data/spec/javascripts/src/math/force_spec.js +134 -0
- data/spec/javascripts/src/math/hit_spec.js +28 -0
- data/spec/javascripts/src/math/hitmap_spec.js +52 -0
- data/spec/javascripts/src/math/limit_spec.js +35 -0
- data/spec/javascripts/src/math/point_spec.js +57 -0
- data/spec/javascripts/src/math/tile_spec.js +78 -0
- data/spec/javascripts/src/media/sound_spec.js +40 -0
- data/spec/javascripts/src/pattern/automap_spec.js +93 -0
- data/spec/javascripts/src/pattern/flicker_spec.js +66 -0
- data/spec/javascripts/src/pattern/timestep_spec.js +23 -0
- data/spec/javascripts/src/save/storage_spec.js +37 -0
- data/spec/javascripts/src/util/log_spec.js +9 -0
- data/spec/javascripts/src/util/polyfill_spec.js +13 -0
- data/spec/javascripts/src/util/random_spec.js +33 -0
- data/spec/javascripts/src/util/scene_spec.js +52 -0
- data/spec/javascripts/src/util/sheet_spec.js +25 -0
- data/spec/javascripts/src/util/support_spec.js +17 -0
- data/spec/javascripts/support/jasmine.yml +76 -0
- data/spec/javascripts/support/jasmine_config.rb +32 -0
- data/spec/javascripts/support/jasmine_runner.rb +32 -0
- data/spec/lib/entityjs/assets_spec.rb +216 -0
- data/spec/lib/entityjs/command_spec.rb +53 -0
- data/spec/lib/entityjs/commands/build_spec.rb +69 -0
- data/spec/lib/entityjs/commands/comp_spec.rb +45 -0
- data/spec/lib/entityjs/commands/font_spec.rb +7 -0
- data/spec/lib/entityjs/commands/new_spec.rb +20 -0
- data/spec/lib/entityjs/commands/templates_spec.rb +9 -0
- data/spec/lib/entityjs/commands/test_spec.rb +31 -0
- data/spec/lib/entityjs/config_spec.rb +19 -0
- data/spec/lib/entityjs/dirc_spec.rb +83 -0
- data/spec/lib/entityjs/version_spec.rb +9 -0
- data/spec/spec_helper.rb +21 -3
- data/spec/support/factories.rb +19 -0
- data/spec/support/mygame.rb +11 -0
- data/src/core/comp.js +318 -0
- data/src/core/entity.js +549 -0
- data/src/core/load.js +242 -0
- data/src/core/query.js +354 -0
- data/src/core/re.js +74 -0
- data/src/core/system.js +121 -0
- data/src/cycle/draw.js +178 -0
- data/src/cycle/tick.js +25 -0
- data/src/{entityjs/cycle → cycle}/tween.js +60 -60
- data/src/{entityjs/cycle → cycle}/update.js +86 -85
- data/src/{entityjs/cycle → cycle}/wait.js +22 -21
- data/src/{entityjs/cycle → cycle}/worker.js +8 -8
- data/src/display/align.js +45 -0
- data/src/display/circle.js +33 -0
- data/src/{entityjs/display → display}/group.js +62 -62
- data/src/display/image.js +35 -0
- data/src/display/imgtext.js +102 -0
- data/src/{entityjs/display → display}/rect.js +18 -18
- data/src/display/screen.js +57 -0
- data/src/display/sprite.js +54 -0
- data/src/display/text.js +44 -0
- data/src/{entityjs/input → input}/keyboard.js +152 -150
- data/src/input/mouse.js +111 -0
- data/src/input/pressed.js +41 -0
- data/src/{entityjs/input → input}/touch.js +24 -28
- data/src/math/bisect.js +84 -0
- data/src/math/body.js +70 -0
- data/src/{entityjs/math → math}/drag.js +44 -38
- data/src/math/force.js +143 -0
- data/src/math/hit.js +32 -0
- data/src/math/hitmap.js +167 -0
- data/src/math/limit.js +37 -0
- data/src/math/point.js +40 -0
- data/src/math/tile.js +109 -0
- data/src/media/channel.js +93 -0
- data/src/{entityjs/media → media}/playlist.js +4 -4
- data/src/media/sound.js +114 -0
- data/src/{entityjs/net → net}/socket.js +51 -51
- data/src/pattern/automap.js +133 -0
- data/src/{entityjs/pattern → pattern}/flicker.js +206 -213
- data/src/pattern/timestep.js +31 -0
- data/src/{entityjs/save → save}/database.js +6 -6
- data/src/{entityjs/save → save}/storage.js +47 -56
- data/src/{entityjs/util → util}/log.js +17 -25
- data/src/{entityjs/util → util}/polyfill.js +24 -24
- data/src/util/random.js +20 -0
- data/src/util/scene.js +102 -0
- data/src/util/sheet.js +35 -0
- data/src/{entityjs/util → util}/support.js +109 -132
- data/{examples/keys → templates/arrow_keys/assets/images}/arrow.png +0 -0
- data/templates/arrow_keys/config.yml +22 -0
- data/templates/arrow_keys/readme.txt +9 -0
- data/templates/arrow_keys/scripts/display/arrow.js +69 -0
- data/templates/arrow_keys/scripts/init.js +10 -0
- data/templates/arrow_keys/scripts/input/controls.js +35 -0
- data/templates/arrow_keys/scripts/scenes/home.js +20 -0
- data/templates/arrow_keys/scripts/scenes/load.js +57 -0
- data/templates/arrow_keys/tests/display/arrow_test.js +29 -0
- data/templates/arrow_keys/tests/init_test.js +4 -0
- data/templates/arrow_keys/tests/input/controls_test.js +32 -0
- data/templates/arrow_keys/tests/scenes/home_test.js +0 -0
- data/templates/arrow_keys/tests/scenes/load_test.js +16 -0
- data/templates/blank/config.yml +22 -0
- data/templates/blank/readme.txt +79 -0
- data/templates/platform/assets/images/bit.png +0 -0
- data/templates/platform/assets/images/hero.png +0 -0
- data/templates/platform/assets/images/items.png +0 -0
- data/templates/platform/assets/images/tiles.png +0 -0
- data/templates/platform/assets/levels/level1.tmx +44 -0
- data/templates/platform/assets/sounds/coin.mp3 +0 -0
- data/templates/platform/assets/sounds/coin.ogg +0 -0
- data/templates/platform/config.yml +22 -0
- data/templates/platform/readme.txt +87 -0
- data/templates/platform/scripts/display/bit.js +12 -0
- data/templates/platform/scripts/display/hero.js +77 -0
- data/templates/platform/scripts/display/tile.js +2 -0
- data/templates/platform/scripts/display/tsprite.js +17 -0
- data/templates/platform/scripts/init.js +7 -0
- data/templates/platform/scripts/items/coin.js +27 -0
- data/templates/platform/scripts/items/item.js +41 -0
- data/templates/platform/scripts/items/spring.js +25 -0
- data/templates/platform/scripts/scenes/home.js +10 -0
- data/templates/platform/scripts/scenes/load.js +27 -0
- data/templates/platform/scripts/scenes/play.js +31 -0
- data/templates/platform/scripts/util/counter.js +34 -0
- data/templates/platform/scripts/util/level.js +84 -0
- data/templates/platform/tests/display/bit_test.js +7 -0
- data/templates/platform/tests/display/hero_test.js +73 -0
- data/templates/platform/tests/display/tile_test.js +7 -0
- data/templates/platform/tests/display/tsprite_test.js +8 -0
- data/templates/platform/tests/factories.js +30 -0
- data/templates/platform/tests/items/coin_test.js +28 -0
- data/templates/platform/tests/items/item_test.js +36 -0
- data/templates/platform/tests/items/spring_test.js +21 -0
- data/templates/platform/tests/scenes/home_test.js +9 -0
- data/templates/platform/tests/scenes/load_test.js +11 -0
- data/templates/platform/tests/scenes/play_test.js +15 -0
- data/templates/platform/tests/util/counter_test.js +9 -0
- data/templates/platform/tests/util/level_test.js +29 -0
- metadata +249 -97
- data/build/build_debug.bat +0 -1
- data/build/build_min.bat +0 -1
- data/build/config.php +0 -64
- data/build/debug.php +0 -48
- data/build/files.php +0 -74
- data/build/jsmin.php +0 -376
- data/build/min.php +0 -50
- data/changelog.txt +0 -53
- data/examples/keys/keys.html +0 -59
- data/examples/keys/keys.js +0 -148
- data/examples/mouse/mouse.html +0 -58
- data/examples/mouse/mouse.js +0 -60
- data/examples/scenes/home.png +0 -0
- data/examples/scenes/scenes.html +0 -55
- data/examples/scenes/scenes.js +0 -134
- data/examples/scenes/win.png +0 -0
- data/examples/sounds/sound1.mp3 +0 -0
- data/examples/sounds/sound1.ogg +0 -0
- data/examples/sounds/sounds.html +0 -56
- data/examples/sounds/sounds.js +0 -44
- data/examples/style/background.png +0 -0
- data/examples/style/sheet.css +0 -762
- data/examples/tiles/tiles.html +0 -56
- data/examples/tiles/tiles.js +0 -85
- data/examples/tiles/tiles.png +0 -0
- data/lib/blank/config.js +0 -4
- data/lib/blank/config.yml +0 -21
- data/lib/blank/home.js +0 -11
- data/lib/blank/init.js +0 -7
- data/lib/blank/load.js +0 -21
- data/lib/blank/play.html +0 -29
- data/lib/entity.debug.js +0 -52
- data/lib/entity.min.js +0 -184
- data/lib/entityjs/comp.rb +0 -11
- data/lib/entityjs/game.rb +0 -93
- data/lib/entityjs/min.rb +0 -11
- data/lib/entityjs/refresh.rb +0 -14
- data/spec/lib/entityjs/game_spec.rb +0 -11
- data/src/entityjs/core/component.js +0 -306
- data/src/entityjs/core/entity.js +0 -516
- data/src/entityjs/core/load.js +0 -224
- data/src/entityjs/core/query.js +0 -410
- data/src/entityjs/core/re.js +0 -70
- data/src/entityjs/core/system.js +0 -125
- data/src/entityjs/cycle/draw.js +0 -185
- data/src/entityjs/cycle/ticker.js +0 -27
- data/src/entityjs/display/anchor.js +0 -53
- data/src/entityjs/display/bitfont.js +0 -93
- data/src/entityjs/display/bitmap.js +0 -37
- data/src/entityjs/display/circle.js +0 -30
- data/src/entityjs/display/font.js +0 -41
- data/src/entityjs/display/screen.js +0 -46
- data/src/entityjs/display/sprite.js +0 -37
- data/src/entityjs/input/mouse.js +0 -123
- data/src/entityjs/input/pressed.js +0 -81
- data/src/entityjs/math/bind.js +0 -76
- data/src/entityjs/math/bisect.js +0 -69
- data/src/entityjs/math/body.js +0 -39
- data/src/entityjs/math/hitmap.js +0 -165
- data/src/entityjs/math/hittest.js +0 -26
- data/src/entityjs/math/physics.js +0 -142
- data/src/entityjs/math/point.js +0 -57
- data/src/entityjs/math/tile.js +0 -91
- data/src/entityjs/media/channel.js +0 -93
- data/src/entityjs/media/sound.js +0 -110
- data/src/entityjs/pattern/arraymap.js +0 -89
- data/src/entityjs/pattern/timestep.js +0 -34
- data/src/entityjs/util/random.js +0 -38
- data/src/entityjs/util/scene.js +0 -101
- data/src/entityjs/util/sheet.js +0 -51
data/src/entityjs/core/query.js
DELETED
@@ -1,410 +0,0 @@
|
|
1
|
-
(function(re){
|
2
|
-
|
3
|
-
/*
|
4
|
-
Searches through all entities using the selector conditions
|
5
|
-
|
6
|
-
//identifiers
|
7
|
-
* identifies all
|
8
|
-
^ identifies a signal
|
9
|
-
# identifies an id
|
10
|
-
- identifies not
|
11
|
-
|
12
|
-
//select all entities
|
13
|
-
re('*');
|
14
|
-
|
15
|
-
//select all entities with 2d and ai components
|
16
|
-
re('2d ai');
|
17
|
-
|
18
|
-
//select all 2d entities without the monster component
|
19
|
-
re('2d -monster');
|
20
|
-
|
21
|
-
//select all draw entities and entities with the id equal to asset
|
22
|
-
re('draw #asset')
|
23
|
-
//returns a random entity
|
24
|
-
.random();
|
25
|
-
|
26
|
-
//select all entities with id of bob and player
|
27
|
-
//warning you cannot query for two ids
|
28
|
-
re('#bob player')
|
29
|
-
//takes values from all objects and returns an array
|
30
|
-
.pluck('width height');
|
31
|
-
|
32
|
-
//find all bitmap entities with update signal.
|
33
|
-
re('bitmap ^update');
|
34
|
-
|
35
|
-
//add color comp to all text components
|
36
|
-
re('text').comp('color');
|
37
|
-
|
38
|
-
//custom entity search
|
39
|
-
re(function(index){
|
40
|
-
|
41
|
-
if(entity.has('health') && entity.health > 0){
|
42
|
-
//add to query
|
43
|
-
return true;
|
44
|
-
}
|
45
|
-
|
46
|
-
//skip entity
|
47
|
-
return false;
|
48
|
-
})
|
49
|
-
//calls reset method on all entities
|
50
|
-
.method('reset');
|
51
|
-
|
52
|
-
//returns direct reference to first entity with id of player
|
53
|
-
re('#player').health = 100;
|
54
|
-
|
55
|
-
*/
|
56
|
-
var q = function(selector){
|
57
|
-
this._e = [];
|
58
|
-
|
59
|
-
if(selector){
|
60
|
-
this.query(selector);
|
61
|
-
}
|
62
|
-
}
|
63
|
-
|
64
|
-
/*
|
65
|
-
Sort a query string into objects
|
66
|
-
*/
|
67
|
-
q._toObj = function(query){
|
68
|
-
if(q.c[query]){
|
69
|
-
return q.c[query];
|
70
|
-
}
|
71
|
-
|
72
|
-
//convert to object
|
73
|
-
var temp = query.split(' ');
|
74
|
-
var comps = [];
|
75
|
-
var signals = [];
|
76
|
-
var minus = [];
|
77
|
-
var id = '';
|
78
|
-
|
79
|
-
//split string
|
80
|
-
var fl;
|
81
|
-
var val;
|
82
|
-
for(var j = 0; j<temp.length; j++){
|
83
|
-
fl = temp[j].charAt(0);
|
84
|
-
val = temp[j].substr(1);
|
85
|
-
|
86
|
-
if(fl == '^'){
|
87
|
-
signals.push(val);
|
88
|
-
} else if(fl == '-'){
|
89
|
-
minus.push(val);
|
90
|
-
} else if(fl == '#'){
|
91
|
-
id = val;
|
92
|
-
} else {
|
93
|
-
comps.push(temp[j]);
|
94
|
-
}
|
95
|
-
}
|
96
|
-
|
97
|
-
var comp = {
|
98
|
-
comp:comps,
|
99
|
-
signal:signals,
|
100
|
-
not:minus,
|
101
|
-
id:id
|
102
|
-
};
|
103
|
-
|
104
|
-
q.c[query] = comp;
|
105
|
-
|
106
|
-
return comp;
|
107
|
-
}
|
108
|
-
|
109
|
-
q.c = {};
|
110
|
-
|
111
|
-
var p = q.prototype;
|
112
|
-
|
113
|
-
p.query = function(select){
|
114
|
-
select = select || '';
|
115
|
-
var i = 0;
|
116
|
-
|
117
|
-
if(typeof select == 'string'){
|
118
|
-
|
119
|
-
if(select == '*'){
|
120
|
-
|
121
|
-
this._e = re._e.slice();
|
122
|
-
|
123
|
-
return this;
|
124
|
-
}
|
125
|
-
|
126
|
-
//optimize search and cache
|
127
|
-
var obj = q._toObj(select);
|
128
|
-
|
129
|
-
var en;
|
130
|
-
main : for(; i<re._e.length; i++){
|
131
|
-
en = re._e[i];
|
132
|
-
|
133
|
-
if(en.has(obj)){
|
134
|
-
|
135
|
-
this._e.push(en);
|
136
|
-
}
|
137
|
-
|
138
|
-
}
|
139
|
-
|
140
|
-
|
141
|
-
} else if(typeof select == 'function'){
|
142
|
-
|
143
|
-
for(; i<re._e.length; i++){
|
144
|
-
|
145
|
-
if(select.call(re._e[i], i, re._e.length)){
|
146
|
-
this._e.push(re._e[i]);
|
147
|
-
}
|
148
|
-
|
149
|
-
}
|
150
|
-
|
151
|
-
}
|
152
|
-
|
153
|
-
return this;
|
154
|
-
}
|
155
|
-
|
156
|
-
/*
|
157
|
-
Returns an array with all queried entities.
|
158
|
-
*/
|
159
|
-
p.toArray = function(){
|
160
|
-
return this._e.slice();
|
161
|
-
}
|
162
|
-
|
163
|
-
/*
|
164
|
-
Calls the given method name on all entities.
|
165
|
-
|
166
|
-
re('enemies').method('rest');
|
167
|
-
*/
|
168
|
-
p.method = function(m){
|
169
|
-
var b = Array.prototype.slice.call(arguments, 1);
|
170
|
-
this.each(function(){
|
171
|
-
|
172
|
-
this[m].apply(this, b);
|
173
|
-
});
|
174
|
-
|
175
|
-
return this;
|
176
|
-
}
|
177
|
-
|
178
|
-
/*
|
179
|
-
example
|
180
|
-
re('draw').each(function(index, length){
|
181
|
-
|
182
|
-
});
|
183
|
-
|
184
|
-
returning false will break the loop
|
185
|
-
*/
|
186
|
-
p.each = function(m){
|
187
|
-
var l = this._e.length, i = -1, e;
|
188
|
-
|
189
|
-
while(++i < l && (e = this._e[i]) && m.call(e, i, l) !== false);
|
190
|
-
|
191
|
-
return this;
|
192
|
-
}
|
193
|
-
|
194
|
-
/*
|
195
|
-
The map method allows multidimensional loops.
|
196
|
-
|
197
|
-
//map through and increase y every 3 entities.
|
198
|
-
|
199
|
-
re('draw').map(3, function(x, y){
|
200
|
-
this.x(x * width);
|
201
|
-
this.y(Y * height);
|
202
|
-
});
|
203
|
-
|
204
|
-
//so instead of getting this back
|
205
|
-
[e,e,e,e,e...]
|
206
|
-
|
207
|
-
//you will get this
|
208
|
-
[
|
209
|
-
[e,e,e],
|
210
|
-
[e,e,e],
|
211
|
-
[e,e,e]
|
212
|
-
...
|
213
|
-
]
|
214
|
-
|
215
|
-
returning false will break the loop
|
216
|
-
|
217
|
-
*/
|
218
|
-
p.map = function(w, method){
|
219
|
-
var x = 0;
|
220
|
-
var y = 0;
|
221
|
-
|
222
|
-
for(var i =0, l = this._e.length; i<l; i++){
|
223
|
-
|
224
|
-
if(method.call(this._e[i], x, y, i, l) == false) break;
|
225
|
-
|
226
|
-
x++;
|
227
|
-
|
228
|
-
if(x == w){
|
229
|
-
x = 0;
|
230
|
-
y++;
|
231
|
-
}
|
232
|
-
}
|
233
|
-
}
|
234
|
-
|
235
|
-
/*
|
236
|
-
Returns an array of all components in the query.
|
237
|
-
*/
|
238
|
-
p.getComps = function(){
|
239
|
-
var l = [];
|
240
|
-
|
241
|
-
this.each(function(){
|
242
|
-
l.concat(this.getComps());
|
243
|
-
});
|
244
|
-
|
245
|
-
return l;
|
246
|
-
}
|
247
|
-
|
248
|
-
/*
|
249
|
-
Returns a random entity.
|
250
|
-
*/
|
251
|
-
p.random = function(){
|
252
|
-
return this._e[~~(Math.random()*this._e.length)];
|
253
|
-
}
|
254
|
-
|
255
|
-
/*
|
256
|
-
The pluck method returns all values from all entities in an array.
|
257
|
-
|
258
|
-
//will return all pos objs from all entities.
|
259
|
-
re('point').pluck('pos visible');
|
260
|
-
|
261
|
-
//if we echo...
|
262
|
-
|
263
|
-
[
|
264
|
-
{pos:0, visible:0}
|
265
|
-
...
|
266
|
-
]
|
267
|
-
|
268
|
-
*/
|
269
|
-
p.pluck = function(value){
|
270
|
-
var t = [];
|
271
|
-
|
272
|
-
var k = value.split(' ');
|
273
|
-
|
274
|
-
this.each(function(){
|
275
|
-
var o = {};
|
276
|
-
|
277
|
-
for(var p in k){
|
278
|
-
if(k.hasOwnProperty(p)){
|
279
|
-
o[k[p]] = this[k[p]];
|
280
|
-
}
|
281
|
-
}
|
282
|
-
|
283
|
-
t.push(o);
|
284
|
-
|
285
|
-
});
|
286
|
-
|
287
|
-
return t;
|
288
|
-
}
|
289
|
-
|
290
|
-
p.extend = function(obj, value){
|
291
|
-
this.each(function(){
|
292
|
-
this.extend(obj,value);
|
293
|
-
});
|
294
|
-
|
295
|
-
return this;
|
296
|
-
}
|
297
|
-
|
298
|
-
p.inherit = function(obj, value){
|
299
|
-
this.each(function(){
|
300
|
-
this.inherit(obj, value);
|
301
|
-
});
|
302
|
-
|
303
|
-
return this;
|
304
|
-
}
|
305
|
-
|
306
|
-
p.addComp = function(c){
|
307
|
-
|
308
|
-
this.each(function(ref){
|
309
|
-
this.addComp(c);
|
310
|
-
});
|
311
|
-
|
312
|
-
return this;
|
313
|
-
}
|
314
|
-
|
315
|
-
p.removeComp = function(c){
|
316
|
-
this.each(function(ref){
|
317
|
-
this.removeComp(c);
|
318
|
-
});
|
319
|
-
}
|
320
|
-
|
321
|
-
p.signal = function(type, method){
|
322
|
-
var p = arguments;
|
323
|
-
|
324
|
-
this.each(function(ref){
|
325
|
-
this.signal.apply(this, p);
|
326
|
-
});
|
327
|
-
|
328
|
-
return this;
|
329
|
-
}
|
330
|
-
|
331
|
-
p.length = function(){
|
332
|
-
return this._e.length;
|
333
|
-
}
|
334
|
-
|
335
|
-
/*
|
336
|
-
filters out entities that do not match credentials
|
337
|
-
|
338
|
-
//spawns all entities that are dead
|
339
|
-
re('2d health').filter(function(i){
|
340
|
-
|
341
|
-
if(this.health <= 0){
|
342
|
-
//keep entity
|
343
|
-
return true;
|
344
|
-
}
|
345
|
-
|
346
|
-
//remove entity
|
347
|
-
return false;
|
348
|
-
|
349
|
-
}).signal('spawn');
|
350
|
-
|
351
|
-
*/
|
352
|
-
p.filter = function(method){
|
353
|
-
|
354
|
-
var q = re();
|
355
|
-
var that = this;
|
356
|
-
|
357
|
-
this.each(function(i, l){
|
358
|
-
|
359
|
-
if(method.call(this, i, l)){
|
360
|
-
//add entity
|
361
|
-
q.push(this);
|
362
|
-
}
|
363
|
-
|
364
|
-
});
|
365
|
-
|
366
|
-
return q;
|
367
|
-
}
|
368
|
-
|
369
|
-
p.has = function(comp){
|
370
|
-
|
371
|
-
for(var i=0; i<this._e.length; i++){
|
372
|
-
if(!this._e.has(comp)){
|
373
|
-
return false;
|
374
|
-
}
|
375
|
-
}
|
376
|
-
|
377
|
-
return this;
|
378
|
-
}
|
379
|
-
|
380
|
-
p.dispose = function(){
|
381
|
-
|
382
|
-
this.each(function(){
|
383
|
-
|
384
|
-
this.dispose();
|
385
|
-
|
386
|
-
});
|
387
|
-
|
388
|
-
return this;
|
389
|
-
}
|
390
|
-
|
391
|
-
/*
|
392
|
-
Get specific entity from given index.
|
393
|
-
*/
|
394
|
-
p.get = function(index){
|
395
|
-
return this._e[index];
|
396
|
-
}
|
397
|
-
|
398
|
-
/*
|
399
|
-
Put entity into query array.
|
400
|
-
*/
|
401
|
-
p.put = function(entity){
|
402
|
-
|
403
|
-
this._e.push(entity);
|
404
|
-
|
405
|
-
return this;
|
406
|
-
}
|
407
|
-
|
408
|
-
re.query = q;
|
409
|
-
|
410
|
-
}(re));
|
data/src/entityjs/core/re.js
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
EntityJS Javascript Game Engine
|
3
|
-
Copyright 2011, Ben D'Angelo
|
4
|
-
http://entityjs.com
|
5
|
-
|
6
|
-
Licensed under MIT http://entityjs.com/license
|
7
|
-
|
8
|
-
*/
|
9
|
-
re = function(selector){
|
10
|
-
return new re.query(selector);
|
11
|
-
};
|
12
|
-
|
13
|
-
//automatically filled when compiled
|
14
|
-
re.version = "$VERSION";
|
15
|
-
|
16
|
-
//contains all entities
|
17
|
-
re._e = [];
|
18
|
-
//contains all components
|
19
|
-
re._c = {};
|
20
|
-
|
21
|
-
re.ready = function(r){
|
22
|
-
re.ready.c.push(r);
|
23
|
-
|
24
|
-
window.onload = function(){
|
25
|
-
for(var k in re.ready.c){
|
26
|
-
re.ready.c[k].call(re);
|
27
|
-
}
|
28
|
-
};
|
29
|
-
};
|
30
|
-
re.ready.c = [];
|
31
|
-
|
32
|
-
/*
|
33
|
-
The $ method is used for selecting ids and tags.
|
34
|
-
*/
|
35
|
-
re.$ = function(s){
|
36
|
-
return re.$.c[s] = re.$.c[s] || (s.charAt(0) == '#') ? document.getElementById(s.substr(1)) : document.getElementsByTagName(s);
|
37
|
-
};
|
38
|
-
//caches dom queries
|
39
|
-
re.$.c = {};
|
40
|
-
|
41
|
-
re.$new = function(n){
|
42
|
-
return document.createElement(n);
|
43
|
-
};
|
44
|
-
|
45
|
-
/*
|
46
|
-
Special polyfills and object additions
|
47
|
-
*/
|
48
|
-
re.listener = function(t, c){
|
49
|
-
if(window.addEventListener){
|
50
|
-
window.addEventListener(t, c, true);
|
51
|
-
} else {
|
52
|
-
document.attachEvent('on'+t, c);
|
53
|
-
}
|
54
|
-
};
|
55
|
-
|
56
|
-
Function.prototype.context = function(c){
|
57
|
-
var that = this;
|
58
|
-
return function(){ return that.apply(c, arguments); };
|
59
|
-
};
|
60
|
-
|
61
|
-
if(!Array.prototype.indexOf){
|
62
|
-
Array.prototype.indexOf = function(o){
|
63
|
-
for(var i=0; i<this.length; i++){
|
64
|
-
if(this[i]==o){
|
65
|
-
return i;
|
66
|
-
}
|
67
|
-
}
|
68
|
-
return -1;
|
69
|
-
}
|
70
|
-
}
|
data/src/entityjs/core/system.js
DELETED
@@ -1,125 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
The system component contains all information and references to the entity js engine.
|
3
|
-
Such as the canvas context, fps, start, stop, canvas.
|
4
|
-
|
5
|
-
You can add the component to entities for quick reference to variables.
|
6
|
-
|
7
|
-
FUTURE
|
8
|
-
-add entity extends to allow local usage.
|
9
|
-
-perhaps allow users to override the system class for their own custom usage. (new arrays of entities and components)
|
10
|
-
*/
|
11
|
-
re.c('system')
|
12
|
-
.inherit({
|
13
|
-
|
14
|
-
contextType:'2d',
|
15
|
-
|
16
|
-
clearColor:'#f9f9f9',
|
17
|
-
|
18
|
-
stepSize:0.03,
|
19
|
-
|
20
|
-
running:false,
|
21
|
-
|
22
|
-
sizeX:0,
|
23
|
-
sizeY:0
|
24
|
-
|
25
|
-
})
|
26
|
-
.extend({
|
27
|
-
|
28
|
-
clear:function(color){
|
29
|
-
|
30
|
-
if(color){
|
31
|
-
this.context.fillStyle = color;
|
32
|
-
this.context.fillRect(0, 0, this.sizeX, this.sizeY);
|
33
|
-
} else {
|
34
|
-
this.context.clearRect(0, 0, this.sizeX, this.sizeY);
|
35
|
-
}
|
36
|
-
|
37
|
-
return this;
|
38
|
-
},
|
39
|
-
|
40
|
-
start:function(){
|
41
|
-
if(!this.running){
|
42
|
-
this.running = true;
|
43
|
-
|
44
|
-
var that = this;
|
45
|
-
|
46
|
-
(function mainLoop(){
|
47
|
-
|
48
|
-
that.system_loop.call(that);
|
49
|
-
|
50
|
-
if(that.running){
|
51
|
-
that.requestAnimationFrame(mainLoop, that.canvas);
|
52
|
-
}
|
53
|
-
|
54
|
-
})();
|
55
|
-
|
56
|
-
|
57
|
-
}
|
58
|
-
|
59
|
-
return this;
|
60
|
-
},
|
61
|
-
|
62
|
-
loop:function(m){
|
63
|
-
|
64
|
-
this.system_loop = m;
|
65
|
-
|
66
|
-
return this;
|
67
|
-
},
|
68
|
-
|
69
|
-
stop:function(){
|
70
|
-
this.running = false;
|
71
|
-
return this;
|
72
|
-
},
|
73
|
-
|
74
|
-
init:function(canvasId, screen, contextType){
|
75
|
-
|
76
|
-
//add comps here because system is extendd earlier
|
77
|
-
this.addComp('polyfill ticker timestep');
|
78
|
-
|
79
|
-
//setup canvas
|
80
|
-
this.canvas = re.$(canvasId);
|
81
|
-
|
82
|
-
this.contextType = contextType || this.contextType;
|
83
|
-
|
84
|
-
this.context = this.canvas.getContext(this.contextType);
|
85
|
-
|
86
|
-
this.sizeX = this.canvas.width;
|
87
|
-
this.sizeY = this.canvas.height;
|
88
|
-
|
89
|
-
screen = screen || re.screen;
|
90
|
-
|
91
|
-
if(screen){
|
92
|
-
screen.sizeX = this.sizeX;
|
93
|
-
screen.sizeY = this.sizeY;
|
94
|
-
|
95
|
-
screen.regX = this.sizeX * 0.5;
|
96
|
-
screen.regY = this.sizeY * 0.5;
|
97
|
-
}
|
98
|
-
|
99
|
-
return this;
|
100
|
-
},
|
101
|
-
|
102
|
-
/*
|
103
|
-
Default main loop
|
104
|
-
*/
|
105
|
-
system_loop:function(){
|
106
|
-
|
107
|
-
this.timestep(this.tick(), function(){
|
108
|
-
//update
|
109
|
-
re._c.update.update.call(re._c.update, this, this.stepSize);
|
110
|
-
});
|
111
|
-
|
112
|
-
//clear
|
113
|
-
this.clear(this.clearColor);
|
114
|
-
|
115
|
-
re._c.draw.draw.call(re._c.draw, this);
|
116
|
-
}
|
117
|
-
|
118
|
-
|
119
|
-
})
|
120
|
-
.run(function(){
|
121
|
-
|
122
|
-
//create default system
|
123
|
-
re.system = re.sys = re.e('system');
|
124
|
-
|
125
|
-
});
|