entityjs 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
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,45 @@
1
+ /*
2
+ The align component contains helper methods for positioning entities relative to system size.
3
+ */
4
+ re.c('align')
5
+ .requires('draw')
6
+ .defines({
7
+
8
+ alignHor:function(o){
9
+ o = o || 0;
10
+ this.posX = re.sys.sizeX * 0.5 - (this.sizeX + this.regX)*0.5 + o | 0;
11
+
12
+ return this;
13
+ },
14
+
15
+ alignVer:function(o){
16
+ o = o || 0;
17
+ this.posY = re.sys.sizeY * 0.5 - (this.sizeY + this.regY)*0.5 + o | 0;
18
+ return this;
19
+ },
20
+
21
+ alignRight:function(x){
22
+ x = x || 0;
23
+ this.posX = re.sys.sizeX - (this.sizeX + this.regX) + x | 0;
24
+ return this;
25
+ },
26
+
27
+ alignLeft:function(x){
28
+ x = x || 0;
29
+ this.posX = x + this.sizeX - (this.sizeX + this.regX) | 0;
30
+ return this;
31
+ },
32
+
33
+ alignTop:function(y){
34
+ y = y || 0;
35
+ this.posY = y + this.sizeY - (this.sizeY + this.regY) | 0;
36
+ return this;
37
+ },
38
+
39
+ alignBottom:function(y){
40
+ y = y || 0;
41
+ this.posY = re.sys.sizeY - (this.sizeY + this.regY) + y | 0;
42
+ return this;
43
+ }
44
+
45
+ });
@@ -0,0 +1,33 @@
1
+ /*
2
+ The circle component draws a rectangle on screen.
3
+ */
4
+ re.c('circle')
5
+ .requires('draw')
6
+ .defaults({
7
+ color:'#82d5f4'
8
+ })
9
+ .defines({
10
+
11
+ draw:function(c){
12
+
13
+ c.fillStyle = this.color;
14
+
15
+ c.beginPath();
16
+
17
+ c.arc(-this.regX + this.sizeX * 0.5, -this.regY + this.sizeX * 0.5, this.sizeX, 0, Math.PI*2, true);
18
+
19
+ c.closePath();
20
+
21
+ c.fill();
22
+ return this;
23
+ },
24
+
25
+ radius:function(r){
26
+ if(re.is(r)){
27
+ this.sizeX = this.sizeY = r;
28
+ return this;
29
+ }
30
+ return this.sizeX;
31
+ }
32
+
33
+ });
@@ -1,63 +1,63 @@
1
- re.c('group')
2
- .inherit({
3
- posX:0,
4
- posY:0
5
- })
6
- .extend({
7
-
8
- group:function(){
9
-
10
- for(var i=0; i<arguments.length; i++){
11
- arguments[i].comp('group').group
12
- }
13
-
14
- },
15
-
16
- ungroup:function(e){
17
-
18
- },
19
-
20
- /*
21
- Overwrite old screen functions
22
- */
23
- getScreenX:function(){
24
- var x = this.posX;
25
- if(this.group) x += this.group.posX;
26
- if(this.screen) x += this.screen.posX;
27
- return x;
28
- },
29
-
30
- getScreenY:function(){
31
- var y = this.posY;
32
- if(this.group) y += this.group.posY;
33
- if(this.screen) y += this.screen.posY;
34
- return y;
35
- },
36
-
37
- /*group:null,*/
38
-
39
- getGroupX:function(){
40
- var x = this.posX;
41
- if(this.group){
42
- x += this.group.posX;
43
- }
44
- return x;
45
- },
46
-
47
- getGroupY:function(){
48
- var y = this.posY;
49
- if(this.group){
50
- y += this.group.posY;
51
- }
52
- return y;
53
- },
54
-
55
- setGroupX:function(x){
56
-
57
- },
58
-
59
- setGroupY:function(y){
60
-
61
- }
62
-
1
+ re.c('group')
2
+ .defaults({
3
+ posX:0,
4
+ posY:0
5
+ })
6
+ .defines({
7
+
8
+ group:function(){
9
+
10
+ for(var i=0; i<arguments.length; i++){
11
+ arguments[i].comp('group').group
12
+ }
13
+
14
+ },
15
+
16
+ ungroup:function(e){
17
+
18
+ },
19
+
20
+ /*
21
+ Overwrite old screen functions
22
+ */
23
+ getScreenX:function(){
24
+ var x = this.posX;
25
+ if(this.group) x += this.group.posX;
26
+ if(this.screen) x += this.screen.posX;
27
+ return x;
28
+ },
29
+
30
+ getScreenY:function(){
31
+ var y = this.posY;
32
+ if(this.group) y += this.group.posY;
33
+ if(this.screen) y += this.screen.posY;
34
+ return y;
35
+ },
36
+
37
+ /*group:null,*/
38
+
39
+ getGroupX:function(){
40
+ var x = this.posX;
41
+ if(this.group){
42
+ x += this.group.posX;
43
+ }
44
+ return x;
45
+ },
46
+
47
+ getGroupY:function(){
48
+ var y = this.posY;
49
+ if(this.group){
50
+ y += this.group.posY;
51
+ }
52
+ return y;
53
+ },
54
+
55
+ setGroupX:function(x){
56
+
57
+ },
58
+
59
+ setGroupY:function(y){
60
+
61
+ }
62
+
63
63
  });
@@ -0,0 +1,35 @@
1
+ /*
2
+ The image component draws an image on screen.
3
+
4
+
5
+ FUTURE - add bitdata component for image manipulation.
6
+ */
7
+ re.c('image')
8
+ .requires('draw')
9
+ .defines({
10
+
11
+ image:function(b){
12
+ if(re.is(b)){
13
+ this.attr({_image:b, sizeX:b.width, sizeY:b.height});
14
+ return this;
15
+ }
16
+ return this._image;
17
+ },
18
+
19
+ visible:function(){
20
+ return this._image && this.parent('draw', 'visible');
21
+ },
22
+
23
+ draw:function(c){
24
+ c.drawImage(this._image, -this.regX, -this.regY, this.sizeX, this.sizeY);
25
+ return this;
26
+ }
27
+
28
+ })
29
+ .init(function(){
30
+
31
+ if(this._image){
32
+ this.image(this._image);
33
+ }
34
+
35
+ });
@@ -0,0 +1,102 @@
1
+ /*
2
+ The imgfont component writes text on the screen using a sprite image.
3
+ This is a faster approach than using the text component for now.
4
+ Plus you don't have to worry about the font not being supported.
5
+
6
+ @usage
7
+ //Must be created as a component to implement the imgtext array.
8
+ //imgtext is an array of all characters and defines the width
9
+ //of each.
10
+
11
+ re.c('serif')
12
+ .requires('imgtext font serif.png')
13
+ .defines('imgtext', [4,4,2,4,3,5,6,7,8,3,4,5])
14
+
15
+ re.e('serif')
16
+ .text('This displays on screen')
17
+
18
+ //find all fonts
19
+ re('font')
20
+
21
+ *could be turned in to a special sprite component but wouldn't
22
+ be very useful.
23
+ */
24
+
25
+ re.c('imgtext')
26
+ .requires('draw')
27
+ .interfaces('imgtext')
28
+ .defaults({
29
+ //remove empty characters in ascii
30
+ charOffset:32
31
+
32
+ })
33
+ .defines({
34
+
35
+ visible:function(){
36
+ return this._text && this._image && this.parent('draw', 'visible');
37
+ },
38
+
39
+ draw:function(c){
40
+
41
+ var slot = 0, charWidth, code, charPos;
42
+
43
+ for(var i=0, l = this._text.length; i<l; ++i){
44
+
45
+ //get char code
46
+ code = this._text.charCodeAt(i) - this.charOffset;
47
+
48
+ //find width of character
49
+ charWidth = this.imgtext[code];
50
+
51
+ //find source character position
52
+ if(!this.charCache[code]){
53
+ charPos = 0;
54
+ for(var p=0; p<code; ++p){
55
+ charPos += this.imgtext[p]+1;
56
+ }
57
+ this.charCache[code] = charPos;
58
+ }
59
+
60
+ c.drawImage(this._image, this.charCache[code], 0, charWidth, this._image.height, -this.regX + slot, -this.regY, charWidth, this._image.height);
61
+
62
+ //append to next character slot
63
+ slot += charWidth;
64
+
65
+ }
66
+
67
+ this.sizeX = slot;
68
+ this.sizeY = this._image.height;
69
+ return this;
70
+ },
71
+
72
+ text:function(t){
73
+ if(re.is(t)){
74
+ this._text = t;
75
+
76
+ var t = 0;
77
+ //TODO size is slightly off
78
+ for(var p=0; p<this._text.length; p++){
79
+ t += this.imgtext[p];
80
+ }
81
+
82
+ this.sizeX = t;
83
+
84
+ if(this._image){
85
+ this.sizeY = this._image.height;
86
+ } else {
87
+ this.sizeY = 0;
88
+ }
89
+
90
+ return this;
91
+ }
92
+ return this._text;
93
+ }
94
+
95
+ })
96
+ .init(function(){
97
+
98
+ if(!this.charCache){
99
+ this.charCache = {};
100
+ }
101
+ this.text('');
102
+ });
@@ -1,19 +1,19 @@
1
- /*
2
- The rect component draws a rectangle on screen.
3
- */
4
- re.c('rect')
5
- .require('draw')
6
- .inherit({
7
- color:'#82d5f4'
8
- })
9
- .extend({
10
-
11
- draw:function(c){
12
-
13
- c.fillStyle = this.color;
14
-
15
- c.fillRect(-this.regX, -this.regY, this.sizeX, this.sizeY);
16
-
17
- }
18
-
1
+ /*
2
+ The rect component draws a rectangle on screen.
3
+ */
4
+ re.c('rect')
5
+ .requires('draw')
6
+ .defaults({
7
+ color:'#82d5f4'
8
+ })
9
+ .defines({
10
+
11
+ draw:function(c){
12
+
13
+ c.fillStyle = this.color;
14
+
15
+ c.fillRect(-this.regX, -this.regY, this.sizeX, this.sizeY);
16
+ return this;
17
+ }
18
+
19
19
  });
@@ -0,0 +1,57 @@
1
+ /*
2
+ The screen component is used for scrolling or shaking all visible objects.
3
+ It simply offsets pos values upon rendering.
4
+
5
+ This is useful for setting up a tile-based game.
6
+ */
7
+ re.c('screen')
8
+ .requires('hit')
9
+ .defines({
10
+
11
+ pos:function(x, y){
12
+ if(!arguments.length){
13
+ return this;
14
+ }
15
+ if(arguments.length == 1){
16
+ y = x.posY;
17
+ x = x.posX;
18
+ }
19
+
20
+ this.posX = x - this.regX;
21
+ this.posY = y - this.regY;
22
+
23
+ return this;
24
+ },
25
+
26
+ toScreenX:function(x){
27
+ return x + this.posX + this.offX;
28
+ },
29
+
30
+ toScreenY:function(y){
31
+ return y + this.posY + this.offY;
32
+ },
33
+
34
+ toScreen:function(x, y){
35
+ if(arguments.length==1){
36
+ y = x.posY || x.y;
37
+ x = x.posX || x.x;
38
+ }
39
+ return {x: this.toScreenX(x), y: this.toScreenY(y)};
40
+ }
41
+
42
+ })
43
+ .defaults({
44
+
45
+ posX:0,
46
+ posY:0,
47
+
48
+ regX:0,
49
+ regY:0,
50
+
51
+ sizeX:0,
52
+ sizeY:0,
53
+
54
+ offX:0,
55
+ offY:0
56
+
57
+ });
@@ -0,0 +1,54 @@
1
+ /*
2
+ The sprite object definess a drawable image for an entity.
3
+
4
+ @usage
5
+ var sprite = re.e('sprite player.png');
6
+
7
+ //move to frame 3
8
+ sprite.fra(3)
9
+
10
+ //get current frame
11
+ sprite.fra()
12
+
13
+ //manually move to frame
14
+ sprite.attr({fraX:0, fraY:1});
15
+
16
+ //add animation
17
+ sprite.comp('flicker')
18
+ //add animation
19
+ sprite.flicker('run', -1, 400, [0, 2, 3, 4])
20
+ //play
21
+ sprite.flicker('run')
22
+ */
23
+
24
+ re.c('sprite')
25
+ .requires('image bisect')
26
+ .defaults({
27
+
28
+ frameX:0,
29
+ frameY:0
30
+
31
+ })
32
+ .defines({
33
+
34
+ frame:function(i){
35
+ if(re.is(i)){
36
+ this.frameX = this.biToTileX(i);
37
+ this.frameY = this.biToTileY(i);
38
+ return this;
39
+ }
40
+ return this.tileToBi(this.frameX, this.frameY);
41
+ },
42
+
43
+ draw:function(c){
44
+ c.drawImage(this._image, this.frameX * this.sizeX, this.frameY * this.sizeY, this.sizeX, this.sizeY, -this.regX, -this.regY, this.sizeX, this.sizeY);
45
+
46
+ return this;
47
+ },
48
+
49
+ //implement for flicker
50
+ flick:function(c){
51
+ this.frame(c);
52
+ }
53
+
54
+ });
@@ -0,0 +1,44 @@
1
+ /*
2
+ The text component displays font on screen using the canvas font api.
3
+
4
+ //create font
5
+ re.e('text')
6
+ .defines({
7
+ text:'Texting Message',
8
+ textColor:'#ff0000'
9
+ });
10
+
11
+ TODO implement size
12
+
13
+ */
14
+ re.c('text')
15
+ .requires('draw')
16
+ .defaults({
17
+ font:"14px sans-serif",
18
+ textColor:'#000000',
19
+ textAlign:'',
20
+ font_text:''
21
+ })
22
+ .defines({
23
+
24
+ visible:function(){
25
+ return this._text && this.parent('draw', 'visible')
26
+ },
27
+
28
+ text:function(t){
29
+ if(re.is(t)){
30
+ this._text = t;
31
+ return this;
32
+ }
33
+ return this._text;
34
+ },
35
+
36
+ draw:function(c){
37
+
38
+ c.font = this.font;
39
+ c.fillStyle = this.textColor;
40
+ c.fillText(this._text, -this.regX, -this.regY);
41
+ return this;
42
+ }
43
+
44
+ });