私は現在、奇妙なバグがある比較的単純なプラットフォーム ゲームに取り組んでいます。地面に落ちることでゲームを開始します (地面から数ブロック上にスポーンします) が、着地すると足がワールド内で動かなくなり、ジャンプするまで移動できなくなります。これが私が意味することです:
プレーヤーの足は、地面から数ピクセル下にあります。ただし、この問題はマップ全体の 3 つの場所でのみ発生し、それらの 3 つの選択した場所でのみ発生します。問題は衝突検出コード内にあると想定していますが、問題が発生してもエラーが発生しないため、完全にはわかりません。
public boolean isCollidingWithBlock(Point pt1, Point pt2) {
//Checks x
for(int x = (int) (this.x / Tile.tileSize); x < (int) (this.x / Tile.tileSize + 4); x++) {
//Checks y
for(int y = (int) (this.y / Tile.tileSize); y < (int) (this.y / Tile.tileSize + 4); y++) {
if(x >= 0 && y >= 0 && x < Component.dungeon.block.length && y < Component.dungeon.block[0].length) {
//If the block is not air
if(Component.dungeon.block[x][y].id != Tile.air) {
//If the player is in contact with point one or two on the block
if(Component.dungeon.block[x][y].contains(pt1) || Component.dungeon.block[x][y].contains(pt2)) {
//Checks for specific blocks
if(Component.dungeon.block[x][y].id == Tile.portalBlock) {
Component.isLevelDone = true;
}
if(Component.dungeon.block[x][y].id == Tile.spike) {
Health.health -= 1;
Component.isJumping = true;
if(Health.health == 0) {
Component.isDead = true;
}
}
return true;
}
}
}
}
}
return false;
}
私が求めているのは、問題をどのように解決するかです。私は自分のコードをかなり長い間調べてきましたが、何が問題なのかわかりません。また、衝突チェックを効率的に行う方法があれば教えてください。
必要なものを教えていただけない場合は、これで十分な情報であることを願っています。必ず追加します。
ありがとうございました!