entityjs 0.4.0 → 0.4.1
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/entityjs.gemspec +1 -1
- data/lib/entityjs/version.rb +1 -1
- data/public/qunit/qunit.entity.js +0 -16
- data/spec/javascripts/src/core/entity_spec.js +15 -5
- data/spec/javascripts/src/display/animate_spec.js +13 -0
- data/spec/javascripts/src/pattern/flicker_spec.js +6 -11
- data/spec/support/mygame.rb +5 -0
- data/src/core/entity.js +12 -5
- data/src/display/align.js +8 -6
- data/src/display/animate.js +50 -0
- data/src/display/draw.js +2 -2
- data/src/display/image.js +1 -1
- data/src/display/imgtext.js +1 -1
- data/src/display/sprite.js +0 -5
- data/src/display/text.js +1 -1
- data/src/pattern/flicker.js +38 -38
- data/templates/animation/assets/images/hero.png +0 -0
- data/templates/animation/scripts/init.js +7 -0
- data/templates/animation/scripts/scenes/home.js +41 -0
- data/templates/animation/scripts/scenes/load.js +11 -0
- data/templates/animation/tests/init_test.js +4 -0
- data/templates/animation/tests/scenes/home_test.js +15 -0
- data/templates/animation/tests/scenes/load_test.js +18 -0
- data/templates/circle/scripts/scenes/home.js +0 -28
- data/templates/isometric/scripts/displays/cursor.js +3 -2
- data/templates/isometric/scripts/levels/level.js +6 -4
- data/templates/platform/scripts/displays/hero.js +11 -11
- data/templates/platform/scripts/items/coin.js +8 -3
- data/templates/platform/scripts/items/item.js +7 -4
- data/templates/platform/scripts/items/spring.js +5 -3
- data/templates/platform/tests/displays/hero_test.js +7 -6
- data/templates/platform/tests/factories.js +6 -1
- data/templates/platform/tests/items/coin_test.js +1 -1
- data/templates/platform/tests/items/spring_test.js +0 -6
- data/templates/pong/scripts/controls/hitmap.js +5 -5
- data/templates/pong/tests/controls/player_test.js +6 -1
- data/templates/tiltmaze/scripts/displays/ball.js +1 -1
- data/templates/tiltmaze/scripts/structs/level.js +3 -3
- data/templates/tiltmaze/tests/displays/ball_test.js +1 -1
- data/templates/tiltmaze/tests/factories.js +6 -0
- metadata +62 -18
data/entityjs.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.add_development_dependency "rspec"
|
25
25
|
s.add_development_dependency "jasmine"
|
26
26
|
|
27
|
-
s.add_dependency "sinatra"
|
27
|
+
s.add_dependency "sinatra", ">= 1.3.0"
|
28
28
|
s.add_dependency "coffee-script"
|
29
29
|
s.add_dependency 'uglifier'
|
30
30
|
s.add_dependency 'json'
|
data/lib/entityjs/version.rb
CHANGED
@@ -101,22 +101,6 @@ function pixelEqual(x, y, r, g, b, a, message){
|
|
101
101
|
QUnit.push(QUnit.equiv(actual, expected), actual, expected, message);
|
102
102
|
}
|
103
103
|
|
104
|
-
/*
|
105
|
-
Expects the given entity to have the given flicker present
|
106
|
-
|
107
|
-
var e = re.e();
|
108
|
-
|
109
|
-
expectFlicker(e, 'run'); //false
|
110
|
-
|
111
|
-
e.comps('flicker').addFlicker('run', 123, 21, [2]);
|
112
|
-
|
113
|
-
expectFlicker(e, 'run') //true
|
114
|
-
|
115
|
-
*/
|
116
|
-
function expectFlicker(ent, flick){
|
117
|
-
ok(ent.flicker_reels[flick] != null, "Expected entity to have flicker "+flick);
|
118
|
-
}
|
119
|
-
|
120
104
|
/*
|
121
105
|
Expects an entity or component to have a current event attached.
|
122
106
|
|
@@ -20,6 +20,16 @@ describe('entity', function(){
|
|
20
20
|
eq(re('dfggggg').length, 1)
|
21
21
|
})
|
22
22
|
|
23
|
+
it('should get', function(){
|
24
|
+
e.blah = 10;
|
25
|
+
e.bla = function(){
|
26
|
+
return 10;
|
27
|
+
};
|
28
|
+
|
29
|
+
eq(e.get('blah'), 10);
|
30
|
+
eq(e.get('bla'), 10);
|
31
|
+
});
|
32
|
+
|
23
33
|
it('comp', function(){
|
24
34
|
e.comp('qwdqwd wer')
|
25
35
|
|
@@ -175,14 +185,14 @@ describe('entity', function(){
|
|
175
185
|
is(re.e().clone())
|
176
186
|
})
|
177
187
|
|
178
|
-
it('
|
188
|
+
it('super', function(){
|
179
189
|
c.defines('d', function(v){return v; })
|
180
190
|
.defaults('y', function(v){return v;})
|
181
191
|
|
182
|
-
eq(e.
|
183
|
-
eq(e.
|
192
|
+
eq(e._super(c.name, 'd', 100), 100)
|
193
|
+
eq(e._super(c.name, 'y', 'bob'), 'bob')
|
184
194
|
e.comp(c.name)
|
185
|
-
ok(e.
|
195
|
+
ok(e._super('','has', c.name))
|
186
196
|
})
|
187
197
|
|
188
198
|
it('attr overwrite method', function(){
|
@@ -226,7 +236,7 @@ describe('entity', function(){
|
|
226
236
|
it('should throw error on undefined parent method', function(){
|
227
237
|
var called = false;
|
228
238
|
try {
|
229
|
-
e.
|
239
|
+
e._super('image', 'asdfsdf')
|
230
240
|
} catch(e){
|
231
241
|
called = true;
|
232
242
|
}
|
@@ -49,11 +49,6 @@ describe('flicker', function(){
|
|
49
49
|
//manually call update
|
50
50
|
|
51
51
|
for(var i=0; i<60 * time; i++){
|
52
|
-
if(i == 37){
|
53
|
-
eq(e.health, 5);
|
54
|
-
} else if(i==37+37){
|
55
|
-
eq(e.health, 10);
|
56
|
-
}
|
57
52
|
e.flicker_update(re.sys.stepSize);
|
58
53
|
}
|
59
54
|
|
@@ -67,13 +62,13 @@ describe('flicker', function(){
|
|
67
62
|
|
68
63
|
e.flicker(1, [5]);
|
69
64
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
eq(e.health, 5);
|
65
|
+
|
66
|
+
for(var i=0; i<3; i++){
|
67
|
+
e.flicker_update(e.stepSize * 0.5);
|
68
|
+
|
75
69
|
}
|
76
|
-
|
70
|
+
eq(e.health, 5);
|
71
|
+
|
77
72
|
})
|
78
73
|
|
79
74
|
});
|
data/spec/support/mygame.rb
CHANGED
data/src/core/entity.js
CHANGED
@@ -97,7 +97,7 @@
|
|
97
97
|
com = pieces[0];
|
98
98
|
}
|
99
99
|
|
100
|
-
if(this.has(com)){
|
100
|
+
if(com && this.has(com)){
|
101
101
|
|
102
102
|
var c = re._c[com];
|
103
103
|
//only remove if it exists
|
@@ -233,10 +233,10 @@
|
|
233
233
|
Use '' to call super of entity
|
234
234
|
|
235
235
|
re.e('draw')
|
236
|
-
.
|
236
|
+
._super('draw', 'screenX')()
|
237
237
|
|
238
238
|
*/
|
239
|
-
p.
|
239
|
+
p._super = function(comp, method){
|
240
240
|
|
241
241
|
var a = Array.prototype.slice.call(arguments, 2);
|
242
242
|
|
@@ -437,7 +437,9 @@
|
|
437
437
|
return this;
|
438
438
|
};
|
439
439
|
|
440
|
-
|
440
|
+
//setters / getters
|
441
|
+
|
442
|
+
p.attr = p.set = function(obj, value){
|
441
443
|
|
442
444
|
if(re.is(obj, 'object')){
|
443
445
|
|
@@ -461,7 +463,12 @@
|
|
461
463
|
|
462
464
|
return this;
|
463
465
|
};
|
464
|
-
|
466
|
+
|
467
|
+
p.get = function(v){
|
468
|
+
var l = this[v];
|
469
|
+
return (re.is(l,'function'))? l() : l;
|
470
|
+
};
|
471
|
+
|
465
472
|
p.def = function(obj, value){
|
466
473
|
|
467
474
|
if(re.is(obj , 'object')){
|
data/src/display/align.js
CHANGED
@@ -15,38 +15,40 @@ re.c('align')
|
|
15
15
|
|
16
16
|
alignHor:function(o){
|
17
17
|
o = o || 0;
|
18
|
-
this.posX
|
18
|
+
this.set('posX', re.sys.sizeX * 0.5 - (this.get('sizeX') - this.get('regX'))*0.5 + o | 0);
|
19
19
|
|
20
20
|
return this;
|
21
21
|
},
|
22
22
|
|
23
23
|
alignVer:function(o){
|
24
24
|
o = o || 0;
|
25
|
-
this.posY
|
25
|
+
this.set('posY', re.sys.sizeY * 0.5 - (this.get('sizeY') - this.get('regY'))*0.5 + o | 0);
|
26
26
|
return this;
|
27
27
|
},
|
28
28
|
|
29
29
|
alignRight:function(x){
|
30
30
|
x = x || 0;
|
31
|
-
this.posX
|
31
|
+
this.set('posX', re.sys.sizeX - (this.get('sizeX') - this.get('regX')) + x | 0);
|
32
32
|
return this;
|
33
33
|
},
|
34
34
|
|
35
35
|
alignLeft:function(x){
|
36
36
|
x = x || 0;
|
37
|
-
|
37
|
+
var s = this.get('sizeX');
|
38
|
+
this.set('posX', x + s - (s - this.get('regX')) | 0);
|
38
39
|
return this;
|
39
40
|
},
|
40
41
|
|
41
42
|
alignTop:function(y){
|
42
43
|
y = y || 0;
|
43
|
-
|
44
|
+
var s = this.get('sizeY');
|
45
|
+
this.set('posY', y + s - (s - this.get('regY')) | 0);
|
44
46
|
return this;
|
45
47
|
},
|
46
48
|
|
47
49
|
alignBottom:function(y){
|
48
50
|
y = y || 0;
|
49
|
-
this.posY
|
51
|
+
this.set('posY', re.sys.sizeY - (this.get('sizeY') - this.get('regY')) + y | 0);
|
50
52
|
return this;
|
51
53
|
}
|
52
54
|
|
@@ -0,0 +1,50 @@
|
|
1
|
+
/*
|
2
|
+
The animate comp defines a simple interface for animating sprites.
|
3
|
+
|
4
|
+
//create entity with sprite sheet and animate comp
|
5
|
+
var apple = re.e('apple.png animate sprite');
|
6
|
+
|
7
|
+
//setup animations to play
|
8
|
+
apple.anis = {
|
9
|
+
//time, frames, loops
|
10
|
+
explode:[1000, [0, 1, 2], 1]
|
11
|
+
//seconds, frames, loops defaults to once
|
12
|
+
trans:[0.5, [3, 4, 5]]
|
13
|
+
};
|
14
|
+
|
15
|
+
//play animation
|
16
|
+
apple.animate('explode');
|
17
|
+
|
18
|
+
//stop animation
|
19
|
+
apple.animate();
|
20
|
+
|
21
|
+
//check animation playing
|
22
|
+
apple.flickering(); //this comes from flicker comp
|
23
|
+
|
24
|
+
*/
|
25
|
+
re.c('animate')
|
26
|
+
.requires('flicker')
|
27
|
+
.defines({
|
28
|
+
|
29
|
+
animate:function(name){
|
30
|
+
//ignore if calling the same frame
|
31
|
+
if(this.flickering() != name){
|
32
|
+
|
33
|
+
var a = this.anis[name] || [];
|
34
|
+
//flicker interface
|
35
|
+
//(duration:int, frames:array, loops:int, id:string)
|
36
|
+
this.flicker(a[0], a[1], a[2], name);
|
37
|
+
|
38
|
+
//only run if a is defined
|
39
|
+
if(a.length)
|
40
|
+
this.flicker_run(); //run first frame
|
41
|
+
}
|
42
|
+
return this;
|
43
|
+
},
|
44
|
+
|
45
|
+
//implement for flicker
|
46
|
+
flick:function(c){
|
47
|
+
this.frame(c);
|
48
|
+
}
|
49
|
+
|
50
|
+
});
|
data/src/display/draw.js
CHANGED
data/src/display/image.js
CHANGED
data/src/display/imgtext.js
CHANGED
data/src/display/sprite.js
CHANGED
@@ -44,11 +44,6 @@ re.c('sprite')
|
|
44
44
|
c.drawImage(this._image, this.frameX * this.sizeX, this.frameY * this.sizeY, this.sizeX, this.sizeY, -this.regX, -this.regY, this.sizeX, this.sizeY);
|
45
45
|
|
46
46
|
return this;
|
47
|
-
},
|
48
|
-
|
49
|
-
//implement for flicker
|
50
|
-
flick:function(c){
|
51
|
-
this.frame(c);
|
52
47
|
}
|
53
48
|
|
54
49
|
});
|
data/src/display/text.js
CHANGED
data/src/pattern/flicker.js
CHANGED
@@ -50,43 +50,43 @@ re.c('flicker')
|
|
50
50
|
|
51
51
|
change:function(){
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
this.flicker_stop();
|
65
|
-
return;
|
66
|
-
}
|
67
|
-
}
|
53
|
+
//check if over
|
54
|
+
if(this.flicker_frame == this.flicker_frames.length){
|
55
|
+
|
56
|
+
if(this.flicker_loops == -1 || --this.flicker_loops >= 1){
|
57
|
+
//loop again
|
58
|
+
|
59
|
+
this.flicker_frame = 0;
|
60
|
+
|
61
|
+
} else {
|
62
|
+
//done flickering
|
68
63
|
|
69
|
-
|
64
|
+
this.flicker_stop();
|
65
|
+
return;
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
this.flicker_run();
|
70
70
|
},
|
71
71
|
|
72
72
|
run:function(){
|
73
73
|
|
74
|
-
var f = this.flicker_frame,
|
75
|
-
fs = this.flicker_frames,
|
76
|
-
l = this.flicker_loops,
|
77
|
-
val = fs[f];
|
74
|
+
var f = this.flicker_frame, //frame number
|
75
|
+
fs = this.flicker_frames, //array of frames
|
76
|
+
l = this.flicker_loops, //loops left
|
77
|
+
val = fs[f]; //flick value
|
78
78
|
|
79
79
|
var quit = this.flick(val, f, fs, l);
|
80
80
|
|
81
81
|
this.trigger('flicker:update', val, f, fs, l);
|
82
82
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
83
|
+
//flick
|
84
|
+
if(quit === false){
|
85
|
+
//stop
|
86
|
+
this.flicker();
|
87
|
+
}
|
88
88
|
|
89
|
-
|
89
|
+
this.flicker_frame++;
|
90
90
|
},
|
91
91
|
|
92
92
|
update:function(t){
|
@@ -107,20 +107,20 @@ re.c('flicker')
|
|
107
107
|
*/
|
108
108
|
flicker:function(duration, frames, loops, id){
|
109
109
|
|
110
|
-
|
111
|
-
if(!re.is(
|
110
|
+
//stop
|
111
|
+
if(!re.is(duration) && this.flickering()){
|
112
112
|
//stop flickering
|
113
113
|
return this.flicker_stop();
|
114
114
|
}
|
115
115
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
116
|
+
//convert to seconds
|
117
|
+
if(duration >= 100){
|
118
|
+
duration /= 1000;
|
119
|
+
}
|
120
|
+
|
121
121
|
this.flicker_duration = duration || 1;
|
122
122
|
|
123
|
-
|
123
|
+
frames = (re.is(frames,'array')) ? frames : [frames];
|
124
124
|
|
125
125
|
//setup counter for loops
|
126
126
|
this.flicker_loops = loops || 1;
|
@@ -128,20 +128,20 @@ re.c('flicker')
|
|
128
128
|
this.stepProgress = 0;
|
129
129
|
this.stepSize = (duration / frames.length) / re.sys.second;
|
130
130
|
|
131
|
-
|
131
|
+
this.flicker_frames = frames;
|
132
132
|
this.flicker_frame = 0;
|
133
133
|
|
134
134
|
if(!this.flickering()){
|
135
135
|
this.on('update', this.flicker_update);
|
136
136
|
}
|
137
137
|
|
138
|
-
|
138
|
+
//sets flicker status
|
139
139
|
this.flicker_id = id || true;
|
140
140
|
|
141
141
|
this.trigger('flicker:start');
|
142
|
-
|
142
|
+
|
143
143
|
//update frame then run
|
144
|
-
this.flicker_run();
|
144
|
+
//this.flicker_run();
|
145
145
|
|
146
146
|
return this;
|
147
147
|
},
|
Binary file
|
@@ -0,0 +1,41 @@
|
|
1
|
+
re.scene('home')
|
2
|
+
.enter(function(){
|
3
|
+
|
4
|
+
re.e('sprite animate hero.png align keyboard')
|
5
|
+
.attr({
|
6
|
+
|
7
|
+
//sets frame size
|
8
|
+
sizeX:25,
|
9
|
+
sizeY:25,
|
10
|
+
|
11
|
+
//animation object for animate comp
|
12
|
+
anis:{
|
13
|
+
//first arg is time in milliseconds, array contains the frame numbers to flick through.
|
14
|
+
//time per frame = time / frames.length
|
15
|
+
random:[300, [0,1,2,3,4,0]]
|
16
|
+
},
|
17
|
+
|
18
|
+
//centers image on screen
|
19
|
+
alignHor:0,
|
20
|
+
alignVer:0
|
21
|
+
|
22
|
+
})
|
23
|
+
//listens for keyup event
|
24
|
+
.on('keyup:enter', function(){
|
25
|
+
//play random animation
|
26
|
+
this.animate('random');
|
27
|
+
|
28
|
+
console.log('Currently animating:',this.flickering());
|
29
|
+
})
|
30
|
+
.on('keyup:q', function(){
|
31
|
+
//ends animation
|
32
|
+
this.animate();
|
33
|
+
});
|
34
|
+
|
35
|
+
//add help text
|
36
|
+
re.e('text align')
|
37
|
+
.text('Press enter to animate')
|
38
|
+
.alignTop(5)
|
39
|
+
.alignLeft(5);
|
40
|
+
|
41
|
+
});
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module('home');
|
2
|
+
|
3
|
+
test('enter home', function(){
|
4
|
+
|
5
|
+
re.scene('home').enter();
|
6
|
+
|
7
|
+
var ref;
|
8
|
+
|
9
|
+
//check if entity exists
|
10
|
+
is(ref = re('animate').first());
|
11
|
+
|
12
|
+
//expects entity to have event listeners
|
13
|
+
expectEvent(ref, 'keyup:enter');
|
14
|
+
expectEvent(ref, 'keyup:q');
|
15
|
+
});
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module('load');
|
2
|
+
|
3
|
+
test('load assets', function(){
|
4
|
+
|
5
|
+
//replace re.scene('home').enter with start()
|
6
|
+
stub(re.scene('home'), 'enter', function(){ start(); });
|
7
|
+
|
8
|
+
//go into the load scene
|
9
|
+
re.scene('load').enter();
|
10
|
+
|
11
|
+
//it should be loading the assets
|
12
|
+
//stop until it finishes and enters the new home scene
|
13
|
+
//the home scene should then call start()
|
14
|
+
stop();
|
15
|
+
|
16
|
+
expect(0);
|
17
|
+
|
18
|
+
});
|
@@ -31,32 +31,4 @@ re.scene('home')
|
|
31
31
|
.alignTop(5)
|
32
32
|
.alignLeft(5);
|
33
33
|
|
34
|
-
//stop the browser from moving around
|
35
|
-
re.preventDefault('left right up down');
|
36
|
-
|
37
|
-
//create new circle on canvas
|
38
|
-
re.e('circle align update')
|
39
|
-
.attr({
|
40
|
-
radius:10,
|
41
|
-
speed:15,
|
42
|
-
color:'#ff0000'
|
43
|
-
})
|
44
|
-
//from align component
|
45
|
-
.align()
|
46
|
-
.on('update', function(){
|
47
|
-
|
48
|
-
//move on keypressed
|
49
|
-
if(re.pressed('a', 'left')) this.posX -= this.speed;
|
50
|
-
if(re.pressed('d', 'right')) this.posX += this.speed;
|
51
|
-
|
52
|
-
if(re.pressed('w', 'up')) this.posY -= this.speed;
|
53
|
-
if(re.pressed('s', 'down')) this.posY += this.speed;
|
54
|
-
|
55
|
-
});
|
56
|
-
|
57
|
-
//add help text
|
58
|
-
re.e('text align')
|
59
|
-
.text('Use WASD or arrow keys to move the circle')
|
60
|
-
.alignTop(5)
|
61
|
-
.alignLeft(5);
|
62
34
|
});
|
@@ -14,7 +14,8 @@ re.c('cursor')
|
|
14
14
|
|
15
15
|
box.place(iso.isoX, iso.isoY);
|
16
16
|
|
17
|
-
|
17
|
+
//get default drawlist
|
18
|
+
re.drawlist().sort();
|
18
19
|
},
|
19
20
|
|
20
21
|
move:function(x, y){
|
@@ -22,7 +23,7 @@ re.c('cursor')
|
|
22
23
|
|
23
24
|
this.place(iso.isoX, iso.isoY);
|
24
25
|
|
25
|
-
re.
|
26
|
+
re.drawlist().sort();
|
26
27
|
}
|
27
28
|
|
28
29
|
})
|
@@ -9,8 +9,10 @@ re.c('level')
|
|
9
9
|
re.iso.sizeZ = 25;
|
10
10
|
|
11
11
|
//setups layers for objects on the same tile
|
12
|
-
re.
|
13
|
-
|
12
|
+
re.layer = {
|
13
|
+
cursor:1,
|
14
|
+
box:2
|
15
|
+
};
|
14
16
|
|
15
17
|
for(var y=0; y<this.map.length; y++){
|
16
18
|
for(var x=0; x<this.map[0].length; x++){
|
@@ -32,13 +34,13 @@ re.c('level')
|
|
32
34
|
}
|
33
35
|
|
34
36
|
this.cursor = re.e('cursor')
|
35
|
-
.attr('layer', re.
|
37
|
+
.attr('layer', re.layer.cursor);
|
36
38
|
|
37
39
|
this.box = re.e('isoimage')
|
38
40
|
.attr({
|
39
41
|
id:'box',
|
40
42
|
frameX:3,
|
41
|
-
layer:re.
|
43
|
+
layer:re.layer.box,
|
42
44
|
place:[0,0]
|
43
45
|
});
|
44
46
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
re.c('hero')
|
2
|
-
.requires('hero.png tsprite update force
|
2
|
+
.requires('hero.png tsprite update force animate body')
|
3
3
|
.defines({
|
4
4
|
|
5
5
|
speed:40 * re.sys.stepSize,
|
@@ -28,18 +28,18 @@ re.c('hero')
|
|
28
28
|
this.velX -= this.speed;
|
29
29
|
this.scaleX = -1;
|
30
30
|
|
31
|
-
if(!this.jump) this.
|
31
|
+
if(!this.jump) this.animate('run');
|
32
32
|
}
|
33
33
|
|
34
34
|
if(re.pressed('d')){
|
35
35
|
this.velX += this.speed;
|
36
36
|
this.scaleX = 1;
|
37
37
|
|
38
|
-
if(!this.jump) this.
|
38
|
+
if(!this.jump) this.animate('run');
|
39
39
|
}
|
40
40
|
|
41
41
|
//switch back to idle animation if stopped moving
|
42
|
-
if(this.isIdle(0.3)) this.
|
42
|
+
if(this.isIdle(0.3)) this.animate('idle');
|
43
43
|
|
44
44
|
},
|
45
45
|
|
@@ -47,7 +47,7 @@ re.c('hero')
|
|
47
47
|
this.jump = true;
|
48
48
|
this.velY -= this.jumpSpeed;
|
49
49
|
|
50
|
-
this.
|
50
|
+
this.animate('jump');
|
51
51
|
},
|
52
52
|
|
53
53
|
jumpReset:function(x, y, tx, ty){
|
@@ -62,12 +62,12 @@ re.c('hero')
|
|
62
62
|
.init(function(){
|
63
63
|
|
64
64
|
//add animations
|
65
|
-
this.
|
66
|
-
idle:[
|
67
|
-
run:[
|
68
|
-
jump:[
|
69
|
-
ladder:[
|
70
|
-
}
|
65
|
+
this.anis = {
|
66
|
+
idle:[800, [0, 1], -1],
|
67
|
+
run:[800, [2, 3], 1],
|
68
|
+
jump:[500, [4, 5, 4], 1],
|
69
|
+
ladder:[500, [6, 7], -1]
|
70
|
+
};
|
71
71
|
|
72
72
|
this.on({
|
73
73
|
update:this.update,
|
@@ -1,5 +1,5 @@
|
|
1
1
|
re.c('coin')
|
2
|
-
.requires('item
|
2
|
+
.requires('item animate')
|
3
3
|
.defines({
|
4
4
|
|
5
5
|
touch:function(){
|
@@ -17,10 +17,15 @@ re.c('coin')
|
|
17
17
|
//add comp for searchability
|
18
18
|
this.comp('coin');
|
19
19
|
|
20
|
+
//create new sound effect
|
20
21
|
this.sfx = re.e('sound coin.sfx');
|
21
22
|
|
22
|
-
|
23
|
-
this.
|
23
|
+
//setup animations to play
|
24
|
+
this.anis = {
|
25
|
+
glow:[1800, [14, 15, 15], -1]
|
26
|
+
};
|
27
|
+
|
28
|
+
this.animate('glow');
|
24
29
|
})
|
25
30
|
//accepted tile frames in items.png which will become coins
|
26
31
|
.alias('t14')
|
@@ -1,11 +1,14 @@
|
|
1
1
|
re.c('item')
|
2
|
-
|
2
|
+
//order matters!
|
3
|
+
//items.png defines sizeX, sizeY
|
4
|
+
//tsprite overwrites the sizes
|
5
|
+
.requires('items.png tsprite update hit')
|
3
6
|
.namespaces({
|
4
7
|
|
5
8
|
update:function(t){
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
+
|
10
|
+
if(this.hero.hitBody(this.posX, this.posY, this.sizeX, this.sizeY, 10, 0)){
|
11
|
+
this.touching = true;
|
9
12
|
this.touch(t);
|
10
13
|
|
11
14
|
} else if(this.touching){
|
@@ -1,5 +1,5 @@
|
|
1
1
|
re.c('spring')
|
2
|
-
.requires('item
|
2
|
+
.requires('item animate')
|
3
3
|
.defines({
|
4
4
|
|
5
5
|
touch:function(){
|
@@ -7,14 +7,16 @@ re.c('spring')
|
|
7
7
|
|
8
8
|
if(re.pressed('w')){
|
9
9
|
this.hero.velY = -25;
|
10
|
-
this.
|
10
|
+
this.animate('bounce');
|
11
11
|
}
|
12
12
|
}
|
13
13
|
|
14
14
|
})
|
15
15
|
.init(function(){
|
16
16
|
//add animation, can also send a string instead of an array
|
17
|
-
this.
|
17
|
+
this.anis = {
|
18
|
+
bounce:[300, [13, 12], 1]
|
19
|
+
};
|
18
20
|
|
19
21
|
this.frame(12);
|
20
22
|
|
@@ -1,11 +1,12 @@
|
|
1
1
|
module('hero', lazy('hero'));
|
2
2
|
|
3
|
-
test('has
|
3
|
+
test('has animations', function(){
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
//these where manually put in
|
6
|
+
is(hero.anis.idle);
|
7
|
+
is(hero.anis.run);
|
8
|
+
is(hero.anis.jump);
|
9
|
+
is(hero.anis.ladder);
|
9
10
|
|
10
11
|
});
|
11
12
|
|
@@ -15,7 +16,7 @@ test('has components', function(){
|
|
15
16
|
|
16
17
|
test('flickers idle when not moving', function(){
|
17
18
|
|
18
|
-
hero.
|
19
|
+
hero.animate('run');
|
19
20
|
|
20
21
|
stub(hero, 'isIdle', true);
|
21
22
|
|
@@ -28,17 +28,17 @@ re.c('hitmap')
|
|
28
28
|
}
|
29
29
|
|
30
30
|
//check hits on paddles
|
31
|
-
re('paddle').each(function(){
|
31
|
+
re('paddle').each(function(i){
|
32
32
|
|
33
|
-
if(
|
33
|
+
if(i.hit(obj)){
|
34
34
|
res.hitX = 1;
|
35
35
|
|
36
|
-
var push = obj.hsizeX +
|
36
|
+
var push = obj.hsizeX + i.hsizeX + 1;
|
37
37
|
|
38
|
-
if(
|
38
|
+
if(i.posX > obj.posX){
|
39
39
|
push *= -1;
|
40
40
|
}
|
41
|
-
res.posX =
|
41
|
+
res.posX = i.posX + push;
|
42
42
|
|
43
43
|
}
|
44
44
|
|
@@ -4,6 +4,8 @@ test('paddle moves down on w press', function(){
|
|
4
4
|
|
5
5
|
player.posY = 30;
|
6
6
|
|
7
|
+
stub(player, 'checkBounds');
|
8
|
+
|
7
9
|
expectValueDown(player, 'posY');
|
8
10
|
|
9
11
|
keypress('w', function(){
|
@@ -15,9 +17,12 @@ test('paddle moves down on w press', function(){
|
|
15
17
|
test('paddle moves up on s press', function(){
|
16
18
|
|
17
19
|
player.posY = 10;
|
18
|
-
|
20
|
+
console.log(player.posY)
|
19
21
|
expectValueUp(player, 'posY');
|
20
22
|
|
23
|
+
//remove this
|
24
|
+
stub(player, 'checkBounds');
|
25
|
+
|
21
26
|
keypress('s', function(){
|
22
27
|
player.update();
|
23
28
|
});
|
@@ -53,10 +53,10 @@ re.level = re.c('level')
|
|
53
53
|
|
54
54
|
var ball = this;
|
55
55
|
|
56
|
-
re('target').each(function(){
|
56
|
+
re('target').each(function(i){
|
57
57
|
|
58
|
-
if(ball.tileX() ==
|
59
|
-
|
58
|
+
if(ball.tileX() == i.tileX() && i.tileY() == ball.tileY()){
|
59
|
+
i.dispose();
|
60
60
|
}
|
61
61
|
|
62
62
|
});
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: entityjs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-05-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: jasmine
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,21 +37,31 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: sinatra
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
42
52
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
53
|
+
version: 1.3.0
|
44
54
|
type: :runtime
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.3.0
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: coffee-script
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ! '>='
|
@@ -54,10 +69,15 @@ dependencies:
|
|
54
69
|
version: '0'
|
55
70
|
type: :runtime
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
58
78
|
- !ruby/object:Gem::Dependency
|
59
79
|
name: uglifier
|
60
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
61
81
|
none: false
|
62
82
|
requirements:
|
63
83
|
- - ! '>='
|
@@ -65,10 +85,15 @@ dependencies:
|
|
65
85
|
version: '0'
|
66
86
|
type: :runtime
|
67
87
|
prerelease: false
|
68
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
69
94
|
- !ruby/object:Gem::Dependency
|
70
95
|
name: json
|
71
|
-
requirement:
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
72
97
|
none: false
|
73
98
|
requirements:
|
74
99
|
- - ! '>='
|
@@ -76,10 +101,15 @@ dependencies:
|
|
76
101
|
version: '0'
|
77
102
|
type: :runtime
|
78
103
|
prerelease: false
|
79
|
-
version_requirements:
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
80
110
|
- !ruby/object:Gem::Dependency
|
81
111
|
name: cobravsmongoose
|
82
|
-
requirement:
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
83
113
|
none: false
|
84
114
|
requirements:
|
85
115
|
- - ! '>='
|
@@ -87,7 +117,12 @@ dependencies:
|
|
87
117
|
version: '0'
|
88
118
|
type: :runtime
|
89
119
|
prerelease: false
|
90
|
-
version_requirements:
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
91
126
|
description: HTML5 Javascript game engine, quickly create robust, flexible and reusable
|
92
127
|
games.
|
93
128
|
email:
|
@@ -156,6 +191,7 @@ files:
|
|
156
191
|
- spec/javascripts/src/cycle/update_spec.js
|
157
192
|
- spec/javascripts/src/cycle/wait_spec.js
|
158
193
|
- spec/javascripts/src/display/align_spec.js
|
194
|
+
- spec/javascripts/src/display/animate_spec.js
|
159
195
|
- spec/javascripts/src/display/circle_spec.js
|
160
196
|
- spec/javascripts/src/display/draw_spec.js
|
161
197
|
- spec/javascripts/src/display/group_spec.js
|
@@ -227,6 +263,7 @@ files:
|
|
227
263
|
- src/cycle/wait.js
|
228
264
|
- src/cycle/worker.js
|
229
265
|
- src/display/align.js
|
266
|
+
- src/display/animate.js
|
230
267
|
- src/display/circle.js
|
231
268
|
- src/display/draw.js
|
232
269
|
- src/display/group.js
|
@@ -268,6 +305,13 @@ files:
|
|
268
305
|
- src/util/scene.js
|
269
306
|
- src/util/sheet.js
|
270
307
|
- src/util/support.js
|
308
|
+
- templates/animation/assets/images/hero.png
|
309
|
+
- templates/animation/scripts/init.js
|
310
|
+
- templates/animation/scripts/scenes/home.js
|
311
|
+
- templates/animation/scripts/scenes/load.js
|
312
|
+
- templates/animation/tests/init_test.js
|
313
|
+
- templates/animation/tests/scenes/home_test.js
|
314
|
+
- templates/animation/tests/scenes/load_test.js
|
271
315
|
- templates/arrow_keys/assets/images/arrow.png
|
272
316
|
- templates/arrow_keys/config.yml
|
273
317
|
- templates/arrow_keys/readme.txt
|
@@ -402,7 +446,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
402
446
|
version: '0'
|
403
447
|
requirements: []
|
404
448
|
rubyforge_project: entityjs
|
405
|
-
rubygems_version: 1.8.
|
449
|
+
rubygems_version: 1.8.24
|
406
450
|
signing_key:
|
407
451
|
specification_version: 3
|
408
452
|
summary: Create HTML5 javascript games in EntityJS.
|