0
我目前正在研究一个相对简单的平台游戏,它有一个奇怪的错误。你通过堕落地面开始游戏(你在地面上生成几块),但是当你着地时,你的脚陷入内心世界,直到你跳跃才能移动。这就是我的意思是:碰撞检测错误
球员的脚都低于地面几个像素。但是,这个问题只发生在整个地图的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;
}
我在问的是我如何解决这个问题。我已经查看了我的代码很长一段时间,我不确定它有什么问题。另外,如果有更有效的方式来做我的碰撞检查,请让我知道!
我希望这是足够的信息,如果它不只是告诉我你需要什么,我一定会添加它。
谢谢!
你的问题是什么? –
已添加。对于那个很抱歉。 – Connor
您是否使用过调试器或添加SOP语句来查看所描述的情况下的变量值?这是我建议你开始的地方。学习如何调试代码就像学习如何编写代码一样重要。 –