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,56 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="X-UA-Compatible" content="chrome=1">
|
6
|
+
<title>Tiles Demo</title>
|
7
|
+
<script language="javascript">
|
8
|
+
//modify path of entity.debug.js
|
9
|
+
path = '../../';
|
10
|
+
</script>
|
11
|
+
<script src="../../lib/entity.debug.js" language="javascript"></script>
|
12
|
+
<script src="tiles.js" language="javascript"></script>
|
13
|
+
|
14
|
+
<link rel="stylesheet" type="text/css" href="../style/sheet.css" />
|
15
|
+
|
16
|
+
</head>
|
17
|
+
|
18
|
+
<body>
|
19
|
+
|
20
|
+
|
21
|
+
<div class="container_24">
|
22
|
+
<div id="content">
|
23
|
+
<h1>Tiles Demo</h1>
|
24
|
+
|
25
|
+
<div class="canvas-container">
|
26
|
+
<canvas id="canvas" width="500" height="400"> </canvas>
|
27
|
+
</div>
|
28
|
+
|
29
|
+
<div class="grid_12">
|
30
|
+
<h2 class="hd-left bg-yellow">Overview</h2>
|
31
|
+
<p>
|
32
|
+
Loads and renders a world from a tile array. View the <a href="tiles.js">source code</a> to see how easy it is to program.
|
33
|
+
</p>
|
34
|
+
</div>
|
35
|
+
|
36
|
+
<div class="grid_12">
|
37
|
+
<h2 class="hd-right bg-yellow">Controls</h2>
|
38
|
+
|
39
|
+
<ul>
|
40
|
+
<li>None</li>
|
41
|
+
|
42
|
+
</ul>
|
43
|
+
|
44
|
+
</div>
|
45
|
+
|
46
|
+
<div class="clear"></div>
|
47
|
+
</div>
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
</div>
|
52
|
+
|
53
|
+
</body>
|
54
|
+
|
55
|
+
|
56
|
+
</html>
|
@@ -0,0 +1,85 @@
|
|
1
|
+
/*
|
2
|
+
This example creates a tile based world from a multi-dimensional array.
|
3
|
+
|
4
|
+
Since tile-based games are popular some helper components have been
|
5
|
+
created. The tile components helps with moving tiles and getting tile
|
6
|
+
coordinates.
|
7
|
+
|
8
|
+
The query system also has a nice method called map which loops
|
9
|
+
through a two-dimensional array.
|
10
|
+
*/
|
11
|
+
|
12
|
+
re.constants = {
|
13
|
+
//enter in tiles from 0-3
|
14
|
+
// 0 is water
|
15
|
+
// 1 is wood wall
|
16
|
+
// 2 is stone wall
|
17
|
+
// 3 is grass
|
18
|
+
map:
|
19
|
+
[
|
20
|
+
[2, 2, 2, 2, 2, 3, 3, 2, 2, 2],
|
21
|
+
[3, 3, 0, 0, 0, 3, 3, 3, 3, 0],
|
22
|
+
[3, 3, 3, 3, 3, 3, 2, 2, 0, 0],
|
23
|
+
[3, 3, 0, 3, 3, 3, 3, 3, 0, 0],
|
24
|
+
[2, 1, 3, 1, 3, 3, 3, 3, 3, 3]
|
25
|
+
],
|
26
|
+
|
27
|
+
canvasId:'#canvas',
|
28
|
+
tileSize:40,
|
29
|
+
assets:'tiles.png'
|
30
|
+
}
|
31
|
+
|
32
|
+
re.ready(function(){
|
33
|
+
|
34
|
+
re.sys.init(re.constants.canvasId).start();
|
35
|
+
|
36
|
+
//setup tile size
|
37
|
+
re.tile.sizeX = re.constants.tileSize;
|
38
|
+
re.tile.sizeY = re.constants.tileSize;
|
39
|
+
|
40
|
+
re.load(re.constants.assets)
|
41
|
+
.complete(function(){
|
42
|
+
|
43
|
+
//load world
|
44
|
+
re.e('level')
|
45
|
+
.load(re.constants.map);
|
46
|
+
|
47
|
+
});
|
48
|
+
|
49
|
+
|
50
|
+
});
|
51
|
+
|
52
|
+
/*
|
53
|
+
The level component loads and handles all tiles in the game.
|
54
|
+
*/
|
55
|
+
re.c('level')
|
56
|
+
.extend({
|
57
|
+
|
58
|
+
//loads given tile map
|
59
|
+
load:function(map){
|
60
|
+
|
61
|
+
var totalTiles = map.length * map[0].length;
|
62
|
+
|
63
|
+
//create tiles
|
64
|
+
//second parameter defines how many entities to create. (default 1)
|
65
|
+
//if count is higher than one it will return a query of all tiles
|
66
|
+
this.tiles = re.e('sprite tile '+re.constants.assets, totalTiles)
|
67
|
+
//returns entities as a two dimensional array
|
68
|
+
//the first value is the width of the array
|
69
|
+
.map(map[0].length, function(x, y){
|
70
|
+
|
71
|
+
//remember to set the crop image size of tiles
|
72
|
+
//or else nothing will appear
|
73
|
+
this.sizeX = re.tile.sizeX;
|
74
|
+
this.sizeY = re.tile.sizeY;
|
75
|
+
|
76
|
+
|
77
|
+
this.setFrameId(map[y][x]);
|
78
|
+
|
79
|
+
this.setTile(x, y);
|
80
|
+
|
81
|
+
});
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
});
|
Binary file
|
data/lib/blank/config.js
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Configure your game settings
|
2
|
+
|
3
|
+
#project name
|
4
|
+
name: mygame
|
5
|
+
|
6
|
+
paths:
|
7
|
+
images: assets/images
|
8
|
+
sounds: assets/sounds
|
9
|
+
levels: assets/levels
|
10
|
+
src: src
|
11
|
+
lib: lib
|
12
|
+
test: tests
|
13
|
+
|
14
|
+
#files to ignore in /src and entity/src
|
15
|
+
#this is useful to ignore unused files
|
16
|
+
ignore:
|
17
|
+
socket
|
18
|
+
|
19
|
+
#although all files are compiled its
|
20
|
+
#useful to include dependent files first
|
21
|
+
order:
|
data/lib/blank/home.js
ADDED
data/lib/blank/init.js
ADDED
data/lib/blank/load.js
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
re.scene('load')
|
2
|
+
.enter(function(){
|
3
|
+
|
4
|
+
re.load(re.images.concat(re.sounds))
|
5
|
+
.complete(function(){
|
6
|
+
console.log('finished loading...')
|
7
|
+
|
8
|
+
//move to home
|
9
|
+
re.scene('home');
|
10
|
+
})
|
11
|
+
.error(function(e){
|
12
|
+
console.log('Error loading asset: '+e);
|
13
|
+
})
|
14
|
+
.progress(function(i){
|
15
|
+
console.log('Finished loading: '+i);
|
16
|
+
});
|
17
|
+
|
18
|
+
})
|
19
|
+
.exit(function(){
|
20
|
+
//exit load scene
|
21
|
+
})
|
data/lib/blank/play.html
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="X-UA-Compatible" content="chrome=1">
|
6
|
+
|
7
|
+
<title>Play</title>
|
8
|
+
|
9
|
+
<script src="lib/entity.debug.js" language="javascript"></script>
|
10
|
+
|
11
|
+
</head>
|
12
|
+
|
13
|
+
<body>
|
14
|
+
|
15
|
+
|
16
|
+
<div id="content">
|
17
|
+
<h1>Play</h1>
|
18
|
+
|
19
|
+
<div class="canvas-container">
|
20
|
+
<canvas id="canvas" width="500" height="400"> </canvas>
|
21
|
+
</div>
|
22
|
+
|
23
|
+
</div>
|
24
|
+
|
25
|
+
|
26
|
+
</body>
|
27
|
+
|
28
|
+
|
29
|
+
</html>
|
data/lib/entity.debug.js
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
/* EntityJS v0.2.2 http://entityjs.com | License http://entityjs.com/license */
|
2
|
+
if(!path) path = '';
|
3
|
+
document.write("<script src='"+path+"src/entityjs/core/re.js' language='javascript'><\/script>");
|
4
|
+
document.write("<script src='"+path+"src/entityjs/core/component.js' language='javascript'><\/script>");
|
5
|
+
document.write("<script src='"+path+"src/entityjs/core/entity.js' language='javascript'><\/script>");
|
6
|
+
document.write("<script src='"+path+"src/entityjs/core/load.js' language='javascript'><\/script>");
|
7
|
+
document.write("<script src='"+path+"src/entityjs/core/query.js' language='javascript'><\/script>");
|
8
|
+
document.write("<script src='"+path+"src/entityjs/core/system.js' language='javascript'><\/script>");
|
9
|
+
document.write("<script src='"+path+"src/entityjs/cycle/draw.js' language='javascript'><\/script>");
|
10
|
+
document.write("<script src='"+path+"src/entityjs/cycle/ticker.js' language='javascript'><\/script>");
|
11
|
+
document.write("<script src='"+path+"src/entityjs/cycle/tween.js' language='javascript'><\/script>");
|
12
|
+
document.write("<script src='"+path+"src/entityjs/cycle/update.js' language='javascript'><\/script>");
|
13
|
+
document.write("<script src='"+path+"src/entityjs/cycle/wait.js' language='javascript'><\/script>");
|
14
|
+
document.write("<script src='"+path+"src/entityjs/cycle/worker.js' language='javascript'><\/script>");
|
15
|
+
document.write("<script src='"+path+"src/entityjs/display/anchor.js' language='javascript'><\/script>");
|
16
|
+
document.write("<script src='"+path+"src/entityjs/display/bitfont.js' language='javascript'><\/script>");
|
17
|
+
document.write("<script src='"+path+"src/entityjs/display/bitmap.js' language='javascript'><\/script>");
|
18
|
+
document.write("<script src='"+path+"src/entityjs/display/circle.js' language='javascript'><\/script>");
|
19
|
+
document.write("<script src='"+path+"src/entityjs/display/font.js' language='javascript'><\/script>");
|
20
|
+
document.write("<script src='"+path+"src/entityjs/display/group.js' language='javascript'><\/script>");
|
21
|
+
document.write("<script src='"+path+"src/entityjs/display/rect.js' language='javascript'><\/script>");
|
22
|
+
document.write("<script src='"+path+"src/entityjs/display/screen.js' language='javascript'><\/script>");
|
23
|
+
document.write("<script src='"+path+"src/entityjs/display/sprite.js' language='javascript'><\/script>");
|
24
|
+
document.write("<script src='"+path+"src/entityjs/input/keyboard.js' language='javascript'><\/script>");
|
25
|
+
document.write("<script src='"+path+"src/entityjs/input/mouse.js' language='javascript'><\/script>");
|
26
|
+
document.write("<script src='"+path+"src/entityjs/input/pressed.js' language='javascript'><\/script>");
|
27
|
+
document.write("<script src='"+path+"src/entityjs/input/touch.js' language='javascript'><\/script>");
|
28
|
+
document.write("<script src='"+path+"src/entityjs/math/bind.js' language='javascript'><\/script>");
|
29
|
+
document.write("<script src='"+path+"src/entityjs/math/bisect.js' language='javascript'><\/script>");
|
30
|
+
document.write("<script src='"+path+"src/entityjs/math/body.js' language='javascript'><\/script>");
|
31
|
+
document.write("<script src='"+path+"src/entityjs/math/drag.js' language='javascript'><\/script>");
|
32
|
+
document.write("<script src='"+path+"src/entityjs/math/hitmap.js' language='javascript'><\/script>");
|
33
|
+
document.write("<script src='"+path+"src/entityjs/math/hittest.js' language='javascript'><\/script>");
|
34
|
+
document.write("<script src='"+path+"src/entityjs/math/physics.js' language='javascript'><\/script>");
|
35
|
+
document.write("<script src='"+path+"src/entityjs/math/point.js' language='javascript'><\/script>");
|
36
|
+
document.write("<script src='"+path+"src/entityjs/math/tile.js' language='javascript'><\/script>");
|
37
|
+
document.write("<script src='"+path+"src/entityjs/media/channel.js' language='javascript'><\/script>");
|
38
|
+
document.write("<script src='"+path+"src/entityjs/media/playlist.js' language='javascript'><\/script>");
|
39
|
+
document.write("<script src='"+path+"src/entityjs/media/sound.js' language='javascript'><\/script>");
|
40
|
+
document.write("<script src='"+path+"src/entityjs/pattern/arraymap.js' language='javascript'><\/script>");
|
41
|
+
document.write("<script src='"+path+"src/entityjs/pattern/flicker.js' language='javascript'><\/script>");
|
42
|
+
document.write("<script src='"+path+"src/entityjs/pattern/timestep.js' language='javascript'><\/script>");
|
43
|
+
document.write("<script src='"+path+"src/entityjs/save/database.js' language='javascript'><\/script>");
|
44
|
+
document.write("<script src='"+path+"src/entityjs/save/storage.js' language='javascript'><\/script>");
|
45
|
+
document.write("<script src='"+path+"src/entityjs/util/log.js' language='javascript'><\/script>");
|
46
|
+
document.write("<script src='"+path+"src/entityjs/util/polyfill.js' language='javascript'><\/script>");
|
47
|
+
document.write("<script src='"+path+"src/entityjs/util/random.js' language='javascript'><\/script>");
|
48
|
+
document.write("<script src='"+path+"src/entityjs/util/scene.js' language='javascript'><\/script>");
|
49
|
+
document.write("<script src='"+path+"src/entityjs/util/sheet.js' language='javascript'><\/script>");
|
50
|
+
document.write("<script src='"+path+"src/entityjs/util/support.js' language='javascript'><\/script>");
|
51
|
+
|
52
|
+
window.onload = function(){ re.version = '0.2.2'; }
|
data/lib/entity.min.js
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
/* EntityJS v0.2.2 http://entityjs.com | License http://entityjs.com/license */
|
2
|
+
re=function(selector){return new re.query(selector);};re.version="0.2.2";re._e=[];re._c={};re.ready=function(r){re.ready.c.push(r);window.onload=function(){for(var k in re.ready.c){re.ready.c[k].call(re);}};};re.ready.c=[];re.$=function(s){return re.$.c[s]=re.$.c[s]||(s.charAt(0)=='#')?document.getElementById(s.substr(1)):document.getElementsByTagName(s);};re.$.c={};re.$new=function(n){return document.createElement(n);};re.listener=function(t,c){if(window.addEventListener){window.addEventListener(t,c,true);}else{document.attachEvent('on'+t,c);}};Function.prototype.context=function(c){var that=this;return function(){return that.apply(c,arguments);};};if(!Array.prototype.indexOf){Array.prototype.indexOf=function(o){for(var i=0;i<this.length;i++){if(this[i]==o){return i;}}
|
3
|
+
return-1;}}
|
4
|
+
var __z=function(n,r){this._checkFinal();if(!this[n]){this[n]=[];}
|
5
|
+
if(typeof r=='string'){this[n]=this[n].concat(r.split(' '));}else{this[n]=this[n].concat(r);}
|
6
|
+
return this;};re.comp=re.c=function(title){if(!re._c[title]){re._c[title]=new re.comp.init(title);}
|
7
|
+
return re._c[title];};re.comp.init=function(name){this.name=name;this._re_signals={};this._re_inherits={};this._re_extends={};this._re_final=false;};re.comp.init.prototype={_checkFinal:function(){if(this._re_final){throw this.name+' is final.';}},global:function(obj,value){this._checkFinal();if(arguments.length==1){for(var type in obj){this[type]=obj[type];}}else{this[obj]=value;}
|
8
|
+
return this;},require:function(r){return __z.call(this,'_re_requires',r);},assert:function(r){return __z.call(this,'_re_asserts',r);},implement:function(r){return __z.call(this,'_re_implments',r);},alias:function(s){this._checkFinal();var p=s.split(' ');if(p.length>1){for(var i in p){this.alias(p[i]);}
|
9
|
+
return this;}
|
10
|
+
if(s.charAt(0)=='-'){if(re._c[s.substr(1)]==this){delete re._c[s.substr(1)];}}else{re._c[s]=this;}
|
11
|
+
return this;},addSignal:function(){return re.e.init.prototype.addSignal.apply(this,arguments);},removeSignal:function(){return re.e.init.prototype.removeSignal.apply(this,arguments);},signal:function(){return re.e.init.prototype.signal.apply(this,arguments);},inherit:function(d,value){this._checkFinal();if(arguments.length==1){for(var k in d){this._re_inherits[k]=d[k];}}else{this._re_inherits[d]=value;}
|
12
|
+
return this;},namespace:function(obj,value){this._checkFinal();var name=this.name+'_';if(arguments.length==1){for(var k in obj){this._re_extends[name+k]=obj[k];}}else{this._re_extends[name+obj]=value;}
|
13
|
+
return this;},extend:function(d,value){this._checkFinal();if(!this._re_extends){this._re_extends={};}
|
14
|
+
if(arguments.length==1){for(var k in d){this._re_extends[k]=d[k];}}else{this._re_extends[d]=value;}
|
15
|
+
return this;},init:function(method){this._checkFinal();this._re_init=method;return this;},dispose:function(method){this._checkFinal();this._re_dispose=method;return this;},lock:function(){this._checkFinal();this._re_final=true;return this;},run:function(method){this._checkFinal();method.call(this);return this;}};(function(re){var q=function(c,count){if(!count){return new re.entity.init(c);}
|
16
|
+
var q=re();for(var i=0;i<count;i++){q._e.push(re.e(c));}
|
17
|
+
return q;};q.id=0;var e=function(c){this._re_comps=[];this._re_signals={};this.id=q.id+'';q.id++;re._e.push(this);this.addComp(c);};var p=e.prototype;p.id='';p.addComp=function(com){this._re_comp(com);if(this._re_interface){for(var i in this._re_interface){if(!this.hasOwnProperty(this._re_interface[i])){throw'implementation: '+this._re_interface[i]+' missing';}}}
|
18
|
+
if(this._re_asserts){for(var t in this._re_asserts){if(this._re_comps.indexOf(c._re_asserts[t])!=-1){throw'assert: '+c.name+' cannot be coupled with '+c._re_asserts[t];}}}
|
19
|
+
return this;};p.removeComp=function(com){var pieces;if(typeof com=='object'){pieces=com;com=com[0];}else{pieces=com.split(' ');}
|
20
|
+
if(pieces.length>1){for(var k in pieces){this._re_comp(pieces[k]);}
|
21
|
+
return this;}
|
22
|
+
var c=re._c[com];if(!this.has(com))return this;this._re_comps.splice(this._re_comps.indexOf(com),1);if(c){if(c._re_dispose){c._re_dispose.call(this,c);}
|
23
|
+
c.signal('dispose',this);}};p._re_comp=function(com){if(!com)return this;var pieces;if(typeof com=='object'){pieces=com;com=com[0];}else{pieces=com.split(' ');}
|
24
|
+
if(pieces.length>1){for(var k in pieces){this._re_comp(pieces[k]);}
|
25
|
+
return this;}
|
26
|
+
var c;var vals=com.split(':');com=vals[0];c=re._c[com];vals[0]=c;if(this.has(com))return this;this._re_comps.push(com);if(c){this._re_comp(c._re_requires);if(c._re_implements){if(!this._re_implements){this._re_implements=[];}
|
27
|
+
this._re_implements=this._re_implements.concat(c._re_implements);}
|
28
|
+
if(c._re_asserts){if(!this._re_asserts){this._re_asserts=[];}
|
29
|
+
this._re_asserts=this._re_asserts.concat(c._re_asserts);}
|
30
|
+
if(c._re_inherits){this.inherit(c._re_inherits);}
|
31
|
+
if(c._re_extends){this.extend(c._re_extends);}
|
32
|
+
if(c._re_init){c._re_init.apply(this,vals);}
|
33
|
+
c.signal('init',this);}
|
34
|
+
return this;}
|
35
|
+
p.getComps=function(){return this._re_comps.slice();}
|
36
|
+
p.clone=function(count){return re.e(this._re_comps,count);}
|
37
|
+
p.parent=function(comp,method){var a=Array.prototype.slice.call(arguments,2);if(comp==''){re.e.init[method].apply(this,a);}
|
38
|
+
var c=re._c[comp];if(c._re_extends[method]){return c._re_extends[method].apply(this,a);}
|
39
|
+
if(c._re_inherits[method]){return c._re_inherits[method].apply(this,a);}
|
40
|
+
return this;}
|
41
|
+
p.has=function(comp){if(typeof comp=='string'){comp=re.query._toObj(comp);}
|
42
|
+
comp.comp=comp.comp||[];comp.id=comp.id||'';comp.signal=comp.signal||[];comp.not=comp.not||[];for(p=0;p<comp.comp.length;p++){if(this._re_comps.indexOf(comp.comp[p])==-1){return false;}}
|
43
|
+
for(p=0;p<comp.not.length;p++){if(this._re_comps.indexOf(comp.not[p])!=-1){return false;}}
|
44
|
+
var s;for(p=0;p<comp.signal.length;p++){s=comp.signal[p];if(!this._re_signals[s]||this._re_signals[s].length==0){return false;}}
|
45
|
+
if(comp.id!=''&&this.id!=comp.id){return false;}
|
46
|
+
return true;};p.addSignal=function(type,method){if(typeof type=='object'){for(var k in type){this.addSignal(k,type[k]);}}else{if(!this._re_signals[type]){this._re_signals[type]=[];}
|
47
|
+
this._re_signals[type].push(method);}
|
48
|
+
return this;};p.removeSignal=function(type,method){if(typeof type=='object'){for(var k in type){this.removeSignal(k,type[k]);}}else{if(typeof method=='function'){for(var k in this._re_signals[type]){if(this._re_signals[type][k]==method){this._re_signals[type].splice(k,1);}}}else{this._re_signals[type]=[];}}
|
49
|
+
return this;};p.signal=function(type){if(!this._re_signals[type])return this;var b;for(var i=0,l=this._re_signals[type].length;i<l;i++){b=this._re_signals[type];if(!b[i])continue;if(b[i].apply((b[i].c)?b[i].c:this,Array.prototype.slice.call(arguments,1))===false){b.splice(i,1);}}
|
50
|
+
return this;};p.extend=function(obj,value){var a=typeof obj;if(a=='object'){for(var key in obj){if(!obj.hasOwnProperty(key))continue;this.extend(key,obj[key]);}}else{this[obj]=value;}
|
51
|
+
return this;}
|
52
|
+
p.inherit=function(obj,value){if(typeof obj=='object'){for(var key in obj){if(!obj.hasOwnProperty(key))continue;this.inherit(key,obj[key]);}}else{if(!this.hasOwnProperty(obj)||typeof this[obj]!=typeof value){this[obj]=value;}}
|
53
|
+
return this;}
|
54
|
+
p.dispose=function(){re._e.splice(re._e.indexOf(this),1);for(var i in this._re_comps){var k=re.c(this._re_comps[i]);if(k._re_dispose){k._re_dispose.call(this,k);}
|
55
|
+
k.signal('dispose',this);}
|
56
|
+
this.signal('dispose');return this;}
|
57
|
+
re.entity=re.e=q;re.entity.init=e;}(re));(function(re){var b=function(assets){return new re.load.init(assets);}
|
58
|
+
b.path="";b.imageExt='img';b.soundExt='sfx';b.images=['gif','jpg','jpeg','png'];b.sounds=['wav','mp3','aac','ogg'];var l=function(assets){if(typeof assets=='string'){this.assets=assets.split(' ');}else{this.assets=assets;}
|
59
|
+
var a;for(var i=0;i<this.assets.length;i++){this.total++;a=this.assets[i];var j=a.lastIndexOf('.')+1;var ext=a.substr(j).toLowerCase();var s=a;var d=a.lastIndexOf('/');if(d!=-1){a=a.substr(d+1,a.length);}
|
60
|
+
var n=a.substr(0,j);if(re.load.images.indexOf(ext)!=-1){this._loadImg(s,a,n);}else if(re.load.sounds.indexOf(ext)!=-1){if(!re.support||re.support(ext)){this._loadSound(s,a,n);}}}
|
61
|
+
return this;}
|
62
|
+
var p=l.prototype;p.current=0;p.total=0;p._loadImg=function(src,a,n){var that=this;var img=new Image();re.c(a).alias(n+re.load.imgExt).global({bitmap:img}).extend({bitmap:img});img.onload=function(){re.c(a).extend({bisect:img.width,sizeX:img.width,sizeY:img.height});that.current++;if(that._p){that._p.call(that,that.current,that.total,a);}
|
63
|
+
if(that.current>=that.total){if(that._s){that._s.call(that,that.assets);}}};img.onerror=function(){if(that._e){that._e.call(that,a);}};img.src=re.load.path+src;return this;}
|
64
|
+
p._loadSound=function(src,a,n){var that=this;var s=new Audio(re.load.path+src);s.preload="auto";s.load();re.c(a).alias(n+re.load.soundExt).global({sound:s}).extend({sound:s});s.addEventListener('canplaythrough',function(){that.current++;if(that._p){that._p.call(that,that.current,that.total,a);}
|
65
|
+
if(that.current>=that.total){if(that._s){that._s.call(that,that.assets);}}},false);s.addEventListener('error',function(){if(that._e){that._e.call(that,a);}},false);}
|
66
|
+
p.progress=function(m){this._p=m;return this;}
|
67
|
+
p.complete=function(m){this._s=m;return this;}
|
68
|
+
p.error=function(m){this._e=m;return this;}
|
69
|
+
re.load=b;re.load.init=l;}(re));(function(re){var q=function(selector){this._e=[];if(selector){this.query(selector);}}
|
70
|
+
q._toObj=function(query){if(q.c[query]){return q.c[query];}
|
71
|
+
var temp=query.split(' ');var comps=[];var signals=[];var minus=[];var id='';var fl;var val;for(var j=0;j<temp.length;j++){fl=temp[j].charAt(0);val=temp[j].substr(1);if(fl=='^'){signals.push(val);}else if(fl=='-'){minus.push(val);}else if(fl=='#'){id=val;}else{comps.push(temp[j]);}}
|
72
|
+
var comp={comp:comps,signal:signals,not:minus,id:id};q.c[query]=comp;return comp;}
|
73
|
+
q.c={};var p=q.prototype;p.query=function(select){select=select||'';var i=0;if(typeof select=='string'){if(select=='*'){this._e=re._e.slice();return this;}
|
74
|
+
var obj=q._toObj(select);var en;main:for(;i<re._e.length;i++){en=re._e[i];if(en.has(obj)){this._e.push(en);}}}else if(typeof select=='function'){for(;i<re._e.length;i++){if(select.call(re._e[i],i,re._e.length)){this._e.push(re._e[i]);}}}
|
75
|
+
return this;}
|
76
|
+
p.toArray=function(){return this._e.slice();}
|
77
|
+
p.method=function(m){var b=Array.prototype.slice.call(arguments,1);this.each(function(){this[m].apply(this,b);});return this;}
|
78
|
+
p.each=function(m){var l=this._e.length,i=-1,e;while(++i<l&&(e=this._e[i])&&m.call(e,i,l)!==false);return this;}
|
79
|
+
p.map=function(w,method){var x=0;var y=0;for(var i=0,l=this._e.length;i<l;i++){if(method.call(this._e[i],x,y,i,l)==false)break;x++;if(x==w){x=0;y++;}}}
|
80
|
+
p.getComps=function(){var l=[];this.each(function(){l.concat(this.getComps());});return l;}
|
81
|
+
p.random=function(){return this._e[~~(Math.random()*this._e.length)];}
|
82
|
+
p.pluck=function(value){var t=[];var k=value.split(' ');this.each(function(){var o={};for(var p in k){if(k.hasOwnProperty(p)){o[k[p]]=this[k[p]];}}
|
83
|
+
t.push(o);});return t;}
|
84
|
+
p.extend=function(obj,value){this.each(function(){this.extend(obj,value);});return this;}
|
85
|
+
p.inherit=function(obj,value){this.each(function(){this.inherit(obj,value);});return this;}
|
86
|
+
p.addComp=function(c){this.each(function(ref){this.addComp(c);});return this;}
|
87
|
+
p.removeComp=function(c){this.each(function(ref){this.removeComp(c);});}
|
88
|
+
p.signal=function(type,method){var p=arguments;this.each(function(ref){this.signal.apply(this,p);});return this;}
|
89
|
+
p.length=function(){return this._e.length;}
|
90
|
+
p.filter=function(method){var q=re();var that=this;this.each(function(i,l){if(method.call(this,i,l)){q.push(this);}});return q;}
|
91
|
+
p.has=function(comp){for(var i=0;i<this._e.length;i++){if(!this._e.has(comp)){return false;}}
|
92
|
+
return this;}
|
93
|
+
p.dispose=function(){this.each(function(){this.dispose();});return this;}
|
94
|
+
p.get=function(index){return this._e[index];}
|
95
|
+
p.put=function(entity){this._e.push(entity);return this;}
|
96
|
+
re.query=q;}(re));re.c('system').inherit({contextType:'2d',clearColor:'#f9f9f9',stepSize:0.03,running:false,sizeX:0,sizeY:0}).extend({clear:function(color){if(color){this.context.fillStyle=color;this.context.fillRect(0,0,this.sizeX,this.sizeY);}else{this.context.clearRect(0,0,this.sizeX,this.sizeY);}
|
97
|
+
return this;},start:function(){if(!this.running){this.running=true;var that=this;(function mainLoop(){that.system_loop.call(that);if(that.running){that.requestAnimationFrame(mainLoop,that.canvas);}})();}
|
98
|
+
return this;},loop:function(m){this.system_loop=m;return this;},stop:function(){this.running=false;return this;},init:function(canvasId,screen,contextType){this.addComp('polyfill ticker timestep');this.canvas=re.$(canvasId);this.contextType=contextType||this.contextType;this.context=this.canvas.getContext(this.contextType);this.sizeX=this.canvas.width;this.sizeY=this.canvas.height;screen=screen||re.screen;if(screen){screen.sizeX=this.sizeX;screen.sizeY=this.sizeY;screen.regX=this.sizeX*0.5;screen.regY=this.sizeY*0.5;}
|
99
|
+
return this;},system_loop:function(){this.timestep(this.tick(),function(){re._c.update.update.call(re._c.update,this,this.stepSize);});this.clear(this.clearColor);re._c.draw.draw.call(re._c.draw,this);}}).run(function(){re.system=re.sys=re.e('system');});re.c('draw').global({listeners:[],draw:function(s){var l=this.listeners;for(var k=0,le=l.length,b;k<le;++k){b=l[k];if(b&&b.sys==s&&b.drawing&&b.isVisible()){b.draw_render(s.context);}}}}).implement('draw').init(function(c){c.listeners.push(this);this.screen=re.screen;}).dispose(function(c){c.listeners.splice(c.listeners.indexOf(this),1);}).inherit({sys:re.sys,drawing:true,rotation:0,alpha:1,scaleX:1,scaleY:1,posX:0,posY:0,sizeX:1,sizeY:1,regX:0,regY:0}).extend({cache:function(){if(!this.image)return this;this.clearCache();var c=re.$new('canvas');var s=Math.max(this.image.width,this.image.height);c.width=s;c.height=s;this.draw_render(c.getContext(re.sys.contextType));this.canvasCache=c;return this;},clearCache:function(){this.canvasCache=null;},drawFirst:function(){var l=re.c('draw').listeners;l.splice(l.indexOf(this),1);l.unshift(this);return this;},drawLast:function(){var l=re.c('draw').listeners;l.splice(l.indexOf(this),1);l.push(this);return this;},drawAfter:function(en){var l=re.c('draw').listeners;var him=l.indexOf(en);var me=l.indexOf(this);if(him>me){var t=l[him];l[him]=l[me];l[me]=t;}
|
100
|
+
return this;},drawBefore:function(en){var l=re.c('draw').listeners;var him=l.indexOf(en);var me=l.indexOf(this);if(him<me){var t=l[him];l[him]=l[me];l[me]=t;}
|
101
|
+
return this;},getScreenX:function(){var x=this.posX;if(this.screen)x-=this.screen.posX;return x;},getScreenY:function(){var y=this.posY;if(this.screen)y-=this.screen.posY;return y;},isVisible:function(){return(!this.screen||this.screen.touches(this.posX-this.regX,this.posY-this.regY,this.sizeX,this.sizeY));}}).namespace({render:function(c){if(!c)c=this.sys.context;this.draw_before(c);this.draw(c);this.draw_after(c);},before:function(c){c.save();if(this.alpha!=1)
|
102
|
+
c.globalAlpha=this.alpha;c.translate(this.getScreenX(),this.getScreenY());if(this.rotation!=0)
|
103
|
+
c.rotate(this.rotation*Math.PI/180);if(this.scaleX!=1||this.scaleY!=1)
|
104
|
+
c.scale(this.scaleX,this.scaleY);},after:function(c){c.restore();}});re.c('ticker').inherit({time:0,maxTick:0.05}).init(function(){this.lastTime=Date.now();}).extend({tick:function(){var wall=Date.now();var delta=(wall-this.lastTime)/1000;this.lastTime=wall;var timeDelta=Math.min(delta,this.maxTick);this.time+=timeDelta;return timeDelta;}});re.c('tween').require('update').global({tween:function(obj,time,props){return obj.comp('tween').tween(time,props);}}).namespace({update:function(t){}}).inherit({tweening:false}).extend({tween:function(time,props){this.time=time||5;if(this.tweening){this.removeSignal('update',this.tween_update);}
|
105
|
+
for(var i in props){if(!props.hasOwnProperty(i))continue;this.tween_props[i]={s:re.sys.stepSize,i:props[i]};}
|
106
|
+
return this;}}).init(function(){this.tween_props={};});re.tween=re.c('tween').tween;re.c('update').global({listeners:[],update:function(s,t){var l=this.listeners;for(var k=0,le=l.length,b;k<le;++k){b=l[k];if(b&&b.sys==s&&b.updating){b.signal('update',t,s.time);}}}}).inherit({updating:true,sys:re.sys}).extend(function(){var l=re.c('update').listeners;return{updateFirst:function(){l.splice(l.indexOf(this),1);l.unshift(this);return this;},updateLast:function(){l.splice(l.indexOf(this),1);l.push(l);return this;},updateAfter:function(e){var him=l.indexOf(e);var me=l.indexOf(this);if(him>me){var t=l[him];l[him]=l[me];l[me]=t;}
|
107
|
+
return this;},updateBefore:function(e){var him=l.indexOf(e);var me=l.indexOf(this);if(him<me){var t=l[him];l[him]=l[me];l[me]=t;}
|
108
|
+
return this;}};}()).init(function(c){c.listeners.push(this);}).dispose(function(c){c.listeners.splice(c.listeners.indexOf(this),1);});re.c('wait').require('update').extend({wait:function(time,callback){var c=0;this.addSignal('update',function(t){c+=t;if(c>=time){this.callback.apply(this,Array.prototype.slice.call(arguments,2));return false;}});}});re.c('anchor').extend({centerX:function(o){o=o||0;this.posX=Math.floor(re.sys.sizeX*0.5-this.sizeX*0.5+o);return this;},centerY:function(o){o=o||0;this.posY=Math.floor(re.sys.sizeY*0.5-this.sizeY*0.5+o);return this;},right:function(x){x=x||0;this.posX=Math.floor(re.sys.sizeX-this.sizeX+x);return this;},left:function(x){x=x||0;this.posX=Math.floor(x);return this;},top:function(y){y=y||0;this.posY=Math.floor(y);return this;},bottom:function(y){y=y||0;this.posY=Math.floor(re.sys.sizeY-this.sizeY+y);return this;}}).inherit({sizeX:0,sizeY:0,posX:0,posY:0});re.c('bitfont').require('draw').inherit({text:'',charOffset:32}).extend({isVisible:function(){return this.text.length!=0&&this.bitmap&&this.parent('draw','isVisible');},draw:function(c){var slot=0,charWidth,code,charPos;for(var i=0,l=this.text.length;i<l;++i){code=this.text.charCodeAt(i)-this.charOffset;charWidth=this.charWidths[code];if(!this.charCache[code]){charPos=0;for(var p=0;p<code;++p){charPos+=this.charWidths[p]+1;}
|
109
|
+
this.charCache[code]=charPos;}
|
110
|
+
c.drawImage(this.bitmap,this.charCache[code],0,charWidth,this.bitmap.height,-this.regX+slot,-this.regY,charWidth,this.bitmap.height);slot+=charWidth;}
|
111
|
+
this.sizeX=slot;this.sizeY=this.bitmap.height;},updateSize:function(){var t=0;for(var p=0;p<this.text.length;p++){t+=this.charWidths[p];}
|
112
|
+
this.sizeX=t;if(this.bitmap){this.sizeY=this.bitmap.height;}else{this.sizeY=0;}
|
113
|
+
return this;},setText:function(text){this.text=text;this.updateSize();return this;}}).init(function(){if(!this.charCache){this.charCache={};}
|
114
|
+
this.updateSize();});re.c('bitmap').require('draw').extend({setBitmap:function(b){this.bitmap=b;if(b){this.sizeX=b.width;this.sizeY=b.height;}
|
115
|
+
return this;},isVisible:function(){return this.bitmap&&this.parent('draw','isVisible');},draw:function(c){c.drawImage(this.bitmap,-this.regX,-this.regY,this.sizeX,this.sizeY);return this;}}).init(function(){if(this.bitmap){this.setBitmap(this.bitmap);}});re.c('circle').require('draw').inherit({color:'#82d5f4'}).extend({draw:function(c){c.fillStyle=this.color;c.beginPath();c.arc(-this.regX,-this.regY,this.sizeX,0,Math.PI*2,true);c.closePath();c.fill();},setRadius:function(r){this.sizeX=this.sizeY=r;return this;}});re.c('font').require('draw').inherit({font:"14px sans-serif",textColor:'#000000',textAlign:'',text:''}).extend({isVisible:function(){return this.text.length!=0;},setText:function(t){this.text=t;return this;},draw:function(c){c.font=this.font;c.fillStyle=this.textColor;c.fillText(this.text,-this.regX,-this.regY);}});re.c('group').inherit({posX:0,posY:0}).extend({group:function(){for(var i=0;i<arguments.length;i++){arguments[i].comp('group').group}},ungroup:function(e){},getScreenX:function(){var x=this.posX;if(this.group)x+=this.group.posX;if(this.screen)x+=this.screen.posX;return x;},getScreenY:function(){var y=this.posY;if(this.group)y+=this.group.posY;if(this.screen)y+=this.screen.posY;return y;},getGroupX:function(){var x=this.posX;if(this.group){x+=this.group.posX;}
|
116
|
+
return x;},getGroupY:function(){var y=this.posY;if(this.group){y+=this.group.posY;}
|
117
|
+
return y;},setGroupX:function(x){},setGroupY:function(y){}});re.c('rect').require('draw').inherit({color:'#82d5f4'}).extend({draw:function(c){c.fillStyle=this.color;c.fillRect(-this.regX,-this.regY,this.sizeX,this.sizeY);}});re.c('screen').require('hittest').extend({setPos:function(x,y){if(arguments.length==1){y=x.posY;x=x.posX;}
|
118
|
+
this.posX=x-this.regX;this.posY=y-this.regY;return this;},toScreenX:function(x){return x+this.posX+this.offX;},toScreenY:function(y){return y+this.posY+this.offY;}}).inherit({posX:0,posY:0,regX:0,regY:0,sizeX:0,sizeY:0,offX:0,offY:0});re.c('sprite').require('bitmap bisect').inherit({frameX:0,frameY:0}).extend({setFrameId:function(id){this.frameX=this.biToXt(id);this.frameY=this.biToYt(id);return this;},getFrameId:function(){return this.toBi(this.frameX,this.frameY);},draw:function(c){c.drawImage(this.bitmap,this.frameX*this.sizeX,this.frameY*this.sizeY,this.sizeX,this.sizeY,-this.regX,-this.regY,this.sizeX,this.sizeY);return this;},flick:function(c){this.setFrameId(c);}});re.c('keyboard').global({listeners:[],keyCodes:{65:'a',66:'b',67:'c',68:'d',69:'e',70:'f',71:'g',72:'h',73:'i',74:'j',75:'k',76:'l',77:'m',78:'n',79:'o',80:'p',81:'q',82:'r',83:'s',84:'t',85:'u',86:'v',87:'w',88:'x',89:'y',90:'z',48:'0',49:'1',50:'2',51:'3',52:'4',53:'5',54:'6',55:'7',56:'8',57:'9',112:'f1',113:'f2',114:'f3',115:'f4',116:'f5',117:'f6',118:'f7',119:'f8',120:'f9',121:'f10',122:'f11',123:'f12',16:'shift',17:'ctrl',18:'alt',24:'cmd',255:'fn',8:'backspace',13:'enter',32:'space',27:'esc',9:'tab',20:'capslock',91:'windows',46:'delete',36:'home',35:'end',33:'pageup',34:'pagedown',37:'left',38:'up',39:'right',40:'down',96:'`',45:'-',187:'=',219:'[',221:']',220:'\\',59:';',222:"'",188:',',190:'.',191:'/'},keyboardEvent:function(e){var that=re.c('keyboard');if(that.body!=document.activeElement){return;}
|
119
|
+
var c=e.keyCode||e.which;var key=that.keyCodes[c];if(re.c('pressed').preventDefault&&re.c('pressed').preventDefault[key]){if(e.preventDefault)
|
120
|
+
e.preventDefault();else
|
121
|
+
e.returnValue=false;}
|
122
|
+
if(re.c('pressed')._pressed){re.c('pressed')._pressed[key]=(e.type=='keydown');}
|
123
|
+
for(var k=0;k<that.listeners.length;k++){that.listeners[k].signal(e.type,key,e).signal(e.type+':'+key,key,e);}},active:false,initListeners:function(){if(!this.active){this.active=true;re.listener('keydown',this.keyboardEvent,false);re.listener('keyup',this.keyboardEvent,false);this.body=re.$('body')[0];}}}).init(function(c){c.initListeners();c.listeners.push(this);}).dispose(function(c){c.listeners.splice(c.listeners.indexOf(this),1);});re.c('mouse').global({listeners:[],mouseAction:function(e){var b;if(e.which==null){if(e.button<2){b='left';}else if(e.button==4){b='middle';}else{b='right';}}else{if(e.which<2){b='left';}else if(e.which==2){b='middle';}else{b='right';}}
|
124
|
+
b='mouse:'+b;if(re.c('pressed')._pressed){re.c('pressed')._pressed[b]=(e.type=='mousedown');}
|
125
|
+
var c=false;if(re.c('pressed').preventDefault){if(re.c('pressed').preventDefault[b]){if(e.preventDefault)
|
126
|
+
e.preventDefault();else
|
127
|
+
e.returnValue=false;c=true;}}
|
128
|
+
re.c('mouse').mouseEvent(e);if(c)return false;},mouseEvent:function(e){var x;var y;if(e.pageX||e.pageY){x=e.pageX;y=e.pageY;}else{x=e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft;y=e.clientY+document.body.scrollTop+document.documentElement.scrollTop;}
|
129
|
+
if(re.sys.canvas){x-=re.sys.canvas.offsetLeft;y-=re.sys.canvas.offsetTop;}
|
130
|
+
if(x<0||y<0||y>re.sys.sizeY||x>re.sys.sizeX){return;}
|
131
|
+
var that=re.c('mouse');var c,t,sx,sy;for(var i=0,l=that.listeners.length;i<l;i++){t=that.listeners[i];if(t.toScreen&&t.screen){sx=t.screen.toScreenX(x);sy=t.screen.toScreenY(y);}else{sx=x;sy=y;}
|
132
|
+
t.signal(e.type,sx,sy,e);}},active:false,initListeners:function(){if(!this.active){this.active=true;re.listener('mousedown',this.mouseAction,false);re.listener('mouseup',this.mouseAction,false);re.listener('mousemove',this.mouseEvent,false);re.listener('click',this.mouseEvent,false);re.listener('dblclick',this.mouseEvent,false);re.listener('contextmenu',this.mouseEvent,false);}}}).inherit({toScreen:false}).init(function(c){c.initListeners();c.listeners.push(this);}).dispose(function(c){c.listeners.splice(c.listeners.indexOf(this),1);});re.c('pressed').global({_pressed:{},preventDefault:{}}).extend({pressed:function(){return re.pressed.apply(this,arguments);},preventDefault:function(){re.preventDefault.apply(this,arguments);return this;}}).init(function(){re._c.keyboard.initListeners();re._c.mouse.initListeners();re._c.touch.initListeners();});re.pressed=function(key){var that=re.c('pressed');var c=arguments;if(typeof key=='object')c=key;for(var i=0;i<c.length;i++){if(that._pressed[c[i]]){return true;}}
|
133
|
+
return false;};re.preventDefault=function(key){var p=key.split(' ');if(p.length>1){for(var k in p){this.preventDefault(p[k]);}
|
134
|
+
return this;}
|
135
|
+
re.c('pressed').preventDefault[key]=true;return this;};re.c('touch').global({touchEvent:function(e){},active:false,initListeners:function(){if(!this.active){this.active=true;re.listener('touchstart',this.touchEvent,false);re.listener('touchmove',this.touchEvent,false);re.listener('touchend',this.touchEvent,false);}}}).init(function(c){c.initListeners();});re.c('bind').require('update').namespace({update:function(){if(!this.bind)return;if(this.posX<this.bindMinX){this.posX=this.bindMinX;}else if(this.posX>this.bindMaxX){this.posX=this.bindMaxX;}
|
136
|
+
if(this.posY<this.bindMinY){this.posY=this.bindMinY;}else if(this.posY>this.bindMaxY){this.posY=this.bindMaxY;}}}).inherit({posX:0,posY:0,bindMinX:0,bindMinY:0,bindMaxX:10,bindMaxY:10,bind:true}).extend({setBind:function(minx,miny,maxx,maxy){this.bindMinX=minx;this.bindMinY=miny;this.bindMaxX=maxx;this.bindMaxY=maxy;return this;}}).init(function(){this.addSignal('update',this.bind_update);}).dispose(function(){this.removeSignal('update',this.bind_update);});re.bisect=re.c('bisect').global({biToX:function(bi,width,size){return this.biToXt(bi,width)*size;},biToY:function(bi,width,size){return this.biToYt(bi,width)*size;},biToXt:function(bi,width,size){return Math.floor(bi%(width/size));},biToYt:function(bi,width,size){return Math.floor((bi*size)/(width-0.1));},toBi:function(xt,yt,w,s){return(xt+(yt*(w/s)))/s;}}).extend({biToX:function(bi){return this.biToXt(bi,this.bisect)*this.sizeX;},biToY:function(bi){return this.biToYt(bi,this.bisect)*this.sizeY;},biToXt:function(bi){return Math.floor(bi%(this.bisect/this.sizeX));},biToYt:function(bi){return Math.floor((bi*this.sizeY)/(this.bisect-0.1));},toBi:function(xt,yt){return(xt+(yt*(this.bisect/this.sizeX)))/this.sizeX;}}).inherit({bisect:1,sizeX:1,sizeY:1});re.c('body').extend({touches:function(x,y,w,h){return!(x>this.posX+this.bodX-this.padX||x+w<this.posX+this.padX||y>this.posY+this.bodY-this.padY||y+h<this.posY+this.padY);},touchesBody:function(x,y,bx,by,px,py){return!(x+px>this.posX+this.bodX+this.padX||x+bx-px<this.posX+this.padX||y+py>this.posY+this.bodY-this.padY||y+by-py<this.posY+this.padY);}}).inherit({padX:0,padY:0,bodX:1,bodY:1});re.c('drag').inherit({posX:0,posY:0,dragX:0,dragY:0,dragging:false}).extend({startDrag:function(x,y){if(!this.dragging){this.dragging=true;this.dragX=x;this.dragY=y;}},endDrag:function(){this.dragging=false;},updateDrag:function(x,y){if(this.dragging){this.posX+=x-this.dragX;this.posY+=y-this.dragY;this.dragX=x;this.dragY=y;}}});re.c('hitmap').require('arraymap').extend({hitValue:1,checkAxisX:function(value,x,y,vx,vy){return value==this.hitValue;},checkAxisY:function(value,x,y,vx,vy){return value==this.hitValue;},checkHit:function(posX,posY,velX,velY,bodX,bodY,padX,padY){if(arguments.length==1){var velX=posX.velX;var velY=posX.velY;var bodX=posX.bodX;var bodY=posX.bodY;var padX=posX.padX;var padY=posX.padY;var posY=posX.posY;posX=posX.posX;}
|
137
|
+
var res={posX:posX,posY:posY,tarX:-1,tarY:-1};var step=~~(Math.max(Math.abs(velX),Math.abs(velY))/((re.tile.sizeX+re.tile.sizeY)*0.5)+0.5);if(step>1){var sx=velX/step;var sy=velY/step;for(var i=0;i<step&&(sx||sy);i++){this.hitmap_step(res,posX,posY,sx,sy,bodX,bodY,padY,padY);if(res.hitX){sx=0;}
|
138
|
+
if(res.hitY){sy=0;}}}else{this.hitmap_step(res,posX,posY,velX,velY,bodX,bodY,padX,padY);}
|
139
|
+
return res;}}).namespace({step:function(res,x,y,vx,vy,width,height,padx,pady){res.posX+=vx;res.posY+=vy;var t,ty,tx;if(vx){t=re.tile.sizeX;var offsetx=(vx>0?width-padx:padx);var firsty=Math.floor((y+pady)/t);var lasty=Math.ceil((y+height-pady)/t);tx=Math.floor((x+vx+offsetx)/t);var offx=(vx<0?t:0);if(tx>=0&&tx<this.lengthX&&lasty>=0&&firsty<this.lengthY){for(ty=firsty;ty<lasty;ty++){if(this.map[ty]){this.signal('hit',this.map[ty][tx],tx,ty);if(this.checkAxisX(this.map[ty][tx],x,y,vx,vy)){res.hitX=true;res.posX=tx*t+offx-offsetx;res.tarX=tx*t;res.tarY=ty*t;break;}}}}}
|
140
|
+
if(vy){t=re.tile.sizeY;var offsety=(vy>0?height-pady:pady);var firstx=Math.floor((res.posX+padx)/t);var lastx=Math.ceil((res.posX+width-padx)/t);ty=Math.floor((y+vy+offsety)/t);var offy=(vy<0?t:0);if(ty>=0&&ty<this.lengthY&&lastx>=0&&firstx<this.lengthX){for(tx=firstx;tx<lastx;tx++){if(this.map[ty]){this.signal('hit',this.map[ty][tx],tx,ty);if(this.checkAxisY(this.map[ty][tx],x,y,vx,vy)){res.hitY=true;res.posY=ty*t+offy-offsety;res.tarX=tx*t;res.tarY=ty*t;break;}}}}}}});re.c('hittest').inherit({posX:0,posY:0,sizeX:0,sizeY:0,touches:function(x,y,w,h){return!(x>this.posX+this.sizeX||x+w<this.posX||y>this.posY+this.sizeY||y+h<this.posY);}});re.physics=re.c('physics').require('update').global({graX:0,graY:0,minVel:0.01}).inherit({posX:0,posY:0,velX:0,velY:0,velMaxX:100,velMaxY:100,friX:0.9,friY:0.4,accX:0,accY:0,resX:0,resY:0,masX:1,masY:1,padX:0,padY:0,bodX:1,bodY:1}).namespace({update:function(t){this.velX=this.force(this.velX,this.accX,this.friX,this.graX,this.masX,this.velMaxX);this.velY=this.force(this.velY,this.accY,this.friY,this.graY,this.masY,this.velMaxY);if(this.hitmap){this.aftermath(this.hitmap.checkHit(this));}else{this.aftermath(this.posX+this.velX,this.posY+this.velY);}}}).extend({aftermath:function(posx,posy,hitx,hity,tarx,tary){if(arguments.length==1){hitx=posx.hitX;hity=posx.hitY;tarx=posx.tarX;tary=posx.tarY;posy=posx.posY;posx=posx.posX;}
|
141
|
+
this.posX=posx;this.posY=posy;this.signal('aftermath',hitx,hity,tarx,tary);if(hitx){this.velX=this.forceRes(this.velX,this.resX);}
|
142
|
+
if(hity){this.velY=this.forceRes(this.velY,this.resY);}},forceRes:function(vel,res){return vel*-res;},forceGra:function(gra,mas){return gra*mas;},forceVel:function(vel,acc,fri){return(vel+acc)*fri;},force:function(vel,acc,fri,gra,mas,max){var v=this.forceVel(vel,acc,fri)+this.forceGra(gra,mas);v=Math.min(max,Math.max(-max,v));if(Math.abs(v)<re.physics.minVel){v=0;}
|
143
|
+
return v;},isIdle:function(){return(this.velY==0&&this.velX==0&&this.accX==0&&this.accY==0);}}).init(function(c){this.hitmap=re.hitmap;this.graX=c.graX;this.graY=c.graY;this.addSignal('update',this.physics_update);}).dispose(function(){this.removeSignal('update',this.physics_update);});re.c('point').inherit({posX:0,posY:0}).extend({setPos:function(x,y){if(arguments.length==1){if(x.y)
|
144
|
+
this.posY=x.posY;if(x.x)
|
145
|
+
this.posX=x.posX;}else{this.posX=x;this.posY=y;}
|
146
|
+
return this;},setPosX:function(x){this.posX=x;return this;},setPosY:function(y){this.posY=y;return this;},distanceTo:function(x,y){if(arguments.length==1){y=x.posY;x=x.posX;}
|
147
|
+
var kx,ky;kx=x-this.posX>>31;ky=y-this.posY>>31;return Math.round(((x-this.posX^kx)-kx)+((y-this.posY^ky)-ky));}});re.tile=re.c('tile').global({sizeX:40,sizeY:40,roundX:function(x,size){if(arguments.length==1){size=re.tile.sizeX;}
|
148
|
+
return re.tile.roundTileX(x)*size;},roundY:function(y,size){if(arguments.length==1){size=re.tile.sizeY;}
|
149
|
+
return re.tile.roundTileY(y)*size;},roundTileX:function(x,size){if(arguments.length==1){size=re.tile.sizeX;}
|
150
|
+
return Math.round((x-size*0.5)/size);},roundTileY:function(y,size){if(arguments.length==1){size=re.tile.sizeY;}
|
151
|
+
return Math.round((y-size*0.5)/size);}}).inherit({posX:0,posY:0}).init(function(){if(!this.sizeX)
|
152
|
+
this.sizeX=re.tile.sizeX;if(!this.sizeY)
|
153
|
+
this.sizeY=re.tile.sizeY;}).extend({setTileFromPoint:function(x,y){this.posX=re.tile.roundX(x);this.posY=re.tile.roundY(y);return this;},setTile:function(xt,yt){this.setTileX(xt);this.setTileY(yt);return this;},setTileX:function(value){this.posX=Math.floor(value*this.sizeX);return this;},getTileX:function(){return Math.floor(this.posX/this.sizeX);},setTileY:function(value){this.posY=Math.floor(value*this.sizeY);return this;},getTileY:function(){return Math.floor(this.posY/this.sizeY);}});re.c('playlist');re.sound=re.c('sound').global({enabled:true}).namespace({hasEvent:false,loops:0}).extend({play:function(loop){if(!this.sound||!re.sound.enabled)return this;var c=this.sound;var that=this;c.currentTime=0;c.play();if(loop){this.sound_loops=0;if(!this.sound_hasEvent){this.sound_hasEvent=true;c.addEventListener('ended',function(){that.signal('sounded',that.sound_loops,loop);if(loop==-1||that.sound_loops<loop){c.currentTime=0;that.sound_loops++;}},false);}}
|
154
|
+
return this;},resume:function(){this.sound.play();return this;},pause:function(){this.sound.pause();return this;},currentTime:function(){return this.sound.currentTime;},ended:function(){return this.sound.ended;}});re.c('arraymap').inherit({lengthX:0,lengthY:0}).extend({value:0,set:function(x,y,value){while(y>=this.map.length){var m=new Array(this.map[0]);for(var l in m){m[l]=this.value;}
|
155
|
+
this.map.push(m);}
|
156
|
+
while(x>=this.map[this.map.length-1].length){for(var k=0;k<this.map.length;k++){this.map[k].push(this.value);}}
|
157
|
+
this.lengthX=this.map[y].length;this.lengthY=this.map.length;this.map[y][x]=value;return this;},within:function(x,y){if(y<0||y>=this.lengthY||x<0||x>=this.lengthX){return false;}
|
158
|
+
return true;},get:function(x,y){if(this.within(x,y)){return this.map[y][x];}
|
159
|
+
return null;},copy:function(a){for(var y=0;y<a.length;y++){for(var x=0;x<a[0].length;x++){this.set(x,y,a[y][x]);}}
|
160
|
+
return this;},copyByRef:function(m){this.map=m;if(m.length>0){this.lengthX=m[0].length;}else{this.lengthX=0;}
|
161
|
+
this.lengthY=m.length;return this;}}).init(function(){this.map=[];});re.c('flicker').require('update timestep').implement('flick').init(function(){this.flicker_reels={};this.flicker_old={};this.flicker_reel={};this.flicker_flickering='';}).extend({flicker_stop:function(){if(this.flickering()){this.signal('animated',this.flicker_flickering);this.flicker_flickering='';this.stepProgress=0;this.frameX=this.flicker_oldX;this.frameY=this.flicker_oldY;this.removeSignal('update',this.flicker_update);}
|
162
|
+
return this;},flicker_update:function(t){this.timestep(t,function(){var c=this.flicker_reel;if(this.flicker_frame==this.flicker_reel.frames.length){if(c.loops==-1||--this.flicker_loops>=1){this.flicker_frame=0;}else{this.flicker_stop();return;}}
|
163
|
+
this.flick(c.frames[this.flicker_frame]);this.flicker_frame++;});},addFlicker:function(id,loops,duration,frames){if(typeof id=='object'){for(var i in id){if(!id.hasOwnProperty(i))continue;var c=id[i].slice();c.unshift(i);this.addFlicker.apply(this,c);}
|
164
|
+
return this;}
|
165
|
+
if(typeof frames=='string')frames=frames.split(' ');this.flicker_reels[id]={frames:frames,duration:duration,loops:loops};return this;},removeFlicker:function(id){if(typeof id=='object'){for(var i in id){if(!id.hasOwnProperty(i))continue;this.removeFlicker.call(this,id[i]);}
|
166
|
+
return this;}
|
167
|
+
delete this.flicker_reels[id];return this;},flicker:function(id,loops,duration,frames){if(arguments.length==0){return this.flicker_stop();}
|
168
|
+
if(id==this.flicker_flickering)return;if(!this.flicker_reels[id]){return this;}
|
169
|
+
var r=this.flicker_reels[id];var c=this.flicker_reel;c.loops=(isNaN(loops))?r.loops:loops;c.duration=(isNaN(duration))?r.duration:duration;c.frames=(typeof frames=='object')?frames:r.frames;this.flicker_loops=c.loops;this.stepProgress=0;this.stepSize=c.duration/c.frames.length;this.flicker_oldX=this.frameX;this.flicker_oldY=this.frameY;this.flicker_frame=0;this.flick(c.frames[this.flicker_frame++]);if(!this.flickering()){this.addSignal('update',this.flicker_update);}
|
170
|
+
this.flicker_flickering=id;return this;},flickering:function(id){if(id){return this.flicker_flickering==id;}
|
171
|
+
return this.flicker_flickering!='';}});re.c('timestep').inherit({stepProgress:0,stepSize:0.3}).extend({timestep:function(progress,callback,context){this.stepProgress+=progress;while(this.stepProgress>=this.stepSize){callback.call((context)?context:this);this.stepProgress-=this.stepSize;}}})
|
172
|
+
re.c('storage').init(function(c,type){this.storage=(type=='session')?sessionStorage:localStorage;}).extend({length:function(){return this.storage.length;},key:function(index){return this.storage.key(index);},getItem:function(key){return this.storage.getItem(key);},getJson:function(key){return JSON.parse(this.getItem(key));},setItem:function(key,data){if(typeof data!='number'||typeof data!='string'){data=JSON.stringify(data);}
|
173
|
+
this.storage.setItem(key,data);return this;},removeItem:function(key){this.storage.removeItem(key);return this;},clear:function(){this.storage.clear();return this;}})
|
174
|
+
re.log=function(){try{console.log.apply(console,arguments);}catch(e){try{opera.postError.apply(opera,arguments);}catch(e){alert(Array.prototype.join.call(arguments," "));}}};re.c('log').extend('log',re.log);re.c('polyfill').extend({requestAnimationFrame:function(callback,canvas){return requestAnimFrame(callback,canvas);}}).run(function(){window.requestAnimFrame=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(callback){window.setTimeout(callback,1000/60);};});re.c('random').extend({random:function(max,min){switch(arguments.length){case 0:return Math.random();case 1:return Math.random()*max;case 2:return Math.random()*(max-min+1)+min;}},randomInt:function(max,min){return Math.floor(this.random.apply(this,arguments));}}).run(function(){var b=re.e('random');re.random=b.random;re.randomInt=b.randomInt;b.dispose();});re.scene=function(title){var s=re.c('scene');if(title.charAt(0)=='-'){delete s._scenes[title.substr(1)];return s;}else if(s._scenes[title]){var current=arguments.callee.current;var t=s._scenes[current];if(t&&typeof t.scene_exit=='function'){t.scene_exit.call(t,title);}
|
175
|
+
arguments.callee.current=title;s.curent=title;t=s._scenes[title];if(typeof t.scene_enter=='function'){t.scene_enter.apply(t,Array.prototype.slice.call(arguments,1));}}else{re.e('scene:'+title);}
|
176
|
+
return s._scenes[title];};re.c('scene').global({_scenes:{}}).init(function(c,title){c._scenes[title]=this;this.sceneName=title;}).dispose(function(c){delete c._scenes[this.sceneName];}).extend({enter:function(m){this.scene_enter=m;return this;},exit:function(m){this.scene_exit=m;return this;},scene:function(){return re.scene.apply(this,arguments);}});re.c('sheet').global({sheet:function(map,padX,padY,sizeX,sizeY){var frameWidth=sizeX||re.tile.sizeX;var frameHeight=sizeY||re.tile.sizeY;if(padX){frameWidth+=padX;}
|
177
|
+
if(padY){frameHeight+=padY;}
|
178
|
+
var x;var y;for(var p in map){x=map[p][0]||0;y=map[p][1]||0;re.c(p).require('sprite').extend({frame:{x:x,y:y},size:{x:frameWidth,y:frameHeight},bitmap:this.bitmap});}
|
179
|
+
return this;}}).require('tile').extend({sheet:re.sheet});re.sheet=re.c('sheet').sheet;re.c('support').global({support:function(s){var that=re.c('support');if(arguments.length>1){var d;for(var i=0;i<arguments.length;i++){d=arguments[i];if(that.support(d)){return d;}}
|
180
|
+
return false;}
|
181
|
+
var k=s.split(' ');var stat=true;for(var j in k){stat=stat&&!!that[k[j]];}
|
182
|
+
return stat;}}).extend({support:function(s){return re.c('support').call(this,s);}}).run(function(){var c=re.c('support');re.support=c.support;c.canvas=!!document.createElement('canvas').getContext;c.text=!!(c.canvas&&typeof document.createElement('canvas').getContext('2d').fillText=='function');var ele=document.createElement('audio');try{if(c.audio=!!ele.canPlayType){c.ogg=ele.canPlayType('audio/ogg; codecs="vorbis"');c.mp3=ele.canPlayType('audio/mpeg;');c.wav=ele.canPlayType('audio/wav; codecs="1"');c.aac=ele.canPlayType('audio/x-m4a;')||ele.canPlayType('audio/aac;');for(var i in c){if(c[i]=='no'||c[i]==''){c[i]=false;}}}}catch(e){}
|
183
|
+
try{c.localstorage=!!localStorage.getItem;}catch(e){c.localstorage=false;}
|
184
|
+
c.worker=!!window.Worker;c.webgl=!!window.WebGLRenderingContext;c.touch='ontouchstart'in window;});
|
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
require 'entityjs/game'
|
3
|
+
require 'entityjs/min'
|
4
|
+
require 'entityjs/refresh'
|
5
|
+
require 'entityjs/comp'
|
6
|
+
|
7
|
+
module Entityjs
|
8
|
+
class Command
|
9
|
+
|
10
|
+
def self.run(command, args=nil)
|
11
|
+
|
12
|
+
case command
|
13
|
+
when 'game'
|
14
|
+
Entityjs::Game.generate(command, args[1..-1])
|
15
|
+
puts 'generated game'
|
16
|
+
|
17
|
+
when 'min'
|
18
|
+
Entityjs::Min.generate(args)
|
19
|
+
|
20
|
+
when 'refresh'
|
21
|
+
Entityjs::Refresh.generate(args)
|
22
|
+
|
23
|
+
when 'comp'
|
24
|
+
Entityjs::Comp.generate(args)
|
25
|
+
|
26
|
+
else
|
27
|
+
puts 'Error enter in one of the following...'
|
28
|
+
puts 'entityjs game [name] [comp]+'
|
29
|
+
puts 'entityjs comp [name]'
|
30
|
+
puts 'entityjs min'
|
31
|
+
puts 'entityjs refresh'
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|