entityjs 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. data/README.md +18 -14
  2. data/entityjs.gemspec +1 -0
  3. data/lib/entityjs/assets.rb +13 -163
  4. data/lib/entityjs/command.rb +5 -2
  5. data/lib/entityjs/commands/build.rb +63 -23
  6. data/lib/entityjs/commands/eunit.rb +44 -0
  7. data/lib/entityjs/commands/release.rb +1 -1
  8. data/lib/entityjs/commands/server.rb +19 -4
  9. data/lib/entityjs/compile.rb +152 -0
  10. data/lib/entityjs/config.rb +8 -0
  11. data/lib/entityjs/dirc.rb +70 -17
  12. data/lib/entityjs/page.rb +106 -0
  13. data/lib/entityjs/parsers/parse_coffee.rb +12 -0
  14. data/lib/entityjs/version.rb +1 -1
  15. data/lib/entityjs.rb +18 -4
  16. data/public/qunit/qunit.css +9 -3
  17. data/public/qunit/qunit.entity.js +113 -31
  18. data/public/qunit/qunit.js +296 -235
  19. data/public/qunit/qunit.mock.js +54 -2
  20. data/public/tests.html +0 -15
  21. data/spec/javascripts/src/cycle/tween_spec.js +59 -0
  22. data/spec/javascripts/src/display/screen_spec.js +0 -15
  23. data/spec/javascripts/src/display/text_spec.js +4 -0
  24. data/spec/javascripts/src/input/mouse_spec.js +18 -18
  25. data/spec/javascripts/src/input/preventdefault_spec.js +14 -0
  26. data/spec/javascripts/src/math/drag_spec.js +2 -2
  27. data/spec/javascripts/src/math/hit_spec.js +24 -0
  28. data/spec/javascripts/src/math/point_spec.js +3 -3
  29. data/spec/javascripts/src/math/tile_spec.js +1 -1
  30. data/spec/javascripts/src/media/sound_spec.js +1 -1
  31. data/spec/javascripts/src/pattern/automap_spec.js +3 -3
  32. data/spec/javascripts/src/pattern/flicker_spec.js +2 -1
  33. data/spec/javascripts/src/util/random_spec.js +17 -0
  34. data/spec/javascripts/src/util/scene_spec.js +15 -0
  35. data/spec/lib/entityjs/assets_spec.rb +2 -201
  36. data/spec/lib/entityjs/commands/build_spec.rb +18 -5
  37. data/spec/lib/entityjs/commands/eunit_spec.rb +18 -0
  38. data/spec/lib/entityjs/commands/release_spec.rb +2 -0
  39. data/spec/lib/entityjs/compile_spec.rb +204 -0
  40. data/spec/lib/entityjs/dirc_spec.rb +8 -4
  41. data/spec/lib/entityjs/page_spec.rb +59 -0
  42. data/spec/support/factories.rb +0 -2
  43. data/src/core/entity.js +4 -18
  44. data/src/core/query.js +1 -1
  45. data/src/core/re.js +6 -6
  46. data/src/core/system.js +17 -12
  47. data/src/cycle/tween.js +93 -31
  48. data/src/display/align.js +11 -6
  49. data/src/display/circle.js +5 -4
  50. data/src/display/imgtext.js +33 -22
  51. data/src/display/screen.js +0 -8
  52. data/src/display/text.js +37 -4
  53. data/src/input/keyboard.js +15 -5
  54. data/src/input/mouse.js +15 -25
  55. data/src/input/preventdefault.js +11 -0
  56. data/src/math/body.js +35 -16
  57. data/src/math/drag.js +2 -2
  58. data/src/math/force.js +2 -2
  59. data/src/math/hit.js +15 -6
  60. data/src/math/hitmap.js +6 -6
  61. data/src/math/point.js +1 -1
  62. data/src/math/tile.js +22 -17
  63. data/src/media/sound.js +1 -1
  64. data/src/pattern/automap.js +16 -27
  65. data/src/pattern/flicker.js +9 -5
  66. data/src/util/random.js +4 -0
  67. data/src/util/scene.js +2 -6
  68. data/templates/arrow_keys/scripts/{display → displays}/arrow.js +0 -0
  69. data/templates/arrow_keys/scripts/{input → inputs}/controls.js +0 -0
  70. data/templates/arrow_keys/tests/{display → displays}/arrow_test.js +1 -1
  71. data/templates/arrow_keys/tests/{input → inputs}/controls_test.js +0 -0
  72. data/templates/arrow_keys/tests/scenes/load_test.js +2 -0
  73. data/templates/{blank → circle}/config.yml +0 -0
  74. data/templates/{blank → circle}/readme.txt +0 -0
  75. data/templates/circle/scripts/init.js +7 -0
  76. data/templates/circle/scripts/scenes/home.js +62 -0
  77. data/templates/circle/scripts/scenes/load.js +11 -0
  78. data/templates/circle/tests/scenes/home_test.js +29 -0
  79. data/templates/circle/tests/scenes/load_test.js +15 -0
  80. data/templates/platform/config.yml +2 -1
  81. data/templates/platform/readme.txt +15 -16
  82. data/templates/platform/scripts/{display → displays}/bit.js +0 -0
  83. data/templates/platform/scripts/{display → displays}/hero.js +0 -0
  84. data/templates/platform/scripts/{display → displays}/tile.js +0 -0
  85. data/templates/platform/scripts/{display → displays}/tsprite.js +0 -0
  86. data/templates/platform/{assets → scripts}/levels/level1.tmx +0 -0
  87. data/templates/platform/scripts/{util → utils}/counter.js +0 -0
  88. data/templates/platform/scripts/{util → utils}/level.js +0 -0
  89. data/templates/platform/tests/{display → displays}/bit_test.js +1 -1
  90. data/templates/platform/tests/displays/hero_test.js +73 -0
  91. data/templates/platform/tests/{display → displays}/tile_test.js +1 -1
  92. data/templates/platform/tests/displays/tsprite_test.js +8 -0
  93. data/templates/platform/tests/items/coin_test.js +10 -10
  94. data/templates/platform/tests/items/item_test.js +9 -9
  95. data/templates/platform/tests/items/spring_test.js +3 -3
  96. data/templates/platform/tests/scenes/load_test.js +2 -1
  97. data/templates/platform/tests/{util → utils}/counter_test.js +2 -2
  98. data/templates/platform/tests/{util → utils}/level_test.js +3 -0
  99. data/templates/pong/config.yml +22 -0
  100. data/templates/pong/readme.txt +3 -0
  101. data/templates/pong/scripts/controls/ai.js +30 -0
  102. data/templates/pong/scripts/controls/arena.js +33 -0
  103. data/templates/pong/scripts/controls/hitmap.js +54 -0
  104. data/templates/pong/scripts/controls/player.js +24 -0
  105. data/templates/pong/scripts/controls/twoarena.js +14 -0
  106. data/templates/pong/scripts/displays/ball.js +29 -0
  107. data/templates/pong/scripts/displays/counter.js +22 -0
  108. data/templates/pong/scripts/displays/paddle.js +22 -0
  109. data/templates/pong/scripts/init.js +9 -0
  110. data/templates/pong/scripts/scenes/game.js +61 -0
  111. data/templates/pong/scripts/scenes/home.js +55 -0
  112. data/templates/pong/scripts/scenes/over.js +29 -0
  113. data/templates/pong/tests/controls/ai_test.js +34 -0
  114. data/templates/pong/tests/controls/arena_test.js +20 -0
  115. data/templates/pong/tests/controls/hitmap_test.js +89 -0
  116. data/templates/pong/tests/controls/player_test.js +25 -0
  117. data/templates/pong/tests/controls/twoarena_test.js +7 -0
  118. data/templates/pong/tests/displays/ball_test.js +10 -0
  119. data/templates/pong/tests/displays/counter_test.js +13 -0
  120. data/templates/pong/tests/displays/paddle_test.js +17 -0
  121. data/templates/pong/tests/scenes/game_test.js +16 -0
  122. data/templates/pong/tests/scenes/home_test.js +30 -0
  123. data/templates/pong/tests/scenes/over_test.js +16 -0
  124. data/templates/tiltmaze/config.yml +25 -0
  125. data/templates/tiltmaze/readme.txt +79 -0
  126. data/templates/tiltmaze/scripts/displays/ball.js +78 -0
  127. data/templates/tiltmaze/scripts/displays/target.js +13 -0
  128. data/templates/tiltmaze/scripts/displays/tile.js +2 -0
  129. data/templates/tiltmaze/scripts/init.js +7 -0
  130. data/templates/tiltmaze/scripts/levels/level1.json +14 -0
  131. data/templates/tiltmaze/scripts/levels/level2.json +14 -0
  132. data/templates/tiltmaze/scripts/levels/level3.json +14 -0
  133. data/templates/tiltmaze/scripts/levels/level4.json +15 -0
  134. data/templates/tiltmaze/scripts/levels/level5.json +18 -0
  135. data/templates/tiltmaze/scripts/scenes/game.js +56 -0
  136. data/templates/tiltmaze/scripts/scenes/home.js +24 -0
  137. data/templates/tiltmaze/scripts/structs/level.js +82 -0
  138. data/templates/tiltmaze/scripts/tiles/walltile.js +147 -0
  139. data/templates/tiltmaze/tests/displays/ball_test.js +67 -0
  140. data/templates/tiltmaze/tests/displays/target_test.js +8 -0
  141. data/templates/tiltmaze/tests/factories.js +38 -0
  142. data/templates/tiltmaze/tests/scenes/game_test.js +59 -0
  143. data/templates/tiltmaze/tests/scenes/home_test.js +7 -0
  144. data/templates/tiltmaze/tests/structs/level_test.js +44 -0
  145. data/templates/tiltmaze/tests/tiles/walltile_test.js +36 -0
  146. metadata +106 -33
  147. data/templates/platform/tests/display/hero_test.js +0 -73
  148. data/templates/platform/tests/display/tsprite_test.js +0 -8
