entityjs 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.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/core/system.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
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 definess 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
|
+
.defaults({
|
|
13
|
+
|
|
14
|
+
clearColor:'#f9f9f9',
|
|
15
|
+
|
|
16
|
+
stepSize:0.03,
|
|
17
|
+
maxTick:0.05,
|
|
18
|
+
|
|
19
|
+
running:false,
|
|
20
|
+
|
|
21
|
+
sizeX:10,
|
|
22
|
+
sizeY:10
|
|
23
|
+
|
|
24
|
+
})
|
|
25
|
+
.defines({
|
|
26
|
+
|
|
27
|
+
clear:function(color){
|
|
28
|
+
|
|
29
|
+
if(color){
|
|
30
|
+
this.context.fillStyle = color;
|
|
31
|
+
this.context.fillRect(0, 0, this.sizeX, this.sizeY);
|
|
32
|
+
} else {
|
|
33
|
+
this.context.clearRect(0, 0, this.sizeX, this.sizeY);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return this;
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
start:function(){
|
|
40
|
+
if(!this.running){
|
|
41
|
+
this.running = true;
|
|
42
|
+
|
|
43
|
+
var that = this;
|
|
44
|
+
(function m(){
|
|
45
|
+
|
|
46
|
+
that.system_loop();
|
|
47
|
+
if(that.running){
|
|
48
|
+
that.requestAnimationFrame(m, that.canvas);
|
|
49
|
+
}
|
|
50
|
+
})();
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return this;
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
loop:function(m){
|
|
58
|
+
|
|
59
|
+
this.system_loop = m;
|
|
60
|
+
|
|
61
|
+
return this;
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
stop:function(){
|
|
65
|
+
this.running = false;
|
|
66
|
+
return this;
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
//scale is currently not implemented!
|
|
70
|
+
init:function(canvasId, scale, contextType){
|
|
71
|
+
//init listeners
|
|
72
|
+
if(re._c.keyboard){
|
|
73
|
+
re._c.keyboard.i();
|
|
74
|
+
}
|
|
75
|
+
if(re._c.mouse){
|
|
76
|
+
re._c.mouse.i();
|
|
77
|
+
}
|
|
78
|
+
if(re._c.touch){
|
|
79
|
+
re._c.touch.i();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
//add comps here because system is defined earlier than other comps
|
|
83
|
+
this.comp('polyfill tick timestep');
|
|
84
|
+
|
|
85
|
+
//setup canvas
|
|
86
|
+
this.canvas = re.$(canvasId);
|
|
87
|
+
|
|
88
|
+
this.scale = scale || 1;
|
|
89
|
+
|
|
90
|
+
this.context = this.canvas.getContext(contextType || '2d');
|
|
91
|
+
var s = re.screen = re.e('screen');
|
|
92
|
+
|
|
93
|
+
this.sizeX = s.sizeX = this.canvas.width;
|
|
94
|
+
this.sizeY = s.sizeY = this.canvas.height;
|
|
95
|
+
|
|
96
|
+
return this;
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
/*
|
|
100
|
+
Default main loop
|
|
101
|
+
*/
|
|
102
|
+
system_loop:function(){
|
|
103
|
+
|
|
104
|
+
this.timestep(Math.min(this.tick() / 1000, this.maxTick), function(){
|
|
105
|
+
//update
|
|
106
|
+
re._c.update.update(this.stepSize);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
//clear
|
|
110
|
+
this.clear(this.clearColor);
|
|
111
|
+
re._c.draw.draw(this.context);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
})
|
|
116
|
+
.run(function(){
|
|
117
|
+
|
|
118
|
+
//create default system
|
|
119
|
+
re.system = re.sys = re.e('system');
|
|
120
|
+
|
|
121
|
+
});
|
data/src/cycle/draw.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
re.c('draw')
|
|
2
|
+
.statics({
|
|
3
|
+
l:[],
|
|
4
|
+
|
|
5
|
+
draw:function(c){
|
|
6
|
+
var lis = this.l;
|
|
7
|
+
|
|
8
|
+
for(var i=0, b; i<lis.length; i++){
|
|
9
|
+
b = lis[i];
|
|
10
|
+
b.drawable && b.visible() && b.draw_render(c);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
})
|
|
16
|
+
.interfaces('draw')
|
|
17
|
+
.init(function(c){
|
|
18
|
+
|
|
19
|
+
c.l.push(this);
|
|
20
|
+
|
|
21
|
+
})
|
|
22
|
+
.dispose(function(c){
|
|
23
|
+
|
|
24
|
+
c.l.splice(c.l.indexOf(this), 1);
|
|
25
|
+
|
|
26
|
+
})
|
|
27
|
+
.defaults({
|
|
28
|
+
screenable:true,
|
|
29
|
+
drawable:true,
|
|
30
|
+
rotation:0,
|
|
31
|
+
alpha:1,
|
|
32
|
+
|
|
33
|
+
scaleX:1,
|
|
34
|
+
scaleY:1,
|
|
35
|
+
|
|
36
|
+
posX:0,
|
|
37
|
+
posY:0,
|
|
38
|
+
|
|
39
|
+
sizeX:10,
|
|
40
|
+
sizeY:10,
|
|
41
|
+
|
|
42
|
+
regX:0,
|
|
43
|
+
regY:0
|
|
44
|
+
|
|
45
|
+
})
|
|
46
|
+
.defines({
|
|
47
|
+
|
|
48
|
+
cache:function(){
|
|
49
|
+
if(!this.image) return this;
|
|
50
|
+
|
|
51
|
+
this.clearCache();
|
|
52
|
+
|
|
53
|
+
var c = re.$new('canvas');
|
|
54
|
+
var s = Math.max(this.image.width, this.image.height);
|
|
55
|
+
c.width = s;
|
|
56
|
+
c.height = s;
|
|
57
|
+
|
|
58
|
+
this.draw_render(c.getContext(re.sys.contextType));
|
|
59
|
+
|
|
60
|
+
this.canvasCache = c;
|
|
61
|
+
|
|
62
|
+
return this;
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
clearCache:function(){
|
|
66
|
+
this.canvasCache = null;
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
drawFirst:function(){
|
|
70
|
+
var l = re.c('draw').l;
|
|
71
|
+
|
|
72
|
+
l.splice(l.indexOf(this), 1);
|
|
73
|
+
|
|
74
|
+
l.unshift(this);
|
|
75
|
+
return this;
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
drawLast:function(){
|
|
79
|
+
var l = re.c('draw').l;
|
|
80
|
+
|
|
81
|
+
l.splice(l.indexOf(this), 1);
|
|
82
|
+
|
|
83
|
+
l.push(this);
|
|
84
|
+
return this;
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
drawAfter:function(en){
|
|
88
|
+
var l = re.c('draw').l;
|
|
89
|
+
var him = l.indexOf(en);
|
|
90
|
+
var me = l.indexOf(this);
|
|
91
|
+
|
|
92
|
+
if(him > me){
|
|
93
|
+
//swap
|
|
94
|
+
var t = l[him];
|
|
95
|
+
l[him] = l[me];
|
|
96
|
+
l[me] = t;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return this;
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
drawBefore:function(en){
|
|
103
|
+
|
|
104
|
+
var l = re.c('draw').l;
|
|
105
|
+
var him = l.indexOf(en);
|
|
106
|
+
var me = l.indexOf(this);
|
|
107
|
+
|
|
108
|
+
if(him < me){
|
|
109
|
+
//swap
|
|
110
|
+
var t = l[him];
|
|
111
|
+
l[him] = l[me];
|
|
112
|
+
l[me] = t;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return this;
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
screenX:function(x){
|
|
119
|
+
if(x){
|
|
120
|
+
this.posX = x + re.screen.posX;
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
return this.posX - re.screen.posX;
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
screenY:function(y){
|
|
127
|
+
if(y){
|
|
128
|
+
this.posY = y + re.screen.posY;
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
return this.posY - re.screen.posY;
|
|
132
|
+
},
|
|
133
|
+
|
|
134
|
+
/*
|
|
135
|
+
Returns true or false wether the object is visible on screen.
|
|
136
|
+
*/
|
|
137
|
+
visible:function(){
|
|
138
|
+
|
|
139
|
+
return re.screen.hit(this.posX - this.regX, this.posY - this.regY, this.sizeX, this.sizeY);
|
|
140
|
+
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
})
|
|
144
|
+
.namespaces({
|
|
145
|
+
|
|
146
|
+
render:function(c){
|
|
147
|
+
|
|
148
|
+
this.draw_before(c);
|
|
149
|
+
this.draw(c);
|
|
150
|
+
this.draw_after(c);
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
before:function(c){
|
|
154
|
+
|
|
155
|
+
c.save();
|
|
156
|
+
|
|
157
|
+
if(this.alpha != 1)
|
|
158
|
+
c.staticsAlpha = this.alpha;
|
|
159
|
+
|
|
160
|
+
if(this.screenable)
|
|
161
|
+
c.translate(this.screenX(), this.screenY());
|
|
162
|
+
else
|
|
163
|
+
c.translate(this.posX, this.posY);
|
|
164
|
+
|
|
165
|
+
if(this.rotation)
|
|
166
|
+
c.rotate(this.rotation * Math.PI / 180);
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
if(this.scaleX != 1 || this.scaleY != 1)
|
|
170
|
+
c.scale(this.scaleX, this.scaleY);
|
|
171
|
+
|
|
172
|
+
},
|
|
173
|
+
|
|
174
|
+
after:function(c){
|
|
175
|
+
c.restore();
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
});
|
data/src/cycle/tick.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
The tick component is a stop watch cyclier. It will return the milliseconds in time
|
|
3
|
+
between tick() calls.
|
|
4
|
+
|
|
5
|
+
var tick = re.e('tick');
|
|
6
|
+
//wait 200 milliseconds
|
|
7
|
+
tick.tick(); //200
|
|
8
|
+
//wait 10 milliseconds
|
|
9
|
+
tick.tick(); //10
|
|
10
|
+
*/
|
|
11
|
+
re.c('tick')
|
|
12
|
+
.init(function(){
|
|
13
|
+
this.lastTime = Date.now();
|
|
14
|
+
})
|
|
15
|
+
.defines({
|
|
16
|
+
|
|
17
|
+
tick:function(){
|
|
18
|
+
var wall = Date.now();
|
|
19
|
+
var last = this.lastTime;
|
|
20
|
+
this.lastTime = wall;
|
|
21
|
+
|
|
22
|
+
return wall - last;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
});
|
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
/*
|
|
2
|
-
The tween component tweens properties of entities to the given value over a period of time.
|
|
3
|
-
|
|
4
|
-
This is useful for animations.
|
|
5
|
-
|
|
6
|
-
re.e('tween')
|
|
7
|
-
.tween(0.8, {x:10});
|
|
8
|
-
|
|
9
|
-
*/
|
|
10
|
-
re.c('tween')
|
|
11
|
-
.
|
|
12
|
-
.
|
|
13
|
-
|
|
14
|
-
tween:function(obj, time, props){
|
|
15
|
-
return obj.comp('tween')
|
|
16
|
-
.tween(time, props);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
})
|
|
20
|
-
.
|
|
21
|
-
|
|
22
|
-
update:function(t){
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
})
|
|
29
|
-
.
|
|
30
|
-
|
|
31
|
-
tweening:false
|
|
32
|
-
|
|
33
|
-
})
|
|
34
|
-
.
|
|
35
|
-
|
|
36
|
-
tween:function(time, props){
|
|
37
|
-
this.time = time || 5;
|
|
38
|
-
|
|
39
|
-
if(this.tweening){
|
|
40
|
-
this.
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
//collect properties
|
|
44
|
-
for(var i in props){
|
|
45
|
-
|
|
46
|
-
if(!props.hasOwnProperty(i)) continue;
|
|
47
|
-
|
|
48
|
-
this.tween_props[i] = {s:re.sys.stepSize, i:props[i]};
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return this;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
})
|
|
56
|
-
.init(function(){
|
|
57
|
-
|
|
58
|
-
this.tween_props = {};
|
|
59
|
-
|
|
60
|
-
});
|
|
1
|
+
/*
|
|
2
|
+
The tween component tweens properties of entities to the given value over a period of time.
|
|
3
|
+
|
|
4
|
+
This is useful for animations.
|
|
5
|
+
|
|
6
|
+
re.e('tween')
|
|
7
|
+
.tween(0.8, {x:10});
|
|
8
|
+
|
|
9
|
+
*/
|
|
10
|
+
re.c('tween')
|
|
11
|
+
.requires('update')
|
|
12
|
+
.statics({
|
|
13
|
+
|
|
14
|
+
tween:function(obj, time, props){
|
|
15
|
+
return obj.comp('tween')
|
|
16
|
+
.tween(time, props);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
})
|
|
20
|
+
.namespaces({
|
|
21
|
+
|
|
22
|
+
update:function(t){
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
})
|
|
29
|
+
.defaults({
|
|
30
|
+
|
|
31
|
+
tweening:false
|
|
32
|
+
|
|
33
|
+
})
|
|
34
|
+
.defines({
|
|
35
|
+
|
|
36
|
+
tween:function(time, props){
|
|
37
|
+
this.time = time || 5;
|
|
38
|
+
|
|
39
|
+
if(this.tweening){
|
|
40
|
+
this.unbind('update', this.tween_update);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//collect properties
|
|
44
|
+
for(var i in props){
|
|
45
|
+
|
|
46
|
+
if(!props.hasOwnProperty(i)) continue;
|
|
47
|
+
|
|
48
|
+
this.tween_props[i] = {s:re.sys.stepSize, i:props[i]};
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
})
|
|
56
|
+
.init(function(){
|
|
57
|
+
|
|
58
|
+
this.tween_props = {};
|
|
59
|
+
|
|
60
|
+
});
|
|
61
61
|
re.tween = re.c('tween').tween;
|
|
@@ -1,86 +1,87 @@
|
|
|
1
|
-
/*
|
|
2
|
-
The update component calls update signals to all listening entities.
|
|
3
|
-
*/
|
|
4
|
-
re.c('update')
|
|
5
|
-
.
|
|
6
|
-
|
|
7
|
-
update:function(
|
|
8
|
-
var l = this.
|
|
9
|
-
|
|
10
|
-
for(var k=0,
|
|
11
|
-
b = l[k];
|
|
12
|
-
|
|
13
|
-
if(b && b.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
})
|
|
24
|
-
.
|
|
25
|
-
|
|
26
|
-
var l = re.c('update').
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
var
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
l[
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
var
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
l[
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
1
|
+
/*
|
|
2
|
+
The update component calls update signals to all listening entities.
|
|
3
|
+
*/
|
|
4
|
+
re.c('update')
|
|
5
|
+
.statics({
|
|
6
|
+
l:[],
|
|
7
|
+
update:function(t){
|
|
8
|
+
var l = this.l;
|
|
9
|
+
|
|
10
|
+
for(var k=0, b; k<l.length; k++){
|
|
11
|
+
b = l[k];
|
|
12
|
+
|
|
13
|
+
if(b && b.updatable){
|
|
14
|
+
b.trigger('update', t);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
.defaults({
|
|
22
|
+
updatable:true
|
|
23
|
+
})
|
|
24
|
+
.defines(function(){
|
|
25
|
+
|
|
26
|
+
var l = re.c('update').l;
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
|
|
30
|
+
updateFirst:function(){
|
|
31
|
+
|
|
32
|
+
l.splice(l.indexOf(this), 1);
|
|
33
|
+
|
|
34
|
+
l.unshift(this);
|
|
35
|
+
|
|
36
|
+
return this;
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
updateLast:function(){
|
|
40
|
+
|
|
41
|
+
l.splice(l.indexOf(this), 1);
|
|
42
|
+
|
|
43
|
+
l.push(this);
|
|
44
|
+
|
|
45
|
+
return this;
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
updateAfter:function(e){
|
|
49
|
+
|
|
50
|
+
var him = l.indexOf(e);
|
|
51
|
+
var me = l.indexOf(this);
|
|
52
|
+
|
|
53
|
+
if(him > me){
|
|
54
|
+
//swap
|
|
55
|
+
var t = l[him];
|
|
56
|
+
l[him] = l[me];
|
|
57
|
+
l[me] = t;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return this;
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
updateBefore:function(e){
|
|
64
|
+
|
|
65
|
+
var him = l.indexOf(e);
|
|
66
|
+
var me = l.indexOf(this);
|
|
67
|
+
|
|
68
|
+
if(him < me){
|
|
69
|
+
//swap
|
|
70
|
+
var t = l[him];
|
|
71
|
+
l[him] = l[me];
|
|
72
|
+
l[me] = t;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
}())
|
|
81
|
+
.init(function(c){
|
|
82
|
+
c.l.push(this);
|
|
83
|
+
})
|
|
84
|
+
.dispose(function(c){
|
|
85
|
+
|
|
86
|
+
c.l.splice(c.l.indexOf(this), 1);
|
|
86
87
|
});
|
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
/*
|
|
2
|
-
The wait component delays function calls.
|
|
3
|
-
*/
|
|
4
|
-
re.c('wait')
|
|
5
|
-
.
|
|
6
|
-
.
|
|
7
|
-
|
|
8
|
-
wait:function(time, callback){
|
|
9
|
-
var c = 0;
|
|
10
|
-
|
|
11
|
-
this.
|
|
12
|
-
c += t;
|
|
13
|
-
|
|
14
|
-
if(c >= time){
|
|
15
|
-
this.callback.apply(this, Array.prototype.slice.call(arguments, 2));
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
/*
|
|
2
|
+
The wait component delays function calls.
|
|
3
|
+
*/
|
|
4
|
+
re.c('wait')
|
|
5
|
+
.requires('update')
|
|
6
|
+
.defines({
|
|
7
|
+
|
|
8
|
+
wait:function(time, callback){
|
|
9
|
+
var c = 0;
|
|
10
|
+
|
|
11
|
+
this.bind('update', function(t){
|
|
12
|
+
c += t;
|
|
13
|
+
|
|
14
|
+
if(c >= time){
|
|
15
|
+
this.callback.apply(this, Array.prototype.slice.call(arguments, 2));
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
|
|
22
23
|
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/*
|
|
2
|
-
The worker component will contain an interface for the new HTML5 webworker.
|
|
3
|
-
|
|
4
|
-
TODO
|
|
5
|
-
*//*
|
|
6
|
-
re.c('worker')
|
|
7
|
-
.init(function(){
|
|
8
|
-
throw 'Not implemented';
|
|
1
|
+
/*
|
|
2
|
+
The worker component will contain an interface for the new HTML5 webworker.
|
|
3
|
+
|
|
4
|
+
TODO
|
|
5
|
+
*//*
|
|
6
|
+
re.c('worker')
|
|
7
|
+
.init(function(){
|
|
8
|
+
throw 'Not implemented';
|
|
9
9
|
});*/
|