質問編集履歴
1
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -96,19 +96,105 @@
|
|
96
96
|
|
97
97
|
|
98
98
|
|
99
|
+
|
100
|
+
|
101
|
+
var cPlayer = {
|
102
|
+
|
103
|
+
MAX_ANIM_ID:0,
|
104
|
+
|
105
|
+
IMG_CHANGE_STEP:0,
|
106
|
+
|
107
|
+
animID:0,
|
108
|
+
|
109
|
+
icStep:0,
|
110
|
+
|
111
|
+
x:0,
|
112
|
+
|
113
|
+
y:0,
|
114
|
+
|
115
|
+
width:0,
|
116
|
+
|
117
|
+
height:0,
|
118
|
+
|
99
|
-
|
119
|
+
vx:0,
|
100
|
-
|
120
|
+
|
101
|
-
|
121
|
+
vy:0,
|
122
|
+
|
102
|
-
|
123
|
+
dir:0,
|
124
|
+
|
125
|
+
y_prev:0,
|
126
|
+
|
127
|
+
y_temp:0,
|
128
|
+
|
129
|
+
jumpFlag:0,
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
init:function(x,y){
|
134
|
+
|
135
|
+
this.MAX_ANIM_ID = 2;
|
136
|
+
|
137
|
+
this.IMG_CHANGE_STEP = 3;
|
138
|
+
|
139
|
+
this.animID = 0;
|
140
|
+
|
141
|
+
this.icStep = 0;
|
142
|
+
|
103
|
-
|
143
|
+
this.x = x;
|
144
|
+
|
145
|
+
this.y = y;
|
146
|
+
|
147
|
+
this.width = 31;
|
148
|
+
|
149
|
+
this.height = 40;
|
150
|
+
|
151
|
+
this.vx = 50;
|
152
|
+
|
153
|
+
this.vy = 0;
|
154
|
+
|
155
|
+
this.dir = "RIGHT";
|
156
|
+
|
157
|
+
this.y_prev = 0;
|
158
|
+
|
159
|
+
this.y_temp = 0;
|
160
|
+
|
161
|
+
this.jumpFlag = false;
|
162
|
+
|
163
|
+
},
|
164
|
+
|
165
|
+
draw:function(){
|
166
|
+
|
167
|
+
if(this.dir == "LEFT"){
|
168
|
+
|
169
|
+
ctx.save(); // canvas状態を保存
|
170
|
+
|
171
|
+
ctx.transform(-1, 0, 0, 1, 0, 0); // 画像を左右反転させる
|
172
|
+
|
173
|
+
ctx.drawImage(Asset.images['box'], this.width * this.animID, 0, this.width, this.height, -this.x - this.width, this.y, this.width, this.height);
|
174
|
+
|
175
|
+
ctx.restore(); // canvasの状態をsaveされた状態に戻す
|
176
|
+
|
177
|
+
}else{
|
178
|
+
|
179
|
+
ctx.drawImage(Asset.images['box'], this.width * this.animID, 0, this.width, this.height, this.x, this.y, this.width, this.height);
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
},
|
184
|
+
|
185
|
+
move:function(){
|
104
186
|
|
105
187
|
//床衝突判定
|
106
188
|
|
189
|
+
if (this.y > this.height && this.y < SCREEN_HEIGHT-this.height &&
|
190
|
+
|
107
|
-
|
191
|
+
collisionMap(this.x , this.y+this.height, MapChip) != 255 ||
|
192
|
+
|
193
|
+
this.y > this.height && this.y < SCREEN_HEIGHT-this.height &&
|
108
194
|
|
109
195
|
collisionMap(this.x+this.width, this.y+this.height, MapChip) != 255){
|
110
196
|
|
111
|
-
this.jumpFlag = false;
|
197
|
+
this.jumpFlag = false;
|
112
198
|
|
113
199
|
this.y = Math.floor((this.y/16)*16);
|
114
200
|
|
@@ -134,9 +220,19 @@
|
|
134
220
|
|
135
221
|
}
|
136
222
|
|
223
|
+
|
224
|
+
|
225
|
+
if(keyCode["RIGHT"]){
|
226
|
+
|
227
|
+
this.dir = "RIGHT";
|
228
|
+
|
229
|
+
this.x += this.vx * delta;
|
230
|
+
|
231
|
+
|
232
|
+
|
137
|
-
//壁衝突判定(右側)
|
233
|
+
//壁衝突判定(右側)
|
138
|
-
|
234
|
+
|
139
|
-
if (collisionMap(this.x, this.y , MapChip) != 255 ||
|
235
|
+
if (collisionMap(this.x, this.y , MapChip) != 255 ||
|
140
236
|
|
141
237
|
collisionMap(this.x+16, this.y+16, MapChip) != 255){
|
142
238
|
|
@@ -144,9 +240,43 @@
|
|
144
240
|
|
145
241
|
}
|
146
242
|
|
243
|
+
// 何回でアニメーションを変えるか
|
244
|
+
|
245
|
+
if(this.icStep >= this.IMG_CHANGE_STEP){
|
246
|
+
|
247
|
+
this.icStep = 0;
|
248
|
+
|
249
|
+
if(this.animID <= this.MAX_ANIM_ID){
|
250
|
+
|
251
|
+
this.animID++; // 次のコマへ
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
else{
|
256
|
+
|
257
|
+
this.animID = 0;
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
}else{
|
262
|
+
|
263
|
+
this.icStep++;
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
else if(keyCode["LEFT"]){
|
270
|
+
|
271
|
+
this.dir = "LEFT";
|
272
|
+
|
273
|
+
this.x -= this.vx * delta;
|
274
|
+
|
275
|
+
|
276
|
+
|
147
|
-
//壁衝突判定(左側)
|
277
|
+
//壁衝突判定(左側)
|
148
|
-
|
278
|
+
|
149
|
-
if (collisionMap(this.x, this.y , MapChip) != 255 ||
|
279
|
+
if (collisionMap(this.x, this.y , MapChip) != 255 ||
|
150
280
|
|
151
281
|
collisionMap(this.x-16, this.y+16, MapChip) != 255){
|
152
282
|
|
@@ -154,4 +284,68 @@
|
|
154
284
|
|
155
285
|
}
|
156
286
|
|
287
|
+
|
288
|
+
|
289
|
+
// 何回でアニメーションを変えるか
|
290
|
+
|
291
|
+
if(this.icStep >= this.IMG_CHANGE_STEP){
|
292
|
+
|
293
|
+
this.icStep = 0;
|
294
|
+
|
295
|
+
if(this.animID <= this.MAX_ANIM_ID){
|
296
|
+
|
297
|
+
this.animID++; // 次のコマへ
|
298
|
+
|
299
|
+
}
|
300
|
+
|
301
|
+
else{
|
302
|
+
|
303
|
+
this.animID = 0;
|
304
|
+
|
305
|
+
}
|
306
|
+
|
307
|
+
}else{
|
308
|
+
|
309
|
+
this.icStep++;
|
310
|
+
|
311
|
+
}
|
312
|
+
|
313
|
+
}
|
314
|
+
|
315
|
+
else{
|
316
|
+
|
317
|
+
this.animID = 0;
|
318
|
+
|
319
|
+
}
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
//ジャンプ処理
|
324
|
+
|
325
|
+
if(this.jumpFlag == true){
|
326
|
+
|
327
|
+
this.y_temp = this.y;
|
328
|
+
|
329
|
+
this.y +=(this.y-this.y_prev)+1;
|
330
|
+
|
331
|
+
this.y_prev = this.y_temp;
|
332
|
+
|
333
|
+
}
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
if(keyCode["SPACE"] && this.jumpFlag == false){
|
338
|
+
|
339
|
+
this.jumpFlag = true;
|
340
|
+
|
341
|
+
this.y_prev = this.y;
|
342
|
+
|
343
|
+
this.y = this.y-16;
|
344
|
+
|
345
|
+
}
|
346
|
+
|
347
|
+
}
|
348
|
+
|
349
|
+
}
|
350
|
+
|
157
351
|
```
|