entityjs 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (264) hide show
  1. data/.gitignore +7 -6
  2. data/.rspec +2 -0
  3. data/README.md +170 -49
  4. data/Rakefile +9 -0
  5. data/bin/entityjs +24 -14
  6. data/entityjs.gemspec +15 -9
  7. data/lib/entityjs/assets.rb +167 -0
  8. data/lib/entityjs/command.rb +52 -27
  9. data/lib/entityjs/commands/build.rb +128 -0
  10. data/lib/entityjs/commands/comp.rb +74 -0
  11. data/lib/entityjs/commands/font.rb +73 -0
  12. data/lib/entityjs/commands/new.rb +59 -0
  13. data/lib/entityjs/commands/server.rb +54 -0
  14. data/lib/entityjs/commands/templates.rb +28 -0
  15. data/lib/entityjs/commands/test.rb +69 -0
  16. data/lib/entityjs/config.rb +130 -0
  17. data/lib/entityjs/dirc.rb +184 -0
  18. data/lib/entityjs/parsers/parse_tmx.rb +41 -0
  19. data/lib/entityjs/parsers/parse_xml.rb +39 -0
  20. data/lib/entityjs/version.rb +1 -1
  21. data/lib/entityjs.rb +53 -0
  22. data/license.txt +1 -1
  23. data/public/play.html +122 -0
  24. data/public/qunit/qunit.css +226 -0
  25. data/public/qunit/qunit.entity.js +190 -0
  26. data/public/qunit/qunit.input.js +200 -0
  27. data/public/qunit/qunit.js +1598 -0
  28. data/public/qunit/qunit.mock.js +97 -0
  29. data/public/tests.html +45 -0
  30. data/spec/javascripts/helpers/accept.png +0 -0
  31. data/spec/javascripts/helpers/alligator.mp3 +0 -0
  32. data/spec/javascripts/helpers/alligator.ogg +0 -0
  33. data/spec/javascripts/helpers/canvas.js +15 -0
  34. data/spec/javascripts/helpers/entityunit.js +50 -0
  35. data/spec/javascripts/helpers/factories.js +11 -0
  36. data/spec/javascripts/helpers/jquery-1.7.1.min.js +4 -0
  37. data/spec/javascripts/src/core/comp_spec.js +145 -0
  38. data/spec/javascripts/src/core/entity_spec.js +324 -0
  39. data/spec/javascripts/src/core/load_spec.js +71 -0
  40. data/spec/javascripts/src/core/query_spec.js +157 -0
  41. data/spec/javascripts/src/core/re_spec.js +61 -0
  42. data/spec/javascripts/src/core/system_spec.js +41 -0
  43. data/spec/javascripts/src/cycle/draw_spec.js +106 -0
  44. data/spec/javascripts/src/cycle/tick_spec.js +20 -0
  45. data/spec/javascripts/src/cycle/update_spec.js +86 -0
  46. data/spec/javascripts/src/display/align_spec.js +43 -0
  47. data/spec/javascripts/src/display/circle_spec.js +26 -0
  48. data/spec/javascripts/src/display/group_spec.js +7 -0
  49. data/spec/javascripts/src/display/image_spec.js +32 -0
  50. data/spec/javascripts/src/display/imgtext_spec.js +32 -0
  51. data/spec/javascripts/src/display/rect_spec.js +13 -0
  52. data/spec/javascripts/src/display/screen_spec.js +47 -0
  53. data/spec/javascripts/src/display/sprite_spec.js +28 -0
  54. data/spec/javascripts/src/display/text_spec.js +30 -0
  55. data/spec/javascripts/src/input/keyboard_spec.js +67 -0
  56. data/spec/javascripts/src/input/mouse_spec.js +133 -0
  57. data/spec/javascripts/src/input/pressed_spec.js +31 -0
  58. data/spec/javascripts/src/math/bisect_spec.js +59 -0
  59. data/spec/javascripts/src/math/body_spec.js +30 -0
  60. data/spec/javascripts/src/math/drag_spec.js +38 -0
  61. data/spec/javascripts/src/math/force_spec.js +134 -0
  62. data/spec/javascripts/src/math/hit_spec.js +28 -0
  63. data/spec/javascripts/src/math/hitmap_spec.js +52 -0
  64. data/spec/javascripts/src/math/limit_spec.js +35 -0
  65. data/spec/javascripts/src/math/point_spec.js +57 -0
  66. data/spec/javascripts/src/math/tile_spec.js +78 -0
  67. data/spec/javascripts/src/media/sound_spec.js +40 -0
  68. data/spec/javascripts/src/pattern/automap_spec.js +93 -0
  69. data/spec/javascripts/src/pattern/flicker_spec.js +66 -0
  70. data/spec/javascripts/src/pattern/timestep_spec.js +23 -0
  71. data/spec/javascripts/src/save/storage_spec.js +37 -0
  72. data/spec/javascripts/src/util/log_spec.js +9 -0
  73. data/spec/javascripts/src/util/polyfill_spec.js +13 -0
  74. data/spec/javascripts/src/util/random_spec.js +33 -0
  75. data/spec/javascripts/src/util/scene_spec.js +52 -0
  76. data/spec/javascripts/src/util/sheet_spec.js +25 -0
  77. data/spec/javascripts/src/util/support_spec.js +17 -0
  78. data/spec/javascripts/support/jasmine.yml +76 -0
  79. data/spec/javascripts/support/jasmine_config.rb +32 -0
  80. data/spec/javascripts/support/jasmine_runner.rb +32 -0
  81. data/spec/lib/entityjs/assets_spec.rb +216 -0
  82. data/spec/lib/entityjs/command_spec.rb +53 -0
  83. data/spec/lib/entityjs/commands/build_spec.rb +69 -0
  84. data/spec/lib/entityjs/commands/comp_spec.rb +45 -0
  85. data/spec/lib/entityjs/commands/font_spec.rb +7 -0
  86. data/spec/lib/entityjs/commands/new_spec.rb +20 -0
  87. data/spec/lib/entityjs/commands/templates_spec.rb +9 -0
  88. data/spec/lib/entityjs/commands/test_spec.rb +31 -0
  89. data/spec/lib/entityjs/config_spec.rb +19 -0
  90. data/spec/lib/entityjs/dirc_spec.rb +83 -0
  91. data/spec/lib/entityjs/version_spec.rb +9 -0
  92. data/spec/spec_helper.rb +21 -3
  93. data/spec/support/factories.rb +19 -0
  94. data/spec/support/mygame.rb +11 -0
  95. data/src/core/comp.js +318 -0
  96. data/src/core/entity.js +549 -0
  97. data/src/core/load.js +242 -0
  98. data/src/core/query.js +354 -0
  99. data/src/core/re.js +74 -0
  100. data/src/core/system.js +121 -0
  101. data/src/cycle/draw.js +178 -0
  102. data/src/cycle/tick.js +25 -0
  103. data/src/{entityjs/cycle → cycle}/tween.js +60 -60
  104. data/src/{entityjs/cycle → cycle}/update.js +86 -85
  105. data/src/{entityjs/cycle → cycle}/wait.js +22 -21
  106. data/src/{entityjs/cycle → cycle}/worker.js +8 -8
  107. data/src/display/align.js +45 -0
  108. data/src/display/circle.js +33 -0
  109. data/src/{entityjs/display → display}/group.js +62 -62
  110. data/src/display/image.js +35 -0
  111. data/src/display/imgtext.js +102 -0
  112. data/src/{entityjs/display → display}/rect.js +18 -18
  113. data/src/display/screen.js +57 -0
  114. data/src/display/sprite.js +54 -0
  115. data/src/display/text.js +44 -0
  116. data/src/{entityjs/input → input}/keyboard.js +152 -150
  117. data/src/input/mouse.js +111 -0
  118. data/src/input/pressed.js +41 -0
  119. data/src/{entityjs/input → input}/touch.js +24 -28
  120. data/src/math/bisect.js +84 -0
  121. data/src/math/body.js +70 -0
  122. data/src/{entityjs/math → math}/drag.js +44 -38
  123. data/src/math/force.js +143 -0
  124. data/src/math/hit.js +32 -0
  125. data/src/math/hitmap.js +167 -0
  126. data/src/math/limit.js +37 -0
  127. data/src/math/point.js +40 -0
  128. data/src/math/tile.js +109 -0
  129. data/src/media/channel.js +93 -0
  130. data/src/{entityjs/media → media}/playlist.js +4 -4
  131. data/src/media/sound.js +114 -0
  132. data/src/{entityjs/net → net}/socket.js +51 -51
  133. data/src/pattern/automap.js +133 -0
  134. data/src/{entityjs/pattern → pattern}/flicker.js +206 -213
  135. data/src/pattern/timestep.js +31 -0
  136. data/src/{entityjs/save → save}/database.js +6 -6
  137. data/src/{entityjs/save → save}/storage.js +47 -56
  138. data/src/{entityjs/util → util}/log.js +17 -25
  139. data/src/{entityjs/util → util}/polyfill.js +24 -24
  140. data/src/util/random.js +20 -0
  141. data/src/util/scene.js +102 -0
  142. data/src/util/sheet.js +35 -0
  143. data/src/{entityjs/util → util}/support.js +109 -132
  144. data/{examples/keys → templates/arrow_keys/assets/images}/arrow.png +0 -0
  145. data/templates/arrow_keys/config.yml +22 -0
  146. data/templates/arrow_keys/readme.txt +9 -0
  147. data/templates/arrow_keys/scripts/display/arrow.js +69 -0
  148. data/templates/arrow_keys/scripts/init.js +10 -0
  149. data/templates/arrow_keys/scripts/input/controls.js +35 -0
  150. data/templates/arrow_keys/scripts/scenes/home.js +20 -0
  151. data/templates/arrow_keys/scripts/scenes/load.js +57 -0
  152. data/templates/arrow_keys/tests/display/arrow_test.js +29 -0
  153. data/templates/arrow_keys/tests/init_test.js +4 -0
  154. data/templates/arrow_keys/tests/input/controls_test.js +32 -0
  155. data/templates/arrow_keys/tests/scenes/home_test.js +0 -0
  156. data/templates/arrow_keys/tests/scenes/load_test.js +16 -0
  157. data/templates/blank/config.yml +22 -0
  158. data/templates/blank/readme.txt +79 -0
  159. data/templates/platform/assets/images/bit.png +0 -0
  160. data/templates/platform/assets/images/hero.png +0 -0
  161. data/templates/platform/assets/images/items.png +0 -0
  162. data/templates/platform/assets/images/tiles.png +0 -0
  163. data/templates/platform/assets/levels/level1.tmx +44 -0
  164. data/templates/platform/assets/sounds/coin.mp3 +0 -0
  165. data/templates/platform/assets/sounds/coin.ogg +0 -0
  166. data/templates/platform/config.yml +22 -0
  167. data/templates/platform/readme.txt +87 -0
  168. data/templates/platform/scripts/display/bit.js +12 -0
  169. data/templates/platform/scripts/display/hero.js +77 -0
  170. data/templates/platform/scripts/display/tile.js +2 -0
  171. data/templates/platform/scripts/display/tsprite.js +17 -0
  172. data/templates/platform/scripts/init.js +7 -0
  173. data/templates/platform/scripts/items/coin.js +27 -0
  174. data/templates/platform/scripts/items/item.js +41 -0
  175. data/templates/platform/scripts/items/spring.js +25 -0
  176. data/templates/platform/scripts/scenes/home.js +10 -0
  177. data/templates/platform/scripts/scenes/load.js +27 -0
  178. data/templates/platform/scripts/scenes/play.js +31 -0
  179. data/templates/platform/scripts/util/counter.js +34 -0
  180. data/templates/platform/scripts/util/level.js +84 -0
  181. data/templates/platform/tests/display/bit_test.js +7 -0
  182. data/templates/platform/tests/display/hero_test.js +73 -0
  183. data/templates/platform/tests/display/tile_test.js +7 -0
  184. data/templates/platform/tests/display/tsprite_test.js +8 -0
  185. data/templates/platform/tests/factories.js +30 -0
  186. data/templates/platform/tests/items/coin_test.js +28 -0
  187. data/templates/platform/tests/items/item_test.js +36 -0
  188. data/templates/platform/tests/items/spring_test.js +21 -0
  189. data/templates/platform/tests/scenes/home_test.js +9 -0
  190. data/templates/platform/tests/scenes/load_test.js +11 -0
  191. data/templates/platform/tests/scenes/play_test.js +15 -0
  192. data/templates/platform/tests/util/counter_test.js +9 -0
  193. data/templates/platform/tests/util/level_test.js +29 -0
  194. metadata +249 -97
  195. data/build/build_debug.bat +0 -1
  196. data/build/build_min.bat +0 -1
  197. data/build/config.php +0 -64
  198. data/build/debug.php +0 -48
  199. data/build/files.php +0 -74
  200. data/build/jsmin.php +0 -376
  201. data/build/min.php +0 -50
  202. data/changelog.txt +0 -53
  203. data/examples/keys/keys.html +0 -59
  204. data/examples/keys/keys.js +0 -148
  205. data/examples/mouse/mouse.html +0 -58
  206. data/examples/mouse/mouse.js +0 -60
  207. data/examples/scenes/home.png +0 -0
  208. data/examples/scenes/scenes.html +0 -55
  209. data/examples/scenes/scenes.js +0 -134
  210. data/examples/scenes/win.png +0 -0
  211. data/examples/sounds/sound1.mp3 +0 -0
  212. data/examples/sounds/sound1.ogg +0 -0
  213. data/examples/sounds/sounds.html +0 -56
  214. data/examples/sounds/sounds.js +0 -44
  215. data/examples/style/background.png +0 -0
  216. data/examples/style/sheet.css +0 -762
  217. data/examples/tiles/tiles.html +0 -56
  218. data/examples/tiles/tiles.js +0 -85
  219. data/examples/tiles/tiles.png +0 -0
  220. data/lib/blank/config.js +0 -4
  221. data/lib/blank/config.yml +0 -21
  222. data/lib/blank/home.js +0 -11
  223. data/lib/blank/init.js +0 -7
  224. data/lib/blank/load.js +0 -21
  225. data/lib/blank/play.html +0 -29
  226. data/lib/entity.debug.js +0 -52
  227. data/lib/entity.min.js +0 -184
  228. data/lib/entityjs/comp.rb +0 -11
  229. data/lib/entityjs/game.rb +0 -93
  230. data/lib/entityjs/min.rb +0 -11
  231. data/lib/entityjs/refresh.rb +0 -14
  232. data/spec/lib/entityjs/game_spec.rb +0 -11
  233. data/src/entityjs/core/component.js +0 -306
  234. data/src/entityjs/core/entity.js +0 -516
  235. data/src/entityjs/core/load.js +0 -224
  236. data/src/entityjs/core/query.js +0 -410
  237. data/src/entityjs/core/re.js +0 -70
  238. data/src/entityjs/core/system.js +0 -125
  239. data/src/entityjs/cycle/draw.js +0 -185
  240. data/src/entityjs/cycle/ticker.js +0 -27
  241. data/src/entityjs/display/anchor.js +0 -53
  242. data/src/entityjs/display/bitfont.js +0 -93
  243. data/src/entityjs/display/bitmap.js +0 -37
  244. data/src/entityjs/display/circle.js +0 -30
  245. data/src/entityjs/display/font.js +0 -41
  246. data/src/entityjs/display/screen.js +0 -46
  247. data/src/entityjs/display/sprite.js +0 -37
  248. data/src/entityjs/input/mouse.js +0 -123
  249. data/src/entityjs/input/pressed.js +0 -81
  250. data/src/entityjs/math/bind.js +0 -76
  251. data/src/entityjs/math/bisect.js +0 -69
  252. data/src/entityjs/math/body.js +0 -39
  253. data/src/entityjs/math/hitmap.js +0 -165
  254. data/src/entityjs/math/hittest.js +0 -26
  255. data/src/entityjs/math/physics.js +0 -142
  256. data/src/entityjs/math/point.js +0 -57
  257. data/src/entityjs/math/tile.js +0 -91
  258. data/src/entityjs/media/channel.js +0 -93
  259. data/src/entityjs/media/sound.js +0 -110
  260. data/src/entityjs/pattern/arraymap.js +0 -89
  261. data/src/entityjs/pattern/timestep.js +0 -34
  262. data/src/entityjs/util/random.js +0 -38
  263. data/src/entityjs/util/scene.js +0 -101
  264. data/src/entityjs/util/sheet.js +0 -51
