質問編集履歴

4

文章を編集

2019/08/27 18:23

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -32,7 +32,9 @@
32
32
 
33
33
 
34
34
 
35
- ![![イメージ説明](4568273af1b85c9723499ba38ffea5![12.jpe](7d539dabb26695947f5c61e1138a57b7.jpeg)g)](879fa411472eebf71d77a3792a15918a.jpeg)
35
+ ![イメージ説明](9277a5013d6e7073fc64522f6ceb8d9f.jpeg)
36
+
37
+ ![イメージ説明](5ae9a3313f42139457a6c25546852d53.jpeg)
36
38
 
37
39
 
38
40
 
@@ -276,6 +278,488 @@
276
278
 
277
279
  }
278
280
 
279
-
280
-
281
281
  ```
282
+
283
+
284
+
285
+
286
+
287
+
288
+
289
+
290
+
291
+
292
+
293
+
294
+
295
+
296
+
297
+ ```ここに言語を入力
298
+
299
+ #include <iostream>
300
+
301
+ #include <fstream>
302
+
303
+ #include "Input.h"
304
+
305
+ #include "Player.h"
306
+
307
+ #include "DxLib.h"
308
+
309
+ #include "Map.h"
310
+
311
+ #include "Animation.h"
312
+
313
+
314
+
315
+ #define MOVE_SPD 5
316
+
317
+ #define JUMP_FORCE 4.0624 * 3
318
+
319
+
320
+
321
+ static std::ofstream ofs("Log.txt");
322
+
323
+
324
+
325
+ /*コンストラクタ*/
326
+
327
+ Player::Player(const char* str, int xx, int yy)
328
+
329
+ {
330
+
331
+
332
+
333
+ //LoadDivGraph(str,7,7,1,64,64,g_handle);
334
+
335
+ AnimeClip = new Animation(anime_s::ewait,str,7,7,1);
336
+
337
+ pos = new Position();
338
+
339
+ prev = new Position();
340
+
341
+ move = new Position();
342
+
343
+
344
+
345
+ AnimeClip->setAnime(anime_s::ewalk,1,3,3);
346
+
347
+ AnimeClip->setAnime(anime_s::ewait, 0, 0, 1);
348
+
349
+ AnimeClip->setAnime(anime_s::ejump, 5, 5, 1);
350
+
351
+
352
+
353
+
354
+
355
+ }
356
+
357
+
358
+
359
+ /*計算更新*/
360
+
361
+ void Player::Update()
362
+
363
+ {
364
+
365
+
366
+
367
+ gravity();
368
+
369
+
370
+
371
+ input_key();
372
+
373
+ jump_up();
374
+
375
+ //side_move();//
376
+
377
+
378
+
379
+ AnimeClip->Update();
380
+
381
+
382
+
383
+ DrawFormatString(200, 280, GetColor(255, 255, 255), "y %d", pos->get_y());
384
+
385
+ DrawFormatString(200, 360, GetColor(255, 255, 255), "x %d", pos->get_x());
386
+
387
+ // ofs << (double)std::atan2((double)pos->get_x(),(double)pos->get_y()) << std::endl;
388
+
389
+ DrawFormatString(100, 200, GetColor(255, 255, 255), "isGround %d", isGround);
390
+
391
+ DrawFormatString(100, 280, GetColor(255, 255, 255), "isJump %d", isJump);
392
+
393
+
394
+
395
+ ofs << "pos.x: " << pos->get_x() << std::endl;
396
+
397
+ ofs << "pos.y: " << pos->get_y() << std::endl;
398
+
399
+
400
+
401
+ *prev = *pos;
402
+
403
+ }
404
+
405
+
406
+
407
+
408
+
409
+ /*描画更新*/
410
+
411
+ void Player::Draw_Update()
412
+
413
+ {
414
+
415
+
416
+
417
+
418
+
419
+
420
+
421
+ if ( key == -1)
422
+
423
+ {
424
+
425
+ //DrawTurnGraph(get_x(), get_y(), g_handle[0], true);
426
+
427
+ ///////
428
+
429
+ DrawTurnGraph(pos->get_x(), pos->get_y(), AnimeClip->draw_setClip(), true);
430
+
431
+
432
+
433
+ }
434
+
435
+
436
+
437
+ /*右→*/
438
+
439
+ if (key == 1)
440
+
441
+ { ///
442
+
443
+ DrawGraph(pos->get_x(), pos->get_y(), AnimeClip->draw_setClip(), true);
444
+
445
+ }
446
+
447
+
448
+
449
+
450
+
451
+
452
+
453
+
454
+
455
+ AnimeClip->Draw_Update();
456
+
457
+
458
+
459
+
460
+
461
+
462
+
463
+ }
464
+
465
+
466
+
467
+ /*キー入力*/
468
+
469
+ void Player::input_key()
470
+
471
+ {
472
+
473
+ if (keybord(KEY_INPUT_LEFT) > 0)//←
474
+
475
+ {
476
+
477
+
478
+
479
+ key = -1;
480
+
481
+ AnimeClip->Update_changeAnime(anime_s::ewalk,key);
482
+
483
+ pos->set_x(-MOVE_SPD);
484
+
485
+ move->new_pos_x(-MOVE_SPD);
486
+
487
+
488
+
489
+
490
+
491
+ }else if (keybord(KEY_INPUT_RIGHT) > 0)//→
492
+
493
+ {
494
+
495
+
496
+
497
+ key = 1;
498
+
499
+ AnimeClip->Update_changeAnime(anime_s::ewalk,key);
500
+
501
+ move->new_pos_x(MOVE_SPD);
502
+
503
+
504
+
505
+
506
+
507
+ pos->set_x(+MOVE_SPD);
508
+
509
+
510
+
511
+ }else if (keybord(KEY_INPUT_UP) > 0)//上
512
+
513
+ {
514
+
515
+ //pos->set_y(+MOVE_SPD);
516
+
517
+
518
+
519
+ }else if (keybord(KEY_INPUT_DOWN) > 0)//下
520
+
521
+ {
522
+
523
+ // pos->set_y(-MOVE_SPD);
524
+
525
+ }
526
+
527
+
528
+
529
+ else if (keybord(KEY_INPUT_SPACE) > 0)//ジャンプ
530
+
531
+ {
532
+
533
+ //AnimeClip->Update_changeAnime(anime_s::ejump);
534
+
535
+
536
+
537
+ if (isGround == true && jf == 0) {
538
+
539
+ //isJump = true;
540
+
541
+ isGround = false;
542
+
543
+ jf = JUMP_FORCE;
544
+
545
+ }
546
+
547
+
548
+
549
+ AnimeClip->Update_changeAnime(anime_s::ejump);
550
+
551
+
552
+
553
+ }
554
+
555
+ else//何も押していない時
556
+
557
+ {
558
+
559
+
560
+
561
+ move->new_pos_x(0);
562
+
563
+
564
+
565
+ AnimeClip->Update_changeAnime(anime_s::ewait);
566
+
567
+
568
+
569
+ }
570
+
571
+
572
+
573
+
574
+
575
+
576
+
577
+
578
+
579
+ }
580
+
581
+
582
+
583
+ /************************ジャンプ ***********************/
584
+
585
+ void Player::jump_up()
586
+
587
+ {
588
+
589
+ if (Map::Collision::player_col(pos, move) == std::nullopt) {
590
+
591
+
592
+
593
+ if (isGround == false) {
594
+
595
+
596
+
597
+ move->new_pos_y((int)jf);
598
+
599
+ pos->set_y((int)jf);
600
+
601
+
602
+
603
+ //if (Fps::gframe() % 20 == 0) {
604
+
605
+
606
+
607
+ jf = ((jf - 0.126953125f * 20.0f));
608
+
609
+
610
+
611
+ if (jf < -0.126953125f * 3.0f * 10.0f)
612
+
613
+ {
614
+
615
+ jf = -0.126953125f * 3.0f * 10.0f;
616
+
617
+ //pos->set_y();
618
+
619
+ }
620
+
621
+ //}
622
+
623
+ }
624
+
625
+
626
+
627
+ }
628
+
629
+ }
630
+
631
+ /*********************************************************/
632
+
633
+
634
+
635
+
636
+
637
+ /***********************重力*******************************/
638
+
639
+ void Player::gravity()
640
+
641
+ {
642
+
643
+
644
+
645
+
646
+
647
+ /*地面着地*/
648
+
649
+ if (Map::Collision::player_col(pos, move) != std::nullopt)
650
+
651
+ {
652
+
653
+ // ofs << "test\n";
654
+
655
+ std::optional<Position> p = Map::Collision::player_col(pos, move);
656
+
657
+ pos->new_pos_x(p->get_x());
658
+
659
+ pos->new_pos_y(p->get_y());
660
+
661
+
662
+
663
+
664
+
665
+ //pos->set_y(p->get_y());
666
+
667
+ //pos->set_x(-p->get_x());
668
+
669
+
670
+
671
+ // ofs << "under_col true\n";
672
+
673
+
674
+
675
+ }
676
+
677
+ else {
678
+
679
+
680
+
681
+ //ofs << "palyer_col nullopt" <<"\n";
682
+
683
+
684
+
685
+ }
686
+
687
+
688
+
689
+ //落下
690
+
691
+ if (Map::Collision::player_col(pos,move) == std::nullopt)
692
+
693
+
694
+
695
+ //if (Map::Collision::under_col(pos, prev) == std::nullopt && isGround == false)
696
+
697
+ {
698
+
699
+
700
+
701
+ //DrawFormatString(200, 200, GetColor(255, 255, 255), "x %d", pos->get_x());
702
+
703
+
704
+
705
+ //if (Map::Collision::player_col(pos, move) == std::nullopt) {
706
+
707
+ if (isGround == false) {
708
+
709
+ move->new_pos_y((int)jf);
710
+
711
+ pos->set_y((int)jf);
712
+
713
+
714
+
715
+ jf = ((jf - 0.126953125f * 20.0f));
716
+
717
+
718
+
719
+ if (jf < -0.126953125f * 3.0f * 10.0f)
720
+
721
+ {
722
+
723
+ jf = -0.126953125f * 3.0f * 10.0f;
724
+
725
+ //pos->set_y();
726
+
727
+ }
728
+
729
+ }
730
+
731
+ else {
732
+
733
+
734
+
735
+ }
736
+
737
+ // }
738
+
739
+
740
+
741
+ }
742
+
743
+
744
+
745
+
746
+
747
+
748
+
749
+
750
+
751
+
752
+
753
+ }
754
+
755
+ /**********************************************************/
756
+
757
+
758
+
759
+
760
+
761
+
762
+
763
+
764
+
765
+ ```

3

画像を追加

2019/08/27 18:23

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -10,19 +10,29 @@
10
10
 
11
11
  また水平に並んだブロックに上から下と右に移動しながら進んできた時に上に座標をずらすといった処理を書きたいのですがどうしたらいいのか実装が思いつかないのですが教えてくれますでしょうか?
12
12
 
13
+
14
+
15
+ 画像:画像の青がプレイやーで端が紫の青いブロックは移動してる時つまりプレイヤーに移動速度してる情報が追加されたときの画像で赤がブロックです。
16
+
17
+
18
+
19
+ 環境:dxlibです右がx++で下がy++の座標系です。2Dです。
20
+
21
+ player_col()部です。
22
+
23
+
24
+
25
+
26
+
27
+
28
+
13
29
  追記ですが下にブロックがあり右の真横にもブロックがる場合上に上がってしましますこれはどうすればいいのでしょうか?
14
30
 
15
-
31
+ 画像の場所です。
16
-
32
+
33
+
34
+
17
- 画像:画像の青がプレで端が紫の青いブロックは移動してる時つまりプレイヤーに移動速度してる情報が追加されたときの画像で赤がブロックです。
35
+ ![![ジ説明](4568273af1b85c9723499ba38ffea5![12.jpe](7d539dabb26695947f5c61e1138a57b7.jpeg)g)](879fa411472eebf71d77a3792a15918a.jpeg)
18
-
19
-
20
-
21
- 環境:dxlibです右がx++で下がy++の座標系です。2Dです。
22
-
23
-
24
-
25
-
26
36
 
27
37
 
28
38
 
@@ -40,15 +50,119 @@
40
50
 
41
51
 
42
52
 
53
+ Position Map::Collision::isMapCell(const Position pos)
54
+
55
+ {
56
+
57
+ Position p;
58
+
59
+ for (int y = 0; y < MAP_HEIGHT; y++)
60
+
61
+ {
62
+
63
+ for (int x = 0; x < MAP_WIDTH; x++)
64
+
65
+ {
66
+
67
+
68
+
69
+ }
70
+
71
+ }
72
+
73
+
74
+
75
+ if (get_mapCell(pos.get_x() / CELL, pos.get_y() / CELL) == (int)mapChip::eBrick ||
76
+
77
+ get_mapCell(pos.get_x() / CELL, pos.get_y() / CELL) == (int)mapChip::eQuestion)
78
+
79
+ {
80
+
81
+
82
+
83
+ p.new_pos_x((pos.get_x() / CELL));
84
+
85
+ p.new_pos_y((pos.get_y() / CELL));
86
+
87
+ ofs << "p.get_x(): " << p.get_x() << std::endl;
88
+
89
+ ofs << "p.get_y(): " << p.get_y() << std::endl;
90
+
91
+
92
+
93
+ return p;
94
+
95
+
96
+
97
+ }
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+ return Position(-1,-1);
110
+
111
+ }
112
+
113
+
114
+
115
+ //座標が引数
116
+
117
+
118
+
119
+ std::optional<Position> Map::Collision::col(const Position p)
120
+
121
+ {
122
+
123
+ Position c_pos(Map::Collision::isMapCell(p));
124
+
125
+
126
+
127
+ if (c_pos.get_x() > -1 && c_pos.get_y() > -1) {
128
+
129
+ if (c_pos.get_x() * CELL <= p.get_x() && (c_pos.get_x() * CELL) + CELL >= p.get_x() )
130
+
131
+ {
132
+
133
+
134
+
135
+ }
136
+
137
+ }
138
+
139
+
140
+
141
+
142
+
143
+
144
+
145
+ return std::nullopt;
146
+
147
+ }
148
+
149
+
150
+
43
151
  /*全方位の当たり判定 return セル番号を返す*/
44
152
 
45
153
  std::optional<Position> Map::Collision::player_col(const Position *pos,const Position *move)
46
154
 
47
155
  {
48
156
 
157
+ Position p;
158
+
49
- //int px = pos->get_x() + move->get_x();
159
+ p.new_pos_x( pos->get_x() + move->get_x() + CELL);
50
-
160
+
51
- //int py = pos->get_y() + move->get_y();
161
+ p.new_pos_y( pos->get_y() + move->get_y() + CELL);
162
+
163
+
164
+
165
+ static bool isground = false;
52
166
 
53
167
 
54
168
 
@@ -58,15 +172,17 @@
58
172
 
59
173
 
60
174
 
175
+
176
+
61
- int add_x = move->get_x();
177
+ int add_x = move->get_x();
62
-
178
+
63
- int add_y = (int)move->get_y();
179
+ int add_y = (int)move->get_y();
64
-
65
-
66
-
180
+
181
+
182
+
67
- ofs << "move->get_x(): " << move->get_x()<<"\n";
183
+ // ofs << "move->get_x(): " << move->get_x()<<"\n";
68
-
184
+
69
- ofs << "move->get_y(): " << move->get_y() << "\n";
185
+ // ofs << "move->get_y(): " << move->get_y() << "\n";
70
186
 
71
187
 
72
188
 
@@ -76,76 +192,90 @@
76
192
 
77
193
 
78
194
 
79
- // ofs <<"aaa"<< px << "\n";
195
+
80
-
81
-
82
-
196
+
197
+
198
+
199
+
200
+
201
+
202
+
83
- for (int y = 0; y < MAP_HEIGHT; y++)
203
+ Position pp = Map::Collision::isMapCell(p);
84
-
204
+
85
- {
205
+ if (pp.get_x() > -1) {
86
-
206
+
207
+
208
+
87
- for (int x = 0; x < MAP_WIDTH; x++)
209
+ if (move->get_x() > 0)
88
210
 
89
211
  {
90
212
 
213
+
214
+
215
+ //ofs << "x補正" << std::endl;
216
+
217
+ //px = pos->get_x() -CELL;
218
+
219
+
220
+
221
+ }
222
+
223
+
224
+
91
- if (get_mapCell(x, y) == (int)mapChip::eBrick || get_mapCell(x, y) == (int)mapChip::eQuestion)
225
+ //ofs << "playe_col isground: " << isground << std::endl;
226
+
227
+
228
+
92
-
229
+ if ((move->get_y() < 0))
230
+
93
- {
231
+ {
232
+
94
-
233
+ ofs << "ground " << std::endl;
234
+
235
+
236
+
95
- if (
237
+ isground = true;
96
-
238
+
239
+
240
+
97
- (pos->get_x() <= (x * CELL) && (pos->get_x() + CELL + add_x) >= (x * CELL) ||
241
+ //py -= ((pos->get_y() + (-move->get_y()) + CELL) - (pp.get_y() * CELL));
98
-
242
+
99
- pos->get_x() >= (x * CELL) && pos->get_x() <= (x * CELL) + CELL)
243
+ //ofs << "pp.get_y(): " << ((pos->get_y() + (-move->get_y()) + CELL) - (pp.get_y() * CELL));
100
-
101
-
102
-
103
- &&
244
+
104
-
245
+
246
+
105
- (pos->get_y() <= (y * CELL) && (pos->get_y() + CELL + add_y) >= (y * CELL) ||
247
+ int yy = ((pos->get_y() + (-move->get_y()) + CELL) - ((pp.get_y() * CELL)));
106
-
248
+
107
- pos->get_y() >= (y * CELL) && pos->get_y() <= (y * CELL) + CELL )
249
+ py -= yy;
108
-
250
+
109
- )
251
+ }
110
-
111
- {
252
+
112
-
113
-
114
-
115
-                     //ここに記入すべきコード
253
+
116
-
117
-
118
-
254
+
255
+
256
+
257
+
258
+
119
- std::optional<Position> p = Position(px, py);
259
+ std::optional<Position> p = Position(px, py);
120
-
260
+
121
- return p.value();//セルを返す
261
+ return p.value();//セルを返す
122
-
123
- // return true;
124
-
125
- }
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
- }
134
-
135
- //pos->get_x() <= (x * CELL) && pos->get_x() + CELL >= (x * CELL)
136
-
137
- }
138
262
 
139
263
  }
140
264
 
141
265
 
142
266
 
267
+
268
+
269
+
270
+
271
+
272
+
273
+
274
+
143
275
  return std::nullopt;
144
276
 
145
277
  }
146
278
 
147
279
 
148
280
 
149
-
150
-
151
281
  ```

