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.
Files changed (264) hide show
  1. data/.gitignore +7 -6
  2. data/.rspec +2 -0
  3. data/README.md +170 -49
  4. data/Rakefile +9 -0
  5. data/bin/entityjs +24 -14
  6. data/entityjs.gemspec +15 -9
  7. data/lib/entityjs/assets.rb +167 -0
  8. data/lib/entityjs/command.rb +52 -27
  9. data/lib/entityjs/commands/build.rb +128 -0
  10. data/lib/entityjs/commands/comp.rb +74 -0
  11. data/lib/entityjs/commands/font.rb +73 -0
  12. data/lib/entityjs/commands/new.rb +59 -0
  13. data/lib/entityjs/commands/server.rb +54 -0
  14. data/lib/entityjs/commands/templates.rb +28 -0
  15. data/lib/entityjs/commands/test.rb +69 -0
  16. data/lib/entityjs/config.rb +130 -0
  17. data/lib/entityjs/dirc.rb +184 -0
  18. data/lib/entityjs/parsers/parse_tmx.rb +41 -0
  19. data/lib/entityjs/parsers/parse_xml.rb +39 -0
  20. data/lib/entityjs/version.rb +1 -1
  21. data/lib/entityjs.rb +53 -0
  22. data/license.txt +1 -1
  23. data/public/play.html +122 -0
  24. data/public/qunit/qunit.css +226 -0
  25. data/public/qunit/qunit.entity.js +190 -0
  26. data/public/qunit/qunit.input.js +200 -0
  27. data/public/qunit/qunit.js +1598 -0
  28. data/public/qunit/qunit.mock.js +97 -0
  29. data/public/tests.html +45 -0
  30. data/spec/javascripts/helpers/accept.png +0 -0
  31. data/spec/javascripts/helpers/alligator.mp3 +0 -0
  32. data/spec/javascripts/helpers/alligator.ogg +0 -0
  33. data/spec/javascripts/helpers/canvas.js +15 -0
  34. data/spec/javascripts/helpers/entityunit.js +50 -0
  35. data/spec/javascripts/helpers/factories.js +11 -0
  36. data/spec/javascripts/helpers/jquery-1.7.1.min.js +4 -0
  37. data/spec/javascripts/src/core/comp_spec.js +145 -0
  38. data/spec/javascripts/src/core/entity_spec.js +324 -0
  39. data/spec/javascripts/src/core/load_spec.js +71 -0
  40. data/spec/javascripts/src/core/query_spec.js +157 -0
  41. data/spec/javascripts/src/core/re_spec.js +61 -0
  42. data/spec/javascripts/src/core/system_spec.js +41 -0
  43. data/spec/javascripts/src/cycle/draw_spec.js +106 -0
  44. data/spec/javascripts/src/cycle/tick_spec.js +20 -0
  45. data/spec/javascripts/src/cycle/update_spec.js +86 -0
  46. data/spec/javascripts/src/display/align_spec.js +43 -0
  47. data/spec/javascripts/src/display/circle_spec.js +26 -0
  48. data/spec/javascripts/src/display/group_spec.js +7 -0
  49. data/spec/javascripts/src/display/image_spec.js +32 -0
  50. data/spec/javascripts/src/display/imgtext_spec.js +32 -0
  51. data/spec/javascripts/src/display/rect_spec.js +13 -0
  52. data/spec/javascripts/src/display/screen_spec.js +47 -0
  53. data/spec/javascripts/src/display/sprite_spec.js +28 -0
  54. data/spec/javascripts/src/display/text_spec.js +30 -0
  55. data/spec/javascripts/src/input/keyboard_spec.js +67 -0
  56. data/spec/javascripts/src/input/mouse_spec.js +133 -0
  57. data/spec/javascripts/src/input/pressed_spec.js +31 -0
  58. data/spec/javascripts/src/math/bisect_spec.js +59 -0
  59. data/spec/javascripts/src/math/body_spec.js +30 -0
  60. data/spec/javascripts/src/math/drag_spec.js +38 -0
  61. data/spec/javascripts/src/math/force_spec.js +134 -0
  62. data/spec/javascripts/src/math/hit_spec.js +28 -0
  63. data/spec/javascripts/src/math/hitmap_spec.js +52 -0
  64. data/spec/javascripts/src/math/limit_spec.js +35 -0
  65. data/spec/javascripts/src/math/point_spec.js +57 -0
  66. data/spec/javascripts/src/math/tile_spec.js +78 -0
  67. data/spec/javascripts/src/media/sound_spec.js +40 -0
  68. data/spec/javascripts/src/pattern/automap_spec.js +93 -0
  69. data/spec/javascripts/src/pattern/flicker_spec.js +66 -0
  70. data/spec/javascripts/src/pattern/timestep_spec.js +23 -0
  71. data/spec/javascripts/src/save/storage_spec.js +37 -0
  72. data/spec/javascripts/src/util/log_spec.js +9 -0
  73. data/spec/javascripts/src/util/polyfill_spec.js +13 -0
  74. data/spec/javascripts/src/util/random_spec.js +33 -0
  75. data/spec/javascripts/src/util/scene_spec.js +52 -0
  76. data/spec/javascripts/src/util/sheet_spec.js +25 -0
  77. data/spec/javascripts/src/util/support_spec.js +17 -0
  78. data/spec/javascripts/support/jasmine.yml +76 -0
  79. data/spec/javascripts/support/jasmine_config.rb +32 -0
  80. data/spec/javascripts/support/jasmine_runner.rb +32 -0
  81. data/spec/lib/entityjs/assets_spec.rb +216 -0
  82. data/spec/lib/entityjs/command_spec.rb +53 -0
  83. data/spec/lib/entityjs/commands/build_spec.rb +69 -0
  84. data/spec/lib/entityjs/commands/comp_spec.rb +45 -0
  85. data/spec/lib/entityjs/commands/font_spec.rb +7 -0
  86. data/spec/lib/entityjs/commands/new_spec.rb +20 -0
  87. data/spec/lib/entityjs/commands/templates_spec.rb +9 -0
  88. data/spec/lib/entityjs/commands/test_spec.rb +31 -0
  89. data/spec/lib/entityjs/config_spec.rb +19 -0
  90. data/spec/lib/entityjs/dirc_spec.rb +83 -0
  91. data/spec/lib/entityjs/version_spec.rb +9 -0
  92. data/spec/spec_helper.rb +21 -3
  93. data/spec/support/factories.rb +19 -0
  94. data/spec/support/mygame.rb +11 -0
  95. data/src/core/comp.js +318 -0
  96. data/src/core/entity.js +549 -0
  97. data/src/core/load.js +242 -0
  98. data/src/core/query.js +354 -0
  99. data/src/core/re.js +74 -0
  100. data/src/core/system.js +121 -0
  101. data/src/cycle/draw.js +178 -0
  102. data/src/cycle/tick.js +25 -0
  103. data/src/{entityjs/cycle → cycle}/tween.js +60 -60
  104. data/src/{entityjs/cycle → cycle}/update.js +86 -85
  105. data/src/{entityjs/cycle → cycle}/wait.js +22 -21
  106. data/src/{entityjs/cycle → cycle}/worker.js +8 -8
  107. data/src/display/align.js +45 -0
  108. data/src/display/circle.js +33 -0
  109. data/src/{entityjs/display → display}/group.js +62 -62
  110. data/src/display/image.js +35 -0
  111. data/src/display/imgtext.js +102 -0
  112. data/src/{entityjs/display → display}/rect.js +18 -18
  113. data/src/display/screen.js +57 -0
  114. data/src/display/sprite.js +54 -0
  115. data/src/display/text.js +44 -0
  116. data/src/{entityjs/input → input}/keyboard.js +152 -150
  117. data/src/input/mouse.js +111 -0
  118. data/src/input/pressed.js +41 -0
  119. data/src/{entityjs/input → input}/touch.js +24 -28
  120. data/src/math/bisect.js +84 -0
  121. data/src/math/body.js +70 -0
  122. data/src/{entityjs/math → math}/drag.js +44 -38
  123. data/src/math/force.js +143 -0
  124. data/src/math/hit.js +32 -0
  125. data/src/math/hitmap.js +167 -0
  126. data/src/math/limit.js +37 -0
  127. data/src/math/point.js +40 -0
  128. data/src/math/tile.js +109 -0
  129. data/src/media/channel.js +93 -0
  130. data/src/{entityjs/media → media}/playlist.js +4 -4
  131. data/src/media/sound.js +114 -0
  132. data/src/{entityjs/net → net}/socket.js +51 -51
  133. data/src/pattern/automap.js +133 -0
  134. data/src/{entityjs/pattern → pattern}/flicker.js +206 -213
  135. data/src/pattern/timestep.js +31 -0
  136. data/src/{entityjs/save → save}/database.js +6 -6
  137. data/src/{entityjs/save → save}/storage.js +47 -56
  138. data/src/{entityjs/util → util}/log.js +17 -25
  139. data/src/{entityjs/util → util}/polyfill.js +24 -24
  140. data/src/util/random.js +20 -0
  141. data/src/util/scene.js +102 -0
  142. data/src/util/sheet.js +35 -0
  143. data/src/{entityjs/util → util}/support.js +109 -132
  144. data/{examples/keys → templates/arrow_keys/assets/images}/arrow.png +0 -0
  145. data/templates/arrow_keys/config.yml +22 -0
  146. data/templates/arrow_keys/readme.txt +9 -0
  147. data/templates/arrow_keys/scripts/display/arrow.js +69 -0
  148. data/templates/arrow_keys/scripts/init.js +10 -0
  149. data/templates/arrow_keys/scripts/input/controls.js +35 -0
  150. data/templates/arrow_keys/scripts/scenes/home.js +20 -0
  151. data/templates/arrow_keys/scripts/scenes/load.js +57 -0
  152. data/templates/arrow_keys/tests/display/arrow_test.js +29 -0
  153. data/templates/arrow_keys/tests/init_test.js +4 -0
  154. data/templates/arrow_keys/tests/input/controls_test.js +32 -0
  155. data/templates/arrow_keys/tests/scenes/home_test.js +0 -0
  156. data/templates/arrow_keys/tests/scenes/load_test.js +16 -0
  157. data/templates/blank/config.yml +22 -0
  158. data/templates/blank/readme.txt +79 -0
  159. data/templates/platform/assets/images/bit.png +0 -0
  160. data/templates/platform/assets/images/hero.png +0 -0
  161. data/templates/platform/assets/images/items.png +0 -0
  162. data/templates/platform/assets/images/tiles.png +0 -0
  163. data/templates/platform/assets/levels/level1.tmx +44 -0
  164. data/templates/platform/assets/sounds/coin.mp3 +0 -0
  165. data/templates/platform/assets/sounds/coin.ogg +0 -0
  166. data/templates/platform/config.yml +22 -0
  167. data/templates/platform/readme.txt +87 -0
  168. data/templates/platform/scripts/display/bit.js +12 -0
  169. data/templates/platform/scripts/display/hero.js +77 -0
  170. data/templates/platform/scripts/display/tile.js +2 -0
  171. data/templates/platform/scripts/display/tsprite.js +17 -0
  172. data/templates/platform/scripts/init.js +7 -0
  173. data/templates/platform/scripts/items/coin.js +27 -0
  174. data/templates/platform/scripts/items/item.js +41 -0
  175. data/templates/platform/scripts/items/spring.js +25 -0
  176. data/templates/platform/scripts/scenes/home.js +10 -0
  177. data/templates/platform/scripts/scenes/load.js +27 -0
  178. data/templates/platform/scripts/scenes/play.js +31 -0
  179. data/templates/platform/scripts/util/counter.js +34 -0
  180. data/templates/platform/scripts/util/level.js +84 -0
  181. data/templates/platform/tests/display/bit_test.js +7 -0
  182. data/templates/platform/tests/display/hero_test.js +73 -0
  183. data/templates/platform/tests/display/tile_test.js +7 -0
  184. data/templates/platform/tests/display/tsprite_test.js +8 -0
  185. data/templates/platform/tests/factories.js +30 -0
  186. data/templates/platform/tests/items/coin_test.js +28 -0
  187. data/templates/platform/tests/items/item_test.js +36 -0
  188. data/templates/platform/tests/items/spring_test.js +21 -0
  189. data/templates/platform/tests/scenes/home_test.js +9 -0
  190. data/templates/platform/tests/scenes/load_test.js +11 -0
  191. data/templates/platform/tests/scenes/play_test.js +15 -0
  192. data/templates/platform/tests/util/counter_test.js +9 -0
  193. data/templates/platform/tests/util/level_test.js +29 -0
  194. metadata +249 -97
  195. data/build/build_debug.bat +0 -1
  196. data/build/build_min.bat +0 -1
  197. data/build/config.php +0 -64
  198. data/build/debug.php +0 -48
  199. data/build/files.php +0 -74
  200. data/build/jsmin.php +0 -376
  201. data/build/min.php +0 -50
  202. data/changelog.txt +0 -53
  203. data/examples/keys/keys.html +0 -59
  204. data/examples/keys/keys.js +0 -148
  205. data/examples/mouse/mouse.html +0 -58
  206. data/examples/mouse/mouse.js +0 -60
  207. data/examples/scenes/home.png +0 -0
  208. data/examples/scenes/scenes.html +0 -55
  209. data/examples/scenes/scenes.js +0 -134
  210. data/examples/scenes/win.png +0 -0
  211. data/examples/sounds/sound1.mp3 +0 -0
  212. data/examples/sounds/sound1.ogg +0 -0
  213. data/examples/sounds/sounds.html +0 -56
  214. data/examples/sounds/sounds.js +0 -44
  215. data/examples/style/background.png +0 -0
  216. data/examples/style/sheet.css +0 -762
  217. data/examples/tiles/tiles.html +0 -56
  218. data/examples/tiles/tiles.js +0 -85
  219. data/examples/tiles/tiles.png +0 -0
  220. data/lib/blank/config.js +0 -4
  221. data/lib/blank/config.yml +0 -21
  222. data/lib/blank/home.js +0 -11
  223. data/lib/blank/init.js +0 -7
  224. data/lib/blank/load.js +0 -21
  225. data/lib/blank/play.html +0 -29
  226. data/lib/entity.debug.js +0 -52
  227. data/lib/entity.min.js +0 -184
  228. data/lib/entityjs/comp.rb +0 -11
  229. data/lib/entityjs/game.rb +0 -93
  230. data/lib/entityjs/min.rb +0 -11
  231. data/lib/entityjs/refresh.rb +0 -14
  232. data/spec/lib/entityjs/game_spec.rb +0 -11
  233. data/src/entityjs/core/component.js +0 -306
  234. data/src/entityjs/core/entity.js +0 -516
  235. data/src/entityjs/core/load.js +0 -224
  236. data/src/entityjs/core/query.js +0 -410
  237. data/src/entityjs/core/re.js +0 -70
  238. data/src/entityjs/core/system.js +0 -125
  239. data/src/entityjs/cycle/draw.js +0 -185
  240. data/src/entityjs/cycle/ticker.js +0 -27
  241. data/src/entityjs/display/anchor.js +0 -53
  242. data/src/entityjs/display/bitfont.js +0 -93
  243. data/src/entityjs/display/bitmap.js +0 -37
  244. data/src/entityjs/display/circle.js +0 -30
  245. data/src/entityjs/display/font.js +0 -41
  246. data/src/entityjs/display/screen.js +0 -46
  247. data/src/entityjs/display/sprite.js +0 -37
  248. data/src/entityjs/input/mouse.js +0 -123
  249. data/src/entityjs/input/pressed.js +0 -81
  250. data/src/entityjs/math/bind.js +0 -76
  251. data/src/entityjs/math/bisect.js +0 -69
  252. data/src/entityjs/math/body.js +0 -39
  253. data/src/entityjs/math/hitmap.js +0 -165
  254. data/src/entityjs/math/hittest.js +0 -26
  255. data/src/entityjs/math/physics.js +0 -142
  256. data/src/entityjs/math/point.js +0 -57
  257. data/src/entityjs/math/tile.js +0 -91
  258. data/src/entityjs/media/channel.js +0 -93
  259. data/src/entityjs/media/sound.js +0 -110
  260. data/src/entityjs/pattern/arraymap.js +0 -89
  261. data/src/entityjs/pattern/timestep.js +0 -34
  262. data/src/entityjs/util/random.js +0 -38
  263. data/src/entityjs/util/scene.js +0 -101
  264. data/src/entityjs/util/sheet.js +0 -51
