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
@@ -1,39 +1,45 @@
1
- /*
2
- The drag component adds functions to move points
3
- in relation to its starting postion.
4
- */
5
- re.c('drag')
6
- .inherit({
7
- posX:0,
8
- posY:0,
9
-
10
- dragX:0,
11
- dragY:0,
12
-
13
- dragging:false
14
- })
15
- .extend({
16
-
17
- startDrag:function(x, y){
18
- if(!this.dragging){
19
- this.dragging = true;
20
- this.dragX = x;
21
- this.dragY = y;
22
- }
23
- },
24
-
25
- endDrag:function(){
26
- this.dragging = false;
27
- },
28
-
29
- updateDrag:function(x, y){
30
- if(this.dragging){
31
- this.posX += x - this.dragX;
32
- this.posY += y - this.dragY;
33
-
34
- this.dragX = x;
35
- this.dragY = y;
36
- }
37
- }
38
-
1
+ /*
2
+ The drag component adds functions to move points
3
+ in relation to its starting postion.
4
+ */
5
+ re.c('drag')
6
+ .defaults({
7
+ posX:0,
8
+ posY:0,
9
+
10
+ dragX:0,
11
+ dragY:0,
12
+
13
+ dragging:false
14
+ })
15
+ .defines({
16
+
17
+ dragStart:function(x, y){
18
+ if(!this.dragging){
19
+ this.dragging = true;
20
+ this.dragX = x;
21
+ this.dragY = y;
22
+ this.trigger('drag:start');
23
+ }
24
+ return this;
25
+ },
26
+
27
+ dragEnd:function(){
28
+ this.dragging = false;
29
+ return this.trigger('drag:end');
30
+ },
31
+
32
+ dragUpdate:function(x, y){
33
+ if(this.dragging){
34
+ this.posX += x - this.dragX;
35
+ this.posY += y - this.dragY;
36
+
37
+ this.dragX = x;
38
+ this.dragY = y;
39
+
40
+ this.trigger('drag:update');
41
+ }
42
+ return this;
43
+ }
44
+
39
45
  });
data/src/math/force.js ADDED
@@ -0,0 +1,143 @@
1
+ /*
2
+ The Force component adds velocity, acceleration and other physical properties to an entity.
3
+
4
+ This does not implement collision detection! This allows an entity to move fluidly
5
+ through 2d, with gravity, and friction.
6
+
7
+ You can add hit collision check by defining a hitmap. Like so:
8
+
9
+ var mountainHits = re.e('hitmap');
10
+
11
+ re.e('force')
12
+ .attr(hitmap:mountainHits);
13
+
14
+ //or define a hitmap for all physics objects
15
+ re.hitmap = re.e('hitmap');
16
+
17
+ var e = re.e('force');
18
+
19
+ e.hitmap == re.hitmap //true
20
+
21
+ Warning - this component is not delta time safe. It assumes a fixed timestep.
22
+ */
23
+ re.force = re.c('force')
24
+ .requires('update')
25
+ .statics({
26
+ graX:0,
27
+ graY:0
28
+ })
29
+ .defaults({
30
+
31
+ posX:0,
32
+ posY:0,
33
+
34
+ velX:0,
35
+ velY:0,
36
+
37
+ friX:0.4,
38
+ friY:0.4,
39
+
40
+ accX:0,
41
+ accY:0,
42
+
43
+ resX:0.4,
44
+ resY:0.4,
45
+
46
+ mass:1
47
+
48
+ })
49
+ .namespaces({
50
+
51
+ update:function(){
52
+
53
+ this.velX = this.force(this.velX, this.accX, this.friX, this.graX, this.mass);
54
+ this.velY = this.force(this.velY, this.accY, this.friY, this.graY, this.mass);
55
+
56
+ //check collisions and get result
57
+ if(this.hitmap){
58
+
59
+ this.aftermath(this.hitmap.checkHit(this));
60
+
61
+ } else {
62
+
63
+ this.aftermath(this.posX + this.velX, this.posY + this.velY);
64
+ }
65
+
66
+ }
67
+
68
+ })
69
+ .defines({
70
+
71
+ aftermath:function(posx, posy, hitx, hity, tarx, tary){
72
+
73
+ if(re.is(posx, 'object')){
74
+ hitx = posx.hitX;
75
+ hity = posx.hitY;
76
+
77
+ tarx = posx.tarX;
78
+ tary = posx.tarY;
79
+
80
+ posy = posx.posY;
81
+ posx = posx.posX;
82
+ }
83
+
84
+ this.posX = posx;
85
+ this.posY = posy;
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
+ return this.trigger('aftermath', hitx, hity, tarx, tary);
96
+ },
97
+
98
+ forceRes:function(vel, res){
99
+ return vel * -res;
100
+ },
101
+
102
+ forceGra:function(gra, mas){
103
+ return gra * mas;
104
+ },
105
+
106
+ forceVel:function(vel, acc, fri){
107
+ return (vel + acc) * fri;
108
+
109
+ },
110
+
111
+ force:function(vel, acc, fri, gra, mas){
112
+
113
+ var v = this.forceVel(vel, acc, fri) + this.forceGra(gra, mas);
114
+
115
+ if(Math.abs(v) < 0.01){
116
+ v = 0;
117
+ }
118
+
119
+ return v;
120
+ },
121
+
122
+ isIdle:function(offset){
123
+ offset = offset || 0;
124
+ return Math.abs(this.velY + this.velX + this.accX + this.accY) <= offset;
125
+ }
126
+
127
+ })
128
+ .init(function(c){
129
+
130
+ //setup defaults
131
+ this.def({
132
+ hitmap:re.hitmap,
133
+ graX:c.graX,
134
+ graY:c.graY
135
+ });
136
+
137
+ this.on('update', this.force_update);
138
+ })
139
+ .dispose(function(){
140
+
141
+ this.off('update', this.force_update);
142
+
143
+ });
data/src/math/hit.js ADDED
@@ -0,0 +1,32 @@
1
+ re.c('hit')
2
+ .defaults({
3
+
4
+ posX:0,
5
+ posY:0,
6
+
7
+ sizeX:1,
8
+ sizeY:1,
9
+
10
+ /*
11
+ checks if the two targets intersect with each other.
12
+
13
+ k.hit(x, y, width, height);
14
+
15
+ */
16
+ hit:function(x, y, w, h){
17
+ if(re.is(x, 'object')){
18
+ y = x.posY || x.y;
19
+ w = x.sizeX || x.w;
20
+ h = x.sizeY || x.h;
21
+ x = x.posX || x.x;
22
+ }
23
+ return !
24
+ (
25
+ x > this.posX + this.sizeX ||
26
+ x + w < this.posX ||
27
+ y > this.posY + this.sizeY ||
28
+ y + h < this.posY
29
+ );
30
+ }
31
+
32
+ });
@@ -0,0 +1,167 @@
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 bind system will allow other developers to easily implement
8
+ their own hit collision system.
9
+ */
10
+ re.c('hitmap')
11
+ .requires('automap')
12
+ .defines({
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(re.is(posX,'object')){
28
+ velX = posX.velX;
29
+ velY = posX.velY;
30
+
31
+ bodX = posX.bodyX || posX.sizeX;
32
+ bodY = posX.bodyY || posX.sizeY;
33
+
34
+ padX = posX.padX || 0;
35
+ padY = posX.padY || 0;
36
+
37
+ posY = posX.posY;
38
+ posX = posX.posX;
39
+ }
40
+
41
+ /*
42
+ Can also include tarX, tarY.
43
+ They contain the target positions of the hit.
44
+ Useful information to calculate which axis was hit
45
+ */
46
+ var res = {
47
+ posX:posX,
48
+ posY:posY
49
+ };
50
+
51
+ var step = (Math.max(Math.abs(velX), Math.abs(velY)) / ((re.tile.sizeX + re.tile.sizeY) * 0.5) + 0.5) | 0;
52
+
53
+ if(step > 1) {
54
+ var sx = velX / step;
55
+ var sy = velY / step;
56
+
57
+ for(var i=0; i<step && (sx || sy); i++) {
58
+
59
+ this.hitmap_step(res, posX, posY, sx, sy, bodX, bodY, padY, padY);
60
+
61
+ if(res.hitX) {
62
+ sx = 0;
63
+ }
64
+
65
+ if(res.hitY) {
66
+ sy = 0;
67
+ }
68
+ }
69
+
70
+ } else {
71
+
72
+ this.hitmap_step(res, posX, posY, velX, velY, bodX, bodY, padX, padY);
73
+
74
+ }
75
+
76
+ return res;
77
+ }
78
+
79
+ })
80
+ .namespaces({
81
+
82
+ /*
83
+ TODO:
84
+ refactor
85
+ possibly utilize entity methods for more robust calculations.
86
+ */
87
+ step:function(res, x, y, vx, vy, width, height, padx, pady){
88
+
89
+ res.posX += vx;
90
+ res.posY += vy;
91
+
92
+ var t, ty, tx;
93
+
94
+ if(vx) {
95
+
96
+ t = re.tile.sizeX;
97
+
98
+ var offsetx = (vx > 0 ? width - padx : padx);
99
+
100
+ var firsty = Math.floor((y + pady)/ t);
101
+ var lasty = Math.ceil((y + height - pady) / t);
102
+
103
+ tx = Math.floor((x + vx + offsetx) / t);
104
+
105
+ var offx = (vx < 0 ? t : 0);
106
+ //is inside
107
+ if(tx >= 0 && tx < this.lenX && lasty >= 0 && firsty < this.lenY) {
108
+
109
+ for(ty = firsty; ty<lasty; ty++){
110
+
111
+ if(this.map[ty]){
112
+
113
+ this.trigger('hit', this.map[ty][tx], tx, ty);
114
+
115
+ if(this.checkAxisX(this.map[ty][tx], x, y, vx, vy)) {
116
+ res.hitX = true;
117
+ res.posX = tx * t + offx - offsetx;
118
+ res.tarX = tx * t;
119
+ res.tarY = ty * t;
120
+ break;
121
+ }
122
+ }
123
+
124
+ }
125
+
126
+ }
127
+
128
+ }
129
+
130
+ if(vy) {
131
+ t = re.tile.sizeY;
132
+
133
+ var offsety = (vy > 0 ? height -pady : pady);
134
+
135
+ var firstx = Math.floor((res.posX + padx) / t);
136
+ var lastx = Math.ceil((res.posX + width - padx) / t);
137
+ ty = Math.floor((y + vy + offsety) / t);
138
+
139
+ var offy = (vy < 0 ? t : 0);
140
+ // Still inside this collision map?
141
+ if(ty >= 0 && ty < this.lenY && lastx >= 0 && firstx< this.lenX) {
142
+
143
+ for(tx = firstx; tx<lastx; tx++) {
144
+
145
+ if(this.map[ty]){
146
+
147
+ this.trigger('hit', this.map[ty][tx], tx, ty);
148
+
149
+ if(this.checkAxisY(this.map[ty][tx], x, y, vx, vy)) {
150
+ res.hitY = true;
151
+ res.posY = ty * t + offy - offsety;
152
+ res.tarX = tx * t;
153
+ res.tarY = ty * t;
154
+ break;
155
+ }
156
+ }
157
+
158
+ }
159
+ }
160
+
161
+
162
+
163
+ }
164
+
165
+ }
166
+
167
+ });
data/src/math/limit.js ADDED
@@ -0,0 +1,37 @@
1
+ /*
2
+ The limit component constraints a value inside a range.
3
+
4
+ This can be useful for maps, characters, enemies, boxes etc..
5
+
6
+ re.e('limit bitmap char.png')
7
+ .limit('posX', 0, 10) //limits to 0-10
8
+ .limit('health', 0) //minimum 0
9
+
10
+ //maybe in the future..
11
+ //.limit('name', 'ben', 'roger', 'bob') //limits name to one of these
12
+ //.limit('name', ['yep', 'beb'])
13
+ //.limit('type, [0, 10, 13])
14
+ */
15
+
16
+ re.c('limit')
17
+ .defines('limit',
18
+ function(prop){
19
+
20
+ var c = arguments;
21
+ //if(re.is(min, 'array')) c = min;
22
+
23
+ //if(re.is(c[1], 'number')){
24
+ if(this[prop] < c[1]){
25
+ this[prop] = c[1];
26
+ } else if(re.is(c[2]) && this[prop] > c[2]){
27
+ this[prop] = c[2];
28
+ }
29
+ /*} else {
30
+
31
+ for(var i=1; i<c.length; i++){
32
+ if(this[prop] == c[i]) return this;
33
+ }
34
+ this[prop] = c[1];
35
+ }*/
36
+ return this;
37
+ });
data/src/math/point.js ADDED
@@ -0,0 +1,40 @@
1
+ /*
2
+ The point component definess 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
+ .defaults({
9
+
10
+ posX:0,
11
+ posY:0
12
+
13
+ })
14
+ .defines({
15
+
16
+ pos:function(x, y){
17
+ if(re.is(x,'object')){
18
+ y = x.posY || x.y;
19
+ x = x.posX || x.x;
20
+ }
21
+
22
+ this.posX = x;
23
+ this.posY = y;
24
+
25
+ return this;
26
+ },
27
+
28
+ distanceTo:function(x, y){
29
+ if(re.is(x,'object')){
30
+ y = x.posY || x.y;
31
+ x = x.posX || x.x;
32
+ }
33
+ var kx, ky;
34
+ kx = x - this.posX;
35
+ ky = y - this.posY;
36
+
37
+ return Math.sqrt(kx*kx + ky*ky) + 0.5 | 0;
38
+ }
39
+
40
+ });
data/src/math/tile.js ADDED
@@ -0,0 +1,109 @@
1
+ /*
2
+ The tile component adds tile positioning functions and helper functions for tile based games.
3
+
4
+ @usage
5
+
6
+ //set tile size
7
+ re.tile.sizeX = 40;
8
+ re.tile.sizeY = 40;
9
+
10
+ //convert mouse coordinates to a tile position..
11
+ var mouse = {x:10, y:234};
12
+
13
+ re.tile.toX(mouse.x) // 0
14
+ re.tile.toY(mouse.y)
15
+
16
+ //create tile
17
+ var tile = re.e('tile sprite tiles.png')
18
+ .tile(2, 4);
19
+
20
+ tile.posX // 2 * re.tile.sizeX == 80
21
+ tile.posY // 4 * re.tile.sizeY == 160
22
+
23
+ //create a bunch of tiles from a map
24
+
25
+ var map =
26
+ [
27
+ [1,2,4,5,0,3,4,5,6,7],
28
+ [1,2,4,5,0,3,4,5,6,7],
29
+ [1,2,4,5,0,3,4,5,6,7],
30
+ [1,2,4,5,0,3,4,5,6,7]
31
+ ];
32
+
33
+ re.e('tile sprite tiles.png', map.length * map[0].length)
34
+ .tilemap(map.length[0].length,function(x, y){
35
+ this.tile(x, y);
36
+ this.frame(map[y][x]);
37
+ });
38
+
39
+
40
+ */
41
+ re.tile = re.c('tile')
42
+ .statics({
43
+ sizeX:40,
44
+ sizeY:40,
45
+
46
+ toX:function(x, size){
47
+ size = size || this.sizeX;
48
+ return this.toTileX(x, size) * size;
49
+ },
50
+
51
+ toY:function(y, size){
52
+ size = size || this.sizeY;
53
+ return this.toTileY(y, size) * size;
54
+ },
55
+
56
+ //converts the given coordinate to a tile position
57
+ toTileX:function(x, size){
58
+ size = size || this.sizeX;
59
+ return (x - size * 0.5) / size + 0.5 | 0
60
+ },
61
+
62
+ toTileY:function(y, size){
63
+ size = size || this.sizeY;
64
+ return (y - size * 0.5) / size + 0.5 | 0
65
+ }
66
+
67
+ })
68
+ .defaults({
69
+
70
+ posX:0,
71
+ posY:0
72
+
73
+ })
74
+ .init(function(){
75
+ this.def({
76
+ sizeX:re.tile.sizeX,
77
+ sizeY:re.tile.sizeY
78
+ });
79
+
80
+ })
81
+ .defines({
82
+
83
+ tile:function(x, y){
84
+ if(re.is(x,'object')){
85
+ y = x.posY || x.y;
86
+ x = x.posX || x.x;
87
+ }
88
+ this.tileX(x);
89
+ this.tileY(y);
90
+ return this;
91
+ },
92
+
93
+ tileX:function(v){
94
+ if(re.is(v)){
95
+ this.posX = v * this.sizeX;
96
+ return this;
97
+ }
98
+ return re.tile.toTileX(this.posX, this.sizeX);
99
+ },
100
+
101
+ tileY:function(v){
102
+ if(re.is(v)){
103
+ this.posY = v * this.sizeY;
104
+ return this;
105
+ }
106
+ return re.tile.toTileY(this.posY, this.sizeY);
107
+ }
108
+
109
+ });
@@ -0,0 +1,93 @@
1
+ /*
2
+ The channel component allows you to play a sound component more than
3
+ once at the sametime. This is useful for shooting or fast games.
4
+
5
+ //create a new channel
6
+ re.e('channel attack.sfx')
7
+ .play()
8
+ .play()
9
+ .play();
10
+
11
+ //extension sfx is created for every
12
+ //sound loaded regards of type
13
+
14
+ //TODO
15
+
16
+ //add more channels
17
+
18
+ //cloning glitch fix
19
+ document.body.appendChild(s);
20
+
21
+ s.addEventListener('canplaythrough', function(e){
22
+
23
+ //multiple channels will allow the sound to be played more at the sametime.
24
+ //this will load the sound multiple times sadly FIX
25
+ for(var i=0; i<re.load.maxChannels-1; i++){
26
+ channels.push(s.cloneNode(true));
27
+ }
28
+
29
+ if(that._p){
30
+ that._p.call(that, that.current, that.total, a);
31
+ }
32
+
33
+ if(that.current >= that.total){
34
+
35
+ if(that._s){
36
+ that._s.call(that, that.assets);
37
+ }
38
+
39
+ }
40
+
41
+ }, false);
42
+ *//*
43
+ re.channel = re.c('channel')
44
+ .requires('sound')
45
+ .defaults({
46
+ volume:1,
47
+ max:3
48
+ })
49
+ .defines({
50
+
51
+ play:function(loop){
52
+ if(!this.channels || !re.sound.enabled) return this;
53
+
54
+ var c;
55
+ for(var i=0; i<this.channels.length; i++){
56
+
57
+ c = this.channels[i];
58
+ if(c.ended || !c.currentTime){
59
+ //play new channel
60
+ c.play();
61
+ break;
62
+ } else if(i == this.channels[i].length-1){
63
+ c.currentTime = 0;
64
+ c.play();
65
+ }
66
+
67
+ }
68
+
69
+ if(loop){
70
+
71
+ var l = 0;
72
+
73
+ c.addEventListener('ended', function(){
74
+
75
+ if(loop == -1 || l >= loop){
76
+ this.currentTime = 0;
77
+ l++;
78
+ }
79
+
80
+ }, false);
81
+
82
+ }
83
+
84
+ return this;
85
+ },
86
+
87
+ stop:function(){
88
+
89
+ //stop all channels
90
+
91
+ }
92
+
93
+ });*/
@@ -1,5 +1,5 @@
1
- /*
2
- The playlist component allows you to play background music during a game.
3
- It has methods for adding tracks and playing through them.
4
- */
1
+ /*
2
+ The playlist component allows you to play background music during a game.
3
+ It has methods for adding tracks and playing through them.
4
+ */
5
5
  re.c('playlist');