質問編集履歴
4
文章を編集
title
CHANGED
File without changes
|
body
CHANGED
@@ -15,7 +15,8 @@
|
|
15
15
|
追記ですが下にブロックがあり右の真横にもブロックがる場合上に上がってしましますこれはどうすればいいのでしょうか?
|
16
16
|
画像の場所です。
|
17
17
|
|
18
|
-

|
19
|
+

|
19
20
|
|
20
21
|
|
21
22
|
|
@@ -137,5 +138,246 @@
|
|
137
138
|
|
138
139
|
return std::nullopt;
|
139
140
|
}
|
141
|
+
```
|
140
142
|
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
```ここに言語を入力
|
150
|
+
#include <iostream>
|
151
|
+
#include <fstream>
|
152
|
+
#include "Input.h"
|
153
|
+
#include "Player.h"
|
154
|
+
#include "DxLib.h"
|
155
|
+
#include "Map.h"
|
156
|
+
#include "Animation.h"
|
157
|
+
|
158
|
+
#define MOVE_SPD 5
|
159
|
+
#define JUMP_FORCE 4.0624 * 3
|
160
|
+
|
161
|
+
static std::ofstream ofs("Log.txt");
|
162
|
+
|
163
|
+
/*コンストラクタ*/
|
164
|
+
Player::Player(const char* str, int xx, int yy)
|
165
|
+
{
|
166
|
+
|
167
|
+
//LoadDivGraph(str,7,7,1,64,64,g_handle);
|
168
|
+
AnimeClip = new Animation(anime_s::ewait,str,7,7,1);
|
169
|
+
pos = new Position();
|
170
|
+
prev = new Position();
|
171
|
+
move = new Position();
|
172
|
+
|
173
|
+
AnimeClip->setAnime(anime_s::ewalk,1,3,3);
|
174
|
+
AnimeClip->setAnime(anime_s::ewait, 0, 0, 1);
|
175
|
+
AnimeClip->setAnime(anime_s::ejump, 5, 5, 1);
|
176
|
+
|
177
|
+
|
178
|
+
}
|
179
|
+
|
180
|
+
/*計算更新*/
|
181
|
+
void Player::Update()
|
182
|
+
{
|
183
|
+
|
184
|
+
gravity();
|
185
|
+
|
186
|
+
input_key();
|
187
|
+
jump_up();
|
188
|
+
//side_move();//
|
189
|
+
|
190
|
+
AnimeClip->Update();
|
191
|
+
|
192
|
+
DrawFormatString(200, 280, GetColor(255, 255, 255), "y %d", pos->get_y());
|
193
|
+
DrawFormatString(200, 360, GetColor(255, 255, 255), "x %d", pos->get_x());
|
194
|
+
// ofs << (double)std::atan2((double)pos->get_x(),(double)pos->get_y()) << std::endl;
|
195
|
+
DrawFormatString(100, 200, GetColor(255, 255, 255), "isGround %d", isGround);
|
196
|
+
DrawFormatString(100, 280, GetColor(255, 255, 255), "isJump %d", isJump);
|
197
|
+
|
198
|
+
ofs << "pos.x: " << pos->get_x() << std::endl;
|
199
|
+
ofs << "pos.y: " << pos->get_y() << std::endl;
|
200
|
+
|
201
|
+
*prev = *pos;
|
202
|
+
}
|
203
|
+
|
204
|
+
|
205
|
+
/*描画更新*/
|
206
|
+
void Player::Draw_Update()
|
207
|
+
{
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
if ( key == -1)
|
212
|
+
{
|
213
|
+
//DrawTurnGraph(get_x(), get_y(), g_handle[0], true);
|
214
|
+
///////
|
215
|
+
DrawTurnGraph(pos->get_x(), pos->get_y(), AnimeClip->draw_setClip(), true);
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
/*右→*/
|
220
|
+
if (key == 1)
|
221
|
+
{ ///
|
222
|
+
DrawGraph(pos->get_x(), pos->get_y(), AnimeClip->draw_setClip(), true);
|
223
|
+
}
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
|
228
|
+
AnimeClip->Draw_Update();
|
229
|
+
|
230
|
+
|
231
|
+
|
232
|
+
}
|
233
|
+
|
234
|
+
/*キー入力*/
|
235
|
+
void Player::input_key()
|
236
|
+
{
|
237
|
+
if (keybord(KEY_INPUT_LEFT) > 0)//←
|
238
|
+
{
|
239
|
+
|
240
|
+
key = -1;
|
241
|
+
AnimeClip->Update_changeAnime(anime_s::ewalk,key);
|
242
|
+
pos->set_x(-MOVE_SPD);
|
243
|
+
move->new_pos_x(-MOVE_SPD);
|
244
|
+
|
245
|
+
|
246
|
+
}else if (keybord(KEY_INPUT_RIGHT) > 0)//→
|
247
|
+
{
|
248
|
+
|
249
|
+
key = 1;
|
250
|
+
AnimeClip->Update_changeAnime(anime_s::ewalk,key);
|
251
|
+
move->new_pos_x(MOVE_SPD);
|
252
|
+
|
253
|
+
|
254
|
+
pos->set_x(+MOVE_SPD);
|
255
|
+
|
256
|
+
}else if (keybord(KEY_INPUT_UP) > 0)//上
|
257
|
+
{
|
258
|
+
//pos->set_y(+MOVE_SPD);
|
259
|
+
|
260
|
+
}else if (keybord(KEY_INPUT_DOWN) > 0)//下
|
261
|
+
{
|
262
|
+
// pos->set_y(-MOVE_SPD);
|
263
|
+
}
|
264
|
+
|
265
|
+
else if (keybord(KEY_INPUT_SPACE) > 0)//ジャンプ
|
266
|
+
{
|
267
|
+
//AnimeClip->Update_changeAnime(anime_s::ejump);
|
268
|
+
|
269
|
+
if (isGround == true && jf == 0) {
|
270
|
+
//isJump = true;
|
271
|
+
isGround = false;
|
272
|
+
jf = JUMP_FORCE;
|
273
|
+
}
|
274
|
+
|
275
|
+
AnimeClip->Update_changeAnime(anime_s::ejump);
|
276
|
+
|
277
|
+
}
|
278
|
+
else//何も押していない時
|
279
|
+
{
|
280
|
+
|
281
|
+
move->new_pos_x(0);
|
282
|
+
|
283
|
+
AnimeClip->Update_changeAnime(anime_s::ewait);
|
284
|
+
|
285
|
+
}
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
|
290
|
+
}
|
291
|
+
|
292
|
+
/************************ジャンプ ***********************/
|
293
|
+
void Player::jump_up()
|
294
|
+
{
|
295
|
+
if (Map::Collision::player_col(pos, move) == std::nullopt) {
|
296
|
+
|
297
|
+
if (isGround == false) {
|
298
|
+
|
299
|
+
move->new_pos_y((int)jf);
|
300
|
+
pos->set_y((int)jf);
|
301
|
+
|
302
|
+
//if (Fps::gframe() % 20 == 0) {
|
303
|
+
|
304
|
+
jf = ((jf - 0.126953125f * 20.0f));
|
305
|
+
|
306
|
+
if (jf < -0.126953125f * 3.0f * 10.0f)
|
307
|
+
{
|
308
|
+
jf = -0.126953125f * 3.0f * 10.0f;
|
309
|
+
//pos->set_y();
|
310
|
+
}
|
311
|
+
//}
|
312
|
+
}
|
313
|
+
|
314
|
+
}
|
315
|
+
}
|
316
|
+
/*********************************************************/
|
317
|
+
|
318
|
+
|
319
|
+
/***********************重力*******************************/
|
320
|
+
void Player::gravity()
|
321
|
+
{
|
322
|
+
|
323
|
+
|
324
|
+
/*地面着地*/
|
325
|
+
if (Map::Collision::player_col(pos, move) != std::nullopt)
|
326
|
+
{
|
327
|
+
// ofs << "test\n";
|
328
|
+
std::optional<Position> p = Map::Collision::player_col(pos, move);
|
329
|
+
pos->new_pos_x(p->get_x());
|
330
|
+
pos->new_pos_y(p->get_y());
|
331
|
+
|
332
|
+
|
333
|
+
//pos->set_y(p->get_y());
|
334
|
+
//pos->set_x(-p->get_x());
|
335
|
+
|
336
|
+
// ofs << "under_col true\n";
|
337
|
+
|
338
|
+
}
|
339
|
+
else {
|
340
|
+
|
341
|
+
//ofs << "palyer_col nullopt" <<"\n";
|
342
|
+
|
343
|
+
}
|
344
|
+
|
345
|
+
//落下
|
346
|
+
if (Map::Collision::player_col(pos,move) == std::nullopt)
|
347
|
+
|
348
|
+
//if (Map::Collision::under_col(pos, prev) == std::nullopt && isGround == false)
|
349
|
+
{
|
350
|
+
|
351
|
+
//DrawFormatString(200, 200, GetColor(255, 255, 255), "x %d", pos->get_x());
|
352
|
+
|
353
|
+
//if (Map::Collision::player_col(pos, move) == std::nullopt) {
|
354
|
+
if (isGround == false) {
|
355
|
+
move->new_pos_y((int)jf);
|
356
|
+
pos->set_y((int)jf);
|
357
|
+
|
358
|
+
jf = ((jf - 0.126953125f * 20.0f));
|
359
|
+
|
360
|
+
if (jf < -0.126953125f * 3.0f * 10.0f)
|
361
|
+
{
|
362
|
+
jf = -0.126953125f * 3.0f * 10.0f;
|
363
|
+
//pos->set_y();
|
364
|
+
}
|
365
|
+
}
|
366
|
+
else {
|
367
|
+
|
368
|
+
}
|
369
|
+
// }
|
370
|
+
|
371
|
+
}
|
372
|
+
|
373
|
+
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
}
|
378
|
+
/**********************************************************/
|
379
|
+
|
380
|
+
|
381
|
+
|
382
|
+
|
141
383
|
```
|
3
画像を追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,73 +4,138 @@
|
|
4
4
|
2Dアクションゲームでベクトルを使って移動した時にブロックや他の画像と重なってしまういわゆる"めり込み"の修正方が知りたいです。自分はベクトルを使い方向の情報を使ってぶつかってきた方向に追い返す処理を考えました。
|
5
5
|
図の場合は右と下に進んでいるのでその逆の左上に追い返す(座標をずらす)ということをしたいです。
|
6
6
|
また水平に並んだブロックに上から下と右に移動しながら進んできた時に上に座標をずらすといった処理を書きたいのですがどうしたらいいのか実装が思いつかないのですが教えてくれますでしょうか?
|
7
|
-
追記ですが下にブロックがあり右の真横にもブロックがる場合上に上がってしましますこれはどうすればいいのでしょうか?
|
8
7
|
|
9
8
|
画像:画像の青がプレイやーで端が紫の青いブロックは移動してる時つまりプレイヤーに移動速度してる情報が追加されたときの画像で赤がブロックです。
|
10
9
|
|
11
10
|
環境:dxlibです右がx++で下がy++の座標系です。2Dです。
|
11
|
+
player_col()部です。
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
+
追記ですが下にブロックがあり右の真横にもブロックがる場合上に上がってしましますこれはどうすればいいのでしょうか?
|
16
|
+
画像の場所です。
|
15
17
|
|
18
|
+
g)](879fa411472eebf71d77a3792a15918a.jpeg)
|
16
19
|
|
17
20
|
|
18
21
|
|
19
22
|
|
23
|
+
|
24
|
+
|
20
25
|
```ここに言語を入力
|
21
26
|
|
27
|
+
Position Map::Collision::isMapCell(const Position pos)
|
28
|
+
{
|
29
|
+
Position p;
|
30
|
+
for (int y = 0; y < MAP_HEIGHT; y++)
|
31
|
+
{
|
32
|
+
for (int x = 0; x < MAP_WIDTH; x++)
|
33
|
+
{
|
34
|
+
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
if (get_mapCell(pos.get_x() / CELL, pos.get_y() / CELL) == (int)mapChip::eBrick ||
|
39
|
+
get_mapCell(pos.get_x() / CELL, pos.get_y() / CELL) == (int)mapChip::eQuestion)
|
40
|
+
{
|
41
|
+
|
42
|
+
p.new_pos_x((pos.get_x() / CELL));
|
43
|
+
p.new_pos_y((pos.get_y() / CELL));
|
44
|
+
ofs << "p.get_x(): " << p.get_x() << std::endl;
|
45
|
+
ofs << "p.get_y(): " << p.get_y() << std::endl;
|
46
|
+
|
47
|
+
return p;
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
return Position(-1,-1);
|
56
|
+
}
|
57
|
+
|
58
|
+
//座標が引数
|
59
|
+
|
60
|
+
std::optional<Position> Map::Collision::col(const Position p)
|
61
|
+
{
|
62
|
+
Position c_pos(Map::Collision::isMapCell(p));
|
63
|
+
|
64
|
+
if (c_pos.get_x() > -1 && c_pos.get_y() > -1) {
|
65
|
+
if (c_pos.get_x() * CELL <= p.get_x() && (c_pos.get_x() * CELL) + CELL >= p.get_x() )
|
66
|
+
{
|
67
|
+
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
return std::nullopt;
|
74
|
+
}
|
75
|
+
|
22
76
|
/*全方位の当たり判定 return セル番号を返す*/
|
23
77
|
std::optional<Position> Map::Collision::player_col(const Position *pos,const Position *move)
|
24
78
|
{
|
79
|
+
Position p;
|
25
|
-
|
80
|
+
p.new_pos_x( pos->get_x() + move->get_x() + CELL);
|
26
|
-
|
81
|
+
p.new_pos_y( pos->get_y() + move->get_y() + CELL);
|
27
82
|
|
83
|
+
static bool isground = false;
|
84
|
+
|
28
85
|
int px = pos->get_x();
|
29
86
|
int py = pos->get_y();
|
30
87
|
|
31
|
-
int add_x = move->get_x();
|
32
|
-
int add_y = (int)move->get_y();
|
33
88
|
|
34
|
-
|
89
|
+
int add_x = move->get_x();
|
35
|
-
|
90
|
+
int add_y = (int)move->get_y();
|
36
91
|
|
92
|
+
// ofs << "move->get_x(): " << move->get_x()<<"\n";
|
93
|
+
// ofs << "move->get_y(): " << move->get_y() << "\n";
|
94
|
+
|
37
95
|
int corr_x = 0;
|
38
96
|
int corr_y = 0;
|
39
97
|
|
40
|
-
// ofs <<"aaa"<< px << "\n";
|
41
98
|
|
99
|
+
|
100
|
+
|
101
|
+
|
42
|
-
|
102
|
+
Position pp = Map::Collision::isMapCell(p);
|
43
|
-
{
|
103
|
+
if (pp.get_x() > -1) {
|
104
|
+
|
44
|
-
|
105
|
+
if (move->get_x() > 0)
|
45
106
|
{
|
46
|
-
if (get_mapCell(x, y) == (int)mapChip::eBrick || get_mapCell(x, y) == (int)mapChip::eQuestion)
|
47
|
-
{
|
48
|
-
if (
|
49
|
-
(pos->get_x() <= (x * CELL) && (pos->get_x() + CELL + add_x) >= (x * CELL) ||
|
50
|
-
pos->get_x() >= (x * CELL) && pos->get_x() <= (x * CELL) + CELL)
|
51
|
-
|
52
|
-
&&
|
53
|
-
(pos->get_y() <= (y * CELL) && (pos->get_y() + CELL + add_y) >= (y * CELL) ||
|
54
|
-
pos->get_y() >= (y * CELL) && pos->get_y() <= (y * CELL) + CELL )
|
55
|
-
)
|
56
|
-
{
|
57
107
|
|
58
|
-
//ここに記入すべきコード
|
59
|
-
|
60
|
-
|
108
|
+
//ofs << "x補正" << std::endl;
|
61
|
-
return p.value();//セルを返す
|
62
|
-
|
109
|
+
//px = pos->get_x() -CELL;
|
63
|
-
}
|
64
110
|
|
65
|
-
|
111
|
+
}
|
66
112
|
|
113
|
+
//ofs << "playe_col isground: " << isground << std::endl;
|
114
|
+
|
115
|
+
if ((move->get_y() < 0))
|
67
|
-
|
116
|
+
{
|
117
|
+
ofs << "ground " << std::endl;
|
118
|
+
|
119
|
+
isground = true;
|
120
|
+
|
68
|
-
//pos->
|
121
|
+
//py -= ((pos->get_y() + (-move->get_y()) + CELL) - (pp.get_y() * CELL));
|
122
|
+
//ofs << "pp.get_y(): " << ((pos->get_y() + (-move->get_y()) + CELL) - (pp.get_y() * CELL));
|
123
|
+
|
124
|
+
int yy = ((pos->get_y() + (-move->get_y()) + CELL) - ((pp.get_y() * CELL)));
|
125
|
+
py -= yy;
|
69
126
|
}
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
std::optional<Position> p = Position(px, py);
|
131
|
+
return p.value();//セルを返す
|
70
132
|
}
|
71
133
|
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
|
72
138
|
return std::nullopt;
|
73
139
|
}
|
74
140
|
|
75
|
-
|
76
141
|
```
|
2
文章を編集し質問内容をつかきしました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,8 +4,8 @@
|
|
4
4
|
2Dアクションゲームでベクトルを使って移動した時にブロックや他の画像と重なってしまういわゆる"めり込み"の修正方が知りたいです。自分はベクトルを使い方向の情報を使ってぶつかってきた方向に追い返す処理を考えました。
|
5
5
|
図の場合は右と下に進んでいるのでその逆の左上に追い返す(座標をずらす)ということをしたいです。
|
6
6
|
また水平に並んだブロックに上から下と右に移動しながら進んできた時に上に座標をずらすといった処理を書きたいのですがどうしたらいいのか実装が思いつかないのですが教えてくれますでしょうか?
|
7
|
+
追記ですが下にブロックがあり右の真横にもブロックがる場合上に上がってしましますこれはどうすればいいのでしょうか?
|
7
8
|
|
8
|
-
|
9
9
|
画像:画像の青がプレイやーで端が紫の青いブロックは移動してる時つまりプレイヤーに移動速度してる情報が追加されたときの画像で赤がブロックです。
|
10
10
|
|
11
11
|
環境:dxlibです右がx++で下がy++の座標系です。2Dです。
|
1
指摘通り文章を編集
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
ベクトルを使った当たり判定の
|
1
|
+
ベクトルを使った当たり判定の実装方法が知りたい
|
body
CHANGED
@@ -1,12 +1,22 @@
|
|
1
|
-
コードが長いので断片的な部分だけ
|
1
|
+
コードが長いので断片的な部分だけです、コメント部の記入すべきコードです。
|
2
|
-
またなんだか同じようなことをやっている気がしてコードがスマートありませんこの辺の改善方法が知りたいです。
|
3
2
|
|
4
3
|
|
4
|
+
2Dアクションゲームでベクトルを使って移動した時にブロックや他の画像と重なってしまういわゆる"めり込み"の修正方が知りたいです。自分はベクトルを使い方向の情報を使ってぶつかってきた方向に追い返す処理を考えました。
|
5
|
+
図の場合は右と下に進んでいるのでその逆の左上に追い返す(座標をずらす)ということをしたいです。
|
6
|
+
また水平に並んだブロックに上から下と右に移動しながら進んできた時に上に座標をずらすといった処理を書きたいのですがどうしたらいいのか実装が思いつかないのですが教えてくれますでしょうか?
|
5
7
|
|
6
8
|
|
9
|
+
画像:画像の青がプレイやーで端が紫の青いブロックは移動してる時つまりプレイヤーに移動速度してる情報が追加されたときの画像で赤がブロックです。
|
7
10
|
|
11
|
+
環境:dxlibです右がx++で下がy++の座標系です。2Dです。
|
8
12
|
|
9
13
|
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
10
20
|
```ここに言語を入力
|
11
21
|
|
12
22
|
/*全方位の当たり判定 return セル番号を返す*/
|
@@ -45,38 +55,8 @@
|
|
45
55
|
)
|
46
56
|
{
|
47
57
|
|
48
|
-
if (pos->get_x() <= (x * CELL) && (pos->get_x() + CELL + add_x) >= (x * CELL))
|
49
|
-
{
|
50
|
-
|
51
|
-
|
52
|
-
|
58
|
+
//ここに記入すべきコード
|
53
|
-
corr_x = (pos->get_x() + CELL + add_x) - (x * CELL);
|
54
|
-
|
55
|
-
if (corr_x <= 0)
|
56
|
-
{
|
57
|
-
corr_x = 0;
|
58
|
-
}
|
59
|
-
|
60
|
-
|
61
|
-
px -= corr_x;
|
62
|
-
}
|
63
59
|
|
64
|
-
|
65
|
-
}
|
66
|
-
//ここのコードです。
|
67
|
-
if (pos->get_y() <= (y * CELL) && (pos->get_y() + CELL + add_y) >= (y * CELL))
|
68
|
-
{
|
69
|
-
//if (add_x == 0) {
|
70
|
-
ofs << "add_x: " << add_x << std::endl;
|
71
|
-
corr_y = (pos->get_y() + CELL + add_y) - (y * CELL);
|
72
|
-
if (corr_y < 0) { corr_y = 0; }
|
73
|
-
ofs << "corr_y : " << corr_y << std::endl;
|
74
|
-
|
75
|
-
py -= (corr_y + 3);
|
76
|
-
//}
|
77
|
-
}
|
78
|
-
|
79
|
-
|
80
60
|
std::optional<Position> p = Position(px, py);
|
81
61
|
return p.value();//セルを返す
|
82
62
|
// return true;
|