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
@@ -1,150 +1,152 @@
1
- re.c('keyboard')
2
- .global({
3
- listeners:[],
4
-
5
- keyCodes: {
6
- /* start the a-z keys */
7
- 65 : 'a',
8
- 66:'b',
9
- 67:'c',
10
- 68:'d',
11
- 69:'e',
12
- 70:'f',
13
- 71:'g',
14
- 72:'h',
15
- 73:'i',
16
- 74:'j',
17
- 75:'k',
18
- 76:'l',
19
- 77:'m',
20
- 78:'n',
21
- 79:'o',
22
- 80:'p',
23
- 81:'q',
24
- 82:'r',
25
- 83:'s',
26
- 84:'t',
27
- 85:'u',
28
- 86:'v',
29
- 87:'w',
30
- 88:'x',
31
- 89:'y',
32
- 90:'z',
33
- /* start number keys */
34
- 48:'0',
35
- 49:'1',
36
- 50:'2',
37
- 51:'3',
38
- 52:'4',
39
- 53:'5',
40
- 54:'6',
41
- 55:'7',
42
- 56:'8',
43
- 57:'9',
44
- /* start the f keys */
45
- 112:'f1',
46
- 113:'f2',
47
- 114:'f3',
48
- 115:'f4',
49
- 116:'f5',
50
- 117:'f6',
51
- 118:'f7',
52
- 119:'f8',
53
- 120:'f9',
54
- 121:'f10',
55
- 122:'f11',
56
- 123:'f12',
57
- /* start the modifier keys */
58
- 16:'shift',
59
- 17:'ctrl', //mac os - control
60
- 18:'alt',//mac os key - option opt
61
- 24:'cmd', //Mac OS key - also command
62
- 255:'fn',//lenovo - function
63
- /* Misc. Keys */
64
- 8:'backspace',
65
- 13:'enter', //max os - return
66
- 32:'space',
67
- 27:'esc',
68
- 9:'tab',
69
- 20:'capslock',
70
- 91:'windows',//mac os - super
71
- 46:'delete', //NOT THE OS X DELETE KEY!
72
- 36:'home',
73
- 35:'end',
74
- 33:'pageup',
75
- 34:'pagedown',
76
- /* Arrow keys */
77
- 37:'left',
78
- 38:'up',
79
- 39:'right',
80
- 40:'down',
81
- /* Special char keys */
82
- 96:'`',
83
- 45:'-',//also insert on mac?
84
- 187:'=',
85
- 219:'[',
86
- 221:']',
87
- 220:'\\', //it's actually a \ but there's two to escape
88
- 59:';',
89
- 222:"'",
90
- 188:',',
91
- 190:'.',
92
- 191:'/'
93
- },
94
-
95
- /*
96
- Add modifiers, shift, alt, ctrl.
97
- .signal('ctrl+k')
98
- */
99
- keyboardEvent: function(e){
100
- var that = re.c('keyboard');
101
-
102
- if(that.body != document.activeElement){
103
- return;
104
- }
105
-
106
- var c = e.keyCode || e.which;
107
-
108
- var key = that.keyCodes[c];
109
-
110
- if(re.c('pressed').preventDefault && re.c('pressed').preventDefault[key]){
111
- if(e.preventDefault)
112
- e.preventDefault();
113
- else
114
- e.returnValue = false;
115
-
116
- }
117
-
118
- if(re.c('pressed')._pressed){
119
- re.c('pressed')._pressed[key] = (e.type == 'keydown');
120
- }
121
-
122
- for(var k=0; k<that.listeners.length; k++){
123
- that.listeners[k]
124
- .signal(e.type, key, e)
125
- .signal(e.type+':'+key, key, e);
126
- }
127
-
128
- },
129
-
130
- active:false,
131
-
132
- initListeners:function(){
133
- if(!this.active){
134
- this.active = true;
135
- re.listener('keydown', this.keyboardEvent, false);
136
- re.listener('keyup', this.keyboardEvent, false);
137
- this.body = re.$('body')[0];
138
- }
139
- }
140
-
141
- })
142
- .init(function(c){
143
- c.initListeners();
144
- //add to global key array
145
- c.listeners.push(this);
146
- })
147
- .dispose(function(c){
148
- //remove from global key array
149
- c.listeners.splice(c.listeners.indexOf(this), 1);
150
- });
1
+ /*
2
+ The keyboard component allows an entity to listen for keyboard events.
3
+
4
+ @usage
5
+ re.e('keyboard')
6
+ .keydown(function(key, event){
7
+ re.log('keydown', key, event);
8
+ })
9
+ .keyup(function(key, event){
10
+ re.log('keyup', key, event);
11
+ });
12
+
13
+ */
14
+ re.c('keyboard')
15
+ .statics({
16
+ //list of listing entities
17
+ l:[],
18
+
19
+ keyCodes: {
20
+ /* start the a-z keys */
21
+ 65 : 'a',
22
+ 66:'b',
23
+ 67:'c',
24
+ 68:'d',
25
+ 69:'e',
26
+ 70:'f',
27
+ 71:'g',
28
+ 72:'h',
29
+ 73:'i',
30
+ 74:'j',
31
+ 75:'k',
32
+ 76:'l',
33
+ 77:'m',
34
+ 78:'n',
35
+ 79:'o',
36
+ 80:'p',
37
+ 81:'q',
38
+ 82:'r',
39
+ 83:'s',
40
+ 84:'t',
41
+ 85:'u',
42
+ 86:'v',
43
+ 87:'w',
44
+ 88:'x',
45
+ 89:'y',
46
+ 90:'z',
47
+ /* start number keys */
48
+ 48:'0',
49
+ 49:'1',
50
+ 50:'2',
51
+ 51:'3',
52
+ 52:'4',
53
+ 53:'5',
54
+ 54:'6',
55
+ 55:'7',
56
+ 56:'8',
57
+ 57:'9',
58
+ /* start the f keys */
59
+ 112:'f1',
60
+ 113:'f2',
61
+ 114:'f3',
62
+ 115:'f4',
63
+ 116:'f5',
64
+ 117:'f6',
65
+ 118:'f7',
66
+ 119:'f8',
67
+ 120:'f9',
68
+ 121:'f10',
69
+ 122:'f11',
70
+ 123:'f12',
71
+ /* start the modifier keys */
72
+ 16:'shift',
73
+ 17:'ctrl', //mac os - control
74
+ 18:'alt',//mac os key - option opt
75
+ 24:'cmd', //Mac OS key - also command
76
+ 255:'fn',//lenovo - function
77
+ /* Misc. Keys */
78
+ 8:'backspace',
79
+ 13:'enter', //max os - return
80
+ 32:'space',
81
+ 27:'esc',
82
+ 9:'tab',
83
+ 20:'capslock',
84
+ 91:'windows',//mac os - super
85
+ 46:'delete', //NOT THE OS X DELETE KEY!
86
+ 36:'home',
87
+ 35:'end',
88
+ 33:'pageup',
89
+ 34:'pagedown',
90
+ /* Arrow keys */
91
+ 37:'left',
92
+ 38:'up',
93
+ 39:'right',
94
+ 40:'down',
95
+ /* Special char keys */
96
+ 96:'`',
97
+ 45:'-',//also insert on mac?
98
+ 187:'=',
99
+ 219:'[',
100
+ 221:']',
101
+ 220:'\\', //it's actually a \ but there's two to escape
102
+ 59:';',
103
+ 222:"'",
104
+ 188:',',
105
+ 190:'.',
106
+ 191:'/'
107
+ },
108
+
109
+ /*
110
+ Add modifiers, shift, alt, ctrl.
111
+ .trigger('ctrl+k')
112
+ */
113
+ event: function(e){
114
+ var that = re._c.keyboard;
115
+
116
+ //disable keyboard keys if focus lost
117
+ if(that.body != document.activeElement){
118
+ return;
119
+ }
120
+
121
+ var c = e.keyCode || e.which;
122
+
123
+ var key = that.keyCodes[c];
124
+
125
+ if(re.pressed.d){
126
+ re.pressed.d[key] = (e.type == 'keydown');
127
+ }
128
+
129
+ for(var k=0; k<that.l.length; k++){
130
+ that.l[k]
131
+ .trigger(e.type, key, e)
132
+ .trigger(e.type+':'+key, key, e);
133
+ }
134
+
135
+ },
136
+
137
+ //initialize function
138
+ i:function(){
139
+ this.body = re.$('body');
140
+ re.listener('keydown', this.event, false);
141
+ re.listener('keyup', this.event, false);
142
+ }
143
+
144
+ })
145
+ .init(function(c){
146
+ //add to statics key array
147
+ c.l.push(this);
148
+ })
149
+ .dispose(function(c){
150
+ //remove from statics key array
151
+ c.l.splice(c.l.indexOf(this), 1);
152
+ });
@@ -0,0 +1,111 @@
1
+ /*
2
+ The mouse component allows an entity to listen to mouse triggers.
3
+
4
+ @usage
5
+ re.e('mouse')
6
+ .on('mousedown:middle', function(m){
7
+ //m.x - x position
8
+ //m.y - y position
9
+ //m.scrX - screen x position
10
+ //m.scrY - screen y position
11
+ })
12
+ */
13
+ re.c('mouse')
14
+ .statics({
15
+ l:[],
16
+
17
+ press:function(e){
18
+ var b, c;
19
+
20
+ //find which key
21
+ if(e.which == null){
22
+ //IE
23
+ if(e.button < 2){
24
+ b = 'left';
25
+ } else if(e.button == 4){
26
+ b = 'middle';
27
+ } else {
28
+ b = 'right';
29
+ }
30
+ } else {
31
+ if(e.which < 2){
32
+ b = 'left';
33
+ } else if(e.which == 2){
34
+ b = 'middle';
35
+ } else {
36
+ b = 'right';
37
+ }
38
+ }
39
+
40
+ c = 'mouse:'+b;
41
+
42
+ //register mouse action
43
+ if(re.pressed.d){
44
+ re.pressed.d[c] = (e.type == 'mousedown');
45
+ }
46
+
47
+ re.c('mouse').event(e, c);
48
+
49
+ },
50
+
51
+ event:function(e, extra){
52
+
53
+ //calculate mouse coordinate
54
+ var x;
55
+ var y;
56
+
57
+ if(e.pageX){
58
+ x = e.pageX;
59
+ y = e.pageY;
60
+ } else {
61
+ x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
62
+ y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
63
+ }
64
+
65
+ //FUTURE fix, does not support multiple canvases
66
+ x -= re.sys.canvas.offsetLeft;
67
+ y -= re.sys.canvas.offsetTop;
68
+
69
+ //ignore if off canvas
70
+ if(x < 0 || y < 0 || y > re.sys.sizeY || x > re.sys.sizeX){
71
+ return;
72
+ }
73
+
74
+ var that = re.c('mouse');
75
+
76
+ //FUTURE automatically transform screen coordinates?
77
+ var c, t, obj;
78
+ for(var i=0; i<that.l.length; i++){
79
+ t = that.l[i];
80
+ obj = {x:x, y:y};
81
+ obj.screenX = re.screen.toScreenX(x);
82
+ obj.screenY = re.screen.toScreenY(y);
83
+
84
+ t.trigger(e.type, obj, e);
85
+
86
+ if(extra){
87
+ t.trigger(e.type+':'+extra, obj, e);
88
+ }
89
+ }
90
+
91
+ },
92
+
93
+ i:function(){
94
+ re.listener('mousedown', this.press, false);
95
+ re.listener('mouseup', this.press, false);
96
+ re.listener('mousemove', this.event, false);
97
+ re.listener('click', this.event, false);
98
+ re.listener('dblclick', this.event, false);
99
+ re.listener('contextmenu', this.event, false);
100
+ }
101
+
102
+ })
103
+ .init(function(c){
104
+ //add to listener array
105
+ c.l.push(this);
106
+ })
107
+ .dispose(function(c){
108
+ //remove from listener array
109
+
110
+ c.l.splice(c.l.indexOf(this), 1);
111
+ });
@@ -0,0 +1,41 @@
1
+ /*
2
+ The pressed method is used to check if a key or keys are currently pressed.
3
+ This is most useful in mousemove, keydown or usually an update listener.
4
+
5
+ @usage
6
+ //move player
7
+ re.e('update image player.png')
8
+ .on('update', function(){
9
+
10
+ if(re.pressed(['w', 'up'])){
11
+ this.posY -= 10;
12
+ }
13
+
14
+ });
15
+
16
+ //click based on key
17
+ re.e('mouse image button.png')
18
+ .on('click', function(){
19
+
20
+ if(re.pressed('mouse:middle')){
21
+ //do something..
22
+ }
23
+
24
+ });
25
+
26
+ */
27
+ re.pressed = function(key){
28
+
29
+ var c = arguments;
30
+
31
+ if(re.is(key, 'array')) c = key;
32
+
33
+ for(var i=0, l = c.length; i<l; i++){
34
+ if(re.pressed.d[c[i]]){
35
+ return true;
36
+ }
37
+ }
38
+
39
+ return false;
40
+ };
41
+ re.pressed.d = {};
@@ -1,28 +1,24 @@
1
- /*
2
- The touch component handles touch events and dispatches signals.
3
- */
4
- re.c('touch')
5
- .global({
6
-
7
- touchEvent:function(e){
8
-
9
- },
10
-
11
- active:false,
12
-
13
- initListeners:function(){
14
- if(!this.active){
15
- this.active = true;
16
-
17
- re.listener('touchstart', this.touchEvent, false);
18
- re.listener('touchmove', this.touchEvent, false);
19
- re.listener('touchend', this.touchEvent, false);
20
-
21
- }
22
- }
23
-
24
- })
25
- .init(function(c){
26
- c.initListeners();
27
-
28
- });
1
+ /*
2
+ The touch component handles touch events and dispatches signals.
3
+ */
4
+ /*re.c('touch')
5
+ .statics({
6
+
7
+ touchEvent:function(e){
8
+
9
+ },
10
+
11
+ active:false,
12
+
13
+ i:function(){
14
+ if(!this.active){
15
+ this.active = true;
16
+
17
+ re.listener('touchstart', this.touchEvent, false);
18
+ re.listener('touchmove', this.touchEvent, false);
19
+ re.listener('touchend', this.touchEvent, false);
20
+
21
+ }
22
+ }
23
+
24
+ });*/
@@ -0,0 +1,84 @@
1
+ /*
2
+ The bisect component cuts an object into equal sections. It supplies helper functions
3
+ for converting to a section and from a section. Useful for sprites and animation.
4
+
5
+ The bisect is the width of an area.
6
+ The size is the size of each equally divided block inside the width.
7
+ For a sprite the bisect would be the total width of the image
8
+ and the size would be the size of each frame.
9
+
10
+ The bisect transforms two numbers, x and y positons, into a single bi number.
11
+
12
+ This works by increasing the bi value once the x position is past the width.
13
+ Note: width is called the bisect and the bi is the transformed x,y positions.
14
+
15
+
16
+
17
+ */
18
+ re.bisect = re.c('bisect')
19
+ .statics({
20
+
21
+ biToX:function(bi, width, size){
22
+
23
+ return this.biToTileX(bi, width, size) * size;
24
+ },
25
+
26
+ biToY:function(bi, width, size){
27
+
28
+ return this.biToTileY(bi, width, size) * size;
29
+ },
30
+
31
+ biToTileX:function(bi, width, size){
32
+
33
+ return bi % (width / size) | 0;
34
+ },
35
+
36
+ biToTileY:function(bi, width, size){
37
+ return (bi * size) / (width - 0.1) | 0;
38
+ },
39
+
40
+ /*
41
+ Accepts Tile positions not normal X,Y
42
+ */
43
+ tileToBi:function(xt, yt, w, s){
44
+
45
+ return (xt + (yt * (w / s)));
46
+ }
47
+
48
+ })
49
+ .defines({
50
+
51
+
52
+ biToX:function(bi){
53
+
54
+ return re.bisect.biToX(bi, this.bisect, this.sizeX);
55
+ },
56
+
57
+ biToY:function(bi){
58
+
59
+ return re.bisect.biToY(bi, this.bisect, this.sizeY);
60
+ },
61
+
62
+ biToTileX:function(bi){
63
+
64
+ return re.bisect.biToTileX(bi, this.bisect, this.sizeX);
65
+ },
66
+
67
+ biToTileY:function(bi){
68
+ return re.bisect.biToTileY(bi, this.bisect, this.sizeY);
69
+ },
70
+
71
+ tileToBi:function(xt, yt){
72
+ return re.bisect.tileToBi(xt, yt, this.bisect, this.sizeX);
73
+ }
74
+
75
+ })
76
+ .defaults({
77
+
78
+ //full width
79
+ bisect:1,
80
+
81
+ sizeX:1,
82
+ sizeY:1
83
+
84
+ });
data/src/math/body.js ADDED
@@ -0,0 +1,70 @@
1
+ /*
2
+ The body component replaces the hittest component for
3
+ a more precise hit test.
4
+
5
+ It also removes the usage of sizeX and sizeX for collision
6
+ boundaries.
7
+
8
+ @usage
9
+
10
+ re.e('body player.png')
11
+ .attr({
12
+ bodyX:40,
13
+ bodyY:40,
14
+ padX:2 //pushes the body in 2 pixels on both right and left
15
+ })
16
+ .touches(0, 0, 40, 40) //touches random thing?
17
+ .touchesBody(0, 0, 40, 40, 2, 2) //touches another body?
18
+
19
+ */
20
+ re.c('body')
21
+ .defines({
22
+
23
+ hit:function(x, y, w, h){
24
+ if(re.is(x,'object')){
25
+ y = x.posY;
26
+ w = x.sizeX;
27
+ h = x.sizeY;
28
+ x = x.posX;
29
+ }
30
+ return !
31
+ (
32
+ x > this.posX + this.bodyX - this.padX ||
33
+ x + w < this.posX + this.padX ||
34
+ y > this.posY + this.bodyY - this.padY||
35
+ y + h < this.posY + this.padY
36
+ );
37
+ },
38
+
39
+ hitBody:function(x, y, bx, by, px, py){
40
+ if(re.is(x,'object')){
41
+ y = x.posY;
42
+ bx = x.bodyX;
43
+ by = x.bodyY;
44
+ px = x.padX;
45
+ py = x.padY;
46
+ x = x.posX;
47
+ }
48
+ return !
49
+ (
50
+ x + px > this.posX + this.bodyX + this.padX ||
51
+ x + bx - px < this.posX + this.padX ||
52
+ y + py > this.posY + this.bodyY - this.padY ||
53
+ y + by - py < this.posY + this.padY
54
+ );
55
+ }
56
+
57
+
58
+ })
59
+ .defaults({
60
+
61
+ posX:0,
62
+ posY:0,
63
+
64
+ padX:0,
65
+ padY:0,
66
+
67
+ bodyX:1,
68
+ bodyY:1
69
+
70
+ });