@@ -0,0 +1,20 @@
1
+ module('controls/arena', lazy('arena'));
2
+
3
+ test('start round', function(){
4
+
5
+ arena.startRound();
6
+
7
+ is(arena.ball);
8
+
9
+ ok(re('ball').length == 1);
10
+
11
+
12
+ });
13
+
14
+ test('stop round', function(){
15
+
16
+ arena.stopRound();
17
+
18
+ expect(0);
19
+
20
+ });
@@ -0,0 +1,89 @@
1
+ /*
2
+ The hitmap controls the balls boundaires, so i'll write some extra tests to make sure it works.
3
+ */
4
+ module('controls/hitmap', {
5
+ setup:function(){
6
+ hitmap = f('hitmap');
7
+ ball = f('ball');
8
+ },
9
+ teardown:function(){
10
+ hitmap.dispose();
11
+ ball.dispose();
12
+ }
13
+ });
14
+
15
+ test('ball hitting the left side should trigger event', function(){
16
+
17
+ ball.posX = -1 + ball.hsizeX;
18
+
19
+ expectTrigger(hitmap, 'score:left');
20
+
21
+ hitmap.checkHit(ball);
22
+
23
+ });
24
+
25
+ test('ball hitting the right side should trigger event', function(){
26
+
27
+ ball.posX = re.sys.sizeX - ball.hsizeX + 1;
28
+
29
+ expectTrigger(hitmap, 'score:right');
30
+
31
+ hitmap.checkHit(ball);
32
+
33
+ });
34
+
35
+ test('ball should hit top', function(){
36
+
37
+ ball.posY = -1 + ball.hsizeY;
38
+
39
+ var res = hitmap.checkHit(ball);
40
+
41
+ eq(res.hitY, 1);
42
+ eq(res.posY, ball.hsizeY);
43
+
44
+ });
45
+
46
+ test('ball should hit bottom', function(){
47
+
48
+ ball.posY = re.sys.sizeY - ball.hsizeY + 1;
49
+
50
+ var res = hitmap.checkHit(ball);
51
+
52
+ eq(res.hitY, 1);
53
+ eq(res.posY, re.sys.sizeY - ball.hsizeY);
54
+
55
+ });
56
+
57
+ test('ball should hit right of paddle', function(){
58
+
59
+ var paddle = re.e('paddle')
60
+ .attr({
61
+ posX:100,
62
+ posY:100
63
+ });
64
+
65
+ ball.posX = paddle.posX + paddle.hsizeX + ball.hsizeX;
66
+
67
+ var res = hitmap.checkHit(ball);
68
+
69
+ ok(res.hitX);
70
+ eq(res.posX, ball.posX+1);
71
+
72
+ })
73
+
74
+ test('ball should hit left of paddle', function(){
75
+
76
+ var paddle = re.e('paddle')
77
+ .attr({
78
+ posX:100,
79
+ posY:100
80
+ });
81
+
82
+ ball.posX = paddle.posX - ball.hsizeX - paddle.hsizeX;
83
+
84
+ var res = hitmap.checkHit(ball);
85
+
86
+ ok(res.hitX);
87
+ eq(res.posX, ball.posX-1);
88
+
89
+ });
@@ -0,0 +1,25 @@
1
+ module('controls/player', lazy('player'));
2
+
3
+ test('paddle moves down on w press', function(){
4
+
5
+ player.posY = 30;
6
+
7
+ expectValueDown(player, 'posY');
8
+
9
+ keypress('w', function(){
10
+ player.update();
11
+ });
12
+
13
+ });
14
+
15
+ test('paddle moves up on s press', function(){
16
+
17
+ player.posY = 10;
18
+
19
+ expectValueUp(player, 'posY');
20
+
21
+ keypress('s', function(){
22
+ player.update();
23
+ });
24
+
25
+ });
@@ -0,0 +1,7 @@
1
+ module('controls/twoarena', lazy('twoarena'));
2
+
3
+ test('creates second player', function(){
4
+
5
+ ok(twoarena.paddle2.has('player'));
6
+
7
+ });
@@ -0,0 +1,10 @@
1
+ module('displays/ball', lazy('ball'));
2
+
3
+ test('reset ball', function(){
4
+
5
+ ball.reset();
6
+
7
+ ok(ball.velX != 0)
8
+ ok(ball.velY != 0)
9
+
10
+ });
@@ -0,0 +1,13 @@
1
+ module('displays/counter', lazy('counter'));
2
+
3
+ test('counting up should trigger win', function(){
4
+
5
+ counter.name = 'blah';
6
+ counter.maxCount = 1;
7
+ counter.count = 0;
8
+
9
+ expectTrigger(counter, 'max', [counter.name]);
10
+
11
+ counter.up();
12
+
13
+ });
@@ -0,0 +1,17 @@
1
+ module('displays/paddle', lazy('paddle'));
2
+
3
+ test('stay within bounds', function(){
4
+
5
+ paddle.posY = -10;
6
+
7
+ paddle.checkBounds();
8
+
9
+ ok(paddle.posY >= 0);
10
+
11
+ paddle.posY = re.sys.sizeY + 10;
12
+
13
+ paddle.checkBounds();
14
+
15
+ ok(paddle.posY <= re.sys.sizeY)
16
+
17
+ });
@@ -0,0 +1,16 @@
1
+ module('scenes/game');
2
+
3
+ test('exit cleanly', function(){
4
+
5
+ re.scene('game').enter();
6
+
7
+ //game finished
8
+ re('counter')[0]
9
+ .attr({
10
+ maxCount:1
11
+ })
12
+ .up();
13
+
14
+ ok(re('counter').length == 0)
15
+
16
+ });
@@ -0,0 +1,30 @@
1
+ module('scenes/home', {
2
+ setup:function(){
3
+ re.scene('home').enter();
4
+ },
5
+ teardown:function(){
6
+ re.scene('home').exit();
7
+ }
8
+ });
9
+
10
+ test('create home screen', function(){
11
+
12
+ is(re('text')[0]);
13
+
14
+ });
15
+
16
+ test('z should go to single player', function(){
17
+
18
+ expectCall(re.scene('game'), 'enter', [false]);
19
+
20
+ keyup('z');
21
+
22
+ });
23
+
24
+ test('x should go to two player', function(){
25
+
26
+ expectCall(re.scene('game'), 'enter', [true]);
27
+
28
+ keyup('x');
29
+
30
+ });
@@ -0,0 +1,16 @@
1
+ module('scenes/over');
2
+
3
+ test('enter over scene', function(){
4
+
5
+ var message = 'You lost!';
6
+
7
+ re.scene('over').enter(message);
8
+
9
+ eq(re('text')[0].text(), message);
10
+
11
+ expectCall(re.scene('home'), 'enter');
12
+
13
+ //back to home
14
+ keyup('z');
15
+
16
+ });
@@ -0,0 +1,25 @@
1
+ # Configure your game settings
2
+
3
+ width: 180
4
+ height: 180
5
+ canvas-id: game-canvas
6
+
7
+ canvas-border: false
8
+
9
+ #files to ignore in /scripts
10
+ scripts-ignore:
11
+
12
+ #specify files to be loaded first in /scripts
13
+ order:
14
+ /tile.js$
15
+
16
+ #components to ignore in the entityjs source
17
+ #reduce file size by ignoring unused components
18
+ entity-ignore:
19
+ socket
20
+ wait
21
+ group
22
+
23
+ #ignore tests in /tests
24
+ tests-ignore:
25
+
@@ -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,78 @@
1
+ re.c('ball')
2
+ .requires('tile draw update')
3
+ .defines({
4
+ color:'#ff0000',
5
+ speed:6,
6
+ moving:false,
7
+ pad:5,
8
+
9
+ draw:function(c){
10
+ c.fillStyle = this.color;
11
+
12
+ c.beginPath();
13
+ var r = 10;
14
+
15
+ c.arc(r + 5, r + 5, r, 0, Math.PI*2, true);
16
+
17
+ c.closePath();
18
+
19
+ c.fill();
20
+ },
21
+
22
+ move:function(x, y){
23
+
24
+ var tx = this.tileX();
25
+ var ty = this.tileY();
26
+
27
+ var tile = this.level.automap(tx, ty);
28
+ var tileAfter = this.level.automap(tx+x, ty+y);
29
+
30
+ if(tileAfter && !tile.checkWallInside(x, y) && !tileAfter.checkWall(x, y)){
31
+
32
+ if(y){
33
+ this.posY += this.speed * y;
34
+ }
35
+ if(x){
36
+ this.posX += this.speed * x;
37
+ }
38
+
39
+ } else {
40
+ this.tile(tx, ty);
41
+ this.moving = false;
42
+ this.off('update');
43
+ this.on('update', this.update);
44
+ this.trigger('move:finish');
45
+ }
46
+
47
+ this.trigger('move:update');
48
+ },
49
+
50
+ keydown:function(x, y){
51
+ if(this.moving) return;
52
+ this.moving = true;
53
+ this.on('update', function(){
54
+ this.move(x, y);
55
+ });
56
+ },
57
+
58
+ update:function(){
59
+
60
+ if(re.pressed('a', 'left')){
61
+ this.keydown(-1, 0);
62
+ } else if(re.pressed('d', 'right')){
63
+ this.keydown(1, 0);
64
+ }
65
+
66
+ if(re.pressed('s', 'down')){
67
+ this.keydown(0, 1);
68
+ } else if(re.pressed('w', 'up')){
69
+ this.keydown(0, -1);
70
+ }
71
+
72
+ }
73
+
74
+ })
75
+ .init(function(){
76
+
77
+ this.on('update', this.update);
78
+ });
@@ -0,0 +1,13 @@
1
+ re.c('target')
2
+ .requires('draw tile')
3
+ .defines({
4
+ color:'#0000ff',
5
+
6
+ draw:function(c){
7
+
8
+ c.fillStyle = this.color;
9
+
10
+ c.fillRect(this.sizeX / 2 - 5, this.sizeY / 2 - 5, 10, 10);
11
+ }
12
+
13
+ });
@@ -0,0 +1,2 @@
1
+ re.tile.sizeX = 30;
2
+ re.tile.sizeY = 30;
@@ -0,0 +1,7 @@
1
+ re.ready(function(){
2
+
3
+ re.sys.init(re.canvas).start();
4
+
5
+ re.scene('home').enter();
6
+
7
+ });
@@ -0,0 +1,14 @@
1
+ {
2
+ "map":[
3
+ [12,1,1,8,1,5],
4
+ [4,0,0,0,0,2],
5
+ [4,0,0,0,0,2],
6
+ [4,0,7,0,0,6],
7
+ [7,0,0,0,0,2],
8
+ [7,3,3,3,10,6]
9
+ ],
10
+ "targets":[
11
+ [5,3]
12
+ ],
13
+ "start":[0,3]
14
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "map":[
3
+ [8,1,13,1,1,11],
4
+ [4,0,0,0,0,2],
5
+ [7,0,2,0,0,2],
6
+ [4,0,0,0,6,2],
7
+ [4,0,0,0,0,2],
8
+ [7,6,3,11,3,6]
9
+ ],
10
+ "targets":[
11
+ [5,0]
12
+ ],
13
+ "start":[0,2]
14
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "map":[
3
+ [8,1,1,1,8,5],
4
+ [4,11,0,0,0,2],
5
+ [10,0,0,0,0,2],
6
+ [4,0,0,8,3,2],
7
+ [4,7,0,0,0,6],
8
+ [7,3,3,3,3,6]
9
+ ],
10
+ "targets":[
11
+ [3,3]
12
+ ],
13
+ "start":[1,1]
14
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "map":[
3
+ [8,1,1,1,5],
4
+ [8,0,8,0,2],
5
+ [4,0,0,0,10],
6
+ [10,0,0,0,2],
7
+ [7,3,7,3,6]
8
+ ],
9
+ "targets":[
10
+ [2,4],
11
+ [4,0],
12
+ [0,4]
13
+ ],
14
+ "start":[3,2]
15
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "map":[
3
+ [8,1,11,1,1,5],
4
+ [4,0,0,0,0,12],
5
+ [4,0,0,0,0,2],
6
+ [4,7,0,1,0,2],
7
+ [4,0,0,4,0,2],
8
+ [7,6,3,3,3,10]
9
+ ],
10
+ "targets":[
11
+ [0,5],
12
+ [0,1],
13
+ [4,5],
14
+ [5,1],
15
+ [2,0]
16
+ ],
17
+ "start":[3,1]
18
+ }
@@ -0,0 +1,56 @@
1
+ re.scene('game')
2
+ .enter(function(levelNum){
3
+
4
+ //prevent default browser actions
5
+ re.preventDefault('left right up down');
6
+
7
+ this.setLevel(levelNum);
8
+ this.currentLevel.setup();
9
+
10
+ var self = this;
11
+
12
+ //set keyboard shortcuts
13
+ re.e('keyboard')
14
+ .on('keyup:q', function(){
15
+ self.quit();
16
+ })
17
+ .on('keyup:r', function(){
18
+ self.restart();
19
+ });
20
+
21
+ })
22
+ .attr({
23
+
24
+ setLevel:function(num){
25
+
26
+ this.currentLevel = re.level.get(num);
27
+ this.num = num;
28
+
29
+ if(!re.is(this.currentLevel)){
30
+ this.num = 1;
31
+ this.currentLevel = re.level.get(1);
32
+ }
33
+
34
+ },
35
+
36
+ advance:function(){
37
+ this.num++;
38
+
39
+ this.enter(this.num);
40
+ },
41
+
42
+ restart:function(){
43
+ this.enter(this.num);
44
+ },
45
+
46
+ quit:function(){
47
+ re.scene('home').enter();
48
+ }
49
+
50
+ })
51
+ .exit(function(){
52
+
53
+ this.currentLevel.teardown();
54
+ re('keyboard').dispose();
55
+
56
+ });
@@ -0,0 +1,24 @@
1
+ re.scene('home')
2
+ .enter(function(){
3
+
4
+ //add help text
5
+ re.e('text align')
6
+ .attr({
7
+ font:'bold 30px Verdina',
8
+ text:'Tiltmaze'
9
+ })
10
+ .align(0, -60);
11
+
12
+ re.e('text align keyboard')
13
+ .text('Press any key to begin\nQ - Quit\nR - Restart')
14
+ .align()
15
+ .on('keyup', function(){
16
+ re.scene('game').enter(1);
17
+ });
18
+
19
+ })
20
+ .exit(function(){
21
+
22
+ re('text').dispose();
23
+
24
+ });