forked from tyt2y3/F.LF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheffects.js
166 lines (149 loc) · 2.93 KB
/
effects.js
1
2
3
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*\
* effect
*
* handle visual effects
* like blood, fire, etc
\*/
define(['LF/global','LF/sprite','F.core/effects-pool'],
function ( Global, Sprite, Feffects_pool)
{
/*\
* effect_set
[ class ]
* effect_set is the set for all kinds of effects
* this is a big manager. there is only 1 instance of effect_set in a match.
- config (object)
- DATA (array) of data (object)
- ID (array) of ID (number)
\*/
function effect_set(config,DATA,ID) //DATA and ID are arrays
{
this.efs={};
for( var i=0; i<DATA.length; i++)
{
var ef_config=
{
init_size: 5,
batch_size: 5,
max_size: 30,
construct: function()
{
return new effect(config,DATA[i],ID[i]);
}
}
var efpool = this.efs[ID[i]] = new Feffects_pool(ef_config);
}
}
effect_set.prototype.destroy=function()
{
for( var i in this.efs)
this.efs[i].destroy();
}
/*\
* effect_set.create
[ method ]
- param (object) `{x,y,z}` position to create the effect
- id (number) id of the desired effect
- subnum (number) specify the variant of an effect
\*/
effect_set.prototype.create=function(param,id,subnum)
{
if( !subnum) subnum=0;
if( this.efs[id])
this.efs[id].create(param,subnum);
}
effect_set.prototype.TU=function()
{
for( var i in this.efs)
this.efs[i].TU();
}
effect_set.prototype.transit=function()
{
}
/** extends Feffects_pool with custom method
note: this have side effect, affecting Feffects_pool globally
*/
Feffects_pool.prototype.TU=function()
{
this.for_each(function(E){
E.TU();
});
}
Feffects_pool.prototype.destroy=function()
{
//destroy all, no matter active or not
for( var i=0; i<this.pool.length; i++)
{
this.pool[i].destroy();
}
}
/*\
* effect_unit
[ class ]
* individual effect
*
* they are like other living objects but much simplier.
* they are short-lived, `born` as triggered by `effects-pool` and `die` spontaneously
\*/
function effect(config,data,id)
{
this.dat=data;
this.type=data.effect_list;
this.id=id;
this.sp = new Sprite(this.dat.bmp, config.stage);
this.sp.hide();
this.frame;
this.frameD;
this.wait=-1;
this.next;
}
effect.prototype.destroy=function()
{
this.sp.destroy();
}
effect.prototype.TU=function()
{
this.sp.show_pic(this.frameD.pic);
this.wait=this.frameD.wait;
this.next=this.frameD.next;
if( this.wait===0)
{
if( this.next===999)
this.next=0;
else if( this.next===1000)
{
this.sp.hide();
this.parent.die();
return ;
}
this.frame=this.next;
this.frameD=this.dat.frame[this.frame];
}
else
this.wait--;
}
effect.prototype.transit=function()
{
}
effect.prototype.set_pos=function(x,y,z)
{
}
effect.prototype.born=function(P,N)
{
var sf;
if( this.type[N] && this.type[N].frame)
sf = this.type[N].frame;
else
sf = 0;
this.frame=sf;
this.frameD=this.dat.frame[this.frame];
var x=P.x - this.frameD.centerx;
var y=P.y - this.frameD.centery;
var z=P.z;
this.sp.set_x_y(x, y+z);
this.sp.set_z(z+1);
this.sp.show_pic(this.frameD.pic);
this.sp.show();
}
return effect_set;
});