entityjs 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/Gemfile +4 -0
- data/README.md +49 -0
- data/Rakefile +1 -0
- data/bin/entityjs +14 -0
- data/build/build_debug.bat +1 -0
- data/build/build_min.bat +1 -0
- data/build/config.php +64 -0
- data/build/debug.php +48 -0
- data/build/files.php +74 -0
- data/build/jsmin.php +376 -0
- data/build/min.php +50 -0
- data/changelog.txt +53 -0
- data/entityjs.gemspec +25 -0
- data/examples/keys/arrow.png +0 -0
- data/examples/keys/keys.html +59 -0
- data/examples/keys/keys.js +148 -0
- data/examples/mouse/mouse.html +58 -0
- data/examples/mouse/mouse.js +60 -0
- data/examples/scenes/home.png +0 -0
- data/examples/scenes/scenes.html +55 -0
- data/examples/scenes/scenes.js +134 -0
- 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 +56 -0
- data/examples/sounds/sounds.js +44 -0
- data/examples/style/background.png +0 -0
- data/examples/style/sheet.css +762 -0
- data/examples/tiles/tiles.html +56 -0
- data/examples/tiles/tiles.js +85 -0
- data/examples/tiles/tiles.png +0 -0
- data/lib/blank/config.js +4 -0
- data/lib/blank/config.yml +21 -0
- data/lib/blank/home.js +11 -0
- data/lib/blank/init.js +7 -0
- data/lib/blank/load.js +21 -0
- data/lib/blank/play.html +29 -0
- data/lib/entity.debug.js +52 -0
- data/lib/entity.min.js +184 -0
- data/lib/entityjs/command.rb +37 -0
- data/lib/entityjs/comp.rb +11 -0
- data/lib/entityjs/game.rb +93 -0
- data/lib/entityjs/min.rb +11 -0
- data/lib/entityjs/refresh.rb +14 -0
- data/lib/entityjs/version.rb +3 -0
- data/lib/entityjs.rb +6 -0
- data/license.txt +1 -0
- data/spec/lib/entityjs/game_spec.rb +11 -0
- data/spec/spec_helper.rb +3 -0
- data/src/entityjs/core/component.js +306 -0
- data/src/entityjs/core/entity.js +516 -0
- data/src/entityjs/core/load.js +224 -0
- data/src/entityjs/core/query.js +410 -0
- data/src/entityjs/core/re.js +70 -0
- data/src/entityjs/core/system.js +125 -0
- data/src/entityjs/cycle/draw.js +185 -0
- data/src/entityjs/cycle/ticker.js +27 -0
- data/src/entityjs/cycle/tween.js +61 -0
- data/src/entityjs/cycle/update.js +86 -0
- data/src/entityjs/cycle/wait.js +22 -0
- data/src/entityjs/cycle/worker.js +9 -0
- data/src/entityjs/display/anchor.js +53 -0
- data/src/entityjs/display/bitfont.js +93 -0
- data/src/entityjs/display/bitmap.js +37 -0
- data/src/entityjs/display/circle.js +30 -0
- data/src/entityjs/display/font.js +41 -0
- data/src/entityjs/display/group.js +63 -0
- data/src/entityjs/display/rect.js +19 -0
- data/src/entityjs/display/screen.js +46 -0
- data/src/entityjs/display/sprite.js +37 -0
- data/src/entityjs/input/keyboard.js +150 -0
- data/src/entityjs/input/mouse.js +123 -0
- data/src/entityjs/input/pressed.js +81 -0
- data/src/entityjs/input/touch.js +28 -0
- data/src/entityjs/math/bind.js +76 -0
- data/src/entityjs/math/bisect.js +69 -0
- data/src/entityjs/math/body.js +39 -0
- data/src/entityjs/math/drag.js +39 -0
- data/src/entityjs/math/hitmap.js +165 -0
- data/src/entityjs/math/hittest.js +26 -0
- data/src/entityjs/math/physics.js +142 -0
- data/src/entityjs/math/point.js +57 -0
- data/src/entityjs/math/tile.js +91 -0
- data/src/entityjs/media/channel.js +93 -0
- data/src/entityjs/media/playlist.js +5 -0
- data/src/entityjs/media/sound.js +110 -0
- data/src/entityjs/net/socket.js +52 -0
- data/src/entityjs/pattern/arraymap.js +89 -0
- data/src/entityjs/pattern/flicker.js +214 -0
- data/src/entityjs/pattern/timestep.js +34 -0
- data/src/entityjs/save/database.js +7 -0
- data/src/entityjs/save/storage.js +57 -0
- data/src/entityjs/util/log.js +25 -0
- data/src/entityjs/util/polyfill.js +25 -0
- data/src/entityjs/util/random.js +38 -0
- data/src/entityjs/util/scene.js +101 -0
- data/src/entityjs/util/sheet.js +51 -0
- data/src/entityjs/util/support.js +132 -0
- metadata +156 -0
@@ -0,0 +1,93 @@
|
|
1
|
+
module Entityjs
|
2
|
+
|
3
|
+
class Game
|
4
|
+
|
5
|
+
def self.generate(name, comps=[])
|
6
|
+
@root = name
|
7
|
+
|
8
|
+
#create directory
|
9
|
+
self.create_dir(name)
|
10
|
+
|
11
|
+
Dir.chdir(Dir.pwd+'/'+name)
|
12
|
+
|
13
|
+
#create html file
|
14
|
+
create_file('play.html')
|
15
|
+
|
16
|
+
create_file('config.yml')
|
17
|
+
|
18
|
+
#create lib
|
19
|
+
self.create_dir('lib')
|
20
|
+
|
21
|
+
#create src directory
|
22
|
+
self.create_dir('src')
|
23
|
+
|
24
|
+
Dir.chdir(Dir.pwd+'/src')
|
25
|
+
|
26
|
+
self.create_file('init.js')
|
27
|
+
|
28
|
+
self.create_dir('display')
|
29
|
+
|
30
|
+
self.create_dir('plugins')
|
31
|
+
|
32
|
+
self.create_dir('scenes')
|
33
|
+
|
34
|
+
Dir.chdir(Dir.pwd+'/scenes')
|
35
|
+
self.create_file('load.js')
|
36
|
+
self.create_file('home.js')
|
37
|
+
|
38
|
+
#create assets
|
39
|
+
Dir.chdir(Dir.pwd+'/../..')
|
40
|
+
|
41
|
+
self.create_dir('assets')
|
42
|
+
|
43
|
+
Dir.chdir(Dir.pwd+'/assets')
|
44
|
+
|
45
|
+
self.create_dir('sounds')
|
46
|
+
|
47
|
+
self.create_dir('images')
|
48
|
+
|
49
|
+
self.create_dir('levels')
|
50
|
+
|
51
|
+
#create test directory
|
52
|
+
Dir.chdir(Dir.pwd+'/..')
|
53
|
+
self.create_dir('tests')
|
54
|
+
|
55
|
+
Dir.chdir(Dir.pwd+'/tests')
|
56
|
+
|
57
|
+
self.create_dir('scenes')
|
58
|
+
self.create_dir('display')
|
59
|
+
|
60
|
+
Entityjs::Command.run('comp', comps)
|
61
|
+
|
62
|
+
Entityjs::Command.run('refresh')
|
63
|
+
|
64
|
+
return true
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.create_file(name)
|
68
|
+
template = File.expand_path(File.dirname(__FILE__) + '/../blank/'+name)
|
69
|
+
FileUtils.cp template, name
|
70
|
+
|
71
|
+
path = "/#{name}"
|
72
|
+
|
73
|
+
cut = Dir.pwd.split(@root)
|
74
|
+
|
75
|
+
if cut.length == 2
|
76
|
+
path = cut.pop+path
|
77
|
+
end
|
78
|
+
|
79
|
+
puts "Created: #{path}"
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.create_dir(name)
|
83
|
+
begin
|
84
|
+
Dir::mkdir(name)
|
85
|
+
puts "Created: /#{name}"
|
86
|
+
rescue
|
87
|
+
puts "Directory: /#{name} already exists!"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
data/lib/entityjs/min.rb
ADDED
data/lib/entityjs.rb
ADDED
data/license.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
/* EntityJS v$VERSION http://entityjs.com | License http://entityjs.com/license */
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,306 @@
|
|
1
|
+
|
2
|
+
/*
|
3
|
+
Quick way to convert sentences to arrays.
|
4
|
+
*/
|
5
|
+
var __z = function(n, r){
|
6
|
+
this._checkFinal();
|
7
|
+
|
8
|
+
if(!this[n]){
|
9
|
+
this[n] = [];
|
10
|
+
}
|
11
|
+
|
12
|
+
if(typeof r == 'string'){
|
13
|
+
this[n] = this[n].concat(r.split(' '));
|
14
|
+
} else {
|
15
|
+
this[n] = this[n].concat(r);
|
16
|
+
}
|
17
|
+
|
18
|
+
return this;
|
19
|
+
};
|
20
|
+
|
21
|
+
/*
|
22
|
+
If component exists, the component will NOT be overwritten.
|
23
|
+
|
24
|
+
@return component reference
|
25
|
+
*/
|
26
|
+
re.comp = re.c = function(title){
|
27
|
+
|
28
|
+
if(!re._c[title]){
|
29
|
+
re._c[title] = new re.comp.init(title);
|
30
|
+
}
|
31
|
+
|
32
|
+
return re._c[title];
|
33
|
+
};
|
34
|
+
|
35
|
+
re.comp.init = function(name){
|
36
|
+
|
37
|
+
this.name = name;
|
38
|
+
this._re_signals = {};
|
39
|
+
this._re_inherits = {};
|
40
|
+
this._re_extends = {};
|
41
|
+
this._re_final = false;
|
42
|
+
};
|
43
|
+
|
44
|
+
/*
|
45
|
+
p._re_requires = null;
|
46
|
+
|
47
|
+
p._re_init = null;
|
48
|
+
|
49
|
+
p._re_dispose = null;
|
50
|
+
|
51
|
+
p._re_asserts = null;
|
52
|
+
|
53
|
+
p._re_interface = null;
|
54
|
+
*/
|
55
|
+
|
56
|
+
re.comp.init.prototype = {
|
57
|
+
|
58
|
+
_checkFinal:function(){
|
59
|
+
|
60
|
+
if(this._re_final){
|
61
|
+
throw this.name+' is final.';
|
62
|
+
}
|
63
|
+
},
|
64
|
+
|
65
|
+
global:function(obj, value){
|
66
|
+
this._checkFinal();
|
67
|
+
|
68
|
+
if(arguments.length == 1){
|
69
|
+
|
70
|
+
for(var type in obj){
|
71
|
+
this[type] = obj[type];
|
72
|
+
}
|
73
|
+
|
74
|
+
} else {
|
75
|
+
this[obj] = value;
|
76
|
+
}
|
77
|
+
|
78
|
+
return this;
|
79
|
+
},
|
80
|
+
|
81
|
+
|
82
|
+
require:function(r){
|
83
|
+
return __z.call(this, '_re_requires', r);
|
84
|
+
},
|
85
|
+
|
86
|
+
/*
|
87
|
+
Upon component init it will throw an error
|
88
|
+
if one of the listed components exist.
|
89
|
+
|
90
|
+
This prevents incompatible components from colliding.
|
91
|
+
*/
|
92
|
+
assert:function(r){
|
93
|
+
return __z.call(this, '_re_asserts', r);
|
94
|
+
},
|
95
|
+
|
96
|
+
/*
|
97
|
+
The implement method checks and enforces implmentation
|
98
|
+
of the given keys. This can create interface components
|
99
|
+
for organization and query searches.
|
100
|
+
|
101
|
+
Forcing an interface on components will allow instant
|
102
|
+
runtime errors and save time.
|
103
|
+
|
104
|
+
//reccommended to put an i infront to represent an interface
|
105
|
+
re.c('ienemy')
|
106
|
+
//create an enemy interface
|
107
|
+
.interface('moveTo spawn attack runAway');
|
108
|
+
|
109
|
+
*/
|
110
|
+
implement:function(r){
|
111
|
+
return __z.call(this, '_re_implments', r);
|
112
|
+
},
|
113
|
+
|
114
|
+
/*
|
115
|
+
Creates new names for a component.
|
116
|
+
|
117
|
+
//create a new alias of draw
|
118
|
+
re.c('draw')
|
119
|
+
.alias('bob');
|
120
|
+
|
121
|
+
//remove alias
|
122
|
+
re.c('draw')
|
123
|
+
.alias('-bob');
|
124
|
+
|
125
|
+
//aliases can even delete components itself
|
126
|
+
re.c('draw').alias('-draw');
|
127
|
+
|
128
|
+
//add two aliases
|
129
|
+
re.c('draw').alias('dr bob');
|
130
|
+
|
131
|
+
*/
|
132
|
+
alias:function(s){
|
133
|
+
this._checkFinal();
|
134
|
+
|
135
|
+
var p = s.split(' ');
|
136
|
+
|
137
|
+
if(p.length > 1){
|
138
|
+
|
139
|
+
for(var i in p){
|
140
|
+
this.alias(p[i]);
|
141
|
+
}
|
142
|
+
|
143
|
+
return this;
|
144
|
+
}
|
145
|
+
|
146
|
+
if(s.charAt(0) == '-'){
|
147
|
+
//only remove if its a reference
|
148
|
+
if(re._c[s.substr(1)] == this){
|
149
|
+
delete re._c[s.substr(1)];
|
150
|
+
}
|
151
|
+
} else {
|
152
|
+
|
153
|
+
re._c[s] = this;
|
154
|
+
}
|
155
|
+
|
156
|
+
return this;
|
157
|
+
},
|
158
|
+
|
159
|
+
addSignal:function(){
|
160
|
+
return re.e.init.prototype.addSignal.apply(this, arguments);
|
161
|
+
},
|
162
|
+
|
163
|
+
removeSignal:function(){
|
164
|
+
return re.e.init.prototype.removeSignal.apply(this, arguments);
|
165
|
+
},
|
166
|
+
|
167
|
+
/*
|
168
|
+
Adds signal functionality to components.
|
169
|
+
All components will automatically call two signals, init and dispose.
|
170
|
+
|
171
|
+
Init on entity creation and dispose on entitiy disposition.
|
172
|
+
|
173
|
+
This is useful for 'watch tower' components that keep a list of
|
174
|
+
all entities that have its component. Check the cycle directory.
|
175
|
+
|
176
|
+
*/
|
177
|
+
signal:function(){
|
178
|
+
return re.e.init.prototype.signal.apply(this, arguments);
|
179
|
+
},
|
180
|
+
|
181
|
+
/*
|
182
|
+
Default adds onto but doesn't overwrite values.
|
183
|
+
*/
|
184
|
+
inherit:function(d, value){
|
185
|
+
this._checkFinal();
|
186
|
+
|
187
|
+
if(arguments.length == 1){
|
188
|
+
|
189
|
+
for(var k in d){
|
190
|
+
this._re_inherits[k] = d[k];
|
191
|
+
}
|
192
|
+
|
193
|
+
} else {
|
194
|
+
|
195
|
+
this._re_inherits[d] = value;
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
return this;
|
200
|
+
},
|
201
|
+
|
202
|
+
/*
|
203
|
+
The namespace method is used to put private component variables
|
204
|
+
in its own space. This prevents unwanted overrites.
|
205
|
+
|
206
|
+
re.c('draw')
|
207
|
+
.namespace({
|
208
|
+
pos:0,
|
209
|
+
type:'none'
|
210
|
+
|
211
|
+
});
|
212
|
+
|
213
|
+
//or
|
214
|
+
re.c('draw')
|
215
|
+
.namespace("pos", 0);
|
216
|
+
|
217
|
+
//Will cast to
|
218
|
+
this.draw_pos = 10;
|
219
|
+
this.draw_type = 'none';
|
220
|
+
|
221
|
+
*/
|
222
|
+
namespace:function(obj, value){
|
223
|
+
this._checkFinal();
|
224
|
+
var name = this.name+'_';
|
225
|
+
|
226
|
+
if(arguments.length == 1){
|
227
|
+
|
228
|
+
for(var k in obj){
|
229
|
+
this._re_extends[name+k] = obj[k];
|
230
|
+
}
|
231
|
+
|
232
|
+
} else {
|
233
|
+
this._re_extends[name+obj] = value;
|
234
|
+
}
|
235
|
+
|
236
|
+
return this;
|
237
|
+
},
|
238
|
+
|
239
|
+
/*
|
240
|
+
extend overrides everything.
|
241
|
+
*/
|
242
|
+
extend:function(d, value){
|
243
|
+
this._checkFinal();
|
244
|
+
|
245
|
+
if(!this._re_extends){
|
246
|
+
this._re_extends = {};
|
247
|
+
}
|
248
|
+
if(arguments.length == 1){
|
249
|
+
|
250
|
+
for(var k in d){
|
251
|
+
this._re_extends[k] = d[k];
|
252
|
+
}
|
253
|
+
|
254
|
+
} else {
|
255
|
+
this._re_extends[d] = value;
|
256
|
+
}
|
257
|
+
|
258
|
+
return this;
|
259
|
+
},
|
260
|
+
|
261
|
+
init:function(method){
|
262
|
+
this._checkFinal();
|
263
|
+
|
264
|
+
this._re_init = method;
|
265
|
+
|
266
|
+
return this;
|
267
|
+
},
|
268
|
+
|
269
|
+
dispose:function(method){
|
270
|
+
this._checkFinal();
|
271
|
+
|
272
|
+
this._re_dispose = method;
|
273
|
+
|
274
|
+
return this;
|
275
|
+
},
|
276
|
+
|
277
|
+
/*
|
278
|
+
The lock method prevents modification to the component.
|
279
|
+
|
280
|
+
This is handy to stop unexpected changes to a component.
|
281
|
+
*/
|
282
|
+
lock:function(){
|
283
|
+
this._checkFinal();
|
284
|
+
|
285
|
+
this._re_final = true;
|
286
|
+
|
287
|
+
return this;
|
288
|
+
},
|
289
|
+
|
290
|
+
/*
|
291
|
+
The run method allows a function to be ran in the context
|
292
|
+
of the component.
|
293
|
+
|
294
|
+
Useful to keep everything in one big component.
|
295
|
+
*/
|
296
|
+
run:function(method){
|
297
|
+
this._checkFinal();
|
298
|
+
|
299
|
+
//re.ready(function(){
|
300
|
+
method.call(this);
|
301
|
+
//});
|
302
|
+
|
303
|
+
return this;
|
304
|
+
}
|
305
|
+
|
306
|
+
};
|