我不知道为什么会这样。第一次碰撞完美无缺。如果我触底,它会停止。如果我击中顶部,它会停在顶部。但是你可以逐步完成第二个平台。有谁知道它为什么这样做?对不起,java新手。我应该提一下,它是我遇到麻烦的第二个平台的底部。
public void customUpdate() { // Remember, all logic goes in here
if(charX > 780) {
charX = 0;
}
if(charX < 0) {
charX = 780;
}
if(gravity) {
charVY += 1;
charY += charVY;
}
if(charY > 670-15) {
charY = 0;
}
if(buttonOne) {
exit = true;
}
if(charY+30 >= wallY) {
charY = wallY-30;
charVY = 0;
wallCollision = true; // numOfJumps set to 0 because it increases by 1 every time you jump, allowing as many jumps as the programmer desires
numOfJumps = 0;
secHasPassed = false;
}
if(charY < platOneY &&
charX < platOneX + platOneW && // Collision for plat 1 and so on
charX + charW > platOneX &&
charY < platOneY + platOneH &&
charH + charY > platOneY) { //TODO Get it so that it stops him when he hits the bottom
charY = platOneY-30;
numOfJumps = 0;
charVY = 0;
wallCollision = true; // Gets top of the platform collision
}
if(charY > platOneY &&
charX < platOneX + platOneW && // Collision for plat 1 and so on
charX + charW > platOneX &&
charY < platOneY + platOneH &&
charH + charY > platOneY) { //TODO Get it so that it stops him when he hits the bottom
charY = platOneY+platOneH+1;
numOfJumps = maxJumps;
charVY = 0;
wallCollision = true; // Gets bottom of platform collision
}
if(charY > platTwoY &&
charX < platTwoX + platTwoW &&
charX + charW > platTwoX &&
charY < platTwoY + platTwoH &&
charH + charY > platTwoY) {
charY = platTwoY+platTwoH+1;
numOfJumps = maxJumps;
charVY = 0;
wallCollision = true;
System.out.println("Bottom");
}
if(charY < platTwoY &&
charX < platTwoX + platTwoW &&
charX + charW > platTwoX &&
charY < platTwoY + platTwoH &&
charH + charY > platTwoY) {
charY = platTwoY-30;
numOfJumps = 0;
charVY = 0;
wallCollision = true;
}
if(charX < platThreeX + platThreeW &&
charX + charW > platThreeX &&
charY < platThreeY + platThreeH &&
charH + charY > platThreeY) {
charY = platThreeY-30;
numOfJumps = 0;
charVY = 0;
wallCollision = true;
}
if(canMoveL) { // Movement Logic
charX -= 5;
}
if(canMoveR) {
charX += 5;
}
if(charVY < -15) {
charVY = -15;
}
}
答案 0 :(得分:0)
{{1}}
我得到了它的工作。我不知道为什么我没有发现这一点。