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
data/.gitignore CHANGED
@@ -1,7 +1,8 @@
1
- Thumbs.db
2
- *.gem
3
- .bundle
4
- Gemfile.lock
5
- pkg/*
6
- .redcar
1
+ Thumbs.db
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
5
+ pkg/*
6
+ .redcar
7
+ ._redcar
7
8
  mygame
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --debug
data/README.md CHANGED
@@ -1,49 +1,170 @@
1
- # Entity JS
2
- An HTML5 javascript game engine utlizing the entity-component design. Write highly flexible code in a powerful javascript framework.
3
-
4
- [EntityJS Website](http://entityjs.com) | [Demos](http://entityjs.com/demos) | [Tutorials](http://entityjs.com/tutorials) | [API](http://entityjs.com/api)
5
-
6
- ## What makes this different from other javascript game engines?
7
- Entity strives to be the most flexible game engine available. We understand no one likes rewritting the same functions and lines of code over and over. So we have developed a solution to this problem and that is the component-entity design. The traditional approach to game engine design is creating a hierarchy of classes. This is infact the **most** tightly coupled design. This creates close coupled classes whos functionality is strictly typed to one class, its not easily portable to other projects, good luck copying that one needed function and as game development progresses classes get bigger and more complex. You will eventually end up with *god-classes* who control most of the game logic.
8
-
9
- This becomes a big mess.
10
-
11
- In the world of *entity-component* designs. All logic is implemented in a *component*, as big or small as you want. You can then create an *entity* and add/remove components to it. The entity is a live represantation of all its components. With this low coupling of components and entities you can mix and match components together to create powerful functionality yet still portable and robust.
12
-
13
- ## Directory Structure
14
-
15
- * **build** Contains two build commands to compile entityjs code.
16
- * **build_min.bat** Will build a minified version for release.
17
- * **build_debug.bat** Will build a debug file for testing offline.
18
- * **lib** Contains two compiled sources *entity.min.js* and *entity.debug.js*
19
- * **src** Contains source code of *entityjs*
20
- * **tutorials** Contains simple tutorials and examples.
21
-
22
- ## Quick Start Guide
23
- This will take you through some quick steps to display an image on a canvas element.
24
-
25
- * Include *entity.min.js* in your html document (All compiled sources can be found in */lib*).
26
-
27
- * Initialize the system by calling *re.system.init*.
28
-
29
- `re.system.init('#canvasId');`
30
-
31
- * Start the *main loop* of the application. This will refresh the screen and update logic.
32
-
33
- `re.system.start();`
34
-
35
- * We now have to load our image *welcome.png*.
36
-
37
- <code>re.load('welcome.png').complete(function(){ });</code>
38
-
39
- * Now inside the complete function body we can display the image. *re.entity* creates a new entity with the given components.
40
-
41
- `re.entity('bitmap welcome.png');`
42
-
43
- That should now display an image on your canvas. Yes! For more information check out [the website](entityjs.com).
44
-
45
- ## Future
46
- * Ruby YUI compiler
47
- * Level Editor
48
- * JS Loader
49
- * More tutorials!
1
+ # EntityJS
2
+ An HTML5 javascript game engine utlizing the entity-component design. Write highly flexible code in a powerful javascript framework.
3
+
4
+ [EntityJS Website](http://entityjs.com) | [Demos](http://entityjs.com/demos) | [Tutorials](http://entityjs.com/tutorials) | [API](http://entityjs.com/api)
5
+
6
+ ## Version 0.3
7
+
8
+ Version 0.3 is a major release with many revisions and a brand new ruby gem to work with. You can now type `entityjs new game-name` and a new game will be created. Of course there are more commands, check below.
9
+
10
+ There is a new directory structure, testing framework, better minifier, better config file and more. This is currently in alpha and most of it doesn't work!
11
+
12
+ **Warning:** there are many name changes which will break older versions!
13
+
14
+ ## API
15
+ Currently the [API](http://entityjs.com/api) is out of date. It will be updated once version 0.3 is released.
16
+
17
+ ## What makes this different from other javascript game engines?
18
+ Entity strives to be the most flexible game engine available. We understand no one likes rewritting the same functions and lines of code over and over. So we have developed a solution to this problem and that is the component-entity design. The traditional approach to game engine design is creating a hierarchy of classes. This is infact the **most** tightly coupled design. This creates close coupled classes whos functionality is strictly typed to one class, its not easily portable to other projects, good luck copying that one needed function and as game development progresses classes get bigger and more complex. You will eventually end up with *god-classes* who control most of the game logic.
19
+
20
+ This becomes a big mess.
21
+
22
+ In the world of *entity-component* designs. All logic is implemented in a *component*, as big or small as you want. You can then create an *entity* and add/remove components to it. The entity is a live represantation of all its components. With this low coupling of components and entities you can mix and match components together to create powerful functionality yet still portable and robust.
23
+
24
+ ## Requirements
25
+
26
+ You must have at least [Ruby 1.8.1+](http://rubyinstaller.org/).
27
+
28
+ ## Installion
29
+
30
+ EntityJS is now an easy to install gem. In the terminal type in:
31
+
32
+ `gem install entityjs`
33
+
34
+ This will install the latest version of the gem and now you can easily create some games!
35
+
36
+
37
+ ## Usage
38
+
39
+ **Warning** at the moment the gemfile is at version 0.2.2 and is **broken**. Wait until version 0.3 to try these commands.
40
+
41
+ When using these commands make sure you are always in the root directory of your game.
42
+
43
+ ### Creating a New Game
44
+
45
+ Creating a game is simple, move to any directory and type in:
46
+
47
+ `entityjs new mygame`
48
+
49
+ This will create a new game using the default template.
50
+
51
+ Create a game with a platform template:
52
+
53
+ `entityjs new mygame platform`
54
+
55
+ See all available templates:
56
+
57
+ `entityjs templates`
58
+
59
+ ### Creating a Component
60
+
61
+ `entityjs comp rock`
62
+
63
+ This will create a new component called *rock* at scripts/rock.js and will create a test file inside test/rock.js
64
+
65
+ `entityjs comp display/hero`
66
+
67
+ This will create a new component in the directory scripts/display.
68
+
69
+ ### Creating a Test
70
+
71
+ `entityjs test name test1 test1`
72
+
73
+ Create a test in tests/name_test.js with two test methods.
74
+
75
+ ### Build Game
76
+
77
+ `entityjs build`
78
+
79
+ This will minify all entityjs src code and game src code into one file inside /builds
80
+
81
+ ### Running the Game / Tests
82
+
83
+ Make sure the server is running:
84
+ `entityjs server`
85
+
86
+ To play visit:
87
+ `localhost:2345`
88
+
89
+ To run tests visit:
90
+ `localhost:2345/tests`
91
+
92
+ Assets are located here:
93
+ `localhost:2345/assets/*name`
94
+
95
+ ## Directory Structure
96
+
97
+ * Assets - Contains all external assets
98
+ * Images - Add any images here and retrieve them with `re.assets.images`
99
+ * Sounds - Add any sounds and retrieve them with `re.assets.sounds`
100
+ * [Custom] - Create any folders or files and they will be available in code.
101
+ * json, tmx, xml, sounds and images are accepted files.
102
+
103
+ * Builds - Contains all finished builds
104
+
105
+ * Scripts - Contains all javascript sources.
106
+ * Plugins - Contains external scripts from other authors.
107
+
108
+ * Tests - Contains test files to run in [QUnit](http://docs.jquery.com/QUnit)
109
+
110
+ * config.yml - Optional, simple configuration.
111
+ * readme.txt - Optional, simple description of the game.
112
+
113
+ ## Changes In V0.3
114
+
115
+ * `Inherit()` is now `defaults()`
116
+ * `Extend()` is now `defines()`
117
+ * `Inherit()` on entities is now `def()`
118
+ * `Extend()` on entities is now `attr()`
119
+
120
+ There are many more name changes, make sure to read the component source code for more information. Also every component has a usage example.
121
+
122
+ ### Short getters and setters
123
+
124
+ var tile = re.e('tile');
125
+ tile.tileX(1); //sets
126
+ tile.tileX(); //gets
127
+
128
+ #### Setters can even be used in `attr()`
129
+
130
+ tile.attr('tileX', 2); //sets
131
+
132
+ #### Setter with multiple parameters
133
+
134
+ tile.tile(1, 2); //sets tilex and tiley
135
+ //or
136
+ tile.attr('tile', [1,2]); //samething
137
+
138
+ ### Signals Changed to on/off
139
+
140
+ * `addSignal()` is now `on()`
141
+ * `removeSignal()` is now `off()`
142
+ * `signal()` is now `trigger()`
143
+
144
+ ## QUnit Testing
145
+
146
+ All games will now use [QUnit](http://docs.jquery.com/QUnit) as the primary test framework. Its light weight and awesome.
147
+
148
+ Special methods like `keypress` and `click` are available to simulate user input. Check `localhost:2345/qunit/qunit.input.js` for more information.
149
+
150
+ ## Tile Map Editor
151
+
152
+ The awesome [tiled](http://www.mapeditor.org/) map editor is now compatible and can be used in your projects.
153
+
154
+ Simply create a new directory in /assets named levels or anything you like to save your maps in. They can accessed in code like so:
155
+
156
+ re('level1.tmx')[0]; //assuming the file name is level1.tmx
157
+ re('level'); //find all levels that are in the /assets/levels directory
158
+
159
+ If you are still confused create a new platform game and view how the levels are used.
160
+
161
+ ## Quick Start Guide
162
+ First you should install [ruby](http://rubyinstaller.org/) and the [entityjs gem](http://rubygems.org/gems/entityjs).
163
+
164
+ Now you can create a new game:
165
+ `entityjs new mygame`
166
+
167
+ Move into the mygame/ directory and lets play the game:
168
+ `entityjs server`
169
+
170
+ Open your browser and navigate to `localhost:2345`
data/Rakefile CHANGED
@@ -1 +1,10 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ begin
4
+ require 'jasmine'
5
+ load 'jasmine/tasks/jasmine.rake'
6
+ rescue LoadError
7
+ task :jasmine do
8
+ abort "Jasmine is not available. In order to run jasmine, you must: (sudo) gem install jasmine"
9
+ end
10
+ end
data/bin/entityjs CHANGED
@@ -1,14 +1,24 @@
1
- #!/usr/bin/env ruby
2
-
3
-
4
- lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
5
- $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
6
-
7
- require 'entityjs'
8
- require 'entityjs/command'
9
-
10
- args = ARGV.dup
11
- ARGV.clear
12
- command = args.shift.strip rescue 'help'
13
-
14
- Entityjs::Command.run(command, args)
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
5
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
6
+
7
+ require 'entityjs'
8
+
9
+ args = ARGV.dup
10
+ ARGV.clear
11
+ command = args.shift.strip rescue 'help'
12
+
13
+ code = Entityjs::Command.run(command, args)
14
+
15
+ case code
16
+ when 1
17
+ puts "Command not found"
18
+ when 2
19
+ puts "EntityJS game not found"
20
+ puts "Move inside the root directory"
21
+ when 3
22
+ puts "File/Directory exists"
23
+
24
+ end
data/entityjs.gemspec CHANGED
@@ -6,20 +6,26 @@ Gem::Specification.new do |s|
6
6
  s.name = "entityjs"
7
7
  s.version = Entityjs::VERSION
8
8
  s.authors = ["Ben D'Angelo"]
9
- s.email = ["ben.dangelo2@gmail.com"]
9
+ s.email = ["ben@entityjs.com"]
10
10
  s.homepage = "http://entityjs.com"
11
- s.summary = %q{A HTML5 Javascript game engine.}
12
- s.description = %q{A HTML5 Javascript game engine.}
13
-
11
+ s.summary = %q{Create HTML5 javascript games in EntityJS.}
12
+ s.description = %q{The EntityJS gem supplies easy to use commands for creating javascript games.}
13
+
14
+ s.license = 'MIT'
15
+
14
16
  s.rubyforge_project = "entityjs"
15
-
17
+
16
18
  s.files = `git ls-files`.split("\n")
17
19
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
20
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
21
  s.require_paths = ["lib"]
20
-
22
+
21
23
  # specify any dependencies here; for example:
22
- # s.add_development_dependency "rspec"
23
- # s.add_runtime_dependency "rest-client"
24
- s.add_runtime_dependency 'uglifier'
24
+ s.add_development_dependency "rspec"
25
+ s.add_development_dependency "jasmine"
26
+
27
+ s.add_dependency "sinatra"
28
+ s.add_dependency 'uglifier'
29
+ s.add_dependency 'json'
30
+ s.add_dependency 'cobravsmongoose'
25
31
  end
@@ -0,0 +1,167 @@
1
+
2
+ module Entityjs
3
+
4
+ class Assets
5
+
6
+ def self.valid_datas
7
+ ['xml', 'json', 'tmx']
8
+ end
9
+
10
+ def self.set_vars(contents, tests=false)
11
+ #read file for changes
12
+ Config.instance.reload
13
+
14
+ contents = contents.gsub("$WIDTH", Config.instance.width.to_s)
15
+ contents = contents.gsub("$HEIGHT", Config.instance.height.to_s)
16
+ contents = contents.gsub("$CANVAS_ID", Config.instance.canvas_id)
17
+
18
+ contents.gsub("$JS", Assets.to_html(tests))
19
+ end
20
+
21
+ #combine all sources into valid html scripts
22
+ def self.to_html(tests=false)
23
+ js = %Q(
24
+ <script type='text/javascript'>
25
+ window.addEventListener\('load', function(){
26
+ #{Assets.to_js}
27
+ re.version = '#{VERSION}';
28
+
29
+ }\);
30
+ </script>
31
+ )
32
+ ent = Dirc.find_entity_src_url(Config.instance.entity_ignore)
33
+ srcs = Dirc.find_scripts_url(Config.instance.scripts_ignore, Config.instance.scripts_order)
34
+
35
+ if tests
36
+ tests_src = Dirc.find_tests_url(Config.instance.tests_ignore)
37
+ else
38
+ tests_src = []
39
+ end
40
+
41
+ merg = ent | srcs | tests_src
42
+
43
+ merg.each do |s|
44
+ js += "\t<script src='#{s}' type='text/javascript'></script>\n"
45
+ end
46
+ js
47
+ end
48
+
49
+ def self.to_js
50
+ out = %Q(
51
+ re.load.path = 'assets/';
52
+ re.assets = {
53
+ images:#{self.images_to_js},
54
+ sounds:#{self.sounds_to_js}
55
+ };
56
+ re.canvas = '##{Config.instance.canvas_id}';
57
+ #{self.datas_to_js}
58
+ )
59
+ end
60
+
61
+ def self.images_to_js
62
+ s = self.search('images').collect{|i| "'#{i}'"}.join(', ')
63
+
64
+ "[#{s}]"
65
+ end
66
+
67
+ def self.sounds_to_js
68
+ s = self.search('sounds').collect{|i| "'#{i}'"}.join(', ')
69
+
70
+ "[#{s}]"
71
+ end
72
+
73
+ def self.datas_to_js
74
+ s = self.search
75
+
76
+ out = ''
77
+
78
+ s.each do |i|
79
+
80
+ basename = File.basename(i)
81
+ dirname = File.dirname(i)
82
+
83
+ #make singular
84
+ if dirname[-1] == 's'
85
+ dirname = dirname[0..-2]
86
+ end
87
+
88
+ contents = self.file_to_json(Dirc.game_root+'/'+Config.assets_folder+'/'+i)
89
+
90
+ out += %Q(
91
+ re.e('#{basename} #{dirname}')
92
+ .attr(#{contents});
93
+ )
94
+
95
+ end
96
+
97
+
98
+ out
99
+ end
100
+
101
+ def self.data_to_json(data, ext)
102
+ case ext
103
+ when /json/
104
+ return data
105
+
106
+ when /tmx/
107
+
108
+ return ParseTMX.parse(data)
109
+
110
+ when /xml/
111
+ return ParseXML.parse(data)
112
+
113
+ when /csv/
114
+ raise 'CSV files are not supported at the moment'
115
+
116
+ when /yml/
117
+ raise 'YML files are not supported at the moment'
118
+
119
+ else
120
+ raise "Extension #{ext} not recognized"
121
+
122
+ end
123
+
124
+ return nil
125
+ end
126
+
127
+ def self.file_to_json(file)
128
+ contents = IO.read(file)
129
+ #remove dot from extension
130
+ ext = File.extname(file).downcase
131
+ return self.data_to_json(contents, ext)
132
+ end
133
+
134
+ def self.search(type='*')
135
+ images_folder = Config.images_folder
136
+ sounds_folder = Config.sounds_folder
137
+ assets_folder = Config.assets_folder
138
+
139
+ case type
140
+ when 'images'
141
+ return self.find_files(images_folder+'/*').select{|i| i.match(/^*\.(gif|png|jpg|jpeg)$/i)}
142
+
143
+ when 'sounds'
144
+ return self.find_files(sounds_folder+'/*').select{|i| i.match(/^*\.(mp3|ogg|aac|wav)$/i)}
145
+
146
+ else
147
+ return self.search_datas
148
+
149
+ end
150
+
151
+ end
152
+
153
+ def self.search_datas
154
+ datas = self.valid_datas.join('|')
155
+ return self.find_files("#{Config.assets_folder}/*/*").select{|i| !i.match(/\/(images|sounds)\//i) && i.match(/^*\.(#{datas})$/i)}
156
+ end
157
+
158
+ def self.find_files(search)
159
+ Dir[Dirc.game_root+'/'+search].collect do |i|
160
+ #remove long string
161
+ i = i.split("assets/").pop
162
+ end
163
+ end
164
+
165
+ end
166
+
167
+ end
@@ -1,36 +1,61 @@
1
-
2
- require 'entityjs/game'
3
- require 'entityjs/min'
4
- require 'entityjs/refresh'
5
- require 'entityjs/comp'
1
+ Dir.glob("#{Entityjs::root}/lib/entityjs/*.rb").each {|f| require f }
2
+ Dir.glob("#{Entityjs::root}/lib/entityjs/*/*.rb").each {|f| require f }
3
+
4
+ # 0 - ok
5
+ # 1 - command not found
6
+ # 2 - not in game directory
7
+ # 3 - file exists
6
8
 
7
9
  module Entityjs
8
10
  class Command
9
11
 
10
12
  def self.run(command, args=nil)
11
-
12
- case command
13
- when 'game'
14
- Entityjs::Game.generate(command, args[1..-1])
15
- puts 'generated game'
16
-
17
- when 'min'
18
- Entityjs::Min.generate(args)
19
-
20
- when 'refresh'
21
- Entityjs::Refresh.generate(args)
22
-
23
- when 'comp'
24
- Entityjs::Comp.generate(args)
25
-
26
- else
27
- puts 'Error enter in one of the following...'
28
- puts 'entityjs game [name] [comp]+'
29
- puts 'entityjs comp [name]'
30
- puts 'entityjs min'
31
- puts 'entityjs refresh'
32
-
13
+
14
+ case command
15
+ when /^(new|n)$/
16
+ return Entityjs::New.generate(args)
17
+ when 'templates'
18
+ return Entityjs::Templates.generate(args)
19
+
20
+ when /^(build|b)$/
21
+ return Entityjs::Build.generate(args)
22
+
23
+ when /^(test|t)$/
24
+ return Entityjs::Test.generate(args)
25
+
26
+ when /^(comp|c)$/
27
+ return Entityjs::Comp.generate(args)
28
+
29
+ when /^(server|s)$/
30
+ return Entityjs::Server.run(args)
31
+
32
+ when /^(font|f)$/
33
+ return Entityjs::Font.generate(args)
34
+
35
+ when /^(version|v)$/
36
+ puts 'EntityJS V'+Entityjs::VERSION
37
+ return 0
38
+
39
+ when /^(help|h)$/
40
+ puts ""
41
+ puts '---- Commands ----'
42
+ puts 'entityjs new [name]'
43
+ puts 'entityjs new [name] [template]'
44
+ puts 'entityjs templates'
45
+ puts 'entityjs comp [name]'
46
+ puts 'entityjs test [name]'
47
+ puts 'entityjs test [name] [tests]+'
48
+ puts 'entityjs font [name] (soon...)'
49
+ puts 'entityjs build'
50
+ puts 'entityjs build [name]'
51
+ puts 'entityjs server'
52
+ puts 'entityjs help'
53
+ puts 'entityjs version'
54
+ return 0
55
+
33
56
  end
57
+
58
+ return 1
34
59
  end
35
60
 
36
61
  end