質問編集履歴
1
文章を追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,68 +1,774 @@
|
|
1
|
+
ジャンプして地面に着くときにバグるときとちゃんと地面に着くときが実行するたびに違っている原因が知りたいです。またジャンプして左右に移動したときだけバグる時がありあます。バグるとは提示画像のように下につっつていしまう。
|
2
|
+
|
3
|
+
![イメージ説明](35f75f333f8b3b014576cb9a7e11f79f.png)
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
|
1
9
|
```ここに言語を入力
|
2
10
|
|
3
11
|
|
4
12
|
|
13
|
+
game.cpp部
|
14
|
+
|
5
15
|
/*キー入力*/
|
6
16
|
|
7
|
-
void Game::input()
|
17
|
+
void Game::input(){
|
18
|
+
|
19
|
+
/////////////文字数の関係でenumによる入力部を割愛
|
20
|
+
|
21
|
+
p->Move(key,action);
|
22
|
+
|
23
|
+
}
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
const char* str = "Log.txt";
|
28
|
+
|
29
|
+
std::ofstream ofs(str);
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
/*当たり判定処理 関数*/
|
34
|
+
|
35
|
+
void Game::Collision_Update()
|
8
36
|
|
9
37
|
{
|
10
38
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
39
|
+
Position *Result = NULL;
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
float offset_x = 0;
|
44
|
+
|
45
|
+
float offset_y = 0;
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
/*移動方向によって異なる*/
|
50
|
+
|
51
|
+
if(p->speed->x > 0)//右
|
52
|
+
|
53
|
+
{
|
54
|
+
|
55
|
+
offset_x = ((p->CELL) + p->speed->x );
|
56
|
+
|
57
|
+
}else if (p->speed->x < 0)//左
|
58
|
+
|
59
|
+
{
|
60
|
+
|
61
|
+
float t = (p->CELL) * - 1;//符号を逆にするマイナス
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
offset_x = (t + p->speed->x);
|
66
|
+
|
67
|
+
// ofs<<offset_x<<std::endl;
|
68
|
+
|
69
|
+
}else{
|
70
|
+
|
71
|
+
offset_x = 0;
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
//if(action == keyState::Jump)
|
78
|
+
|
79
|
+
if(p->speed->y < 0)
|
80
|
+
|
81
|
+
{
|
82
|
+
|
83
|
+
offset_y = - ((p->CELL - 1 ) - p->speed->y );
|
84
|
+
|
85
|
+
//}else if (action == keyState::Down)
|
86
|
+
|
87
|
+
}else if (p->speed->y > 0)
|
88
|
+
|
89
|
+
{/*落下*/
|
90
|
+
|
91
|
+
offset_y = ((p->CELL) + p->speed->y);
|
92
|
+
|
93
|
+
//ofs<<offset_y <<std::endl;
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
/* Y 軸 */
|
104
|
+
|
105
|
+
// Position* now_y_left = new Position(p->pos->x, p->pos->y + ((p->CELL / 2) - 1));
|
106
|
+
|
107
|
+
// Position* future_y_left = new Position(p->pos->x, p->pos->y + ((p->CELL / 2) - 2) + offset_y);
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
// Position* now_y_right = new Position(p->pos->x + (p->CELL - 1), p->pos->y + ((p->CELL / 2) - 1));
|
112
|
+
|
113
|
+
// Position* future_y_right = new Position(p->pos->x + (p->CELL - 1), p->pos->y + ((p->CELL / 2) - 2) + offset_y);
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
//ofs << "future_x_up: " << future_x_up.x << std::endl;
|
120
|
+
|
121
|
+
// ofs << "future_x_down: " << future_x_down.x << std::endl;
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
bool NoCol_x = true;
|
128
|
+
|
129
|
+
bool NoCol_y = true;
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
/**********************************************当たり判定***********************************************************************/
|
138
|
+
|
139
|
+
for (int y = 0; y < 100; y++) {
|
140
|
+
|
141
|
+
for (int x = 0;x < 100; x++) {
|
142
|
+
|
143
|
+
if (m->isMap(Position((float)x,(float)y)) == true) {
|
144
|
+
|
145
|
+
float Fix_x_up = -1;
|
146
|
+
|
147
|
+
float Fix_x_down = -1;
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
float Fix_y_left = -1;
|
152
|
+
|
153
|
+
float Fix_y_right = -1;
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
/* X 軸 */
|
158
|
+
|
159
|
+
Position now_x_up(p->pos->x + ((p->CELL / 2) - 1), p->pos->y);
|
160
|
+
|
161
|
+
Position future_x_up((p->pos->x + ((p->CELL / 2) - 1)) + offset_x, p->pos->y);
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
Position now_x_down(p->pos->x + ((p->CELL / 2) - 1), (p->pos->y + (p->CELL - 1)));
|
166
|
+
|
167
|
+
Position future_x_down((p->pos->x + ((p->CELL / 2) - 1)) + offset_x, (p->pos->y + (p->CELL - 1)));
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
/*=================空中に居る時で 左右に"動いているとき"=================*/
|
174
|
+
|
175
|
+
//if (p->isGround == false && p->isJump == true)
|
176
|
+
|
177
|
+
if(true)
|
178
|
+
|
179
|
+
{
|
180
|
+
|
181
|
+
// ofs << "Collisition " << std::endl;
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
DrawFormatString(400, 400, GetColor(255, 255, 255), "Collisition",true);
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
int r = cross_pos(&Result, now_x_up, future_x_up,
|
190
|
+
|
191
|
+
Position((x * p->CELL) + ( (p->CELL / 2) - 1),y * p->CELL), Position((x * p->CELL) + ((p->CELL / 2) - 1), ((y + 1) * p->CELL) - 1 ));
|
192
|
+
|
193
|
+
if( r != 0)
|
194
|
+
|
195
|
+
{
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
NoCol_x = false;
|
200
|
+
|
201
|
+
DrawFormatString(400, 400, GetColor(255, 255, 255), "now_x_up", true);
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
if(p->speed->x > 0){
|
206
|
+
|
207
|
+
Fix_x_up = Result->x - ( (p->CELL - 1) + (p->CELL /2) );
|
208
|
+
|
209
|
+
//ix_x_up = now_x_up.x;
|
210
|
+
|
211
|
+
}else if(p->speed->x < 0)
|
212
|
+
|
213
|
+
{
|
214
|
+
|
215
|
+
Fix_x_up = Result->x + (p->CELL / 2) + 1;
|
216
|
+
|
217
|
+
//Fix_x_up = now_x_up.x;
|
218
|
+
|
219
|
+
}
|
220
|
+
|
221
|
+
delete(Result);
|
222
|
+
|
223
|
+
Result = NULL;
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
if(p->isGround == false){
|
232
|
+
|
233
|
+
r = cross_pos(&Result, now_x_down, future_x_down,
|
234
|
+
|
235
|
+
Position( (x * p->CELL) + ((p->CELL / 2) - 1), y * p->CELL), Position((x * p->CELL) + ((p->CELL / 2) - 1), ((y + 1) * p->CELL) - 1));
|
236
|
+
|
237
|
+
if (r != 0)
|
238
|
+
|
239
|
+
{
|
240
|
+
|
241
|
+
NoCol_x = false;
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
DrawFormatString(400, 500, GetColor(255, 255, 255), "now_x_down", true);
|
246
|
+
|
247
|
+
if (p->speed->x > 0) {
|
248
|
+
|
249
|
+
Fix_x_down = Result->x - ((p->CELL - 1) + (p->CELL / 2));
|
250
|
+
|
251
|
+
//Fix_x_down = now_x_down.x;
|
252
|
+
|
253
|
+
}else if (p->speed->x < 0) {
|
254
|
+
|
255
|
+
Fix_x_down = Result->x + (p->CELL / 2) + 1;
|
256
|
+
|
257
|
+
//Fix_x_down = now_x_down.x;
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
delete(Result);
|
262
|
+
|
263
|
+
Result = NULL;
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
}
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
/*X 補正*/
|
274
|
+
|
275
|
+
if (Fix_x_up != -1 || Fix_x_down != -1)
|
276
|
+
|
277
|
+
{
|
278
|
+
|
279
|
+
if (p->speed->x > 0)/*右*/
|
280
|
+
|
281
|
+
{
|
282
|
+
|
283
|
+
if (Fix_x_up == -1)
|
284
|
+
|
285
|
+
{
|
286
|
+
|
287
|
+
p->pos->x = Fix_x_down;
|
288
|
+
|
289
|
+
}
|
290
|
+
|
291
|
+
else if(Fix_x_down == -1)
|
292
|
+
|
293
|
+
{
|
294
|
+
|
295
|
+
p->pos->x = Fix_x_up;
|
296
|
+
|
297
|
+
}
|
298
|
+
|
299
|
+
else {
|
300
|
+
|
301
|
+
if (Fix_x_up < Fix_x_down)
|
302
|
+
|
303
|
+
{
|
304
|
+
|
305
|
+
p->pos->x = Fix_x_up;
|
306
|
+
|
307
|
+
}
|
308
|
+
|
309
|
+
else
|
310
|
+
|
311
|
+
{
|
312
|
+
|
313
|
+
p->pos->x = Fix_x_down;
|
314
|
+
|
315
|
+
}
|
316
|
+
|
317
|
+
}
|
318
|
+
|
319
|
+
}
|
320
|
+
|
321
|
+
else if (p->speed->x < 0)/*左*/
|
322
|
+
|
323
|
+
{
|
324
|
+
|
325
|
+
if (Fix_x_up == -1)
|
326
|
+
|
327
|
+
{
|
328
|
+
|
329
|
+
p->pos->x = Fix_x_down;
|
330
|
+
|
331
|
+
}
|
332
|
+
|
333
|
+
else if (Fix_x_down == -1)
|
334
|
+
|
335
|
+
{
|
336
|
+
|
337
|
+
p->pos->x = Fix_x_up;
|
338
|
+
|
339
|
+
}
|
340
|
+
|
341
|
+
else {
|
342
|
+
|
343
|
+
if (Fix_x_up < Fix_x_down)
|
344
|
+
|
345
|
+
{
|
346
|
+
|
347
|
+
p->pos->x = Fix_x_down;
|
348
|
+
|
349
|
+
}
|
350
|
+
|
351
|
+
else
|
352
|
+
|
353
|
+
{
|
354
|
+
|
355
|
+
p->pos->x = Fix_x_up;
|
356
|
+
|
357
|
+
}
|
358
|
+
|
359
|
+
}
|
360
|
+
|
361
|
+
}
|
362
|
+
|
363
|
+
}
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
/*********************************************** Y軸 *************************************************************************************/
|
368
|
+
|
369
|
+
/* Y 軸 値設定*/
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
Position now_y_left(p->pos->x, p->pos->y + ((p->CELL / 2) - 1));
|
376
|
+
|
377
|
+
Position future_y_left(p->pos->x, p->pos->y + ((p->CELL / 2) - 1 ) + offset_y);
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
Position now_y_right(p->pos->x + (p->CELL - 1), p->pos->y + ((p->CELL / 2) - 1));
|
382
|
+
|
383
|
+
Position future_y_right(p->pos->x + (p->CELL - 1), p->pos->y + ((p->CELL / 2) - 1 ) + offset_y);
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
ofs << future_y_left.y << std::endl;
|
388
|
+
|
389
|
+
ofs << future_y_right.y << std::endl;
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
r = cross_pos(&Result,now_y_left,future_y_left,
|
394
|
+
|
395
|
+
Position( (x * p->CELL), (y * p->CELL) + ((p->CELL / 2) - 1)),Position((x * p->CELL) + (p->CELL - 1), (y * p->CELL) + ((p->CELL / 2) ) - 1 ));
|
396
|
+
|
397
|
+
if(r != 0)
|
398
|
+
|
399
|
+
{
|
400
|
+
|
401
|
+
NoCol_y = false;
|
402
|
+
|
403
|
+
DrawFormatString(350, 600, GetColor(255, 255, 255), "now_y_left", true);
|
404
|
+
|
405
|
+
ofs<<"y_col left"<<std::endl;
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
/*落下*/
|
410
|
+
|
411
|
+
if (p->speed->y > 0)
|
412
|
+
|
413
|
+
{
|
414
|
+
|
415
|
+
Fix_y_left = (Result->y - ((p->CELL) + ((p->CELL / 2)) - 1));
|
416
|
+
|
417
|
+
//ofs << Fix_y_left->y << std::endl;
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
// p->speed->y = 0;
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
p->isGround = true;
|
426
|
+
|
427
|
+
p->isJump = false;
|
428
|
+
|
429
|
+
}
|
430
|
+
|
431
|
+
/*ジャンプ*/
|
432
|
+
|
433
|
+
else if (p->speed->y < 0) {
|
434
|
+
|
435
|
+
//p->speed->y = 0;
|
436
|
+
|
437
|
+
Fix_y_left = Result->y + ((p->CELL / 2) + 1);
|
438
|
+
|
439
|
+
// ofs<<Fix_y_left<<std::endl;
|
440
|
+
|
441
|
+
}
|
442
|
+
|
443
|
+
|
444
|
+
|
445
|
+
delete(Result);
|
446
|
+
|
447
|
+
Result = NULL;
|
448
|
+
|
449
|
+
}
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
r = cross_pos(&Result, now_y_right, future_y_right,
|
454
|
+
|
455
|
+
Position((x * p->CELL), (y * p->CELL) + ((p->CELL / 2) - 1)), Position((x * p->CELL) + (p->CELL - 1), (y * p->CELL) + ((p->CELL / 2) - 1)));
|
456
|
+
|
457
|
+
if (r != 0)
|
458
|
+
|
459
|
+
{
|
460
|
+
|
461
|
+
ofs << "y_col right" << std::endl;
|
462
|
+
|
463
|
+
NoCol_y = false;
|
464
|
+
|
465
|
+
DrawFormatString(350, 300, GetColor(255, 255, 255), "now_y_right", true);
|
466
|
+
|
467
|
+
|
468
|
+
|
469
|
+
/*ジャンプ*/
|
470
|
+
|
471
|
+
if(p->speed->y < 0)
|
472
|
+
|
473
|
+
{
|
474
|
+
|
475
|
+
Fix_y_right = Result->y - ( (p->CELL) + ( (p->CELL / 2) - 1));
|
476
|
+
|
477
|
+
ofs << Fix_y_right << std::endl;
|
478
|
+
|
479
|
+
// p->speed->y = 0;
|
480
|
+
|
481
|
+
|
482
|
+
|
483
|
+
/*落下*/
|
484
|
+
|
485
|
+
}else if (p->speed->y > 0) {
|
486
|
+
|
487
|
+
// p->speed->y = 0;
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
Fix_y_right = Result->y + ((p->CELL / 2) - 1);
|
492
|
+
|
493
|
+
p->isGround = true;
|
494
|
+
|
495
|
+
p->isJump = false;
|
496
|
+
|
497
|
+
|
498
|
+
|
499
|
+
// ofs << Fix_y_right->y << std::endl;
|
500
|
+
|
501
|
+
}
|
502
|
+
|
503
|
+
|
504
|
+
|
505
|
+
|
506
|
+
|
507
|
+
|
508
|
+
|
509
|
+
}
|
510
|
+
|
511
|
+
|
512
|
+
|
513
|
+
/* Y 補正 */
|
514
|
+
|
515
|
+
if(Fix_y_left != -1 || Fix_y_right != -1)
|
516
|
+
|
517
|
+
{
|
518
|
+
|
519
|
+
/*落下*/
|
520
|
+
|
521
|
+
if(p->speed->y > 0){
|
522
|
+
|
523
|
+
if(Fix_y_left == -1)
|
524
|
+
|
525
|
+
{
|
526
|
+
|
527
|
+
p->pos->y = Fix_y_right;
|
528
|
+
|
529
|
+
}else if(Fix_y_right == -1)
|
530
|
+
|
531
|
+
{
|
532
|
+
|
533
|
+
p->pos->y = Fix_y_left;
|
534
|
+
|
535
|
+
}else{
|
536
|
+
|
537
|
+
if(Fix_y_left < Fix_y_right)
|
538
|
+
|
539
|
+
{
|
540
|
+
|
541
|
+
p->pos->y = Fix_y_left;
|
542
|
+
|
543
|
+
}else{
|
544
|
+
|
545
|
+
p->pos->y = Fix_y_right;
|
546
|
+
|
547
|
+
}
|
548
|
+
|
549
|
+
}
|
550
|
+
|
551
|
+
/*ジャンプ */
|
552
|
+
|
553
|
+
}else if (p->speed->y < 0) {
|
554
|
+
|
555
|
+
p->speed->y = 0;
|
556
|
+
|
557
|
+
|
558
|
+
|
559
|
+
if (Fix_y_left == -1)
|
560
|
+
|
561
|
+
{
|
562
|
+
|
563
|
+
p->pos->y = Fix_y_right;
|
564
|
+
|
565
|
+
}
|
566
|
+
|
567
|
+
else if (Fix_y_right == -1)
|
568
|
+
|
569
|
+
{
|
570
|
+
|
571
|
+
p->pos->y = Fix_y_left;
|
572
|
+
|
573
|
+
}
|
574
|
+
|
575
|
+
else {
|
576
|
+
|
577
|
+
if (Fix_y_left < Fix_y_right)
|
578
|
+
|
579
|
+
{
|
580
|
+
|
581
|
+
p->pos->y = Fix_y_right;
|
582
|
+
|
583
|
+
}
|
584
|
+
|
585
|
+
else {
|
586
|
+
|
587
|
+
p->pos->y = Fix_y_left;
|
588
|
+
|
589
|
+
}
|
590
|
+
|
591
|
+
}
|
592
|
+
|
593
|
+
}
|
594
|
+
|
595
|
+
}
|
596
|
+
|
597
|
+
|
598
|
+
|
599
|
+
|
600
|
+
|
601
|
+
}
|
602
|
+
|
603
|
+
}
|
604
|
+
|
605
|
+
}
|
606
|
+
|
607
|
+
}
|
608
|
+
|
609
|
+
|
610
|
+
|
611
|
+
|
612
|
+
|
613
|
+
|
614
|
+
|
615
|
+
|
616
|
+
|
617
|
+
if(NoCol_x == true)
|
618
|
+
|
619
|
+
{
|
620
|
+
|
621
|
+
float xx = p->speed->x;
|
622
|
+
|
623
|
+
p->pos->x += xx;
|
624
|
+
|
625
|
+
|
626
|
+
|
627
|
+
}
|
628
|
+
|
629
|
+
|
630
|
+
|
631
|
+
if (NoCol_y == true)
|
632
|
+
|
633
|
+
{
|
634
|
+
|
635
|
+
float yy = p->speed->y;
|
636
|
+
|
637
|
+
p->pos->y += yy;
|
638
|
+
|
639
|
+
|
20
640
|
|
21
641
|
|
22
642
|
|
23
643
|
}
|
24
644
|
|
645
|
+
|
646
|
+
|
647
|
+
|
648
|
+
|
649
|
+
|
650
|
+
|
651
|
+
}
|
652
|
+
|
653
|
+
/****************************************************************************************************************************/
|
654
|
+
|
655
|
+
///////////////////////////////////////////////////////////Move()関数部
|
656
|
+
|
25
|
-
|
657
|
+
void Player::Move(keyState key,keyState action)
|
26
|
-
|
658
|
+
|
27
|
-
|
659
|
+
{
|
28
|
-
|
660
|
+
|
29
|
-
|
661
|
+
if (key == keyState::Left)
|
662
|
+
|
663
|
+
{
|
664
|
+
|
665
|
+
Direction->x = -1;
|
666
|
+
|
667
|
+
speed->x = m * Direction->x;
|
668
|
+
|
669
|
+
}
|
670
|
+
|
671
|
+
else if(key == keyState::Right) {
|
672
|
+
|
673
|
+
Direction->x = 1;
|
674
|
+
|
675
|
+
speed->x = m * Direction->x;
|
676
|
+
|
677
|
+
}
|
678
|
+
|
679
|
+
else if (key == keyState::Invalid)
|
680
|
+
|
681
|
+
{
|
682
|
+
|
683
|
+
Direction->x = 0;
|
684
|
+
|
685
|
+
speed->x = 0;
|
686
|
+
|
687
|
+
}
|
688
|
+
|
689
|
+
|
690
|
+
|
691
|
+
//const float jd = 100;
|
692
|
+
|
693
|
+
|
694
|
+
|
695
|
+
|
696
|
+
|
697
|
+
if (action == keyState::Jump && isGround == true && isJump == false)
|
698
|
+
|
699
|
+
{
|
700
|
+
|
701
|
+
ofs2<<"isJump"<<std::endl;
|
702
|
+
|
703
|
+
|
704
|
+
|
705
|
+
isGround = false;
|
706
|
+
|
707
|
+
isJump = true;
|
708
|
+
|
709
|
+
speed->y = -20.0f;
|
710
|
+
|
711
|
+
}
|
712
|
+
|
713
|
+
|
714
|
+
|
715
|
+
|
716
|
+
|
717
|
+
|
718
|
+
|
719
|
+
if(isGround == false)
|
720
|
+
|
721
|
+
{
|
722
|
+
|
723
|
+
|
724
|
+
|
725
|
+
t = 0.6;
|
726
|
+
|
727
|
+
g = 2.5;
|
728
|
+
|
729
|
+
vo = 0.4;
|
730
|
+
|
731
|
+
|
30
732
|
|
31
733
|
|
32
734
|
|
735
|
+
float tt = speed->y + vo * t + 0.5 * g * t * t;
|
736
|
+
|
737
|
+
|
738
|
+
|
739
|
+
if(tt < 30)
|
740
|
+
|
741
|
+
{
|
742
|
+
|
743
|
+
speed->y = speed->y + vo * t + 0.5 * g * t * t;
|
744
|
+
|
33
|
-
}
|
745
|
+
}
|
34
|
-
|
746
|
+
|
747
|
+
|
748
|
+
|
35
|
-
else
|
749
|
+
}else{
|
36
|
-
|
750
|
+
|
37
|
-
|
751
|
+
speed->y = 0;
|
38
|
-
|
39
|
-
|
40
752
|
|
41
753
|
}
|
42
754
|
|
43
755
|
|
44
756
|
|
757
|
+
|
758
|
+
|
45
759
|
|
46
760
|
|
761
|
+
|
762
|
+
|
763
|
+
|
764
|
+
|
47
|
-
|
765
|
+
//////////////////////////////////////////////////////////////////
|
48
|
-
|
766
|
+
|
49
|
-
|
767
|
+
//ofs2<< "speed->x: " << speed->x << std::endl;
|
50
|
-
|
51
|
-
|
768
|
+
|
52
|
-
|
53
|
-
action = keyState::Jump;
|
54
|
-
|
55
|
-
|
769
|
+
//ofs2<<"speed->y: "<<speed->y<<std::endl;
|
56
|
-
|
57
|
-
|
770
|
+
|
58
|
-
|
59
|
-
|
771
|
+
//////////////////////////////////////////////////////////////////
|
60
|
-
|
61
|
-
}
|
62
|
-
|
63
|
-
p->Move(key,action);
|
64
|
-
|
65
|
-
|
66
772
|
|
67
773
|
|
68
774
|
|
@@ -70,640 +776,4 @@
|
|
70
776
|
|
71
777
|
|
72
778
|
|
73
|
-
const char* str = "Log.txt";
|
74
|
-
|
75
|
-
std::ofstream ofs(str);
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
/*当たり判定処理 関数*/
|
84
|
-
|
85
|
-
void Game::Collision_Update()
|
86
|
-
|
87
|
-
{
|
88
|
-
|
89
|
-
Position *Result = NULL;
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
float offset_x = 0;
|
94
|
-
|
95
|
-
float offset_y = 0;
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
/*移動方向によって異なる*/
|
100
|
-
|
101
|
-
if(p->speed->x > 0)//右
|
102
|
-
|
103
|
-
{
|
104
|
-
|
105
|
-
offset_x = ((p->CELL) + p->speed->x );
|
106
|
-
|
107
|
-
}else if (p->speed->x < 0)//左
|
108
|
-
|
109
|
-
{
|
110
|
-
|
111
|
-
float t = (p->CELL) * - 1;//符号を逆にするマイナス
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
offset_x = (t + p->speed->x);
|
116
|
-
|
117
|
-
// ofs<<offset_x<<std::endl;
|
118
|
-
|
119
|
-
}else{
|
120
|
-
|
121
|
-
offset_x = 0;
|
122
|
-
|
123
|
-
}
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
//if(action == keyState::Jump)
|
128
|
-
|
129
|
-
if(p->speed->y < 0)
|
130
|
-
|
131
|
-
{
|
132
|
-
|
133
|
-
offset_y = - ((p->CELL - 1 ) - p->speed->y );
|
134
|
-
|
135
|
-
//}else if (action == keyState::Down)
|
136
|
-
|
137
|
-
}else if (p->speed->y > 0)
|
138
|
-
|
139
|
-
{/*落下*/
|
140
|
-
|
141
|
-
offset_y = ((p->CELL) + p->speed->y);
|
142
|
-
|
143
|
-
//ofs<<offset_y <<std::endl;
|
144
|
-
|
145
|
-
}
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
/* Y 軸 */
|
154
|
-
|
155
|
-
// Position* now_y_left = new Position(p->pos->x, p->pos->y + ((p->CELL / 2) - 1));
|
156
|
-
|
157
|
-
// Position* future_y_left = new Position(p->pos->x, p->pos->y + ((p->CELL / 2) - 2) + offset_y);
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
// Position* now_y_right = new Position(p->pos->x + (p->CELL - 1), p->pos->y + ((p->CELL / 2) - 1));
|
162
|
-
|
163
|
-
// Position* future_y_right = new Position(p->pos->x + (p->CELL - 1), p->pos->y + ((p->CELL / 2) - 2) + offset_y);
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
//ofs << "future_x_up: " << future_x_up.x << std::endl;
|
170
|
-
|
171
|
-
// ofs << "future_x_down: " << future_x_down.x << std::endl;
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
bool NoCol_x = true;
|
178
|
-
|
179
|
-
bool NoCol_y = true;
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
/**********************************************当たり判定***********************************************************************/
|
188
|
-
|
189
|
-
for (int y = 0; y < 100; y++) {
|
190
|
-
|
191
|
-
for (int x = 0;x < 100; x++) {
|
192
|
-
|
193
|
-
if (m->isMap(Position((float)x,(float)y)) == true) {
|
194
|
-
|
195
|
-
float Fix_x_up = -1;
|
196
|
-
|
197
|
-
float Fix_x_down = -1;
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
float Fix_y_left = -1;
|
202
|
-
|
203
|
-
float Fix_y_right = -1;
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
/* X 軸 */
|
208
|
-
|
209
|
-
Position now_x_up(p->pos->x + ((p->CELL / 2) - 1), p->pos->y);
|
210
|
-
|
211
|
-
Position future_x_up((p->pos->x + ((p->CELL / 2) - 1)) + offset_x, p->pos->y);
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
Position now_x_down(p->pos->x + ((p->CELL / 2) - 1), (p->pos->y + (p->CELL - 1)));
|
216
|
-
|
217
|
-
Position future_x_down((p->pos->x + ((p->CELL / 2) - 1)) + offset_x, (p->pos->y + (p->CELL - 1)));
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
/*=================空中に居る時で 左右に"動いているとき"=================*/
|
224
|
-
|
225
|
-
//if (p->isGround == false && p->isJump == true)
|
226
|
-
|
227
|
-
if(true)
|
228
|
-
|
229
|
-
{
|
230
|
-
|
231
|
-
// ofs << "Collisition " << std::endl;
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
DrawFormatString(400, 400, GetColor(255, 255, 255), "Collisition",true);
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
int r = cross_pos(&Result, now_x_up, future_x_up,
|
240
|
-
|
241
|
-
Position((x * p->CELL) + ( (p->CELL / 2) - 1),y * p->CELL), Position((x * p->CELL) + ((p->CELL / 2) - 1), ((y + 1) * p->CELL) - 1 ));
|
242
|
-
|
243
|
-
if( r != 0)
|
244
|
-
|
245
|
-
{
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
NoCol_x = false;
|
250
|
-
|
251
|
-
DrawFormatString(400, 400, GetColor(255, 255, 255), "now_x_up", true);
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
if(p->speed->x > 0){
|
256
|
-
|
257
|
-
Fix_x_up = Result->x - ( (p->CELL - 1) + (p->CELL /2) );
|
258
|
-
|
259
|
-
//ix_x_up = now_x_up.x;
|
260
|
-
|
261
|
-
}else if(p->speed->x < 0)
|
262
|
-
|
263
|
-
{
|
264
|
-
|
265
|
-
Fix_x_up = Result->x + (p->CELL / 2) + 1;
|
266
|
-
|
267
|
-
//Fix_x_up = now_x_up.x;
|
268
|
-
|
269
|
-
}
|
270
|
-
|
271
|
-
delete(Result);
|
272
|
-
|
273
|
-
Result = NULL;
|
274
|
-
|
275
|
-
}
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
if(p->isGround == false){
|
282
|
-
|
283
|
-
r = cross_pos(&Result, now_x_down, future_x_down,
|
284
|
-
|
285
|
-
Position( (x * p->CELL) + ((p->CELL / 2) - 1), y * p->CELL), Position((x * p->CELL) + ((p->CELL / 2) - 1), ((y + 1) * p->CELL) - 1));
|
286
|
-
|
287
|
-
if (r != 0)
|
288
|
-
|
289
|
-
{
|
290
|
-
|
291
|
-
NoCol_x = false;
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
DrawFormatString(400, 500, GetColor(255, 255, 255), "now_x_down", true);
|
296
|
-
|
297
|
-
if (p->speed->x > 0) {
|
298
|
-
|
299
|
-
Fix_x_down = Result->x - ((p->CELL - 1) + (p->CELL / 2));
|
300
|
-
|
301
|
-
//Fix_x_down = now_x_down.x;
|
302
|
-
|
303
|
-
}else if (p->speed->x < 0) {
|
304
|
-
|
305
|
-
Fix_x_down = Result->x + (p->CELL / 2) + 1;
|
306
|
-
|
307
|
-
//Fix_x_down = now_x_down.x;
|
308
|
-
|
309
|
-
}
|
310
|
-
|
311
|
-
delete(Result);
|
312
|
-
|
313
|
-
Result = NULL;
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
}
|
318
|
-
|
319
|
-
}
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
/*X 補正*/
|
324
|
-
|
325
|
-
if (Fix_x_up != -1 || Fix_x_down != -1)
|
326
|
-
|
327
|
-
{
|
328
|
-
|
329
|
-
if (p->speed->x > 0)/*右*/
|
330
|
-
|
331
|
-
{
|
332
|
-
|
333
|
-
if (Fix_x_up == -1)
|
334
|
-
|
335
|
-
{
|
336
|
-
|
337
|
-
p->pos->x = Fix_x_down;
|
338
|
-
|
339
|
-
}
|
340
|
-
|
341
|
-
else if(Fix_x_down == -1)
|
342
|
-
|
343
|
-
{
|
344
|
-
|
345
|
-
p->pos->x = Fix_x_up;
|
346
|
-
|
347
|
-
}
|
348
|
-
|
349
|
-
else {
|
350
|
-
|
351
|
-
if (Fix_x_up < Fix_x_down)
|
352
|
-
|
353
|
-
{
|
354
|
-
|
355
|
-
p->pos->x = Fix_x_up;
|
356
|
-
|
357
|
-
}
|
358
|
-
|
359
|
-
else
|
360
|
-
|
361
|
-
{
|
362
|
-
|
363
|
-
p->pos->x = Fix_x_down;
|
364
|
-
|
365
|
-
}
|
366
|
-
|
367
|
-
}
|
368
|
-
|
369
|
-
}
|
370
|
-
|
371
|
-
else if (p->speed->x < 0)/*左*/
|
372
|
-
|
373
|
-
{
|
374
|
-
|
375
|
-
if (Fix_x_up == -1)
|
376
|
-
|
377
|
-
{
|
378
|
-
|
379
|
-
p->pos->x = Fix_x_down;
|
380
|
-
|
381
|
-
}
|
382
|
-
|
383
|
-
else if (Fix_x_down == -1)
|
384
|
-
|
385
|
-
{
|
386
|
-
|
387
|
-
p->pos->x = Fix_x_up;
|
388
|
-
|
389
|
-
}
|
390
|
-
|
391
|
-
else {
|
392
|
-
|
393
|
-
if (Fix_x_up < Fix_x_down)
|
394
|
-
|
395
|
-
{
|
396
|
-
|
397
|
-
p->pos->x = Fix_x_down;
|
398
|
-
|
399
|
-
}
|
400
|
-
|
401
|
-
else
|
402
|
-
|
403
|
-
{
|
404
|
-
|
405
|
-
p->pos->x = Fix_x_up;
|
406
|
-
|
407
|
-
}
|
408
|
-
|
409
|
-
}
|
410
|
-
|
411
|
-
}
|
412
|
-
|
413
|
-
}
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
/*********************************************** Y軸 *************************************************************************************/
|
418
|
-
|
419
|
-
/* Y 軸 値設定*/
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
Position now_y_left(p->pos->x, p->pos->y + ((p->CELL / 2) - 1));
|
426
|
-
|
427
|
-
Position future_y_left(p->pos->x, p->pos->y + ((p->CELL / 2) - 1 ) + offset_y);
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
Position now_y_right(p->pos->x + (p->CELL - 1), p->pos->y + ((p->CELL / 2) - 1));
|
432
|
-
|
433
|
-
Position future_y_right(p->pos->x + (p->CELL - 1), p->pos->y + ((p->CELL / 2) - 1 ) + offset_y);
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
ofs << future_y_left.y << std::endl;
|
438
|
-
|
439
|
-
ofs << future_y_right.y << std::endl;
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
r = cross_pos(&Result,now_y_left,future_y_left,
|
444
|
-
|
445
|
-
Position( (x * p->CELL), (y * p->CELL) + ((p->CELL / 2) - 1)),Position((x * p->CELL) + (p->CELL - 1), (y * p->CELL) + ((p->CELL / 2) ) - 1 ));
|
446
|
-
|
447
|
-
if(r != 0)
|
448
|
-
|
449
|
-
{
|
450
|
-
|
451
|
-
NoCol_y = false;
|
452
|
-
|
453
|
-
DrawFormatString(350, 600, GetColor(255, 255, 255), "now_y_left", true);
|
454
|
-
|
455
|
-
ofs<<"y_col left"<<std::endl;
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
/*落下*/
|
460
|
-
|
461
|
-
if (p->speed->y > 0)
|
462
|
-
|
463
|
-
{
|
464
|
-
|
465
|
-
Fix_y_left = (Result->y - ((p->CELL) + ((p->CELL / 2)) - 1));
|
466
|
-
|
467
|
-
//ofs << Fix_y_left->y << std::endl;
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
// p->speed->y = 0;
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
p->isGround = true;
|
476
|
-
|
477
|
-
p->isJump = false;
|
478
|
-
|
479
|
-
}
|
480
|
-
|
481
|
-
/*ジャンプ*/
|
482
|
-
|
483
|
-
else if (p->speed->y < 0) {
|
484
|
-
|
485
|
-
//p->speed->y = 0;
|
486
|
-
|
487
|
-
Fix_y_left = Result->y + ((p->CELL / 2) + 1);
|
488
|
-
|
489
|
-
// ofs<<Fix_y_left<<std::endl;
|
490
|
-
|
491
|
-
}
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
delete(Result);
|
496
|
-
|
497
|
-
Result = NULL;
|
498
|
-
|
499
|
-
}
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
r = cross_pos(&Result, now_y_right, future_y_right,
|
504
|
-
|
505
|
-
Position((x * p->CELL), (y * p->CELL) + ((p->CELL / 2) - 1)), Position((x * p->CELL) + (p->CELL - 1), (y * p->CELL) + ((p->CELL / 2) - 1)));
|
506
|
-
|
507
|
-
if (r != 0)
|
508
|
-
|
509
|
-
{
|
510
|
-
|
511
|
-
ofs << "y_col right" << std::endl;
|
512
|
-
|
513
|
-
NoCol_y = false;
|
514
|
-
|
515
|
-
DrawFormatString(350, 300, GetColor(255, 255, 255), "now_y_right", true);
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
/*ジャンプ*/
|
520
|
-
|
521
|
-
if(p->speed->y < 0)
|
522
|
-
|
523
|
-
{
|
524
|
-
|
525
|
-
Fix_y_right = Result->y - ( (p->CELL) + ( (p->CELL / 2) - 1));
|
526
|
-
|
527
|
-
ofs << Fix_y_right << std::endl;
|
528
|
-
|
529
|
-
// p->speed->y = 0;
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
/*落下*/
|
534
|
-
|
535
|
-
}else if (p->speed->y > 0) {
|
536
|
-
|
537
|
-
// p->speed->y = 0;
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
Fix_y_right = Result->y + ((p->CELL / 2) - 1);
|
542
|
-
|
543
|
-
p->isGround = true;
|
544
|
-
|
545
|
-
p->isJump = false;
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
// ofs << Fix_y_right->y << std::endl;
|
550
|
-
|
551
|
-
}
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
}
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
/* Y 補正 */
|
564
|
-
|
565
|
-
if(Fix_y_left != -1 || Fix_y_right != -1)
|
566
|
-
|
567
|
-
{
|
568
|
-
|
569
|
-
/*落下*/
|
570
|
-
|
571
|
-
if(p->speed->y > 0){
|
572
|
-
|
573
|
-
if(Fix_y_left == -1)
|
574
|
-
|
575
|
-
{
|
576
|
-
|
577
|
-
p->pos->y = Fix_y_right;
|
578
|
-
|
579
|
-
}else if(Fix_y_right == -1)
|
580
|
-
|
581
|
-
{
|
582
|
-
|
583
|
-
p->pos->y = Fix_y_left;
|
584
|
-
|
585
|
-
}else{
|
586
|
-
|
587
|
-
if(Fix_y_left < Fix_y_right)
|
588
|
-
|
589
|
-
{
|
590
|
-
|
591
|
-
p->pos->y = Fix_y_left;
|
592
|
-
|
593
|
-
}else{
|
594
|
-
|
595
|
-
p->pos->y = Fix_y_right;
|
596
|
-
|
597
|
-
}
|
598
|
-
|
599
|
-
}
|
600
|
-
|
601
|
-
/*ジャンプ */
|
602
|
-
|
603
|
-
}else if (p->speed->y < 0) {
|
604
|
-
|
605
|
-
p->speed->y = 0;
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
if (Fix_y_left == -1)
|
610
|
-
|
611
|
-
{
|
612
|
-
|
613
|
-
p->pos->y = Fix_y_right;
|
614
|
-
|
615
|
-
}
|
616
|
-
|
617
|
-
else if (Fix_y_right == -1)
|
618
|
-
|
619
|
-
{
|
620
|
-
|
621
|
-
p->pos->y = Fix_y_left;
|
622
|
-
|
623
|
-
}
|
624
|
-
|
625
|
-
else {
|
626
|
-
|
627
|
-
if (Fix_y_left < Fix_y_right)
|
628
|
-
|
629
|
-
{
|
630
|
-
|
631
|
-
p->pos->y = Fix_y_right;
|
632
|
-
|
633
|
-
}
|
634
|
-
|
635
|
-
else {
|
636
|
-
|
637
|
-
p->pos->y = Fix_y_left;
|
638
|
-
|
639
|
-
}
|
640
|
-
|
641
|
-
}
|
642
|
-
|
643
|
-
}
|
644
|
-
|
645
|
-
}
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
}
|
652
|
-
|
653
|
-
}
|
654
|
-
|
655
|
-
}
|
656
|
-
|
657
|
-
}
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
if(NoCol_x == true)
|
668
|
-
|
669
|
-
{
|
670
|
-
|
671
|
-
float xx = p->speed->x;
|
672
|
-
|
673
|
-
p->pos->x += xx;
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
}
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
if (NoCol_y == true)
|
682
|
-
|
683
|
-
{
|
684
|
-
|
685
|
-
float yy = p->speed->y;
|
686
|
-
|
687
|
-
p->pos->y += yy;
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
}
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
}
|
706
|
-
|
707
|
-
/****************************************************************************************************************************/
|
708
|
-
|
709
779
|
```
|