entityjs 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -6
- data/.rspec +2 -0
- data/README.md +170 -49
- data/Rakefile +9 -0
- data/bin/entityjs +24 -14
- data/entityjs.gemspec +15 -9
- data/lib/entityjs/assets.rb +167 -0
- data/lib/entityjs/command.rb +52 -27
- data/lib/entityjs/commands/build.rb +128 -0
- data/lib/entityjs/commands/comp.rb +74 -0
- data/lib/entityjs/commands/font.rb +73 -0
- data/lib/entityjs/commands/new.rb +59 -0
- data/lib/entityjs/commands/server.rb +54 -0
- data/lib/entityjs/commands/templates.rb +28 -0
- data/lib/entityjs/commands/test.rb +69 -0
- data/lib/entityjs/config.rb +130 -0
- data/lib/entityjs/dirc.rb +184 -0
- data/lib/entityjs/parsers/parse_tmx.rb +41 -0
- data/lib/entityjs/parsers/parse_xml.rb +39 -0
- data/lib/entityjs/version.rb +1 -1
- data/lib/entityjs.rb +53 -0
- data/license.txt +1 -1
- data/public/play.html +122 -0
- data/public/qunit/qunit.css +226 -0
- data/public/qunit/qunit.entity.js +190 -0
- data/public/qunit/qunit.input.js +200 -0
- data/public/qunit/qunit.js +1598 -0
- data/public/qunit/qunit.mock.js +97 -0
- data/public/tests.html +45 -0
- data/spec/javascripts/helpers/accept.png +0 -0
- data/spec/javascripts/helpers/alligator.mp3 +0 -0
- data/spec/javascripts/helpers/alligator.ogg +0 -0
- data/spec/javascripts/helpers/canvas.js +15 -0
- data/spec/javascripts/helpers/entityunit.js +50 -0
- data/spec/javascripts/helpers/factories.js +11 -0
- data/spec/javascripts/helpers/jquery-1.7.1.min.js +4 -0
- data/spec/javascripts/src/core/comp_spec.js +145 -0
- data/spec/javascripts/src/core/entity_spec.js +324 -0
- data/spec/javascripts/src/core/load_spec.js +71 -0
- data/spec/javascripts/src/core/query_spec.js +157 -0
- data/spec/javascripts/src/core/re_spec.js +61 -0
- data/spec/javascripts/src/core/system_spec.js +41 -0
- data/spec/javascripts/src/cycle/draw_spec.js +106 -0
- data/spec/javascripts/src/cycle/tick_spec.js +20 -0
- data/spec/javascripts/src/cycle/update_spec.js +86 -0
- data/spec/javascripts/src/display/align_spec.js +43 -0
- data/spec/javascripts/src/display/circle_spec.js +26 -0
- data/spec/javascripts/src/display/group_spec.js +7 -0
- data/spec/javascripts/src/display/image_spec.js +32 -0
- data/spec/javascripts/src/display/imgtext_spec.js +32 -0
- data/spec/javascripts/src/display/rect_spec.js +13 -0
- data/spec/javascripts/src/display/screen_spec.js +47 -0
- data/spec/javascripts/src/display/sprite_spec.js +28 -0
- data/spec/javascripts/src/display/text_spec.js +30 -0
- data/spec/javascripts/src/input/keyboard_spec.js +67 -0
- data/spec/javascripts/src/input/mouse_spec.js +133 -0
- data/spec/javascripts/src/input/pressed_spec.js +31 -0
- data/spec/javascripts/src/math/bisect_spec.js +59 -0
- data/spec/javascripts/src/math/body_spec.js +30 -0
- data/spec/javascripts/src/math/drag_spec.js +38 -0
- data/spec/javascripts/src/math/force_spec.js +134 -0
- data/spec/javascripts/src/math/hit_spec.js +28 -0
- data/spec/javascripts/src/math/hitmap_spec.js +52 -0
- data/spec/javascripts/src/math/limit_spec.js +35 -0
- data/spec/javascripts/src/math/point_spec.js +57 -0
- data/spec/javascripts/src/math/tile_spec.js +78 -0
- data/spec/javascripts/src/media/sound_spec.js +40 -0
- data/spec/javascripts/src/pattern/automap_spec.js +93 -0
- data/spec/javascripts/src/pattern/flicker_spec.js +66 -0
- data/spec/javascripts/src/pattern/timestep_spec.js +23 -0
- data/spec/javascripts/src/save/storage_spec.js +37 -0
- data/spec/javascripts/src/util/log_spec.js +9 -0
- data/spec/javascripts/src/util/polyfill_spec.js +13 -0
- data/spec/javascripts/src/util/random_spec.js +33 -0
- data/spec/javascripts/src/util/scene_spec.js +52 -0
- data/spec/javascripts/src/util/sheet_spec.js +25 -0
- data/spec/javascripts/src/util/support_spec.js +17 -0
- data/spec/javascripts/support/jasmine.yml +76 -0
- data/spec/javascripts/support/jasmine_config.rb +32 -0
- data/spec/javascripts/support/jasmine_runner.rb +32 -0
- data/spec/lib/entityjs/assets_spec.rb +216 -0
- data/spec/lib/entityjs/command_spec.rb +53 -0
- data/spec/lib/entityjs/commands/build_spec.rb +69 -0
- data/spec/lib/entityjs/commands/comp_spec.rb +45 -0
- data/spec/lib/entityjs/commands/font_spec.rb +7 -0
- data/spec/lib/entityjs/commands/new_spec.rb +20 -0
- data/spec/lib/entityjs/commands/templates_spec.rb +9 -0
- data/spec/lib/entityjs/commands/test_spec.rb +31 -0
- data/spec/lib/entityjs/config_spec.rb +19 -0
- data/spec/lib/entityjs/dirc_spec.rb +83 -0
- data/spec/lib/entityjs/version_spec.rb +9 -0
- data/spec/spec_helper.rb +21 -3
- data/spec/support/factories.rb +19 -0
- data/spec/support/mygame.rb +11 -0
- data/src/core/comp.js +318 -0
- data/src/core/entity.js +549 -0
- data/src/core/load.js +242 -0
- data/src/core/query.js +354 -0
- data/src/core/re.js +74 -0
- data/src/core/system.js +121 -0
- data/src/cycle/draw.js +178 -0
- data/src/cycle/tick.js +25 -0
- data/src/{entityjs/cycle → cycle}/tween.js +60 -60
- data/src/{entityjs/cycle → cycle}/update.js +86 -85
- data/src/{entityjs/cycle → cycle}/wait.js +22 -21
- data/src/{entityjs/cycle → cycle}/worker.js +8 -8
- data/src/display/align.js +45 -0
- data/src/display/circle.js +33 -0
- data/src/{entityjs/display → display}/group.js +62 -62
- data/src/display/image.js +35 -0
- data/src/display/imgtext.js +102 -0
- data/src/{entityjs/display → display}/rect.js +18 -18
- data/src/display/screen.js +57 -0
- data/src/display/sprite.js +54 -0
- data/src/display/text.js +44 -0
- data/src/{entityjs/input → input}/keyboard.js +152 -150
- data/src/input/mouse.js +111 -0
- data/src/input/pressed.js +41 -0
- data/src/{entityjs/input → input}/touch.js +24 -28
- data/src/math/bisect.js +84 -0
- data/src/math/body.js +70 -0
- data/src/{entityjs/math → math}/drag.js +44 -38
- data/src/math/force.js +143 -0
- data/src/math/hit.js +32 -0
- data/src/math/hitmap.js +167 -0
- data/src/math/limit.js +37 -0
- data/src/math/point.js +40 -0
- data/src/math/tile.js +109 -0
- data/src/media/channel.js +93 -0
- data/src/{entityjs/media → media}/playlist.js +4 -4
- data/src/media/sound.js +114 -0
- data/src/{entityjs/net → net}/socket.js +51 -51
- data/src/pattern/automap.js +133 -0
- data/src/{entityjs/pattern → pattern}/flicker.js +206 -213
- data/src/pattern/timestep.js +31 -0
- data/src/{entityjs/save → save}/database.js +6 -6
- data/src/{entityjs/save → save}/storage.js +47 -56
- data/src/{entityjs/util → util}/log.js +17 -25
- data/src/{entityjs/util → util}/polyfill.js +24 -24
- data/src/util/random.js +20 -0
- data/src/util/scene.js +102 -0
- data/src/util/sheet.js +35 -0
- data/src/{entityjs/util → util}/support.js +109 -132
- data/{examples/keys → templates/arrow_keys/assets/images}/arrow.png +0 -0
- data/templates/arrow_keys/config.yml +22 -0
- data/templates/arrow_keys/readme.txt +9 -0
- data/templates/arrow_keys/scripts/display/arrow.js +69 -0
- data/templates/arrow_keys/scripts/init.js +10 -0
- data/templates/arrow_keys/scripts/input/controls.js +35 -0
- data/templates/arrow_keys/scripts/scenes/home.js +20 -0
- data/templates/arrow_keys/scripts/scenes/load.js +57 -0
- data/templates/arrow_keys/tests/display/arrow_test.js +29 -0
- data/templates/arrow_keys/tests/init_test.js +4 -0
- data/templates/arrow_keys/tests/input/controls_test.js +32 -0
- data/templates/arrow_keys/tests/scenes/home_test.js +0 -0
- data/templates/arrow_keys/tests/scenes/load_test.js +16 -0
- data/templates/blank/config.yml +22 -0
- data/templates/blank/readme.txt +79 -0
- data/templates/platform/assets/images/bit.png +0 -0
- data/templates/platform/assets/images/hero.png +0 -0
- data/templates/platform/assets/images/items.png +0 -0
- data/templates/platform/assets/images/tiles.png +0 -0
- data/templates/platform/assets/levels/level1.tmx +44 -0
- data/templates/platform/assets/sounds/coin.mp3 +0 -0
- data/templates/platform/assets/sounds/coin.ogg +0 -0
- data/templates/platform/config.yml +22 -0
- data/templates/platform/readme.txt +87 -0
- data/templates/platform/scripts/display/bit.js +12 -0
- data/templates/platform/scripts/display/hero.js +77 -0
- data/templates/platform/scripts/display/tile.js +2 -0
- data/templates/platform/scripts/display/tsprite.js +17 -0
- data/templates/platform/scripts/init.js +7 -0
- data/templates/platform/scripts/items/coin.js +27 -0
- data/templates/platform/scripts/items/item.js +41 -0
- data/templates/platform/scripts/items/spring.js +25 -0
- data/templates/platform/scripts/scenes/home.js +10 -0
- data/templates/platform/scripts/scenes/load.js +27 -0
- data/templates/platform/scripts/scenes/play.js +31 -0
- data/templates/platform/scripts/util/counter.js +34 -0
- data/templates/platform/scripts/util/level.js +84 -0
- data/templates/platform/tests/display/bit_test.js +7 -0
- data/templates/platform/tests/display/hero_test.js +73 -0
- data/templates/platform/tests/display/tile_test.js +7 -0
- data/templates/platform/tests/display/tsprite_test.js +8 -0
- data/templates/platform/tests/factories.js +30 -0
- data/templates/platform/tests/items/coin_test.js +28 -0
- data/templates/platform/tests/items/item_test.js +36 -0
- data/templates/platform/tests/items/spring_test.js +21 -0
- data/templates/platform/tests/scenes/home_test.js +9 -0
- data/templates/platform/tests/scenes/load_test.js +11 -0
- data/templates/platform/tests/scenes/play_test.js +15 -0
- data/templates/platform/tests/util/counter_test.js +9 -0
- data/templates/platform/tests/util/level_test.js +29 -0
- metadata +249 -97
- data/build/build_debug.bat +0 -1
- data/build/build_min.bat +0 -1
- data/build/config.php +0 -64
- data/build/debug.php +0 -48
- data/build/files.php +0 -74
- data/build/jsmin.php +0 -376
- data/build/min.php +0 -50
- data/changelog.txt +0 -53
- data/examples/keys/keys.html +0 -59
- data/examples/keys/keys.js +0 -148
- data/examples/mouse/mouse.html +0 -58
- data/examples/mouse/mouse.js +0 -60
- data/examples/scenes/home.png +0 -0
- data/examples/scenes/scenes.html +0 -55
- data/examples/scenes/scenes.js +0 -134
- data/examples/scenes/win.png +0 -0
- data/examples/sounds/sound1.mp3 +0 -0
- data/examples/sounds/sound1.ogg +0 -0
- data/examples/sounds/sounds.html +0 -56
- data/examples/sounds/sounds.js +0 -44
- data/examples/style/background.png +0 -0
- data/examples/style/sheet.css +0 -762
- data/examples/tiles/tiles.html +0 -56
- data/examples/tiles/tiles.js +0 -85
- data/examples/tiles/tiles.png +0 -0
- data/lib/blank/config.js +0 -4
- data/lib/blank/config.yml +0 -21
- data/lib/blank/home.js +0 -11
- data/lib/blank/init.js +0 -7
- data/lib/blank/load.js +0 -21
- data/lib/blank/play.html +0 -29
- data/lib/entity.debug.js +0 -52
- data/lib/entity.min.js +0 -184
- data/lib/entityjs/comp.rb +0 -11
- data/lib/entityjs/game.rb +0 -93
- data/lib/entityjs/min.rb +0 -11
- data/lib/entityjs/refresh.rb +0 -14
- data/spec/lib/entityjs/game_spec.rb +0 -11
- data/src/entityjs/core/component.js +0 -306
- data/src/entityjs/core/entity.js +0 -516
- data/src/entityjs/core/load.js +0 -224
- data/src/entityjs/core/query.js +0 -410
- data/src/entityjs/core/re.js +0 -70
- data/src/entityjs/core/system.js +0 -125
- data/src/entityjs/cycle/draw.js +0 -185
- data/src/entityjs/cycle/ticker.js +0 -27
- data/src/entityjs/display/anchor.js +0 -53
- data/src/entityjs/display/bitfont.js +0 -93
- data/src/entityjs/display/bitmap.js +0 -37
- data/src/entityjs/display/circle.js +0 -30
- data/src/entityjs/display/font.js +0 -41
- data/src/entityjs/display/screen.js +0 -46
- data/src/entityjs/display/sprite.js +0 -37
- data/src/entityjs/input/mouse.js +0 -123
- data/src/entityjs/input/pressed.js +0 -81
- data/src/entityjs/math/bind.js +0 -76
- data/src/entityjs/math/bisect.js +0 -69
- data/src/entityjs/math/body.js +0 -39
- data/src/entityjs/math/hitmap.js +0 -165
- data/src/entityjs/math/hittest.js +0 -26
- data/src/entityjs/math/physics.js +0 -142
- data/src/entityjs/math/point.js +0 -57
- data/src/entityjs/math/tile.js +0 -91
- data/src/entityjs/media/channel.js +0 -93
- data/src/entityjs/media/sound.js +0 -110
- data/src/entityjs/pattern/arraymap.js +0 -89
- data/src/entityjs/pattern/timestep.js +0 -34
- data/src/entityjs/util/random.js +0 -38
- data/src/entityjs/util/scene.js +0 -101
- data/src/entityjs/util/sheet.js +0 -51
data/src/util/random.js
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
/*
|
2
|
+
The random component implements two helper methods for calculating random numbers.
|
3
|
+
|
4
|
+
|
5
|
+
re.random() // 0 - 1
|
6
|
+
re.random(10) // 0 - 9
|
7
|
+
re.random(10, 30) // 10 - 30
|
8
|
+
|
9
|
+
*/
|
10
|
+
re.random = function(max, min){
|
11
|
+
var r = Math.random();
|
12
|
+
switch(arguments.length){
|
13
|
+
case 0:
|
14
|
+
return r;
|
15
|
+
case 1:
|
16
|
+
return r * max;
|
17
|
+
case 2:
|
18
|
+
return r * (max - min + 1) + min;
|
19
|
+
}
|
20
|
+
};
|
data/src/util/scene.js
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
|
2
|
+
/*
|
3
|
+
Goes to an other scene in the game. This calls the scene method with a possible object argument.
|
4
|
+
|
5
|
+
Scenes are a helpful way to organize stages of a game.
|
6
|
+
|
7
|
+
//create scene
|
8
|
+
re.scene('game')
|
9
|
+
.enter(function(data){
|
10
|
+
|
11
|
+
//remove all 2d elements
|
12
|
+
re('2d').dispose();
|
13
|
+
|
14
|
+
loadLevel(data.level);
|
15
|
+
|
16
|
+
});
|
17
|
+
|
18
|
+
//go to scene
|
19
|
+
re.scene('game').enter({tiles:[]} );
|
20
|
+
|
21
|
+
*warning- bad idea passing in functions as the first argument
|
22
|
+
|
23
|
+
//create manually
|
24
|
+
re.e('scene:game')
|
25
|
+
.enter(function(){
|
26
|
+
|
27
|
+
})
|
28
|
+
|
29
|
+
*/
|
30
|
+
re.scene = function(title){
|
31
|
+
var s = re.c('scene');
|
32
|
+
|
33
|
+
if(!re.is(title)){
|
34
|
+
return s._scenes[re.scene.current];
|
35
|
+
}
|
36
|
+
|
37
|
+
if(!s._scenes[title]){
|
38
|
+
//add scene
|
39
|
+
re.e('scene:'+title);
|
40
|
+
}
|
41
|
+
|
42
|
+
return s._scenes[title];
|
43
|
+
};
|
44
|
+
|
45
|
+
re.c('scene')
|
46
|
+
.statics({
|
47
|
+
|
48
|
+
_scenes:{}
|
49
|
+
|
50
|
+
})
|
51
|
+
.init(function(c, title){
|
52
|
+
|
53
|
+
c._scenes[title] = this;
|
54
|
+
this.sceneName = title;
|
55
|
+
|
56
|
+
})
|
57
|
+
.dispose(function(c){
|
58
|
+
|
59
|
+
delete c._scenes[this.sceneName];
|
60
|
+
|
61
|
+
})
|
62
|
+
.defines({
|
63
|
+
|
64
|
+
enter:function(title){
|
65
|
+
if(!re.is(title, 'function')){
|
66
|
+
|
67
|
+
if(re.scene.current)
|
68
|
+
re.scene().exit(title);
|
69
|
+
|
70
|
+
//set current scene
|
71
|
+
re.scene.current = this.sceneName
|
72
|
+
|
73
|
+
if(this.scene_enter)
|
74
|
+
this.scene_enter.apply(this, arguments);
|
75
|
+
return this;
|
76
|
+
} else {
|
77
|
+
//set new enter method
|
78
|
+
this.scene_enter = title;
|
79
|
+
}
|
80
|
+
|
81
|
+
return this;
|
82
|
+
},
|
83
|
+
|
84
|
+
exit:function(m){
|
85
|
+
if(!re.is(m, 'function')){
|
86
|
+
|
87
|
+
re.scene.current = '';
|
88
|
+
|
89
|
+
if(re.is(this.scene_exit, 'function')){
|
90
|
+
this.scene_exit.apply(this, arguments);
|
91
|
+
}
|
92
|
+
|
93
|
+
if(this.scene_exit)
|
94
|
+
this.scene_exit.apply(this, arguments);
|
95
|
+
} else {
|
96
|
+
this.scene_exit = m;
|
97
|
+
}
|
98
|
+
|
99
|
+
return this;
|
100
|
+
}
|
101
|
+
|
102
|
+
});
|
data/src/util/sheet.js
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
/*
|
2
|
+
The sheet component converts a each frame of a sprite sheet into their own components.
|
3
|
+
*/
|
4
|
+
re.sheet = function(map, components, sizeX, sizeY){
|
5
|
+
|
6
|
+
var frameWidth = sizeX || re.tile.sizeX;
|
7
|
+
var frameHeight = sizeY || re.tile.sizeY;
|
8
|
+
|
9
|
+
if(re.is(components,'array')){
|
10
|
+
components = components.join(' ');
|
11
|
+
}
|
12
|
+
|
13
|
+
//create new sprites for sheet
|
14
|
+
|
15
|
+
//save frame positions from map
|
16
|
+
var x;
|
17
|
+
var y;
|
18
|
+
var b = [];
|
19
|
+
for(var p in map){
|
20
|
+
x = map[p][0] || 0;
|
21
|
+
y = map[p][1] || 0;
|
22
|
+
b.push(p);
|
23
|
+
re.c(p)
|
24
|
+
.requires('sprite '+components)
|
25
|
+
.defines({
|
26
|
+
frameX:x,
|
27
|
+
frameY:y,
|
28
|
+
sizeX:frameWidth,
|
29
|
+
sizeY:frameHeight
|
30
|
+
});
|
31
|
+
|
32
|
+
}
|
33
|
+
|
34
|
+
return b;
|
35
|
+
};
|
@@ -1,132 +1,109 @@
|
|
1
|
-
/*
|
2
|
-
The support component contains information about supported
|
3
|
-
functionality of the browser.
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
//
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
}
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
.
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
}
|
111
|
-
}
|
112
|
-
|
113
|
-
}
|
114
|
-
|
115
|
-
} catch(e){}
|
116
|
-
|
117
|
-
//check local storage
|
118
|
-
try {
|
119
|
-
c.localstorage = !!localStorage.getItem;
|
120
|
-
} catch(e){
|
121
|
-
c.localstorage = false;
|
122
|
-
}
|
123
|
-
|
124
|
-
//check web worker
|
125
|
-
c.worker = !!window.Worker;
|
126
|
-
|
127
|
-
//check webgl
|
128
|
-
c.webgl = !!window.WebGLRenderingContext;
|
129
|
-
|
130
|
-
c.touch = 'ontouchstart' in window;
|
131
|
-
|
132
|
-
});
|
1
|
+
/*
|
2
|
+
The support component contains information about supported
|
3
|
+
functionality of the browser.
|
4
|
+
|
5
|
+
//returns true if canvas AND text is supported
|
6
|
+
if(re.support('canvas text')){
|
7
|
+
//supports
|
8
|
+
}
|
9
|
+
|
10
|
+
//checks all arguments and returns first thing thats supported
|
11
|
+
re.support('ogg', 'aac', 'mp3', 'wav');
|
12
|
+
|
13
|
+
//find first supported storage storage
|
14
|
+
re.support('database', 'localstorage');
|
15
|
+
|
16
|
+
this is helpful to find a supported codec or a storage component
|
17
|
+
|
18
|
+
or add to entity
|
19
|
+
|
20
|
+
re.e('support').support('canvas');
|
21
|
+
|
22
|
+
---- possible support checks
|
23
|
+
canvas
|
24
|
+
text
|
25
|
+
audio
|
26
|
+
ogg
|
27
|
+
mp3
|
28
|
+
wav
|
29
|
+
aac
|
30
|
+
localstorage
|
31
|
+
worker
|
32
|
+
webgl
|
33
|
+
|
34
|
+
*/
|
35
|
+
re.support = function(s){
|
36
|
+
if(arguments.length > 1){
|
37
|
+
//find first supported arg and return
|
38
|
+
|
39
|
+
var d;
|
40
|
+
for(var i=0; i<arguments.length; i++){
|
41
|
+
d = arguments[i];
|
42
|
+
if(re.support(d)){
|
43
|
+
return d;
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
return false;
|
48
|
+
}
|
49
|
+
|
50
|
+
//find if supported
|
51
|
+
var k = s.split(' ');
|
52
|
+
|
53
|
+
var stat = true;
|
54
|
+
|
55
|
+
//check multiple supports
|
56
|
+
for(var j in k){
|
57
|
+
stat = stat && !!re.support[k[j]];
|
58
|
+
}
|
59
|
+
|
60
|
+
return stat;
|
61
|
+
}
|
62
|
+
|
63
|
+
//add supports to component
|
64
|
+
var c = re.support;
|
65
|
+
|
66
|
+
//check canvas support
|
67
|
+
c.canvas = !!document.createElement('canvas').getContext;
|
68
|
+
|
69
|
+
//check for text support
|
70
|
+
c.text = !!(c.canvas && typeof document.createElement('canvas').getContext('2d').fillText == 'function');
|
71
|
+
|
72
|
+
//check audio support
|
73
|
+
var ele = document.createElement('audio');
|
74
|
+
|
75
|
+
try {
|
76
|
+
|
77
|
+
if(c.audio = !!ele.canPlayType){
|
78
|
+
|
79
|
+
c.ogg = ele.canPlayType('audio/ogg; codecs="vorbis"');
|
80
|
+
c.mp3 = ele.canPlayType('audio/mpeg;');
|
81
|
+
c.wav = ele.canPlayType('audio/wav; codecs="1"');
|
82
|
+
c.aac = ele.canPlayType('audio/x-m4a;') || ele.canPlayType('audio/aac;');
|
83
|
+
|
84
|
+
//switch unsupported codecs to false
|
85
|
+
for(var i in c){
|
86
|
+
if(c[i] == 'no' || c[i] == ''){
|
87
|
+
c[i] = false;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
} catch(e){}
|
94
|
+
|
95
|
+
//check local storage
|
96
|
+
try {
|
97
|
+
c.localstorage = !!localStorage.getItem;
|
98
|
+
} catch(e){
|
99
|
+
c.localstorage = false;
|
100
|
+
}
|
101
|
+
|
102
|
+
//check web worker
|
103
|
+
c.worker = !!window.Worker;
|
104
|
+
|
105
|
+
//check webgl
|
106
|
+
c.webgl = !!window.WebGLRenderingContext;
|
107
|
+
|
108
|
+
c.touch = 'ontouchstart' in window;
|
109
|
+
|
File without changes
|
@@ -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,9 @@
|
|
1
|
+
--------------- Arrow Keys ------------
|
2
|
+
|
3
|
+
# About
|
4
|
+
|
5
|
+
This is a simple example demostrating the usefulness of EntityJS.
|
6
|
+
It shows how to use sprites and keyboard controls to move around arrows
|
7
|
+
and remove them from screen.
|
8
|
+
|
9
|
+
For more information on the engine visit www.entityjs.com
|
@@ -0,0 +1,69 @@
|
|
1
|
+
/*
|
2
|
+
The arrow component is a simple sprite with key controls.
|
3
|
+
It listens to system updates and will move around based on WASD keys.
|
4
|
+
|
5
|
+
The image comes from arrow.png, you can view the element here, re.c('arrow.png').image.
|
6
|
+
|
7
|
+
The sprite component automatically finds the ._image on the entity and draws it to screen.
|
8
|
+
It will chop the image into frames based on the sizeX and sizeY values.
|
9
|
+
|
10
|
+
The original image is 80x80 and has 4 frames. So its frame sizes will be 40x40.
|
11
|
+
|
12
|
+
Switch between frames by using .frame(id), and get the current frame with .frame()
|
13
|
+
|
14
|
+
The posX and posY come from the sprite component and defines the position of the image on screen.
|
15
|
+
|
16
|
+
*/
|
17
|
+
re.c('arrow')
|
18
|
+
.requires('update sprite keyboard arrow.png')
|
19
|
+
.defines({
|
20
|
+
|
21
|
+
//speed of the arrow
|
22
|
+
speed:10,
|
23
|
+
//defines the sprite frame size
|
24
|
+
sizeX:40,
|
25
|
+
sizeY:40,
|
26
|
+
|
27
|
+
update:function(){
|
28
|
+
var s = this.speed;
|
29
|
+
|
30
|
+
//if w or up key is currently pressed..
|
31
|
+
if(re.pressed('w', 'up')){
|
32
|
+
//moves position y
|
33
|
+
this.posY -= s;
|
34
|
+
|
35
|
+
//change sprite frame
|
36
|
+
this.frame(0);
|
37
|
+
|
38
|
+
} else if(re.pressed('s', 'down')){
|
39
|
+
|
40
|
+
this.posY += s;
|
41
|
+
this.frame(2);
|
42
|
+
|
43
|
+
}
|
44
|
+
|
45
|
+
if(re.pressed('a', 'left')){
|
46
|
+
|
47
|
+
this.posX -= s;
|
48
|
+
this.frame(3);
|
49
|
+
|
50
|
+
} else if(re.pressed('d', 'right')){
|
51
|
+
|
52
|
+
this.posX += s;
|
53
|
+
this.frame(1);
|
54
|
+
|
55
|
+
}
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
})
|
60
|
+
.init(function(){
|
61
|
+
|
62
|
+
//move to the center of the screen
|
63
|
+
this.posX = re.sys.sizeX * 0.5;
|
64
|
+
this.posY = re.sys.sizeY * 0.5;
|
65
|
+
|
66
|
+
//add event listener
|
67
|
+
this.on('update', this.update);
|
68
|
+
|
69
|
+
});
|
@@ -0,0 +1,10 @@
|
|
1
|
+
//runs when the window is finished loading
|
2
|
+
re.ready(function(){
|
3
|
+
//Starts the system and listens for inputs
|
4
|
+
//re.canvas in automatically defined and can be changed in config.yml
|
5
|
+
re.sys.init(re.canvas).start();
|
6
|
+
|
7
|
+
//enter the next scene
|
8
|
+
re.scene('load').enter();
|
9
|
+
|
10
|
+
});
|
@@ -0,0 +1,35 @@
|
|
1
|
+
/*
|
2
|
+
The controls component listens for keyevents and creates new arrows
|
3
|
+
based on keys pressed.
|
4
|
+
*/
|
5
|
+
re.c('controls')
|
6
|
+
.requires('keyboard')
|
7
|
+
.defines({
|
8
|
+
|
9
|
+
addArrow:function(count){
|
10
|
+
count = count || 1;
|
11
|
+
//creates a new arrow
|
12
|
+
re.e('arrow', count);
|
13
|
+
},
|
14
|
+
|
15
|
+
removeArrow:function(){
|
16
|
+
//finds an entity with the arrow component and removes it.
|
17
|
+
re('arrow').random().dispose();
|
18
|
+
}
|
19
|
+
|
20
|
+
})
|
21
|
+
.init(function(){
|
22
|
+
//called on instantiation
|
23
|
+
|
24
|
+
//listen for key events
|
25
|
+
//these come from the keyboard component
|
26
|
+
this.on({
|
27
|
+
'keydown:space': function(){
|
28
|
+
this.addArrow();
|
29
|
+
},
|
30
|
+
'keyup:r': function(){
|
31
|
+
this.removeArrow();
|
32
|
+
}
|
33
|
+
});
|
34
|
+
|
35
|
+
});
|
@@ -0,0 +1,20 @@
|
|
1
|
+
/*
|
2
|
+
The home scene is the entry point of the game.
|
3
|
+
It creates a new controls entity and a starting arrow to play with.
|
4
|
+
*/
|
5
|
+
re.scene('home')
|
6
|
+
.enter(function(){
|
7
|
+
|
8
|
+
console.log('entering home scene. . .');
|
9
|
+
|
10
|
+
//add controls
|
11
|
+
re.controls = re.e('controls');
|
12
|
+
|
13
|
+
//add first arrow
|
14
|
+
re.controls.addArrow();
|
15
|
+
})
|
16
|
+
.exit(function(){
|
17
|
+
|
18
|
+
console.log('exiting home scene. . .');
|
19
|
+
|
20
|
+
})
|
@@ -0,0 +1,57 @@
|
|
1
|
+
/*
|
2
|
+
The load scene loads all images and sounds in the game.
|
3
|
+
|
4
|
+
The re.assets object contains two arrays:
|
5
|
+
|
6
|
+
re.assets.images
|
7
|
+
re.assets.sounds
|
8
|
+
|
9
|
+
re.assets is automatically created for you and will contains whatever images
|
10
|
+
you place in the /assets/images or /assets/sounds directory.
|
11
|
+
|
12
|
+
You can even create new directories and place json or xml inside.
|
13
|
+
|
14
|
+
/assets/levels/level1.json
|
15
|
+
|
16
|
+
The file contents will be turned into a component and can be used on entities.
|
17
|
+
|
18
|
+
If /assets/levels/level1.json contains this:
|
19
|
+
|
20
|
+
{"something":100}
|
21
|
+
|
22
|
+
It will do this in the background for you:
|
23
|
+
|
24
|
+
re.c('level1.json level')
|
25
|
+
.defines({
|
26
|
+
something:100
|
27
|
+
});
|
28
|
+
|
29
|
+
You can even look in the source code and see for yourself.
|
30
|
+
|
31
|
+
Of course this will all be included when you run 'entityjs build'
|
32
|
+
|
33
|
+
Currently only, json, xml and tmx are supported. Tmx is a special file type used by
|
34
|
+
the map maker tiled and it can be used to create levels. More info: http://www.mapeditor.org/
|
35
|
+
|
36
|
+
*/
|
37
|
+
re.scene('load')
|
38
|
+
.enter(function(){
|
39
|
+
|
40
|
+
re.load(re.assets)
|
41
|
+
.complete(function(){
|
42
|
+
console.log('finished loading...');
|
43
|
+
|
44
|
+
//move to home
|
45
|
+
re.scene('home').enter();
|
46
|
+
})
|
47
|
+
.error(function(e){
|
48
|
+
console.log('Error loading asset: '+e);
|
49
|
+
})
|
50
|
+
.progress(function(i){
|
51
|
+
console.log('Finished loading: '+i);
|
52
|
+
});
|
53
|
+
|
54
|
+
})
|
55
|
+
.exit(function(){
|
56
|
+
//exit load scene
|
57
|
+
})
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module('arrow');
|
2
|
+
|
3
|
+
var arrow = re.e('arrow');
|
4
|
+
|
5
|
+
//verify the arrow has the correct sizes
|
6
|
+
test('size', function(){
|
7
|
+
|
8
|
+
equal(arrow.sizeX, 40);
|
9
|
+
equal(arrow.sizeY, 40);
|
10
|
+
|
11
|
+
});
|
12
|
+
|
13
|
+
test('keys move arrow', function(){
|
14
|
+
|
15
|
+
//mock/stub methods in qunit/qunit.mock.js
|
16
|
+
//expects 4 calls to frame
|
17
|
+
expectCall(arrow, 'frame', 4);
|
18
|
+
|
19
|
+
//simulate keypress / mouse clicks with qunit/qunit.input.js
|
20
|
+
//dispatches a keydown on each key, calls the given method
|
21
|
+
//then dispatches keyup.
|
22
|
+
keypress(['w', 's', 'd', 'a'], function(){
|
23
|
+
arrow.update();
|
24
|
+
});
|
25
|
+
|
26
|
+
//by the end of the method e.frame() should have been called 4 times
|
27
|
+
//take a look at scripts/display/arrow.js @ update()
|
28
|
+
|
29
|
+
});
|