pictcode / app / webroot / js / pictcode / block_action.js @ 9af585b9
履歴 | 表示 | アノテート | ダウンロード (4.482 KB)
1 |
define(function(){
|
---|---|
2 |
|
3 |
var behaviors ={
|
4 |
//移動
|
5 |
move:function(){ |
6 |
//経過時間
|
7 |
var passedTime = 0; |
8 |
//所要時間、単位時間当たりのx、y方向の移動距離、単位時間
|
9 |
var duration, dx, dy, dt;
|
10 |
//ブロックの命令を初期化
|
11 |
var initialize = function(det, drtn, vector){ |
12 |
passedTime = 0;
|
13 |
//所要時間をミリ秒に変換
|
14 |
drtn *= 1000;
|
15 |
dx = vector.x/drtn*det; |
16 |
dy = vector.y/drtn*det; |
17 |
duration = drtn; |
18 |
dt = det; |
19 |
} |
20 |
|
21 |
//単位時間ごとの動き
|
22 |
var behave = function(sprite, trigger, goNextBlock){ |
23 |
sprite.position.x += dx; |
24 |
sprite.position.y += dy; |
25 |
passedTime += dt; |
26 |
if (passedTime >= duration) {
|
27 |
goNextBlock(sprite, trigger); |
28 |
}; |
29 |
} |
30 |
|
31 |
return{
|
32 |
initialize:initialize,
|
33 |
behave:behave,
|
34 |
}; |
35 |
}, |
36 |
|
37 |
rotate_left:function(){ |
38 |
var passedTime = 0; |
39 |
//角度、単位時間
|
40 |
var duration, da, dt;
|
41 |
|
42 |
var initialize = function(det, drtn, angle){ |
43 |
passedTime = 0;
|
44 |
duration = drtn * 1000;
|
45 |
//単位時間あたりの回転角度
|
46 |
da = angle / (drtn/det); |
47 |
dt = det; |
48 |
} |
49 |
|
50 |
var behave = function(sprite, trigger, goNextBlock){ |
51 |
sprite.angle += da; |
52 |
passedTime += dt; |
53 |
if (passedTime >= duration) {
|
54 |
goNextBlock(sprite, trigger); |
55 |
}; |
56 |
} |
57 |
|
58 |
return{
|
59 |
initialize:initialize,
|
60 |
behave:behave,
|
61 |
}; |
62 |
}, |
63 |
|
64 |
rotate_right:function(){ |
65 |
var passedTime = 0; |
66 |
//角度、単位時間
|
67 |
var duration, da, dt;
|
68 |
|
69 |
var initialize = function(det, drtn, angle){ |
70 |
passedTime = 0;
|
71 |
duration = drtn * 1000;
|
72 |
//単位時間あたりの回転角度
|
73 |
da = angle / (drtn/det); |
74 |
dt = det; |
75 |
} |
76 |
|
77 |
var behave = function(sprite, trigger, goNextBlock){ |
78 |
sprite.angle -= da; |
79 |
passedTime += dt; |
80 |
if (passedTime >= duration) {
|
81 |
goNextBlock(sprite, trigger); |
82 |
}; |
83 |
} |
84 |
|
85 |
return{
|
86 |
initialize:initialize,
|
87 |
behave:behave,
|
88 |
}; |
89 |
}, |
90 |
|
91 |
zoom:function(){ |
92 |
var passedTime = 0; |
93 |
//角度、単位時間
|
94 |
var duration, ds, dt;
|
95 |
|
96 |
var initialize = function(det, drtn, scale){ |
97 |
passedTime = 0;
|
98 |
duration = drtn * 1000;
|
99 |
//単位時間あたりのスケール変化量
|
100 |
ds = scale / (drtn/det); |
101 |
dt = det; |
102 |
} |
103 |
|
104 |
var behave = function(sprite, trigger, goNextBlock){ |
105 |
sprite.scale += ds; |
106 |
passedTime += dt; |
107 |
if (passedTime >= duration) {
|
108 |
goNextBlock(sprite, trigger); |
109 |
}; |
110 |
} |
111 |
|
112 |
return{
|
113 |
initialize:initialize,
|
114 |
behave:behave,
|
115 |
}; |
116 |
}, |
117 |
|
118 |
opacity:function(){ |
119 |
var passedTime = 0; |
120 |
//角度、単位時間
|
121 |
var duration, dopct, dt;
|
122 |
|
123 |
var initialize = function(det, drtn, opacity){ |
124 |
passedTime = 0;
|
125 |
duration = drtn * 1000;
|
126 |
//単位時間あたりのスケール変化量
|
127 |
dopct = opacity / (drtn/det); |
128 |
dt = det; |
129 |
} |
130 |
|
131 |
var behave = function(sprite, trigger, goNextBlock){ |
132 |
sprite.opacity += dopct; |
133 |
passedTime += dt; |
134 |
if (passedTime >= duration) {
|
135 |
goNextBlock(sprite, trigger); |
136 |
}; |
137 |
} |
138 |
|
139 |
return{
|
140 |
initialize:initialize,
|
141 |
behave:behave,
|
142 |
}; |
143 |
}, |
144 |
|
145 |
mirror:function(){ |
146 |
var passedTime = 0; |
147 |
//角度、単位時間
|
148 |
var duration, direction, dt;
|
149 |
|
150 |
var initialize = function(det, drtn, mirror){ |
151 |
passedTime = 0;
|
152 |
duration = drtn * 1000;
|
153 |
//単位時間あたりのスケール変化量
|
154 |
direction = mirror; |
155 |
dt = det; |
156 |
} |
157 |
|
158 |
var behave = function(sprite, trigger, goNextBlock){ |
159 |
sprite.mirrored = direction; |
160 |
passedTime += dt; |
161 |
if (passedTime >= duration) {
|
162 |
goNextBlock(sprite, trigger); |
163 |
}; |
164 |
} |
165 |
|
166 |
return{
|
167 |
initialize:initialize,
|
168 |
behave:behave,
|
169 |
}; |
170 |
}, |
171 |
|
172 |
wait:function(){ |
173 |
var passedTime = 0; |
174 |
var duration, dt;
|
175 |
|
176 |
var initialize = function(det, drtn){ |
177 |
passedTime = 0;
|
178 |
duration = drtn * 1000;
|
179 |
dt = det; |
180 |
} |
181 |
|
182 |
var behave = function(sprite, trigger, goNextBlock){ |
183 |
passedTime += dt; |
184 |
if (passedTime >= duration) {
|
185 |
goNextBlock(sprite, trigger); |
186 |
}; |
187 |
} |
188 |
|
189 |
return{
|
190 |
initialize:initialize,
|
191 |
behave:behave,
|
192 |
}; |
193 |
} |
194 |
}; |
195 |
|
196 |
return {
|
197 |
behaviors:behaviors
|
198 |
}; |
199 |
}); |