@@ -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
- .require('update')
12
- .global({
13
-
14
- tween:function(obj, time, props){
15
- return obj.comp('tween')
16
- .tween(time, props);
17
- }
18
-
19
- })
20
- .namespace({
21
-
22
- update:function(t){
23
-
24
-
25
-
26
- }
27
-
28
- })
29
- .inherit({
30
-
31
- tweening:false
32
-
33
- })
34
- .extend({
35
-
36
- tween:function(time, props){
37
- this.time = time || 5;
38
-
39
- if(this.tweening){
40
- this.removeSignal('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
- });
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
- .global({
6
- listeners:[],
7
- update:function(s,t){
8
- var l = this.listeners;
9
-
10
- for(var k=0, le = l.length, b; k < le; ++k){
11
- b = l[k];
12
-
13
- if(b && b.sys == s && b.updating){
14
- b.signal('update', t, s.time);
15
- }
16
- }
17
-
18
- }
19
- })
20
- .inherit({
21
- updating:true,
22
- sys:re.sys
23
- })
24
- .extend(function(){
25
-
26
- var l = re.c('update').listeners;
27
-
28
- return {
29
- updateFirst:function(){
30
-
31
- l.splice(l.indexOf(this), 1);
32
-
33
- l.unshift(this);
34
-
35
- return this;
36
- },
37
-
38
- updateLast:function(){
39
-
40
- l.splice(l.indexOf(this), 1);
41
-
42
- l.push(l);
43
-
44
- return this;
45
- },
46
-
47
- updateAfter:function(e){
48
-
49
- var him = l.indexOf(e);
50
- var me = l.indexOf(this);
51
-
52
- if(him > me){
53
- //swap
54
- var t = l[him];
55
- l[him] = l[me];
56
- l[me] = t;
57
- }
58
-
59
- return this;
60
- },
61
-
62
- updateBefore:function(e){
63
-
64
- var him = l.indexOf(e);
65
- var me = l.indexOf(this);
66
-
67
- if(him < me){
68
- //swap
69
- var t = l[him];
70
- l[him] = l[me];
71
- l[me] = t;
72
- }
73
-
74
- return this;
75
- }
76
-
77
- };
78
-
79
- }())
80
- .init(function(c){
81
- c.listeners.push(this);
82
- })
83
- .dispose(function(c){
84
-
85
- c.listeners.splice(c.listeners.indexOf(this), 1);
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
- .require('update')
6
- .extend({
7
-
8
- wait:function(time, callback){
9
- var c = 0;
10
-
11
- this.addSignal('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
- }
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
  });*/