entityjs 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +18 -14
- data/entityjs.gemspec +1 -0
- data/lib/entityjs/assets.rb +13 -163
- data/lib/entityjs/command.rb +5 -2
- data/lib/entityjs/commands/build.rb +63 -23
- data/lib/entityjs/commands/eunit.rb +44 -0
- data/lib/entityjs/commands/release.rb +1 -1
- data/lib/entityjs/commands/server.rb +19 -4
- data/lib/entityjs/compile.rb +152 -0
- data/lib/entityjs/config.rb +8 -0
- data/lib/entityjs/dirc.rb +70 -17
- data/lib/entityjs/page.rb +106 -0
- data/lib/entityjs/parsers/parse_coffee.rb +12 -0
- data/lib/entityjs/version.rb +1 -1
- data/lib/entityjs.rb +18 -4
- data/public/qunit/qunit.css +9 -3
- data/public/qunit/qunit.entity.js +113 -31
- data/public/qunit/qunit.js +296 -235
- data/public/qunit/qunit.mock.js +54 -2
- data/public/tests.html +0 -15
- data/spec/javascripts/src/cycle/tween_spec.js +59 -0
- data/spec/javascripts/src/display/screen_spec.js +0 -15
- data/spec/javascripts/src/display/text_spec.js +4 -0
- data/spec/javascripts/src/input/mouse_spec.js +18 -18
- data/spec/javascripts/src/input/preventdefault_spec.js +14 -0
- data/spec/javascripts/src/math/drag_spec.js +2 -2
- data/spec/javascripts/src/math/hit_spec.js +24 -0
- data/spec/javascripts/src/math/point_spec.js +3 -3
- data/spec/javascripts/src/math/tile_spec.js +1 -1
- data/spec/javascripts/src/media/sound_spec.js +1 -1
- data/spec/javascripts/src/pattern/automap_spec.js +3 -3
- data/spec/javascripts/src/pattern/flicker_spec.js +2 -1
- data/spec/javascripts/src/util/random_spec.js +17 -0
- data/spec/javascripts/src/util/scene_spec.js +15 -0
- data/spec/lib/entityjs/assets_spec.rb +2 -201
- data/spec/lib/entityjs/commands/build_spec.rb +18 -5
- data/spec/lib/entityjs/commands/eunit_spec.rb +18 -0
- data/spec/lib/entityjs/commands/release_spec.rb +2 -0
- data/spec/lib/entityjs/compile_spec.rb +204 -0
- data/spec/lib/entityjs/dirc_spec.rb +8 -4
- data/spec/lib/entityjs/page_spec.rb +59 -0
- data/spec/support/factories.rb +0 -2
- data/src/core/entity.js +4 -18
- data/src/core/query.js +1 -1
- data/src/core/re.js +6 -6
- data/src/core/system.js +17 -12
- data/src/cycle/tween.js +93 -31
- data/src/display/align.js +11 -6
- data/src/display/circle.js +5 -4
- data/src/display/imgtext.js +33 -22
- data/src/display/screen.js +0 -8
- data/src/display/text.js +37 -4
- data/src/input/keyboard.js +15 -5
- data/src/input/mouse.js +15 -25
- data/src/input/preventdefault.js +11 -0
- data/src/math/body.js +35 -16
- data/src/math/drag.js +2 -2
- data/src/math/force.js +2 -2
- data/src/math/hit.js +15 -6
- data/src/math/hitmap.js +6 -6
- data/src/math/point.js +1 -1
- data/src/math/tile.js +22 -17
- data/src/media/sound.js +1 -1
- data/src/pattern/automap.js +16 -27
- data/src/pattern/flicker.js +9 -5
- data/src/util/random.js +4 -0
- data/src/util/scene.js +2 -6
- data/templates/arrow_keys/scripts/{display → displays}/arrow.js +0 -0
- data/templates/arrow_keys/scripts/{input → inputs}/controls.js +0 -0
- data/templates/arrow_keys/tests/{display → displays}/arrow_test.js +1 -1
- data/templates/arrow_keys/tests/{input → inputs}/controls_test.js +0 -0
- data/templates/arrow_keys/tests/scenes/load_test.js +2 -0
- data/templates/{blank → circle}/config.yml +0 -0
- data/templates/{blank → circle}/readme.txt +0 -0
- data/templates/circle/scripts/init.js +7 -0
- data/templates/circle/scripts/scenes/home.js +62 -0
- data/templates/circle/scripts/scenes/load.js +11 -0
- data/templates/circle/tests/scenes/home_test.js +29 -0
- data/templates/circle/tests/scenes/load_test.js +15 -0
- data/templates/platform/config.yml +2 -1
- data/templates/platform/readme.txt +15 -16
- data/templates/platform/scripts/{display → displays}/bit.js +0 -0
- data/templates/platform/scripts/{display → displays}/hero.js +0 -0
- data/templates/platform/scripts/{display → displays}/tile.js +0 -0
- data/templates/platform/scripts/{display → displays}/tsprite.js +0 -0
- data/templates/platform/{assets → scripts}/levels/level1.tmx +0 -0
- data/templates/platform/scripts/{util → utils}/counter.js +0 -0
- data/templates/platform/scripts/{util → utils}/level.js +0 -0
- data/templates/platform/tests/{display → displays}/bit_test.js +1 -1
- data/templates/platform/tests/displays/hero_test.js +73 -0
- data/templates/platform/tests/{display → displays}/tile_test.js +1 -1
- data/templates/platform/tests/displays/tsprite_test.js +8 -0
- data/templates/platform/tests/items/coin_test.js +10 -10
- data/templates/platform/tests/items/item_test.js +9 -9
- data/templates/platform/tests/items/spring_test.js +3 -3
- data/templates/platform/tests/scenes/load_test.js +2 -1
- data/templates/platform/tests/{util → utils}/counter_test.js +2 -2
- data/templates/platform/tests/{util → utils}/level_test.js +3 -0
- data/templates/pong/config.yml +22 -0
- data/templates/pong/readme.txt +3 -0
- data/templates/pong/scripts/controls/ai.js +30 -0
- data/templates/pong/scripts/controls/arena.js +33 -0
- data/templates/pong/scripts/controls/hitmap.js +54 -0
- data/templates/pong/scripts/controls/player.js +24 -0
- data/templates/pong/scripts/controls/twoarena.js +14 -0
- data/templates/pong/scripts/displays/ball.js +29 -0
- data/templates/pong/scripts/displays/counter.js +22 -0
- data/templates/pong/scripts/displays/paddle.js +22 -0
- data/templates/pong/scripts/init.js +9 -0
- data/templates/pong/scripts/scenes/game.js +61 -0
- data/templates/pong/scripts/scenes/home.js +55 -0
- data/templates/pong/scripts/scenes/over.js +29 -0
- data/templates/pong/tests/controls/ai_test.js +34 -0
- data/templates/pong/tests/controls/arena_test.js +20 -0
- data/templates/pong/tests/controls/hitmap_test.js +89 -0
- data/templates/pong/tests/controls/player_test.js +25 -0
- data/templates/pong/tests/controls/twoarena_test.js +7 -0
- data/templates/pong/tests/displays/ball_test.js +10 -0
- data/templates/pong/tests/displays/counter_test.js +13 -0
- data/templates/pong/tests/displays/paddle_test.js +17 -0
- data/templates/pong/tests/scenes/game_test.js +16 -0
- data/templates/pong/tests/scenes/home_test.js +30 -0
- data/templates/pong/tests/scenes/over_test.js +16 -0
- data/templates/tiltmaze/config.yml +25 -0
- data/templates/tiltmaze/readme.txt +79 -0
- data/templates/tiltmaze/scripts/displays/ball.js +78 -0
- data/templates/tiltmaze/scripts/displays/target.js +13 -0
- data/templates/tiltmaze/scripts/displays/tile.js +2 -0
- data/templates/tiltmaze/scripts/init.js +7 -0
- data/templates/tiltmaze/scripts/levels/level1.json +14 -0
- data/templates/tiltmaze/scripts/levels/level2.json +14 -0
- data/templates/tiltmaze/scripts/levels/level3.json +14 -0
- data/templates/tiltmaze/scripts/levels/level4.json +15 -0
- data/templates/tiltmaze/scripts/levels/level5.json +18 -0
- data/templates/tiltmaze/scripts/scenes/game.js +56 -0
- data/templates/tiltmaze/scripts/scenes/home.js +24 -0
- data/templates/tiltmaze/scripts/structs/level.js +82 -0
- data/templates/tiltmaze/scripts/tiles/walltile.js +147 -0
- data/templates/tiltmaze/tests/displays/ball_test.js +67 -0
- data/templates/tiltmaze/tests/displays/target_test.js +8 -0
- data/templates/tiltmaze/tests/factories.js +38 -0
- data/templates/tiltmaze/tests/scenes/game_test.js +59 -0
- data/templates/tiltmaze/tests/scenes/home_test.js +7 -0
- data/templates/tiltmaze/tests/structs/level_test.js +44 -0
- data/templates/tiltmaze/tests/tiles/walltile_test.js +36 -0
- metadata +106 -33
- data/templates/platform/tests/display/hero_test.js +0 -73
- data/templates/platform/tests/display/tsprite_test.js +0 -8
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
module('hero', lazy('hero'));
|
|
2
|
+
|
|
3
|
+
test('has flicks', function(){
|
|
4
|
+
|
|
5
|
+
expectFlicker(hero, 'idle');
|
|
6
|
+
expectFlicker(hero, 'run');
|
|
7
|
+
expectFlicker(hero, 'jump');
|
|
8
|
+
expectFlicker(hero, 'ladder');
|
|
9
|
+
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('has components', function(){
|
|
13
|
+
ok(hero.has('hero.png tsprite update force flicker body'));
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('flickers idle when not moving', function(){
|
|
17
|
+
|
|
18
|
+
hero.flicker('run');
|
|
19
|
+
|
|
20
|
+
stub(hero, 'isIdle', true);
|
|
21
|
+
|
|
22
|
+
hero.update();
|
|
23
|
+
|
|
24
|
+
ok(hero.flickering('idle'));
|
|
25
|
+
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('moves right', function(){
|
|
29
|
+
|
|
30
|
+
expectCall(hero, 'flicker');
|
|
31
|
+
|
|
32
|
+
keypress('d', function(){
|
|
33
|
+
hero.update();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('moves left', function(){
|
|
40
|
+
|
|
41
|
+
expectCall(hero, 'flicker');
|
|
42
|
+
|
|
43
|
+
keypress('a', function(){
|
|
44
|
+
hero.update();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('jumps when w pressed', function(){
|
|
50
|
+
|
|
51
|
+
//setup requrements for jumping
|
|
52
|
+
hero.ground = true;
|
|
53
|
+
hero.jump = false;
|
|
54
|
+
|
|
55
|
+
expectCall(hero, 'forceJump');
|
|
56
|
+
|
|
57
|
+
keypress('w', function(){
|
|
58
|
+
hero.update();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('resets jump when hitting the y axis', function(){
|
|
64
|
+
|
|
65
|
+
hero.ground = false;
|
|
66
|
+
hero.jump = true;
|
|
67
|
+
|
|
68
|
+
hero.jumpReset(false, true, 10, 999);
|
|
69
|
+
|
|
70
|
+
ok(hero.ground);
|
|
71
|
+
ok(!hero.jump);
|
|
72
|
+
|
|
73
|
+
});
|
|
@@ -2,27 +2,27 @@ module('coin', lazy('coin'));
|
|
|
2
2
|
|
|
3
3
|
test('valid', function(){
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
expectEvent(coin, 'update');
|
|
6
6
|
|
|
7
|
-
expectFlicker(
|
|
7
|
+
expectFlicker(coin, 'glow');
|
|
8
8
|
|
|
9
9
|
});
|
|
10
10
|
|
|
11
11
|
test('touch should collect', function(){
|
|
12
12
|
|
|
13
|
-
expectCall(
|
|
13
|
+
expectCall(coin, 'collect');
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
coin.touch();
|
|
16
16
|
|
|
17
|
-
})
|
|
17
|
+
});
|
|
18
18
|
|
|
19
19
|
test('collect should dispose and stuff', function(){
|
|
20
20
|
|
|
21
|
-
expectCall(
|
|
22
|
-
expectCall(
|
|
21
|
+
expectCall(coin.sfx, 'play');
|
|
22
|
+
expectCall(coin, 'dispose');
|
|
23
23
|
|
|
24
|
-
expectTrigger(
|
|
24
|
+
expectTrigger(coin, 'collect');
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
coin.collect();
|
|
27
27
|
|
|
28
|
-
})
|
|
28
|
+
});
|
|
@@ -2,35 +2,35 @@ module('item', lazy('item'));
|
|
|
2
2
|
|
|
3
3
|
test('has components', function(){
|
|
4
4
|
|
|
5
|
-
ok(
|
|
5
|
+
ok(item.has('tsprite update items.png'))
|
|
6
6
|
|
|
7
7
|
});
|
|
8
8
|
|
|
9
9
|
test('update method', function(){
|
|
10
10
|
|
|
11
11
|
//touching default to false
|
|
12
|
-
ok(!
|
|
12
|
+
ok(!item.touching)
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
expectEvent(item, 'update');
|
|
15
15
|
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
test('hitting hero should call touch', function(){
|
|
19
19
|
|
|
20
|
-
expectCall(
|
|
20
|
+
expectCall(item, 'touch');
|
|
21
21
|
|
|
22
22
|
//fake hitBody and always return true
|
|
23
|
-
stub(
|
|
23
|
+
stub(item.hero, 'hitBody', true);
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
item.item_update();
|
|
26
26
|
|
|
27
27
|
//should call untouch afterwards
|
|
28
28
|
|
|
29
29
|
//force hitbody to always return false now...
|
|
30
|
-
stub(
|
|
30
|
+
stub(item.hero, 'hitBody', false);
|
|
31
31
|
|
|
32
|
-
expectCall(
|
|
32
|
+
expectCall(item, 'untouch');
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
item.item_update();
|
|
35
35
|
|
|
36
36
|
});
|
|
@@ -2,7 +2,7 @@ module('spring', lazy('spring'));
|
|
|
2
2
|
|
|
3
3
|
test('flicker animation', function(){
|
|
4
4
|
|
|
5
|
-
expectFlicker(
|
|
5
|
+
expectFlicker(spring, 'bounce');
|
|
6
6
|
|
|
7
7
|
});
|
|
8
8
|
|
|
@@ -14,8 +14,8 @@ test('bounce on touch and key press', function(){
|
|
|
14
14
|
return true;
|
|
15
15
|
});
|
|
16
16
|
|
|
17
|
-
expectCall(
|
|
17
|
+
expectCall(spring, 'flicker');
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
spring.touch();
|
|
20
20
|
|
|
21
21
|
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Configure your game settings
|
|
2
|
+
|
|
3
|
+
width: 400
|
|
4
|
+
height: 300
|
|
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,30 @@
|
|
|
1
|
+
re.c('ai')
|
|
2
|
+
.requires('paddle update point')
|
|
3
|
+
.defines({
|
|
4
|
+
|
|
5
|
+
update:function(){
|
|
6
|
+
|
|
7
|
+
var ball = re('ball')[0];
|
|
8
|
+
|
|
9
|
+
if(this.distance(ball.posX, this.posY) > 150) return;
|
|
10
|
+
|
|
11
|
+
if(ball.posY + ball.hsizeY > this.posY + this.hsizeY){
|
|
12
|
+
this.posY += this.speed;
|
|
13
|
+
} else if(ball.posY - ball.hsizeY < this.posY - this.hsizeX){
|
|
14
|
+
this.posY -= this.speed;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
this.checkBounds();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
})
|
|
21
|
+
.init(function(){
|
|
22
|
+
|
|
23
|
+
this.on('update', this.update);
|
|
24
|
+
|
|
25
|
+
})
|
|
26
|
+
.dispose(function(){
|
|
27
|
+
|
|
28
|
+
this.off();
|
|
29
|
+
|
|
30
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
re.c('arena')
|
|
2
|
+
.defines({
|
|
3
|
+
|
|
4
|
+
startRound:function(){
|
|
5
|
+
this.ball = re.e('ball');
|
|
6
|
+
this.ball.reset();
|
|
7
|
+
},
|
|
8
|
+
|
|
9
|
+
stopRound:function(){
|
|
10
|
+
//reset players
|
|
11
|
+
if(this.ball) this.ball.dispose();
|
|
12
|
+
return this;
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
restartRound:function(){
|
|
16
|
+
this.stopRound();
|
|
17
|
+
this.startRound();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
})
|
|
21
|
+
.init(function(){
|
|
22
|
+
|
|
23
|
+
//player
|
|
24
|
+
re.e('player').alignRight(-10);
|
|
25
|
+
|
|
26
|
+
//ai or player 2
|
|
27
|
+
this.paddle2 = re.e('paddle ai');
|
|
28
|
+
|
|
29
|
+
})
|
|
30
|
+
.dispose(function(){
|
|
31
|
+
re('paddle').dispose();
|
|
32
|
+
this.stopRound();
|
|
33
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
re.c('hitmap')
|
|
2
|
+
.defines({
|
|
3
|
+
|
|
4
|
+
//things to note:
|
|
5
|
+
//paddle and ball are centered to make calculations easier
|
|
6
|
+
checkHit:function(obj){
|
|
7
|
+
var res = {
|
|
8
|
+
posX:obj.posX,
|
|
9
|
+
posY:obj.posY
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
//check collisions against top and bottom
|
|
13
|
+
if(obj.posY - obj.hsizeY < 0){
|
|
14
|
+
res.hitY = 1;
|
|
15
|
+
res.posY = obj.hsizeY;
|
|
16
|
+
} else if(obj.posY + obj.hsizeY > re.sys.sizeY){
|
|
17
|
+
res.hitY = 1;
|
|
18
|
+
res.posY = re.sys.sizeY - obj.hsizeY;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//check hits against right and left
|
|
22
|
+
if(obj.posX - obj.hsizeX < 0){
|
|
23
|
+
res.hitX = 1;
|
|
24
|
+
this.trigger('score:left');
|
|
25
|
+
} else if(obj.posX + obj.hsizeX > re.sys.sizeX){
|
|
26
|
+
res.hitX = 1;
|
|
27
|
+
this.trigger('score:right');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//check hits on paddles
|
|
31
|
+
re('paddle').each(function(){
|
|
32
|
+
|
|
33
|
+
if(this.hit(obj)){
|
|
34
|
+
res.hitX = 1;
|
|
35
|
+
|
|
36
|
+
var push = obj.hsizeX + this.hsizeX + 1;
|
|
37
|
+
|
|
38
|
+
if(this.posX > obj.posX){
|
|
39
|
+
push *= -1;
|
|
40
|
+
}
|
|
41
|
+
res.posX = this.posX + push;
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
//if everythings ok, move forward
|
|
48
|
+
if(!res.hitX) res.posX += obj.velX;
|
|
49
|
+
if(!res.hitY) res.posY += obj.velY;
|
|
50
|
+
|
|
51
|
+
return res;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
re.c('player')
|
|
2
|
+
.requires('update paddle')
|
|
3
|
+
.defines({
|
|
4
|
+
|
|
5
|
+
upKey:'w',
|
|
6
|
+
downKey:'s',
|
|
7
|
+
|
|
8
|
+
update:function(){
|
|
9
|
+
|
|
10
|
+
if(re.pressed(this.upKey)){
|
|
11
|
+
this.posY -= this.speed;
|
|
12
|
+
} else if(re.pressed(this.downKey)){
|
|
13
|
+
this.posY += this.speed;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
this.checkBounds();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
})
|
|
20
|
+
.init(function(){
|
|
21
|
+
|
|
22
|
+
this.on('update', this.update);
|
|
23
|
+
|
|
24
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
re.c('ball')
|
|
2
|
+
.requires('rect align force limit')
|
|
3
|
+
.defines({
|
|
4
|
+
color:'#fff',
|
|
5
|
+
sizeX:6,
|
|
6
|
+
sizeY:6,
|
|
7
|
+
|
|
8
|
+
hsizeX:3,
|
|
9
|
+
hsizeY:3,
|
|
10
|
+
|
|
11
|
+
regX:3,
|
|
12
|
+
regY:3,
|
|
13
|
+
|
|
14
|
+
resX:1.1,
|
|
15
|
+
resY:1.1,
|
|
16
|
+
|
|
17
|
+
friX:1,
|
|
18
|
+
friY:1,
|
|
19
|
+
|
|
20
|
+
initVel:4,
|
|
21
|
+
|
|
22
|
+
reset:function(){
|
|
23
|
+
this.alignHor();
|
|
24
|
+
this.alignVer();
|
|
25
|
+
this.velX = re.random(this.initVel * 0.5, this.initVel) * re.random([-1, 1]);
|
|
26
|
+
this.velY = re.random(this.initVel * 0.5, this.initVel) * re.random([-1, 1]);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
re.c('counter')
|
|
2
|
+
.requires('text align')
|
|
3
|
+
.defines({
|
|
4
|
+
|
|
5
|
+
count:-1,
|
|
6
|
+
maxCount:5,
|
|
7
|
+
|
|
8
|
+
up:function(){
|
|
9
|
+
this.count++;
|
|
10
|
+
|
|
11
|
+
this.text(this.count);
|
|
12
|
+
|
|
13
|
+
if(this.count >= this.maxCount){
|
|
14
|
+
this.trigger('max', this.name);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
})
|
|
19
|
+
.init(function(){
|
|
20
|
+
//setup text
|
|
21
|
+
this.up();
|
|
22
|
+
})
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
re.c('paddle')
|
|
2
|
+
.requires('rect align limit hit')
|
|
3
|
+
.defines({
|
|
4
|
+
color:'#fff',
|
|
5
|
+
sizeX:6,
|
|
6
|
+
sizeY:30,
|
|
7
|
+
|
|
8
|
+
hsizeX:3,
|
|
9
|
+
hsizeY:15,
|
|
10
|
+
|
|
11
|
+
regX:3,
|
|
12
|
+
regY:15,
|
|
13
|
+
|
|
14
|
+
alignVer:0,
|
|
15
|
+
alignLeft:10,
|
|
16
|
+
speed:10,
|
|
17
|
+
|
|
18
|
+
checkBounds:function(){
|
|
19
|
+
this.limit('posY', this.hsizeY, re.sys.sizeY - this.hsizeY);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
re.scene('game')
|
|
2
|
+
.enter(function(twoPlayer){
|
|
3
|
+
|
|
4
|
+
re.hitmap = re.e('hitmap');
|
|
5
|
+
|
|
6
|
+
//setup counters
|
|
7
|
+
|
|
8
|
+
//counter for player 1
|
|
9
|
+
var p1 = re.e('counter')
|
|
10
|
+
.alignHor(40)
|
|
11
|
+
.on('max', function(){
|
|
12
|
+
var message = 'You win!';
|
|
13
|
+
if(twoPlayer) message = 'Player 1 wins!';
|
|
14
|
+
|
|
15
|
+
re.scene('over').enter(message);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
//counter for player 2
|
|
19
|
+
var p2 = re.e('counter')
|
|
20
|
+
.alignHor(-60)
|
|
21
|
+
.on('max', function(){
|
|
22
|
+
var message = 'You lose!';
|
|
23
|
+
|
|
24
|
+
if(twoPlayer) message = 'Player 2 wins!';
|
|
25
|
+
|
|
26
|
+
re.scene('over').enter(message);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
//setup arena playing field
|
|
30
|
+
var arena = re.e((twoPlayer)?'twoarena':'arena');
|
|
31
|
+
|
|
32
|
+
//setup hitmap
|
|
33
|
+
re.hitmap
|
|
34
|
+
.on('score:left', function(){
|
|
35
|
+
arena.restartRound();
|
|
36
|
+
p1.up();
|
|
37
|
+
})
|
|
38
|
+
.on('score:right', function(){
|
|
39
|
+
arena.restartRound();
|
|
40
|
+
p2.up();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
//exit game
|
|
44
|
+
re.e('keyboard')
|
|
45
|
+
.on('keyup:q', function(){
|
|
46
|
+
re.scene('home').enter();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
//start game
|
|
50
|
+
arena.startRound();
|
|
51
|
+
|
|
52
|
+
})
|
|
53
|
+
.exit(function(){
|
|
54
|
+
|
|
55
|
+
re('arena').dispose();
|
|
56
|
+
re('counter').dispose();
|
|
57
|
+
|
|
58
|
+
re.hitmap.dispose();
|
|
59
|
+
delete re.hitmap;
|
|
60
|
+
|
|
61
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
re.scene('home')
|
|
2
|
+
.enter(function(){
|
|
3
|
+
|
|
4
|
+
//default text color to white
|
|
5
|
+
re.c('text')
|
|
6
|
+
.defines('textColor', '#fff')
|
|
7
|
+
.requires('align');
|
|
8
|
+
|
|
9
|
+
//prevent default for all keys used in game
|
|
10
|
+
re.preventDefault('left right up down');
|
|
11
|
+
|
|
12
|
+
re.e('text')
|
|
13
|
+
.attr({
|
|
14
|
+
font:'30px sans-serif',
|
|
15
|
+
text:'Pong',
|
|
16
|
+
alignHor:0,
|
|
17
|
+
alignVer:-100
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
re.e('text keyboard')
|
|
21
|
+
.attr({
|
|
22
|
+
text:'Press z to start!',
|
|
23
|
+
alignHor:0,
|
|
24
|
+
alignVer:0
|
|
25
|
+
})
|
|
26
|
+
.on('keyup:z', function(){
|
|
27
|
+
|
|
28
|
+
re.scene('game').enter(false);
|
|
29
|
+
})
|
|
30
|
+
.on('keyup:x', function(){
|
|
31
|
+
re.scene('game').enter(true);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
re.e('text')
|
|
35
|
+
.attr({
|
|
36
|
+
text:'Press x for two player',
|
|
37
|
+
alignHor:0,
|
|
38
|
+
alignVer:25
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
//credits
|
|
42
|
+
re.e('text')
|
|
43
|
+
.attr({
|
|
44
|
+
text:'http://www.entityjs.com',
|
|
45
|
+
alignBottom:-5,
|
|
46
|
+
alignLeft:5
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
})
|
|
50
|
+
.exit(function(){
|
|
51
|
+
|
|
52
|
+
//remove all draw objects
|
|
53
|
+
re('draw').dispose();
|
|
54
|
+
|
|
55
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
re.scene('over')
|
|
2
|
+
.enter(function(message){
|
|
3
|
+
|
|
4
|
+
re.e('text')
|
|
5
|
+
.attr({
|
|
6
|
+
font:'30px sans-serif',
|
|
7
|
+
text:message,
|
|
8
|
+
alignVer:-60,
|
|
9
|
+
alignHor:0
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
re.e('text keyboard')
|
|
13
|
+
.attr({
|
|
14
|
+
text:'Press Z to continue',
|
|
15
|
+
alignVer:-20,
|
|
16
|
+
alignHor:0
|
|
17
|
+
})
|
|
18
|
+
.on('keyup:z', function(){
|
|
19
|
+
|
|
20
|
+
re.scene('home').enter();
|
|
21
|
+
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
})
|
|
25
|
+
.exit(function(){
|
|
26
|
+
|
|
27
|
+
re('text').dispose();
|
|
28
|
+
|
|
29
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module('controls/ai', {
|
|
2
|
+
setup:function(){
|
|
3
|
+
ai = f('ai');
|
|
4
|
+
ball = f('ball');
|
|
5
|
+
},
|
|
6
|
+
teardown:function(){
|
|
7
|
+
ai.dispose();
|
|
8
|
+
ball.dispose();
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('move towards ball', function(){
|
|
13
|
+
|
|
14
|
+
ball.posX = 50;
|
|
15
|
+
ball.posY = ai.posY + 40;
|
|
16
|
+
|
|
17
|
+
expectValueUp(ai, 'posY');
|
|
18
|
+
|
|
19
|
+
ai.update();
|
|
20
|
+
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('move towards ball', function(){
|
|
24
|
+
|
|
25
|
+
ball.posX = 50;
|
|
26
|
+
ball.posY = 10;
|
|
27
|
+
|
|
28
|
+
ai.posY = 40;
|
|
29
|
+
|
|
30
|
+
expectValueDown(ai, 'posY');
|
|
31
|
+
|
|
32
|
+
ai.update();
|
|
33
|
+
|
|
34
|
+
});
|