dxlibです。ベクトルを使ってめり込みを回避したいんですが真横に当たった時にブロックのめり込みそれをx軸を戻した時に同時にy軸も動いてしまい真横の上のブロックに上がってしまうバグの対処方がわかりません別途例外処理のようなものを作ればいいの思うんですがどうすればいいのかわかりませんちなみに左から右に行く処理を作っています。yだけxだけならなんとなく完成したのでそのですが
/*全方位の当たり判定 return セル番号を返す*/ std::optional<Position> Map::Collision::player_col(const Position *pos,const Position *move) { int px2 = pos->get_x() + move->get_x(); int py2 = pos->get_y() + move->get_y(); static bool isground = false; int px = pos->get_x(); int py = pos->get_y(); int add_x = move->get_x(); int add_y = (int)move->get_y(); // ofs << "move->get_x(): " << move->get_x()<<"\n"; // ofs << "move->get_y(): " << move->get_y() << "\n"; int corr_x = 0; int corr_y = 0; // ofs <<"aaa"<< px << "\n"; for (int y = 0; y < MAP_HEIGHT; y++) { for (int x = 0; x < MAP_WIDTH; x++) { if (get_mapCell(x, y) == (int)mapChip::eBrick || get_mapCell(x, y) == (int)mapChip::eQuestion) { if ( (pos->get_x() <= (x * CELL) && (pos->get_x() + CELL + add_x) >= (x * CELL) || pos->get_x() >= (x * CELL) && pos->get_x() <= (x * CELL) + CELL) && (pos->get_y() <= (y * CELL) && (pos->get_y() + CELL + add_y) >= (y * CELL) || pos->get_y() >= (y * CELL) && pos->get_y() <= (y * CELL) + CELL ) ) { if ((pos->get_x() <= (x * CELL) && pos->get_x() + CELL + add_x >= (x * CELL))) { ofs << "x補正" << std::endl; px = (x * CELL) - CELL; } ofs << "playe_col isground: " << isground << std::endl; if ( (move->get_y() < 0) ) { ofs << "ground "<< std::endl; isground = true; py = ((y * CELL) - CELL ); } std::optional<Position> p = Position(px, py); return p.value();//セルを返す // return true; } } //pos->get_x() <= (x * CELL) && pos->get_x() + CELL >= (x * CELL) } } return std::nullopt; }
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/26 05:42