entityjs 0.3.2 → 0.4.0
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/.gitignore +1 -1
- data/lib/entityjs/config.rb +4 -4
- data/lib/entityjs/dirc.rb +2 -2
- data/lib/entityjs/page.rb +7 -1
- data/lib/entityjs/version.rb +1 -1
- data/public/qunit/qunit.entity.js +27 -12
- data/spec/javascripts/src/core/comp_spec.js +11 -0
- data/spec/javascripts/src/core/entity_spec.js +88 -5
- data/spec/javascripts/src/core/query_spec.js +196 -15
- data/spec/javascripts/src/cycle/drawlist_spec.js +36 -0
- data/spec/javascripts/src/cycle/tween_spec.js +1 -1
- data/spec/javascripts/src/cycle/wait_spec.js +31 -0
- data/spec/javascripts/src/{cycle → display}/draw_spec.js +25 -9
- data/spec/javascripts/src/display/sprite_spec.js +18 -0
- data/spec/javascripts/src/display/text_spec.js +8 -0
- data/spec/javascripts/src/input/mouse_spec.js +24 -36
- data/spec/javascripts/src/math/bisect_spec.js +4 -4
- data/spec/javascripts/src/math/distance_spec.js +11 -0
- data/spec/javascripts/src/math/iso_spec.js +131 -0
- data/spec/javascripts/src/math/point_spec.js +3 -3
- data/spec/javascripts/src/{util → math}/random_spec.js +0 -0
- data/spec/javascripts/src/math/range_spec.js +9 -0
- data/spec/javascripts/src/math/tile_spec.js +22 -7
- data/spec/javascripts/src/pattern/automap_spec.js +2 -2
- data/spec/javascripts/src/pattern/flicker_spec.js +34 -22
- data/spec/javascripts/src/pattern/pathfind_spec.js +55 -0
- data/src/core/comp.js +16 -16
- data/src/core/entity.js +52 -51
- data/src/core/load.js +5 -5
- data/src/core/query.js +214 -74
- data/src/core/system.js +16 -6
- data/src/cycle/drawlist.js +79 -0
- data/src/cycle/tween.js +7 -20
- data/src/cycle/wait.js +10 -19
- data/src/{cycle → display}/draw.js +24 -34
- data/src/display/image.js +1 -1
- data/src/display/screen.js +3 -3
- data/src/display/sprite.js +3 -3
- data/src/display/text.js +3 -1
- data/src/input/mouse.js +35 -12
- data/src/math/bisect.js +11 -10
- data/src/math/distance.js +7 -0
- data/src/math/iso.js +147 -0
- data/src/math/point.js +1 -5
- data/src/math/random.js +21 -0
- data/src/math/range.js +14 -0
- data/src/math/tile.js +40 -27
- data/src/pattern/automap.js +12 -11
- data/src/pattern/flicker.js +87 -135
- data/src/pattern/pathfind.js +168 -0
- data/src/pattern/timestep.js +4 -1
- data/src/util/polyfill.js +1 -1
- data/templates/isometric/assets/images/isotiles.png +0 -0
- data/templates/isometric/config.yml +22 -0
- data/templates/isometric/readme.txt +79 -0
- data/templates/isometric/scripts/displays/cursor.js +34 -0
- data/templates/isometric/scripts/displays/isoimage.js +32 -0
- data/templates/isometric/scripts/init.js +7 -0
- data/templates/isometric/scripts/levels/level.js +55 -0
- data/templates/isometric/scripts/levels/level1.js +11 -0
- data/templates/isometric/scripts/scenes/home.js +10 -0
- data/templates/isometric/scripts/scenes/load.js +11 -0
- data/templates/isometric/tests/scenes/load_test.js +15 -0
- metadata +42 -21
- data/src/net/socket.js +0 -52
- data/src/util/random.js +0 -24
@@ -0,0 +1,79 @@
|
|
1
|
+
/*
|
2
|
+
The drawlist is an array of draw entities. Which can all be drawn at once using the .draw() method.
|
3
|
+
|
4
|
+
The draw component contains one drawlist for basic drawing. For cases when multiple drawlists is needed,
|
5
|
+
such as for large depth sorts, its more efficient to depth sort on the wanted draw objects rather than all
|
6
|
+
existing draw entities.
|
7
|
+
|
8
|
+
For example:
|
9
|
+
|
10
|
+
In a case of an isometric game, certain tiles should appear behind or in
|
11
|
+
|
12
|
+
*/
|
13
|
+
re.drawlist = function(name){
|
14
|
+
var d = re.c('drawlist'), name = name || '';
|
15
|
+
|
16
|
+
//name default to '' and returns default drawlist
|
17
|
+
|
18
|
+
if(!d._lists[name]){
|
19
|
+
//add new list
|
20
|
+
re.e('drawlist:'+name);
|
21
|
+
}
|
22
|
+
|
23
|
+
return d._lists[name];
|
24
|
+
};
|
25
|
+
|
26
|
+
re.c('drawlist')
|
27
|
+
.statics({
|
28
|
+
_lists:{}
|
29
|
+
})
|
30
|
+
.defines({
|
31
|
+
|
32
|
+
add:function(e){
|
33
|
+
if(e.drawlist){
|
34
|
+
e.drawlist.remove(e);
|
35
|
+
}
|
36
|
+
|
37
|
+
e.drawlist = this;
|
38
|
+
this.list.last(e);
|
39
|
+
return this;
|
40
|
+
},
|
41
|
+
|
42
|
+
remove:function(e){
|
43
|
+
if(e.drawlist){
|
44
|
+
this.list.erase(e);
|
45
|
+
e.drawlist = null;
|
46
|
+
}
|
47
|
+
return this;
|
48
|
+
},
|
49
|
+
|
50
|
+
drawlist:function(c){
|
51
|
+
var lis = this.list;
|
52
|
+
|
53
|
+
for(var i=0, b; i<lis.length; i++){
|
54
|
+
b = lis[i];
|
55
|
+
b.visible() && b.render(c);
|
56
|
+
}
|
57
|
+
|
58
|
+
},
|
59
|
+
|
60
|
+
sort:function(){
|
61
|
+
|
62
|
+
this.list.sort(function(a, b){
|
63
|
+
if(a.depth && b.depth){
|
64
|
+
return a.depth() - b.depth();
|
65
|
+
}
|
66
|
+
return 0;
|
67
|
+
});
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
})
|
72
|
+
.init(function(c, name){
|
73
|
+
c._lists[name] = this;
|
74
|
+
this.listName = name;
|
75
|
+
this.list = re();
|
76
|
+
})
|
77
|
+
.dispose(function(c){
|
78
|
+
delete c._lists[this.listName];
|
79
|
+
});
|
data/src/cycle/tween.js
CHANGED
@@ -47,15 +47,9 @@ re.c('tween')
|
|
47
47
|
|
48
48
|
this.tweening = false;
|
49
49
|
|
50
|
-
this.
|
51
|
-
|
52
|
-
//remove from queue
|
53
|
-
var next = this.tween_queue.shift();
|
54
|
-
|
55
|
-
if(next){
|
56
|
-
this.tween.apply(this, next);
|
57
|
-
}
|
50
|
+
this.off('update', this.tween_update);
|
58
51
|
|
52
|
+
this.trigger('tween:finish');
|
59
53
|
}
|
60
54
|
|
61
55
|
}
|
@@ -73,17 +67,13 @@ re.c('tween')
|
|
73
67
|
.defines({
|
74
68
|
|
75
69
|
tween:function(time, props){
|
76
|
-
if(this.tweening){
|
77
|
-
this.tween_queue.push(arguments);
|
78
|
-
return;
|
79
|
-
}
|
80
70
|
|
81
71
|
//accepts ms or seconds
|
82
|
-
if(time >=
|
72
|
+
if(time >= 100){
|
83
73
|
time /= 1000;
|
84
74
|
}
|
85
75
|
|
86
|
-
var maxTime = (time || 1) /
|
76
|
+
var maxTime = (time || 1) / re.sys.second;
|
87
77
|
this.tween_time = 0;
|
88
78
|
//steps are substracted until it reaches zero
|
89
79
|
|
@@ -104,18 +94,15 @@ re.c('tween')
|
|
104
94
|
//tween maximum time
|
105
95
|
this.tween_t = maxTime;
|
106
96
|
|
97
|
+
if(!this.tweening){
|
98
|
+
this.on('update', this.tween_update);
|
99
|
+
}
|
107
100
|
|
108
101
|
this.tweening = true;
|
109
102
|
|
110
103
|
return this.trigger('tween:start', starts);
|
111
104
|
}
|
112
105
|
|
113
|
-
})
|
114
|
-
.init(function(){
|
115
|
-
|
116
|
-
this.on('update', this.tween_update);
|
117
|
-
this.tween_queue = [];
|
118
|
-
|
119
106
|
});
|
120
107
|
|
121
108
|
re.tween = function(obj, time, props){
|
data/src/cycle/wait.js
CHANGED
@@ -1,23 +1,14 @@
|
|
1
|
-
/*
|
2
|
-
The wait component delays function calls.
|
3
|
-
*/
|
4
1
|
re.c('wait')
|
5
|
-
.requires('update')
|
6
2
|
.defines({
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
this.callback.apply(this, Array.prototype.slice.call(arguments, 2));
|
16
|
-
return false;
|
17
|
-
}
|
18
|
-
});
|
19
|
-
|
3
|
+
|
4
|
+
wait:function(method, time){
|
5
|
+
time = time || 1000;
|
6
|
+
|
7
|
+
//convert seconds to milliseconds
|
8
|
+
if(time < 100) time *= 1000;
|
9
|
+
|
10
|
+
setTimeout(method, time);
|
20
11
|
return this;
|
21
|
-
|
22
|
-
|
12
|
+
}
|
13
|
+
|
23
14
|
});
|
@@ -1,28 +1,10 @@
|
|
1
1
|
re.c('draw')
|
2
|
-
.statics({
|
3
|
-
l:[],
|
4
|
-
|
5
|
-
draw:function(c){
|
6
|
-
var lis = this.l;
|
7
|
-
|
8
|
-
for(var i=0, b; i<lis.length; i++){
|
9
|
-
b = lis[i];
|
10
|
-
b.drawable && b.visible() && b.draw_render(c);
|
11
|
-
}
|
12
|
-
|
13
|
-
}
|
14
|
-
|
15
|
-
})
|
16
2
|
.interfaces('draw')
|
17
|
-
.init(function(
|
18
|
-
|
19
|
-
c.l.push(this);
|
20
|
-
|
3
|
+
.init(function(){
|
4
|
+
re.drawlist().add(this);
|
21
5
|
})
|
22
6
|
.dispose(function(c){
|
23
|
-
|
24
|
-
c.l.splice(c.l.indexOf(this), 1);
|
25
|
-
|
7
|
+
this.drawlist.remove(this);
|
26
8
|
})
|
27
9
|
.defaults({
|
28
10
|
screenable:true,
|
@@ -45,6 +27,11 @@ re.c('draw')
|
|
45
27
|
})
|
46
28
|
.defines({
|
47
29
|
|
30
|
+
depth:function(){
|
31
|
+
return this.posY;
|
32
|
+
},
|
33
|
+
|
34
|
+
/* NOT WORKING
|
48
35
|
cache:function(){
|
49
36
|
if(!this.image) return this;
|
50
37
|
|
@@ -65,9 +52,9 @@ re.c('draw')
|
|
65
52
|
clearCache:function(){
|
66
53
|
this.canvasCache = null;
|
67
54
|
},
|
68
|
-
|
55
|
+
*/
|
69
56
|
drawFirst:function(){
|
70
|
-
|
57
|
+
var l = this.drawlist.list;
|
71
58
|
|
72
59
|
l.splice(l.indexOf(this), 1);
|
73
60
|
|
@@ -76,7 +63,7 @@ re.c('draw')
|
|
76
63
|
},
|
77
64
|
|
78
65
|
drawLast:function(){
|
79
|
-
var l =
|
66
|
+
var l = this.drawlist.list;
|
80
67
|
|
81
68
|
l.splice(l.indexOf(this), 1);
|
82
69
|
|
@@ -85,7 +72,7 @@ re.c('draw')
|
|
85
72
|
},
|
86
73
|
|
87
74
|
drawAfter:function(en){
|
88
|
-
var l =
|
75
|
+
var l = this.drawlist.list;
|
89
76
|
var him = l.indexOf(en);
|
90
77
|
var me = l.indexOf(this);
|
91
78
|
|
@@ -101,7 +88,7 @@ re.c('draw')
|
|
101
88
|
|
102
89
|
drawBefore:function(en){
|
103
90
|
|
104
|
-
var l =
|
91
|
+
var l = this.drawlist.list;
|
105
92
|
var him = l.indexOf(en);
|
106
93
|
var me = l.indexOf(this);
|
107
94
|
|
@@ -131,25 +118,28 @@ re.c('draw')
|
|
131
118
|
return this.posY - re.screen.posY;
|
132
119
|
},
|
133
120
|
|
121
|
+
/*
|
122
|
+
Renders the entity to the canvas. Goes through the transformations, scaling, alpha etc...
|
123
|
+
*/
|
124
|
+
render:function(c){
|
125
|
+
|
126
|
+
this.draw_before(c);
|
127
|
+
this.draw(c);
|
128
|
+
this.draw_after(c);
|
129
|
+
},
|
130
|
+
|
134
131
|
/*
|
135
132
|
Returns true or false wether the object is visible on screen.
|
136
133
|
*/
|
137
134
|
visible:function(){
|
138
135
|
|
139
|
-
return re.screen.hit(this.posX - this.regX, this.posY - this.regY, this.sizeX, this.sizeY);
|
136
|
+
return this.drawable && re.screen.hit(this.posX - this.regX, this.posY - this.regY, this.sizeX, this.sizeY);
|
140
137
|
|
141
138
|
}
|
142
139
|
|
143
140
|
})
|
144
141
|
.namespaces({
|
145
142
|
|
146
|
-
render:function(c){
|
147
|
-
|
148
|
-
this.draw_before(c);
|
149
|
-
this.draw(c);
|
150
|
-
this.draw_after(c);
|
151
|
-
},
|
152
|
-
|
153
143
|
before:function(c){
|
154
144
|
|
155
145
|
c.save();
|
data/src/display/image.js
CHANGED
data/src/display/screen.js
CHANGED
data/src/display/sprite.js
CHANGED
@@ -5,13 +5,13 @@ The sprite object definess a drawable image for an entity.
|
|
5
5
|
var sprite = re.e('sprite player.png');
|
6
6
|
|
7
7
|
//move to frame 3
|
8
|
-
sprite.
|
8
|
+
sprite.frame(3)
|
9
9
|
|
10
10
|
//get current frame
|
11
|
-
sprite.
|
11
|
+
sprite.frame()
|
12
12
|
|
13
13
|
//manually move to frame
|
14
|
-
sprite.attr({
|
14
|
+
sprite.attr({frameX:0, frameY:1});
|
15
15
|
|
16
16
|
//add animation
|
17
17
|
sprite.comp('flicker')
|
data/src/display/text.js
CHANGED
data/src/input/mouse.js
CHANGED
@@ -6,9 +6,12 @@ re.e('mouse')
|
|
6
6
|
.on('mousedown:middle', function(m){
|
7
7
|
//m.x - x position
|
8
8
|
//m.y - y position
|
9
|
-
//m.
|
10
|
-
//m.
|
9
|
+
//m.screenX - screen x position
|
10
|
+
//m.screenY - screen y position
|
11
11
|
})
|
12
|
+
|
13
|
+
FUTURE: rename triggers to the standard format
|
14
|
+
mousemove -> mouse:move
|
12
15
|
*/
|
13
16
|
re.c('mouse')
|
14
17
|
.statics({
|
@@ -50,11 +53,22 @@ re.c('mouse')
|
|
50
53
|
|
51
54
|
event:function(e, extra){
|
52
55
|
|
56
|
+
var canvas = re.sys.canvas;
|
53
57
|
//calculate mouse coordinate
|
54
|
-
var x =
|
55
|
-
var y =
|
58
|
+
var x = canvas.width / canvas.offsetWidth;
|
59
|
+
var y = canvas.height / canvas.offsetHeight;
|
60
|
+
|
61
|
+
//calculate offset
|
62
|
+
if(e.offsetX != null){ //chrome, opera
|
63
|
+
x *= e.offsetX;
|
64
|
+
y *= e.offsetY;
|
65
|
+
} else { //firefox
|
66
|
+
x *= e.layerX - canvas.offsetLeft;
|
67
|
+
y *= e.layerY - canvas.offsetTop;
|
68
|
+
}
|
69
|
+
|
56
70
|
|
57
|
-
var
|
71
|
+
var listeners = re.c('mouse').l;
|
58
72
|
|
59
73
|
/*
|
60
74
|
if(re.preventDefault && re.preventDefault.d[key]){
|
@@ -63,16 +77,21 @@ re.c('mouse')
|
|
63
77
|
*/
|
64
78
|
|
65
79
|
var c, t, obj;
|
66
|
-
for(var i=0; i<
|
67
|
-
t =
|
68
|
-
|
69
|
-
|
70
|
-
|
80
|
+
for(var i=0; i<listeners.length; i++){
|
81
|
+
t = listeners[i];
|
82
|
+
if(t.screenable){
|
83
|
+
x = re.screen.toScreenX(x);
|
84
|
+
y = re.screen.toScreenY(y);
|
85
|
+
}
|
86
|
+
|
87
|
+
//offset mouse coordinates
|
88
|
+
var tx = x + t.offX;
|
89
|
+
var ty = y + t.offY;
|
71
90
|
|
72
|
-
t.trigger(e.type,
|
91
|
+
t.trigger(e.type, tx, ty, e);
|
73
92
|
|
74
93
|
if(extra){
|
75
|
-
t.trigger(e.type+':'+extra,
|
94
|
+
t.trigger(e.type+':'+extra, tx, ty, e);
|
76
95
|
}
|
77
96
|
}
|
78
97
|
|
@@ -89,6 +108,10 @@ re.c('mouse')
|
|
89
108
|
}
|
90
109
|
|
91
110
|
})
|
111
|
+
.defaults({
|
112
|
+
offX:0,
|
113
|
+
offY:0
|
114
|
+
})
|
92
115
|
.init(function(c){
|
93
116
|
//add to listener array
|
94
117
|
c.l.push(this);
|
data/src/math/bisect.js
CHANGED
@@ -18,22 +18,22 @@ Note: width is called the bisect and the bi is the transformed x,y positions.
|
|
18
18
|
re.bisect = re.c('bisect')
|
19
19
|
.statics({
|
20
20
|
|
21
|
-
|
21
|
+
toX:function(bi, width, size){
|
22
22
|
|
23
|
-
return this.
|
23
|
+
return this.toTileX(bi, width, size) * size;
|
24
24
|
},
|
25
25
|
|
26
|
-
|
26
|
+
toY:function(bi, width, size){
|
27
27
|
|
28
|
-
return this.
|
28
|
+
return this.toTileY(bi, width, size) * size;
|
29
29
|
},
|
30
30
|
|
31
|
-
|
31
|
+
toTileX:function(bi, width, size){
|
32
32
|
|
33
33
|
return bi % (width / size) | 0;
|
34
34
|
},
|
35
35
|
|
36
|
-
|
36
|
+
toTileY:function(bi, width, size){
|
37
37
|
return (bi * size) / (width - 0.1) | 0;
|
38
38
|
},
|
39
39
|
|
@@ -51,21 +51,22 @@ re.bisect = re.c('bisect')
|
|
51
51
|
|
52
52
|
biToX:function(bi){
|
53
53
|
|
54
|
-
return re.bisect.
|
54
|
+
return re.bisect.toX(bi, this.bisect, this.sizeX);
|
55
55
|
},
|
56
56
|
|
57
57
|
biToY:function(bi){
|
58
58
|
|
59
|
-
return re.bisect.
|
59
|
+
return re.bisect.toY(bi, this.bisect, this.sizeX);
|
60
60
|
},
|
61
61
|
|
62
62
|
biToTileX:function(bi){
|
63
63
|
|
64
|
-
return re.bisect.
|
64
|
+
return re.bisect.toTileX(bi, this.bisect, this.sizeX);
|
65
65
|
},
|
66
66
|
|
67
67
|
biToTileY:function(bi){
|
68
|
-
|
68
|
+
//sizeY doesn't matter when dealing with bisects
|
69
|
+
return re.bisect.toTileY(bi, this.bisect, this.sizeX);
|
69
70
|
},
|
70
71
|
|
71
72
|
tileToBi:function(xt, yt){
|