2

文章を編集し質問内容をつかきしました。

2019/08/27 18:21

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  また水平に並んだブロックに上から下と右に移動しながら進んできた時に上に座標をずらすといった処理を書きたいのですがどうしたらいいのか実装が思いつかないのですが教えてくれますでしょうか?
12
12
 
13
-
13
+ 追記ですが下にブロックがあり右の真横にもブロックがる場合上に上がってしましますこれはどうすればいいのでしょうか?
14
14
 
15
15
 
16
16
 

1

指摘通り文章を編集

2019/08/27 16:04

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- ベクトルを使った当たり判定のコードで画面で真横の壁に当たっときの上に上がってしまう修正実装が知りたい
1
+ ベクトルを使った当たり判定の実装方法が知りたい
test CHANGED
@@ -1,6 +1,26 @@
1
- コードが長いので断片的な部分だけ修正しました。コメント部のここでコードなのですが真横の壁に当たると左に補正されることは実装できたのですが同時に真横の壁の上に座標が修正されてしまいますこれを修正するにはどのようにコードなコードを書くべきなのでしょうか?
1
+ ![イメージ説明](78ebd99a2f9d628381c57f439ded137e.jpeg)コードが長いので断片的な部分だけです、コメント部の記入べきコードです
2
2
 
3
+
4
+
5
+
6
+
7
+ 2Dアクションゲームでベクトルを使って移動した時にブロックや他の画像と重なってしまういわゆる"めり込み"の修正方が知りたいです。自分はベクトルを使い方向の情報を使ってぶつかってきた方向に追い返す処理を考えました。
8
+
3
- またなだか同じよことをやっている気がてコードがスマートありませんこの辺の改善方法が知りたいです。
9
+ 図の場合は右と下に進でいるのでその逆の左上に追い返す(座標をずらす)ということをしたいです。
10
+
11
+ また水平に並んだブロックに上から下と右に移動しながら進んできた時に上に座標をずらすといった処理を書きたいのですがどうしたらいいのか実装が思いつかないのですが教えてくれますでしょうか?
12
+
13
+
14
+
15
+
16
+
17
+ 画像:画像の青がプレイやーで端が紫の青いブロックは移動してる時つまりプレイヤーに移動速度してる情報が追加されたときの画像で赤がブロックです。
18
+
19
+
20
+
21
+ 環境:dxlibです右がx++で下がy++の座標系です。2Dです。
22
+
23
+
4
24
 
