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/entityjs/cycle/draw.js
DELETED
@@ -1,185 +0,0 @@
|
|
1
|
-
re.c('draw')
|
2
|
-
.global({
|
3
|
-
listeners:[],
|
4
|
-
|
5
|
-
draw:function(s){
|
6
|
-
var l = this.listeners;
|
7
|
-
|
8
|
-
for(var k=0, le = l.length, b; k < le; ++k){
|
9
|
-
b = l[k];
|
10
|
-
|
11
|
-
if(b && b.sys == s && b.drawing && b.isVisible()){
|
12
|
-
/*if(!b.canvasCache){
|
13
|
-
b.draw_render(c);
|
14
|
-
} else {
|
15
|
-
b.signal('draw', c);
|
16
|
-
}*/
|
17
|
-
b.draw_render(s.context);
|
18
|
-
|
19
|
-
}
|
20
|
-
}
|
21
|
-
|
22
|
-
}
|
23
|
-
|
24
|
-
})
|
25
|
-
.implement('draw')
|
26
|
-
.init(function(c){
|
27
|
-
|
28
|
-
c.listeners.push(this);
|
29
|
-
|
30
|
-
//set default screen
|
31
|
-
this.screen = re.screen;
|
32
|
-
|
33
|
-
})
|
34
|
-
.dispose(function(c){
|
35
|
-
|
36
|
-
c.listeners.splice(c.listeners.indexOf(this), 1);
|
37
|
-
|
38
|
-
})
|
39
|
-
.inherit({
|
40
|
-
|
41
|
-
sys:re.sys,
|
42
|
-
drawing:true,
|
43
|
-
rotation:0,
|
44
|
-
alpha:1,
|
45
|
-
|
46
|
-
scaleX:1,
|
47
|
-
scaleY:1,
|
48
|
-
|
49
|
-
posX:0,
|
50
|
-
posY:0,
|
51
|
-
|
52
|
-
sizeX:1,
|
53
|
-
sizeY:1,
|
54
|
-
|
55
|
-
regX:0,
|
56
|
-
regY:0
|
57
|
-
|
58
|
-
})
|
59
|
-
.extend({
|
60
|
-
|
61
|
-
cache:function(){
|
62
|
-
if(!this.image) return this;
|
63
|
-
|
64
|
-
this.clearCache();
|
65
|
-
|
66
|
-
var c = re.$new('canvas');
|
67
|
-
var s = Math.max(this.image.width, this.image.height);
|
68
|
-
c.width = s;
|
69
|
-
c.height = s;
|
70
|
-
|
71
|
-
this.draw_render(c.getContext(re.sys.contextType));
|
72
|
-
|
73
|
-
this.canvasCache = c;
|
74
|
-
|
75
|
-
return this;
|
76
|
-
},
|
77
|
-
|
78
|
-
clearCache:function(){
|
79
|
-
this.canvasCache = null;
|
80
|
-
},
|
81
|
-
|
82
|
-
drawFirst:function(){
|
83
|
-
var l = re.c('draw').listeners;
|
84
|
-
|
85
|
-
l.splice(l.indexOf(this), 1);
|
86
|
-
|
87
|
-
l.unshift(this);
|
88
|
-
return this;
|
89
|
-
},
|
90
|
-
|
91
|
-
drawLast:function(){
|
92
|
-
var l = re.c('draw').listeners;
|
93
|
-
|
94
|
-
l.splice(l.indexOf(this), 1);
|
95
|
-
|
96
|
-
l.push(this);
|
97
|
-
return this;
|
98
|
-
},
|
99
|
-
|
100
|
-
drawAfter:function(en){
|
101
|
-
var l = re.c('draw').listeners;
|
102
|
-
var him = l.indexOf(en);
|
103
|
-
var me = l.indexOf(this);
|
104
|
-
|
105
|
-
if(him > me){
|
106
|
-
//swap
|
107
|
-
var t = l[him];
|
108
|
-
l[him] = l[me];
|
109
|
-
l[me] = t;
|
110
|
-
}
|
111
|
-
|
112
|
-
return this;
|
113
|
-
},
|
114
|
-
|
115
|
-
drawBefore:function(en){
|
116
|
-
|
117
|
-
var l = re.c('draw').listeners;
|
118
|
-
var him = l.indexOf(en);
|
119
|
-
var me = l.indexOf(this);
|
120
|
-
|
121
|
-
if(him < me){
|
122
|
-
//swap
|
123
|
-
var t = l[him];
|
124
|
-
l[him] = l[me];
|
125
|
-
l[me] = t;
|
126
|
-
}
|
127
|
-
|
128
|
-
return this;
|
129
|
-
},
|
130
|
-
|
131
|
-
getScreenX:function(){
|
132
|
-
var x = this.posX;
|
133
|
-
if(this.screen) x -= this.screen.posX;
|
134
|
-
return x;
|
135
|
-
},
|
136
|
-
|
137
|
-
getScreenY:function(){
|
138
|
-
var y = this.posY;
|
139
|
-
if(this.screen) y -= this.screen.posY;
|
140
|
-
return y;
|
141
|
-
},
|
142
|
-
|
143
|
-
/*
|
144
|
-
Returns true or false wether the object is visible on screen.
|
145
|
-
*/
|
146
|
-
isVisible:function(){
|
147
|
-
|
148
|
-
return (!this.screen || this.screen.touches(this.posX - this.regX, this.posY - this.regY, this.sizeX, this.sizeY));
|
149
|
-
|
150
|
-
}
|
151
|
-
|
152
|
-
})
|
153
|
-
.namespace({
|
154
|
-
|
155
|
-
render:function(c){
|
156
|
-
if(!c) c = this.sys.context;
|
157
|
-
|
158
|
-
this.draw_before(c);
|
159
|
-
this.draw(c);
|
160
|
-
this.draw_after(c);
|
161
|
-
},
|
162
|
-
|
163
|
-
before:function(c){
|
164
|
-
|
165
|
-
c.save();
|
166
|
-
|
167
|
-
if(this.alpha != 1)
|
168
|
-
c.globalAlpha = this.alpha;
|
169
|
-
|
170
|
-
c.translate(this.getScreenX(), this.getScreenY());
|
171
|
-
|
172
|
-
if(this.rotation != 0)
|
173
|
-
c.rotate(this.rotation * Math.PI / 180);
|
174
|
-
|
175
|
-
|
176
|
-
if(this.scaleX != 1 || this.scaleY != 1)
|
177
|
-
c.scale(this.scaleX, this.scaleY);
|
178
|
-
|
179
|
-
},
|
180
|
-
|
181
|
-
after:function(c){
|
182
|
-
c.restore();
|
183
|
-
}
|
184
|
-
|
185
|
-
});
|
@@ -1,27 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
The ticker component calculates time between steps for animation or special effects.
|
3
|
-
*/
|
4
|
-
re.c('ticker')
|
5
|
-
.inherit({
|
6
|
-
time:0,
|
7
|
-
maxTick:0.05
|
8
|
-
})
|
9
|
-
.init(function(){
|
10
|
-
this.lastTime = Date.now();
|
11
|
-
})
|
12
|
-
.extend({
|
13
|
-
|
14
|
-
tick:function(){
|
15
|
-
var wall = Date.now();
|
16
|
-
var delta = (wall - this.lastTime) / 1000;
|
17
|
-
|
18
|
-
this.lastTime = wall;
|
19
|
-
|
20
|
-
var timeDelta = Math.min(delta, this.maxTick);
|
21
|
-
|
22
|
-
this.time += timeDelta;
|
23
|
-
|
24
|
-
return timeDelta;
|
25
|
-
}
|
26
|
-
|
27
|
-
});
|
@@ -1,53 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
The anchor component contains helper methods for positioning entities relative to system size.
|
3
|
-
*/
|
4
|
-
re.c('anchor')
|
5
|
-
.extend({
|
6
|
-
|
7
|
-
centerX:function(o){
|
8
|
-
o = o || 0;
|
9
|
-
this.posX = Math.floor(re.sys.sizeX * 0.5 - this.sizeX * 0.5 + o);
|
10
|
-
|
11
|
-
return this;
|
12
|
-
},
|
13
|
-
|
14
|
-
centerY:function(o){
|
15
|
-
o = o || 0;
|
16
|
-
this.posY = Math.floor(re.sys.sizeY * 0.5 - this.sizeY * 0.5 + o);
|
17
|
-
return this;
|
18
|
-
},
|
19
|
-
|
20
|
-
right:function(x){
|
21
|
-
x = x || 0;
|
22
|
-
this.posX = Math.floor(re.sys.sizeX - this.sizeX + x);
|
23
|
-
return this;
|
24
|
-
},
|
25
|
-
|
26
|
-
left:function(x){
|
27
|
-
x = x || 0;
|
28
|
-
this.posX = Math.floor(x);
|
29
|
-
return this;
|
30
|
-
},
|
31
|
-
|
32
|
-
top:function(y){
|
33
|
-
y = y || 0;
|
34
|
-
this.posY = Math.floor(y);
|
35
|
-
return this;
|
36
|
-
},
|
37
|
-
|
38
|
-
bottom:function(y){
|
39
|
-
y = y || 0;
|
40
|
-
this.posY = Math.floor(re.sys.sizeY - this.sizeY + y);
|
41
|
-
return this;
|
42
|
-
}
|
43
|
-
|
44
|
-
})
|
45
|
-
.inherit({
|
46
|
-
|
47
|
-
sizeX:0,
|
48
|
-
sizeY:0,
|
49
|
-
|
50
|
-
posX:0,
|
51
|
-
posY:0
|
52
|
-
|
53
|
-
});
|
@@ -1,93 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
The bitfont component writes text on the screen using a sprite image.
|
3
|
-
This is a faster approach than using the text component for now.
|
4
|
-
Plus you don't have to worry about the user not supporting the
|
5
|
-
wanted font.
|
6
|
-
|
7
|
-
*/
|
8
|
-
|
9
|
-
re.c('bitfont')
|
10
|
-
.require('draw')
|
11
|
-
.inherit({
|
12
|
-
|
13
|
-
text:'',
|
14
|
-
//default width if charwidths not extendd
|
15
|
-
charOffset:32
|
16
|
-
|
17
|
-
})
|
18
|
-
.extend({
|
19
|
-
|
20
|
-
isVisible:function(){
|
21
|
-
return this.text.length != 0 && this.bitmap && this.parent('draw', 'isVisible');
|
22
|
-
},
|
23
|
-
|
24
|
-
draw:function(c){
|
25
|
-
|
26
|
-
var slot = 0, charWidth, code, charPos;
|
27
|
-
|
28
|
-
for(var i=0, l = this.text.length; i<l; ++i){
|
29
|
-
|
30
|
-
//get char code
|
31
|
-
code = this.text.charCodeAt(i) - this.charOffset;
|
32
|
-
|
33
|
-
//find width of character
|
34
|
-
charWidth = this.charWidths[code];
|
35
|
-
|
36
|
-
//find source character position
|
37
|
-
if(!this.charCache[code]){
|
38
|
-
charPos = 0;
|
39
|
-
for(var p=0; p<code; ++p){
|
40
|
-
charPos += this.charWidths[p]+1;
|
41
|
-
}
|
42
|
-
this.charCache[code] = charPos;
|
43
|
-
}
|
44
|
-
|
45
|
-
c.drawImage(this.bitmap, this.charCache[code], 0, charWidth, this.bitmap.height, -this.regX + slot, -this.regY, charWidth, this.bitmap.height);
|
46
|
-
|
47
|
-
//append to next character slot
|
48
|
-
slot += charWidth;
|
49
|
-
|
50
|
-
}
|
51
|
-
|
52
|
-
this.sizeX = slot;
|
53
|
-
this.sizeY = this.bitmap.height;
|
54
|
-
|
55
|
-
|
56
|
-
},
|
57
|
-
|
58
|
-
updateSize:function(){
|
59
|
-
|
60
|
-
var t = 0;
|
61
|
-
//TODO size is slightly off
|
62
|
-
for(var p=0; p<this.text.length; p++){
|
63
|
-
t += this.charWidths[p];
|
64
|
-
}
|
65
|
-
|
66
|
-
this.sizeX = t;
|
67
|
-
|
68
|
-
if(this.bitmap){
|
69
|
-
this.sizeY = this.bitmap.height;
|
70
|
-
} else {
|
71
|
-
this.sizeY = 0;
|
72
|
-
}
|
73
|
-
return this;
|
74
|
-
},
|
75
|
-
|
76
|
-
setText:function(text){
|
77
|
-
|
78
|
-
this.text = text;
|
79
|
-
this.updateSize();
|
80
|
-
|
81
|
-
return this;
|
82
|
-
}
|
83
|
-
|
84
|
-
})
|
85
|
-
.init(function(){
|
86
|
-
|
87
|
-
if(!this.charCache){
|
88
|
-
this.charCache = {};
|
89
|
-
}
|
90
|
-
|
91
|
-
this.updateSize();
|
92
|
-
|
93
|
-
});
|
@@ -1,37 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
The bitmap component draws an image on screen.
|
3
|
-
|
4
|
-
|
5
|
-
FUTURE - add bitdata component for image manipulation.
|
6
|
-
*/
|
7
|
-
re.c('bitmap')
|
8
|
-
.require('draw')
|
9
|
-
.extend({
|
10
|
-
|
11
|
-
setBitmap:function(b){
|
12
|
-
this.bitmap = b;
|
13
|
-
if(b){
|
14
|
-
this.sizeX = b.width;
|
15
|
-
this.sizeY = b.height;
|
16
|
-
}
|
17
|
-
return this;
|
18
|
-
},
|
19
|
-
|
20
|
-
isVisible:function(){
|
21
|
-
return this.bitmap && this.parent('draw', 'isVisible');
|
22
|
-
},
|
23
|
-
|
24
|
-
draw:function(c){
|
25
|
-
|
26
|
-
c.drawImage(this.bitmap, -this.regX, -this.regY, this.sizeX, this.sizeY);
|
27
|
-
return this;
|
28
|
-
}
|
29
|
-
|
30
|
-
})
|
31
|
-
.init(function(){
|
32
|
-
|
33
|
-
if(this.bitmap){
|
34
|
-
this.setBitmap(this.bitmap);
|
35
|
-
}
|
36
|
-
|
37
|
-
});
|
@@ -1,30 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
The circle component draws a rectangle on screen.
|
3
|
-
*/
|
4
|
-
re.c('circle')
|
5
|
-
.require('draw')
|
6
|
-
.inherit({
|
7
|
-
color:'#82d5f4'
|
8
|
-
})
|
9
|
-
.extend({
|
10
|
-
|
11
|
-
draw:function(c){
|
12
|
-
|
13
|
-
c.fillStyle = this.color;
|
14
|
-
|
15
|
-
c.beginPath();
|
16
|
-
|
17
|
-
c.arc(-this.regX, -this.regY, this.sizeX, 0, Math.PI*2, true);
|
18
|
-
|
19
|
-
c.closePath();
|
20
|
-
|
21
|
-
c.fill();
|
22
|
-
|
23
|
-
},
|
24
|
-
|
25
|
-
setRadius:function(r){
|
26
|
-
this.sizeX = this.sizeY = r;
|
27
|
-
return this;
|
28
|
-
}
|
29
|
-
|
30
|
-
});
|
@@ -1,41 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
The font component displays font on screen using the canvas font api.
|
3
|
-
|
4
|
-
//create font
|
5
|
-
re.e('font')
|
6
|
-
.extend({
|
7
|
-
text:'Texting Message',
|
8
|
-
textColor:'#ff0000'
|
9
|
-
});
|
10
|
-
|
11
|
-
TODO implement size
|
12
|
-
|
13
|
-
*/
|
14
|
-
re.c('font')
|
15
|
-
.require('draw')
|
16
|
-
.inherit({
|
17
|
-
font:"14px sans-serif",
|
18
|
-
textColor:'#000000',
|
19
|
-
textAlign:'',
|
20
|
-
text:''
|
21
|
-
})
|
22
|
-
.extend({
|
23
|
-
|
24
|
-
isVisible:function(){
|
25
|
-
return this.text.length != 0;
|
26
|
-
},
|
27
|
-
|
28
|
-
setText:function(t){
|
29
|
-
this.text = t;
|
30
|
-
return this;
|
31
|
-
},
|
32
|
-
|
33
|
-
draw:function(c){
|
34
|
-
|
35
|
-
c.font = this.font;
|
36
|
-
c.fillStyle = this.textColor;
|
37
|
-
c.fillText(this.text, -this.regX, -this.regY);
|
38
|
-
|
39
|
-
}
|
40
|
-
|
41
|
-
});
|
@@ -1,46 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
The screen component is used for scrolling or shaking all visible objects.
|
3
|
-
It simply offsets pos values upon rendering.
|
4
|
-
|
5
|
-
This is useful for setting up a tile-based game.
|
6
|
-
*/
|
7
|
-
re.c('screen')
|
8
|
-
.require('hittest')
|
9
|
-
.extend({
|
10
|
-
|
11
|
-
setPos:function(x, y){
|
12
|
-
if(arguments.length == 1){
|
13
|
-
y = x.posY;
|
14
|
-
x = x.posX;
|
15
|
-
}
|
16
|
-
|
17
|
-
this.posX = x - this.regX;
|
18
|
-
this.posY = y - this.regY;
|
19
|
-
|
20
|
-
return this;
|
21
|
-
},
|
22
|
-
|
23
|
-
toScreenX:function(x){
|
24
|
-
return x + this.posX + this.offX;
|
25
|
-
},
|
26
|
-
|
27
|
-
toScreenY:function(y){
|
28
|
-
return y + this.posY + this.offY;
|
29
|
-
}
|
30
|
-
|
31
|
-
})
|
32
|
-
.inherit({
|
33
|
-
|
34
|
-
posX:0,
|
35
|
-
posY:0,
|
36
|
-
|
37
|
-
regX:0,
|
38
|
-
regY:0,
|
39
|
-
|
40
|
-
sizeX:0,
|
41
|
-
sizeY:0,
|
42
|
-
|
43
|
-
offX:0,
|
44
|
-
offY:0
|
45
|
-
|
46
|
-
});
|
@@ -1,37 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
The sprite object extends a drawable image for an entity.
|
3
|
-
*/
|
4
|
-
|
5
|
-
re.c('sprite')
|
6
|
-
.require('bitmap bisect')
|
7
|
-
.inherit({
|
8
|
-
|
9
|
-
frameX:0,
|
10
|
-
frameY:0
|
11
|
-
|
12
|
-
})
|
13
|
-
.extend({
|
14
|
-
|
15
|
-
setFrameId:function(id){
|
16
|
-
this.frameX = this.biToXt(id);
|
17
|
-
this.frameY = this.biToYt(id);
|
18
|
-
|
19
|
-
return this;
|
20
|
-
},
|
21
|
-
|
22
|
-
getFrameId:function(){
|
23
|
-
return this.toBi(this.frameX, this.frameY);
|
24
|
-
},
|
25
|
-
|
26
|
-
draw:function(c){
|
27
|
-
c.drawImage(this.bitmap, this.frameX * this.sizeX, this.frameY * this.sizeY, this.sizeX, this.sizeY, -this.regX, -this.regY, this.sizeX, this.sizeY);
|
28
|
-
|
29
|
-
return this;
|
30
|
-
},
|
31
|
-
|
32
|
-
//implement for flicker
|
33
|
-
flick:function(c){
|
34
|
-
this.setFrameId(c);
|
35
|
-
}
|
36
|
-
|
37
|
-
});
|
data/src/entityjs/input/mouse.js
DELETED
@@ -1,123 +0,0 @@
|
|
1
|
-
re.c('mouse')
|
2
|
-
.global({
|
3
|
-
listeners:[],
|
4
|
-
|
5
|
-
mouseAction:function(e){
|
6
|
-
var b;
|
7
|
-
|
8
|
-
//find which key
|
9
|
-
if(e.which == null){
|
10
|
-
//IE
|
11
|
-
if(e.button < 2){
|
12
|
-
b = 'left';
|
13
|
-
} else if(e.button == 4){
|
14
|
-
b = 'middle';
|
15
|
-
} else {
|
16
|
-
b = 'right';
|
17
|
-
}
|
18
|
-
} else {
|
19
|
-
if(e.which < 2){
|
20
|
-
b = 'left';
|
21
|
-
} else if(e.which == 2){
|
22
|
-
b = 'middle';
|
23
|
-
} else {
|
24
|
-
b = 'right';
|
25
|
-
}
|
26
|
-
}
|
27
|
-
|
28
|
-
b = 'mouse:'+b;
|
29
|
-
|
30
|
-
//register mouse action
|
31
|
-
if(re.c('pressed')._pressed){
|
32
|
-
re.c('pressed')._pressed[b] = (e.type == 'mousedown');
|
33
|
-
}
|
34
|
-
|
35
|
-
var c = false;
|
36
|
-
|
37
|
-
if(re.c('pressed').preventDefault){
|
38
|
-
if(re.c('pressed').preventDefault[b]){
|
39
|
-
if(e.preventDefault)
|
40
|
-
e.preventDefault();
|
41
|
-
else
|
42
|
-
e.returnValue = false;
|
43
|
-
|
44
|
-
c = true;
|
45
|
-
}
|
46
|
-
}
|
47
|
-
|
48
|
-
re.c('mouse').mouseEvent(e);
|
49
|
-
|
50
|
-
if(c) return false;
|
51
|
-
},
|
52
|
-
|
53
|
-
mouseEvent:function(e){
|
54
|
-
|
55
|
-
//calculate mouse coordinate
|
56
|
-
var x;
|
57
|
-
var y;
|
58
|
-
|
59
|
-
if(e.pageX || e.pageY){
|
60
|
-
x = e.pageX;
|
61
|
-
y = e.pageY;
|
62
|
-
} else {
|
63
|
-
x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
|
64
|
-
y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
|
65
|
-
}
|
66
|
-
|
67
|
-
//FUTURE fix, does not support multiple canvases
|
68
|
-
if(re.sys.canvas){
|
69
|
-
x -= re.sys.canvas.offsetLeft;
|
70
|
-
y -= re.sys.canvas.offsetTop;
|
71
|
-
}
|
72
|
-
|
73
|
-
//ignore if off canvas
|
74
|
-
if(x < 0 || y < 0 || y > re.sys.sizeY || x > re.sys.sizeX){
|
75
|
-
return;
|
76
|
-
}
|
77
|
-
|
78
|
-
var that = re.c('mouse');
|
79
|
-
|
80
|
-
//FUTURE automatically transform screen coordinates?
|
81
|
-
var c, t, sx, sy;
|
82
|
-
for(var i=0, l = that.listeners.length; i<l; i++){
|
83
|
-
t = that.listeners[i];
|
84
|
-
if(t.toScreen && t.screen){
|
85
|
-
sx = t.screen.toScreenX(x);
|
86
|
-
sy = t.screen.toScreenY(y);
|
87
|
-
} else {
|
88
|
-
sx = x;
|
89
|
-
sy = y;
|
90
|
-
}
|
91
|
-
t.signal(e.type, sx, sy, e);
|
92
|
-
}
|
93
|
-
|
94
|
-
},
|
95
|
-
|
96
|
-
active:false,
|
97
|
-
initListeners:function(){
|
98
|
-
if(!this.active){
|
99
|
-
this.active = true;
|
100
|
-
|
101
|
-
re.listener('mousedown', this.mouseAction, false);
|
102
|
-
re.listener('mouseup', this.mouseAction, false);
|
103
|
-
re.listener('mousemove', this.mouseEvent, false);
|
104
|
-
re.listener('click', this.mouseEvent, false);
|
105
|
-
re.listener('dblclick', this.mouseEvent, false);
|
106
|
-
re.listener('contextmenu', this.mouseEvent, false);
|
107
|
-
}
|
108
|
-
}
|
109
|
-
|
110
|
-
})
|
111
|
-
.inherit({
|
112
|
-
toScreen:false
|
113
|
-
})
|
114
|
-
.init(function(c){
|
115
|
-
//add to listener array
|
116
|
-
c.initListeners();
|
117
|
-
c.listeners.push(this);
|
118
|
-
})
|
119
|
-
.dispose(function(c){
|
120
|
-
//remove from listener array
|
121
|
-
|
122
|
-
c.listeners.splice(c.listeners.indexOf(this), 1);
|
123
|
-
});
|