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,81 +0,0 @@
1
- re.c('pressed')
2
- .global({
3
- //contains pressed keys and mouse clicks
4
- _pressed:{},
5
- preventDefault:{}
6
-
7
- })
8
- .extend({
9
-
10
- /*
11
- This function is usually used in conjunction with mousemove or update for controls.
12
-
13
- //if either one is true
14
- if(this.pressed('w', 'up')){
15
- this.posY--;
16
- }
17
-
18
- //or
19
- if(this.pressed(['w', 'up']){
20
-
21
- }
22
-
23
- */
24
- pressed:function(){
25
- return re.pressed.apply(this, arguments);
26
- },
27
-
28
- /*
29
- Stops inputs default value.
30
-
31
- FUTURE
32
- -be able to remove prevents
33
- */
34
- preventDefault:function(){
35
- re.preventDefault.apply(this, arguments);
36
- return this;
37
- }
38
-
39
- })
40
- .init(function(){
41
-
42
- //int mouse and keyboard
43
- re._c.keyboard.initListeners();
44
- re._c.mouse.initListeners();
45
- re._c.touch.initListeners();
46
-
47
- });
48
-
49
- re.pressed = function(key){
50
- var that = re.c('pressed');
51
-
52
- var c = arguments;
53
-
54
- if(typeof key == 'object') c = key;
55
-
56
- for(var i=0; i<c.length; i++){
57
- if(that._pressed[c[i]]){
58
- return true;
59
- }
60
- }
61
-
62
- return false;
63
- };
64
-
65
- re.preventDefault = function(key){
66
-
67
- var p = key.split(' ');
68
-
69
- if(p.length > 1){
70
-
71
- for(var k in p){
72
- this.preventDefault(p[k]);
73
- }
74
-
75
- return this;
76
- }
77
-
78
- re.c('pressed').preventDefault[key] = true;
79
-
80
- return this;
81
- };
@@ -1,76 +0,0 @@
1
- /*
2
- The bind component prevents points from going outside of the set parameters.
3
-
4
- This can be useful for maps, characters, enemies, boxes etc..
5
-
6
- re.e('bind bitmap char.png')
7
- .bind = {min:{x:0, y:0}, max:{x:100, y: 10}};
8
-
9
- */
10
-
11
- re.c('bind')
12
- .require('update')
13
- .namespace({
14
-
15
- update:function(){
16
- if(!this.bind) return;
17
-
18
- if(this.posX < this.bindMinX){
19
-
20
- this.posX = this.bindMinX;
21
-
22
- } else if(this.posX > this.bindMaxX){
23
-
24
- this.posX = this.bindMaxX;
25
- }
26
-
27
- if(this.posY < this.bindMinY){
28
-
29
- this.posY = this.bindMinY;
30
-
31
- } else if(this.posY > this.bindMaxY){
32
-
33
- this.posY = this.bindMaxY;
34
- }
35
-
36
- }
37
-
38
- })
39
- .inherit({
40
-
41
- posX:0,
42
- posY:0,
43
-
44
- bindMinX:0,
45
- bindMinY:0,
46
-
47
- bindMaxX:10,
48
- bindMaxY:10,
49
-
50
- bind:true
51
-
52
- })
53
- .extend({
54
-
55
- setBind:function(minx, miny, maxx, maxy){
56
-
57
- this.bindMinX = minx;
58
- this.bindMinY = miny;
59
-
60
- this.bindMaxX = maxx;
61
- this.bindMaxY = maxy;
62
-
63
- return this;
64
- }
65
-
66
- })
67
- .init(function(){
68
-
69
- this.addSignal('update', this.bind_update);
70
-
71
- })
72
- .dispose(function(){
73
-
74
- this.removeSignal('update', this.bind_update);
75
-
76
- });
@@ -1,69 +0,0 @@
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
- re.bisect = re.c('bisect')
6
- .global({
7
-
8
- biToX:function(bi, width, size){
9
-
10
- return this.biToXt(bi, width) * size;
11
- },
12
-
13
- biToY:function(bi, width, size){
14
-
15
- return this.biToYt(bi, width) * size;
16
- },
17
-
18
- biToXt:function(bi, width, size){
19
-
20
- return Math.floor(bi % (width / size) );
21
- },
22
-
23
- biToYt:function(bi, width, size){
24
- return Math.floor((bi * size) / (width - 0.1));
25
- },
26
-
27
- toBi:function(xt, yt, w, s){
28
-
29
- return (xt + (yt * (w / s))) / s;
30
- }
31
-
32
- })
33
- .extend({
34
-
35
-
36
- biToX:function(bi){
37
-
38
- return this.biToXt(bi, this.bisect) * this.sizeX;
39
- },
40
-
41
- biToY:function(bi){
42
-
43
- return this.biToYt(bi, this.bisect) * this.sizeY;
44
- },
45
-
46
- biToXt:function(bi){
47
-
48
- return Math.floor(bi % (this.bisect / this.sizeX) );
49
- },
50
-
51
- biToYt:function(bi){
52
- return Math.floor((bi * this.sizeY) / (this.bisect - 0.1));
53
- },
54
-
55
- toBi:function(xt, yt){
56
-
57
- return (xt + (yt * (this.bisect / this.sizeX))) / this.sizeX;
58
- }
59
-
60
- })
61
- .inherit({
62
-
63
- //spliting width
64
- bisect:1,
65
-
66
- sizeX:1,
67
- sizeY:1
68
-
69
- });
@@ -1,39 +0,0 @@
1
- /*
2
- The body component replaces the hittest component for
3
- a more precise touch checking.
4
-
5
- */
6
- re.c('body')
7
- .extend({
8
-
9
- touches:function(x, y, w, h){
10
- return !
11
- (
12
- x > this.posX + this.bodX - this.padX ||
13
- x + w < this.posX + this.padX ||
14
- y > this.posY + this.bodY - this.padY||
15
- y + h < this.posY + this.padY
16
- );
17
- },
18
-
19
- touchesBody:function(x, y, bx, by, px, py){
20
- return !
21
- (
22
- x + px > this.posX + this.bodX + this.padX ||
23
- x + bx - px < this.posX + this.padX ||
24
- y + py > this.posY + this.bodY - this.padY ||
25
- y + by - py < this.posY + this.padY
26
- );
27
- }
28
-
29
-
30
- })
31
- .inherit({
32
-
33
- padX:0,
34
- padY:0,
35
-
36
- bodX:1,
37
- bodY:1
38
-
39
- });
@@ -1,165 +0,0 @@
1
- /*
2
-
3
- The hitmap component is used for collision detection in a tile-based game.
4
- This can be sent to a physics entity and it will recieve checks if it hits
5
- a tile.
6
-
7
- Creating this signal system will allow other developers to easily implement
8
- their own hit collision system.
9
- */
10
- re.c('hitmap')
11
- .require('arraymap')
12
- .extend({
13
-
14
- hitValue:1,
15
-
16
- checkAxisX:function(value, x, y, vx, vy){
17
-
18
- return value == this.hitValue;
19
-
20
- },
21
-
22
- checkAxisY:function(value, x, y, vx, vy){
23
- return value == this.hitValue;
24
- },
25
-
26
- checkHit:function(posX, posY, velX, velY, bodX, bodY, padX, padY){
27
- if(arguments.length == 1){
28
- var velX = posX.velX;
29
- var velY = posX.velY;
30
-
31
- var bodX = posX.bodX;
32
- var bodY = posX.bodY;
33
-
34
- var padX = posX.padX;
35
- var padY = posX.padY;
36
-
37
- var posY = posX.posY;
38
- posX = posX.posX;
39
- }
40
-
41
- var res = {
42
- posX:posX,
43
- posY:posY,
44
- tarX:-1,
45
- tarY:-1
46
- };
47
-
48
- var step = ~~(Math.max(Math.abs(velX), Math.abs(velY)) / ((re.tile.sizeX + re.tile.sizeY) * 0.5) + 0.5);
49
-
50
- if(step > 1) {
51
- var sx = velX / step;
52
- var sy = velY / step;
53
-
54
- for(var i=0; i<step && (sx || sy); i++) {
55
-
56
- this.hitmap_step(res, posX, posY, sx, sy, bodX, bodY, padY, padY);
57
-
58
- if(res.hitX) {
59
- sx = 0;
60
- }
61
-
62
- if(res.hitY) {
63
- sy = 0;
64
- }
65
- }
66
-
67
- } else {
68
-
69
- this.hitmap_step(res, posX, posY, velX, velY, bodX, bodY, padX, padY);
70
-
71
- }
72
-
73
- return res;
74
- }
75
-
76
- })
77
- .namespace({
78
-
79
- /*
80
- TODO:
81
- refactor
82
- possibly utilize entity methods for more robust calculations.
83
- */
84
- step:function(res, x, y, vx, vy, width, height, padx, pady){
85
-
86
- res.posX += vx;
87
- res.posY += vy;
88
-
89
- var t, ty, tx;
90
-
91
- if(vx) {
92
-
93
- t = re.tile.sizeX;
94
-
95
- var offsetx = (vx > 0 ? width - padx : padx);
96
-
97
- var firsty = Math.floor((y + pady)/ t);
98
- var lasty = Math.ceil((y + height - pady) / t);
99
-
100
- tx = Math.floor((x + vx + offsetx) / t);
101
-
102
- var offx = (vx < 0 ? t : 0);
103
- //is inside
104
- if(tx >= 0 && tx < this.lengthX && lasty >= 0 && firsty < this.lengthY) {
105
-
106
- for(ty = firsty; ty<lasty; ty++){
107
-
108
- if(this.map[ty]){
109
-
110
- //signal
111
- this.signal('hit', this.map[ty][tx], tx, ty);
112
-
113
- if(this.checkAxisX(this.map[ty][tx], x, y, vx, vy)) {
114
- res.hitX = true;
115
- res.posX = tx * t + offx - offsetx;
116
- res.tarX = tx * t;
117
- res.tarY = ty * t;
118
- break;
119
- }
120
- }
121
-
122
- }
123
-
124
- }
125
-
126
- }
127
-
128
- if(vy) {
129
- t = re.tile.sizeY;
130
-
131
- var offsety = (vy > 0 ? height -pady : pady);
132
-
133
- var firstx = Math.floor((res.posX + padx) / t);
134
- var lastx = Math.ceil((res.posX + width - padx) / t);
135
- ty = Math.floor((y + vy + offsety) / t);
136
-
137
- var offy = (vy < 0 ? t : 0);
138
- // Still inside this collision map?
139
- if(ty >= 0 && ty < this.lengthY && lastx >= 0 && firstx< this.lengthX) {
140
-
141
- for(tx = firstx; tx<lastx; tx++) {
142
-
143
- if(this.map[ty]){
144
-
145
- this.signal('hit', this.map[ty][tx], tx, ty);
146
-
147
- if(this.checkAxisY(this.map[ty][tx], x, y, vx, vy)) {
148
- res.hitY = true;
149
- res.posY = ty * t + offy - offsety;
150
- res.tarX = tx * t;
151
- res.tarY = ty * t;
152
- break;
153
- }
154
- }
155
-
156
- }
157
- }
158
-
159
-
160
-
161
- }
162
-
163
- }
164
-
165
- });
@@ -1,26 +0,0 @@
1
- re.c('hittest')
2
- .inherit({
3
-
4
- posX:0,
5
- posY:0,
6
-
7
- sizeX:0,
8
- sizeY:0,
9
-
10
- /*
11
- checks if the two targets intersect with each other.
12
-
13
- k.touches(x, y, width, height);
14
-
15
- */
16
- touches:function(x, y, w, h){
17
- return !
18
- (
19
- x > this.posX + this.sizeX ||
20
- x + w < this.posX ||
21
- y > this.posY + this.sizeY ||
22
- y + h < this.posY
23
- );
24
- }
25
-
26
- });
@@ -1,142 +0,0 @@
1
- /*
2
- The Physics component adds new physical and time calculated variables to an entity.
3
-
4
- These variables will give the entity a more fluid movement in 2d space.
5
-
6
- Warning - this component is not delta time safe. It assumes a fixed timestep.
7
- */
8
- re.physics = re.c('physics')
9
- .require('update')
10
- .global({
11
- graX:0,
12
- graY:0,
13
-
14
- //velocity lower than this will be rounded down
15
- minVel:0.01
16
- })
17
- .inherit({
18
-
19
- posX:0,
20
- posY:0,
21
-
22
- velX:0,
23
- velY:0,
24
-
25
- velMaxX:100,
26
- velMaxY:100,
27
-
28
- friX:0.9,
29
- friY:0.4,
30
-
31
- accX:0,
32
- accY:0,
33
-
34
- resX:0,
35
- resY:0,
36
-
37
- masX:1,
38
- masY:1,
39
-
40
- padX:0,
41
- padY:0,
42
-
43
- bodX:1,
44
- bodY:1
45
-
46
- })
47
- .namespace({
48
-
49
- update:function(t){
50
-
51
- this.velX = this.force(this.velX, this.accX, this.friX, this.graX, this.masX, this.velMaxX);
52
- this.velY = this.force(this.velY, this.accY, this.friY, this.graY, this.masY, this.velMaxY);
53
-
54
- //check collisions and get result
55
- if(this.hitmap){
56
-
57
- this.aftermath(this.hitmap.checkHit(this));
58
-
59
- } else {
60
-
61
- this.aftermath(this.posX + this.velX, this.posY + this.velY);
62
- }
63
-
64
- }
65
-
66
- })
67
- .extend({
68
-
69
- aftermath:function(posx, posy, hitx, hity, tarx, tary){
70
-
71
- if(arguments.length == 1){
72
- hitx = posx.hitX;
73
- hity = posx.hitY;
74
-
75
- tarx = posx.tarX;
76
- tary = posx.tarY;
77
-
78
- posy = posx.posY;
79
- posx = posx.posX;
80
- }
81
-
82
- this.posX = posx;
83
- this.posY = posy;
84
-
85
- this.signal('aftermath', hitx, hity, tarx, tary);
86
-
87
- if(hitx){
88
- this.velX = this.forceRes(this.velX, this.resX);
89
- }
90
-
91
- if(hity){
92
- this.velY = this.forceRes(this.velY, this.resY);
93
- }
94
-
95
- },
96
-
97
- forceRes:function(vel, res){
98
- return vel * -res;
99
- },
100
-
101
- forceGra:function(gra, mas){
102
- return gra * mas;
103
- },
104
-
105
- forceVel:function(vel, acc, fri){
106
- return (vel + acc) * fri;
107
-
108
- },
109
-
110
- force:function(vel, acc, fri, gra, mas, max){
111
-
112
- var v = this.forceVel(vel, acc, fri) + this.forceGra(gra, mas);
113
-
114
- v = Math.min(max, Math.max(-max, v));
115
-
116
- if(Math.abs(v) < re.physics.minVel){
117
- v = 0;
118
- }
119
-
120
- return v;
121
- },
122
-
123
- isIdle:function(){
124
- return (this.velY == 0 && this.velX == 0 && this.accX == 0 && this.accY == 0);
125
- }
126
-
127
- })
128
- .init(function(c){
129
-
130
- //setup defaults
131
- this.hitmap = re.hitmap;
132
-
133
- this.graX = c.graX;
134
- this.graY = c.graY;
135
-
136
- this.addSignal('update', this.physics_update);
137
- })
138
- .dispose(function(){
139
-
140
- this.removeSignal('update', this.physics_update);
141
-
142
- });
@@ -1,57 +0,0 @@
1
- /*
2
- The point component extends an entity that has a 2d position in space.
3
- This can be used for 2d calculations or most commonly 2d sprite positioning.
4
-
5
- */
6
-
7
- re.c('point')
8
- .inherit({
9
-
10
- posX:0,
11
- posY:0
12
-
13
- })
14
- .extend({
15
-
16
- setPos:function(x, y){
17
-
18
- if(arguments.length == 1){
19
- if(x.y)
20
- this.posY = x.posY;
21
-
22
- if(x.x)
23
- this.posX = x.posX;
24
-
25
- } else {
26
-
27
- this.posX = x;
28
- this.posY = y;
29
-
30
- }
31
-
32
- return this;
33
- },
34
-
35
- setPosX:function(x){
36
- this.posX = x;
37
- return this;
38
- },
39
-
40
- setPosY:function(y){
41
- this.posY = y;
42
- return this;
43
- },
44
-
45
- distanceTo:function(x, y){
46
- if(arguments.length == 1){
47
- y = x.posY;
48
- x = x.posX;
49
- }
50
- var kx, ky;
51
- kx = x-this.posX>>31;
52
- ky = y-this.posY>>31;
53
-
54
- return Math.round(((x-this.posX ^kx)-kx)+((y-this.posY^ky)-ky));
55
- }
56
-
57
- });