5
25
 
6
26
 
@@ -92,69 +112,9 @@
92
112
 
93
113
 
94
114
 
95
- if (pos->get_x() <= (x * CELL) && (pos->get_x() + CELL + add_x) >= (x * CELL))
96
-
97
- {
98
-
99
-
100
-
101
-
102
-
103
- if (add_x > 0) {
115
+                     //ここに記入すべきコード
104
-
105
- corr_x = (pos->get_x() + CELL + add_x) - (x * CELL);
106
-
107
-
108
-
109
- if (corr_x <= 0)
110
-
111
- {
112
-
113
- corr_x = 0;
114
-
115
- }
116
-
117
-
118
-
119
-
120
-
121
- px -= corr_x;
122
-
123
- }
124
116
 
125
117
 
126
-
127
-
128
-
129
- }
130
-
131
- //ここのコードです。
132
-
133
- if (pos->get_y() <= (y * CELL) && (pos->get_y() + CELL + add_y) >= (y * CELL))
134
-
135
- {
136
-
137
- //if (add_x == 0) {
138
-
139
- ofs << "add_x: " << add_x << std::endl;
140
-
141
- corr_y = (pos->get_y() + CELL + add_y) - (y * CELL);
142
-
143
- if (corr_y < 0) { corr_y = 0; }
144
-
145
- ofs << "corr_y : " << corr_y << std::endl;
146
-
147
-
148
-
149
- py -= (corr_y + 3);
150
-
151
- //}
152
-
153
- }
154
-
155
-
156
-
157
-
158
118
 
159
119
  std::optional<Position> p = Position(px, py);
160
120