@@ -0,0 +1,32 @@
1
+ module('controls');
2
+
3
+ var controls = re.e('controls');
4
+
5
+ test('addArrow', function(){
6
+
7
+ var old = re('arrow').length;
8
+
9
+ //should call addarrow
10
+ expectCall(controls, 'addArrow');
11
+
12
+ //press space
13
+ keypress('space');
14
+
15
+ //check that a new arrow was created
16
+ equal(re('arrow').length, old+1);
17
+
18
+ });
19
+
20
+ test('removeArrow', function(){
21
+
22
+ var old = re('arrow').length;
23
+
24
+ expectCall(controls, 'removeArrow');
25
+
26
+ //press r
27
+ keypress('r');
28
+
29
+ //check that a new arrow was removed
30
+ equal(re('arrow').length, old-1);
31
+
32
+ });
File without changes
@@ -0,0 +1,16 @@
1
+ module('load');
2
+
3
+ test('load assets', function(){
4
+
5
+ //replace re.scene('home').enter with start()
6
+ stub(re.scene('home'), 'enter', function(){ start(); });
7
+
8
+ //go into the load scene
9
+ re.scene('load').enter();
10
+
11
+ //it should be loading the assets
12
+ //stop until it finishes and enters the new home scene
13
+ //the home scene should then call start()
14
+ stop();
15
+
16
+ });
@@ -0,0 +1,22 @@
1
+ # Configure your game settings
2
+
3
+ width: 500
4
+ height: 400
5
+ canvas-id: game-canvas
6
+
7
+ #files to ignore in /scripts
8
+ scripts-ignore:
9
+
10
+ #specify files to be loaded first in /scripts
11
+ order:
12
+
13
+ #components to ignore in the entityjs source
14
+ #reduce file size by ignoring unused components
15
+ entity-ignore:
16
+ socket
17
+ wait
18
+ group
19
+
20
+ #ignore tests in /tests
21
+ tests-ignore:
22
+
@@ -0,0 +1,79 @@
1
+ ------------- EntityJS Gem ----------------------
2
+
3
+ The EntityJS Gem lets you quickly create HTML5 javascript games.
4
+
5
+ # Directory Structure
6
+
7
+ ## /assets
8
+ Contains all sounds, images and data files. Place all sounds in the sounds directory
9
+ and all the images in the images directory. These directories will be looked at
10
+ and an asset array will be created for easy asset loading (see scripts/scenes/load.js)
11
+
12
+ Creating any other directory or placing files in the levels directory will be seen
13
+ as data files and will be read and automatically put in js files.
14
+
15
+ For example, if I have a directory like /assets/animations/monster.json.
16
+
17
+ The file will automatically be read upon calling 'entityjs refresh' and will be turned into this:
18
+
19
+ re.e('monster.json animation')
20
+ .attr(**Animation JSON here**);
21
+
22
+ Which means you can edit files in different programs and not worry about copying and pasting
23
+ the contents. Just run entityjs refresh.
24
+
25
+ At the moment JSON, XML and TMX is supported but in the future, YAML, and CSV will be supported.
26
+ TMX is a special XML format for a tile map editor called tiled.
27
+
28
+ ## /builds
29
+
30
+ Contains assets and minified code for the game.
31
+
32
+ ## /scripts
33
+
34
+ Contains javascripts for the game.
35
+
36
+ ## /tests
37
+
38
+ Contains tests for the game. It is good practice to keep this structured exactly the same as the scripts
39
+ directory.
40
+
41
+ ## config.yml
42
+
43
+ A configuration file in yaml. This can be edited in any text editor.
44
+
45
+ ## readme.txt
46
+
47
+ Good practice to make one for every game to help other people.
48
+
49
+ # Commands
50
+
51
+ ## create a new entityjs game
52
+ entityjs new [project_name]
53
+
54
+ - example
55
+ entityjs new alien_shooter
56
+
57
+ - create game with arrow_keys template
58
+ entityjs new alien_shooter alien arrow_keys
59
+
60
+ ## create a new component
61
+ entityjs comp [component_name]
62
+
63
+ - example
64
+ entityjs comp hero
65
+
66
+ ## build game
67
+ entityjs build
68
+
69
+ Exports game in builds directory
70
+
71
+ ## build game with custom name
72
+ entityjs build release1
73
+
74
+ ## Run server
75
+ entityjs server
76
+ or
77
+ entityjs s
78
+
79
+ Navigate to localhost:2345 to play the game.
@@ -0,0 +1,44 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <map version="1.0" orientation="orthogonal" width="20" height="16" tilewidth="25" tileheight="25">
3
+ <tileset firstgid="1" name="tiles" tilewidth="25" tileheight="25">
4
+ <image source="../images/tiles.png" width="200" height="25"/>
5
+ </tileset>
6
+ <tileset firstgid="9" name="Hero" tilewidth="25" tileheight="25">
7
+ <image source="../images/hero.png" width="225" height="50"/>
8
+ </tileset>
9
+ <tileset firstgid="27" name="items" tilewidth="25" tileheight="25">
10
+ <image source="../images/items.png" width="250" height="50"/>
11
+ </tileset>
12
+ <layer name="Base" width="20" height="16">
13
+ <data encoding="csv">
14
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,7,0,0,0,0,0,0,
15
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
16
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
17
+ 0,0,0,0,0,7,8,0,0,0,0,0,0,0,0,0,0,0,0,0,
18
+ 0,0,0,0,0,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
19
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
20
+ 0,0,0,0,0,0,0,0,0,7,0,0,0,7,7,0,0,0,0,0,
21
+ 0,0,0,0,0,0,0,0,7,0,0,0,7,0,8,0,0,0,0,0,
22
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
23
+ 0,0,0,0,0,0,0,0,0,0,7,0,0,0,0,0,0,0,0,0,
24
+ 5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,0,0,
25
+ 1,2,2,5,0,0,0,0,7,0,0,0,6,2,5,0,0,0,0,0,
26
+ 1,1,1,3,0,0,6,2,2,5,0,6,1,1,1,5,0,0,0,0,
27
+ 1,1,1,3,0,6,1,1,1,1,2,1,1,1,1,1,5,0,0,0,
28
+ 1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,
29
+ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
30
+ </data>
31
+ </layer>
32
+ <objectgroup color="#5e3ea4" name="Hero" width="20" height="16">
33
+ <object gid="9" x="0" y="25"/>
34
+ </objectgroup>
35
+ <objectgroup name="Items" width="20" height="16">
36
+ <object gid="41" x="350" y="150"/>
37
+ <object gid="41" x="275" y="300"/>
38
+ <object gid="41" x="125" y="225"/>
39
+ <object gid="41" x="425" y="250"/>
40
+ <object gid="39" x="175" y="300"/>
41
+ <object gid="39" x="225" y="150"/>
42
+ <object gid="41" x="125" y="75"/>
43
+ </objectgroup>
44
+ </map>
@@ -0,0 +1,22 @@
1
+ # Configure your game settings
2
+
3
+ width: 500
4
+ height: 400
5
+ canvas-id: game-canvas
6
+
7
+ #files to ignore in /scripts
8
+ scripts-ignore:
9
+
10
+ #specify files to be loaded first in /scripts
11
+ order:
12
+
13
+ #components to ignore in the entityjs source
14
+ #reduce file size by ignoring unused components
15
+ entity-ignore:
16
+ socket
17
+ wait
18
+ group
19
+
20
+ #ignore tests in /tests
21
+ tests-ignore:
22
+
@@ -0,0 +1,87 @@
1
+ ------------- EntityJS Gem ----------------------
2
+
3
+ The EntityJS Gem lets you quickly create HTML5 javascript games.
4
+
5
+ # Directory Structure
6
+
7
+ ## /assets
8
+ Contains all sounds, images and data files. Place all sounds in the sounds directory
9
+ and all the images in the images directory. These directories will be looked at
10
+ and an asset array will be created for easy asset loading (see scripts/scenes/load.js)
11
+
12
+ Creating any other directory or placing files in the levels directory will be seen
13
+ as data files and will be read and automatically put in js files.
14
+
15
+ For example, if I have a directory like /assets/animations/monster.json.
16
+
17
+ The file will automatically be read upon calling 'entityjs refresh' and will be turned into this:
18
+
19
+ re.e('monster.json animation')
20
+ .attr(**Animation JSON here**);
21
+
22
+ Which means you can edit files in different programs and not worry about copying and pasting
23
+ the contents. Just run entityjs refresh.
24
+
25
+ At the moment only JSON is supported but in the future, XML, YAML, CSV and TMX will be supported.
26
+ TMX is a special XML format for a tile map editor.
27
+
28
+ ## /builds
29
+
30
+ Contains assets and minified code for the game.
31
+
32
+ ## /scripts
33
+
34
+ Contains javascripts for the game.
35
+
36
+ ## /tests
37
+
38
+ Contains tests for the game. It is good practice to keep this structured exactly the same as the scripts
39
+ directory.
40
+
41
+ ## /tmp
42
+
43
+ Contains temporary files generated by EntityJS Gem. Usually don't have to touch this.
44
+ Might be removed and replaced in the future.
45
+
46
+ ## config.yml
47
+
48
+ A configuration file in yaml. This can be edited in any text editor.
49
+
50
+ ## play.html
51
+
52
+ The current game. If its missing files, run 'entityjs r'
53
+
54
+ # Commands
55
+
56
+ ## create a new entityjs game
57
+ entityjs new [project_name] [comps]+
58
+
59
+ - example
60
+ entityjs new alien_shooter
61
+
62
+ - example with components
63
+ entityjs new alien_shooter alien hero lazer
64
+
65
+ This will create a new game called 'alien_shooter'
66
+ with three components, alien, hero, lazer
67
+
68
+ ## create a new component
69
+ entityjs comp [component_name]
70
+
71
+ - example
72
+ entityjs comp hero
73
+
74
+ ## build game
75
+ entityjs build
76
+
77
+ Exports game in builds directory
78
+
79
+ ## build game with custom name
80
+ entityjs build release1
81
+
82
+ ## refresh sources
83
+ entityjs refresh
84
+ or
85
+ entityjs r
86
+
87
+ Creates a file called game.debug.js inside /tmp
@@ -0,0 +1,12 @@
1
+ /*
2
+ The bit component defines an image text to draw text on screen.
3
+ */
4
+ re.c('bit')
5
+ .requires('imgtext bit.png align')
6
+ .defines({
7
+ //defines the width of each character
8
+ imgtext:[
9
+ 8,4,8,12,10,12,12,4,6,6,8,8,6,8,4,12,10,6,10,10,10,10,10,10,10,10,4,4,8,8,8,10,
10
+ 12,10,10,8,10,8,8,10,10,8,10,10,8,12,10,10,10,10,10,10,8,10,10,12,10,10,8,6,12,
11
+ 6,8,10,6,10,10,8,10,10,8,10,10,4,6,10,4,12,10,10,10,10,8,10,8,10,10,12,8,10,10,8,4,8]
12
+ });
@@ -0,0 +1,77 @@
1
+ re.c('hero')
2
+ .requires('hero.png tsprite update force flicker body')
3
+ .defines({
4
+
5
+ speed:40 * re.sys.stepSize,
6
+
7
+ friX:0.75,
8
+ friY:0.95,
9
+
10
+ padX:6,
11
+
12
+ bodyX:24,
13
+ bodyY:24,
14
+
15
+ jumpSpeed:480 * re.sys.stepSize,
16
+ jump:false,
17
+ ground:true,
18
+
19
+ update:function(){
20
+
21
+ //jump
22
+ if(this.ground && !this.jump && re.pressed('w')){
23
+ this.forceJump();
24
+ }
25
+
26
+ //walk back and fourth
27
+ if(re.pressed('a')){
28
+ this.velX -= this.speed;
29
+ this.scaleX = -1;
30
+
31
+ if(!this.jump) this.flicker('run');
32
+ }
33
+
34
+ if(re.pressed('d')){
35
+ this.velX += this.speed;
36
+ this.scaleX = 1;
37
+
38
+ if(!this.jump) this.flicker('run');
39
+ }
40
+
41
+ //switch back to idle animation if stopped moving
42
+ if(this.isIdle(0.3)) this.flicker('idle');
43
+
44
+ },
45
+
46
+ forceJump:function(){
47
+ this.jump = true;
48
+ this.velY -= this.jumpSpeed;
49
+
50
+ this.flicker('jump');
51
+ },
52
+
53
+ jumpReset:function(x, y, tx, ty){
54
+ //check if a hit happened on the y axis
55
+ if(y){
56
+ this.jump = false;
57
+ this.ground = (ty >= this.posY);
58
+ }
59
+ }
60
+
61
+ })
62
+ .init(function(){
63
+
64
+ //add animations
65
+ this.addFlicker({
66
+ idle:[-1, 600, [0, 1]],
67
+ run:[-1, 800, [2, 3]],
68
+ jump:[1, 500, [4, 5, 4]],
69
+ ladder:[-1, 500, [6, 7]]
70
+ });
71
+
72
+ this.on({
73
+ update:this.update,
74
+ aftermath:this.jumpReset
75
+ });
76
+
77
+ });
@@ -0,0 +1,2 @@
1
+ re.c('tile')
2
+ .requires('tsprite tiles.png');
@@ -0,0 +1,17 @@
1
+ /*
2
+ The tsprite component is a simple extension to sprite that defaults the size attributes.
3
+ */
4
+ re.c('tsprite')
5
+ .requires('sprite')
6
+ .init(function(){
7
+ this.sizeX = re.tile.sizeX;
8
+ this.sizeY = re.tile.sizeY;
9
+
10
+ this.bodyX = re.tile.sizeX;
11
+ this.bodyY = re.tile.sizeY;
12
+
13
+ //setup registration point
14
+ this.regX = this.sizeX * 0.5;
15
+ this.regY = this.sizeY * 0.5;
16
+
17
+ });
@@ -0,0 +1,7 @@
1
+ re.ready(function(){
2
+
3
+ re.sys.init(re.canvas).start();
4
+
5
+ re.scene('load').enter();
6
+
7
+ });
@@ -0,0 +1,27 @@
1
+ re.c('coin')
2
+ .requires('item flicker')
3
+ .defines({
4
+
5
+ touch:function(){
6
+ this.collect();
7
+ },
8
+
9
+ collect:function(){
10
+ this.sfx.play();
11
+ this.trigger('collect');
12
+ this.dispose();
13
+ }
14
+
15
+ })
16
+ .init(function(){
17
+ //add comp for searchability
18
+ this.comp('coin');
19
+
20
+ this.sfx = re.e('sound coin.sfx');
21
+
22
+ this.addFlicker('glow', -1, 1800, '14 15 15');
23
+ this.flicker('glow');
24
+ })
25
+ //accepted tile frames in items.png which will become coins
26
+ .alias('t14')
27
+ .alias('t15');
@@ -0,0 +1,41 @@
1
+ re.c('item')
2
+ .requires('tsprite update hit items.png')
3
+ .namespaces({
4
+
5
+ update:function(t){
6
+
7
+ if(this.hero.hitBody(this.posX, this.posY, this.sizeX, this.sizeY, 10, 0)){
8
+ this.touching = true;
9
+ this.touch(t);
10
+
11
+ } else if(this.touching){
12
+
13
+ this.touching = false;
14
+
15
+ this.untouch(t);
16
+ }
17
+
18
+ }
19
+
20
+ })
21
+ .defaults({
22
+ touching:false,
23
+
24
+ touch:function(){
25
+
26
+ },
27
+
28
+ untouch:function(){
29
+
30
+ }
31
+ })
32
+ .init(function(){
33
+ this.hero = re('hero')[0];
34
+
35
+ this.on('update', this.item_update);
36
+
37
+ this.updateBefore(this.hero);
38
+ })
39
+ .dispose(function(){
40
+ this.off();
41
+ });
@@ -0,0 +1,25 @@
1
+ re.c('spring')
2
+ .requires('item flicker')
3
+ .defines({
4
+
5
+ touch:function(){
6
+ this.hero.velY = -5;
7
+
8
+ if(re.pressed('w')){
9
+ this.hero.velY = -25;
10
+ this.flicker('bounce');
11
+ }
12
+ }
13
+
14
+ })
15
+ .init(function(){
16
+ //add animation, can also send a string instead of an array
17
+ this.addFlicker('bounce', 1, 300, '13 12');
18
+
19
+ this.frame(12);
20
+
21
+ this.comp('spring');
22
+ })
23
+ //used to place it in level.js
24
+ .alias('t12')
25
+ .alias('t13');
@@ -0,0 +1,10 @@
1
+ re.scene('home')
2
+ .enter(function(){
3
+
4
+ re.scene('play').enter('level1');
5
+
6
+ })
7
+ .exit(function(){
8
+
9
+
10
+ });
@@ -0,0 +1,27 @@
1
+ re.scene('load')
2
+ .enter(function(){
3
+
4
+ re.tile.sizeX = re.tile.sizeY = 25;
5
+
6
+ re.sys.clearColor = '#D6F8FA';
7
+
8
+ //setup gravity
9
+ re.force.graY = 30 * re.sys.stepSize;
10
+
11
+ re.load(re.assets)
12
+ .complete(function(){
13
+
14
+ //move to home
15
+ re.scene('home').enter();
16
+ })
17
+ .error(function(e){
18
+
19
+ })
20
+ .progress(function(i){
21
+
22
+ });
23
+
24
+ })
25
+ .exit(function(){
26
+ //exit load scene
27
+ });
@@ -0,0 +1,31 @@
1
+ re.scene('play')
2
+ .enter(function(level){
3
+
4
+ //offset screen because all tiles are centered..
5
+ //checkout tsprite.js
6
+ re.screen.pos(-re.tile.sizeX * 0.5, -re.tile.sizeY * 0.5);
7
+
8
+ //display coin text
9
+ var counter = this.counter = re.e('counter');
10
+
11
+ //find level
12
+ this.level = re(level+'.tmx')[0];
13
+
14
+ //load it
15
+ this.level.build();
16
+
17
+ //let the player collect coins
18
+ //listen for collect events from all coins
19
+ re('coin').on('collect', function(){
20
+ counter.add(1);
21
+ });
22
+
23
+ })
24
+ .exit(function(){
25
+
26
+ this.counter.dispose();
27
+
28
+ //teardown level
29
+ this.level.teardown();
30
+
31
+ });
@@ -0,0 +1,34 @@
1
+ re.c('counter')
2
+ .defines({
3
+
4
+ _count:0,
5
+
6
+ add:function(value){
7
+ if(re.is(value)){
8
+ this._count += value;
9
+ this.coinText.text("Coins: "+this._count);
10
+
11
+ return this;
12
+ }
13
+
14
+ return this._count;
15
+ }
16
+
17
+ })
18
+ .init(function(){
19
+
20
+ //define text
21
+ this.coinText = re.e('bit')
22
+ .alignLeft(5)
23
+ .alignTop(5)
24
+ //ignore screen coordinates
25
+ .attr('screenable', false);
26
+
27
+ //set default text
28
+ this.add(0);
29
+ })
30
+ .dispose(function(){
31
+
32
+ this.coinText.dispose();
33
+
34
+ });