为什么第二个矩形碰撞不起作用,而第一个矩形碰撞起作用?
Why does the second rectangle collision not work when the first does?
我不知道为什么会这样。第一次碰撞完美无缺。如果我触底,它就会停止。如果我到达顶部,它就会停在顶部。但是您可以逐步通过第二个平台。有人知道为什么要这样做吗?抱歉,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;
}
}
if (charY > platTwoY - 15) {
charX < platTwoX + platTwoW &&
charX + charW > platTwoX &&
charY < platTwoY + platTwoH &&
charH + charY > platTwoY) {
charY = platTwoY + platTwoH + 1;
charVY = 0;
numOfJumps = maxJumps;
wallCollision = true;
}
我成功了。我不知道为什么我没有发现这一点。
我不知道为什么会这样。第一次碰撞完美无缺。如果我触底,它就会停止。如果我到达顶部,它就会停在顶部。但是您可以逐步通过第二个平台。有人知道为什么要这样做吗?抱歉,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;
}
}
if (charY > platTwoY - 15) {
charX < platTwoX + platTwoW &&
charX + charW > platTwoX &&
charY < platTwoY + platTwoH &&
charH + charY > platTwoY) {
charY = platTwoY + platTwoH + 1;
charVY = 0;
numOfJumps = maxJumps;
wallCollision = true;
}
我成功了。我不知道为什么我没有发现这一点。