Ich habe ein Problem mit der Wall Jumping-Mechanik im 2D-Plattformer-Java-SpielJava

Java-Forum
Anonymous
 Ich habe ein Problem mit der Wall Jumping-Mechanik im 2D-Plattformer-Java-Spiel

Post by Anonymous »

Also, ich programmiere einen 2D-Plattformer in Java, ich habe bereits eine Wallslide-Mechanik erstellt und der Walljump funktioniert auch, aber ich habe Probleme mit einem Detail im Walljump:
Angenommen, du gehst nach rechts, wenn du an eine Wand springst und daran hängen bleibst, und wenn du WIEDER springst, gehst du nach links (wie es sein sollte), aber wenn du weiterhin rechts bleibst, anstatt nach rechts zu gehen, Du gehst für immer nach links, bis du es zulässt los.
Was ich möchte, ist eine Mechanik wie „Super Meat Boy“, bei der es nach einem Sprung eine kleine Verzögerung beim Tastenwechsel gibt, aber wenn man die rechte Maustaste gedrückt hält, Du gehst richtig.
Das ist die Tick-Methode meines Player.Java (entschuldigen Sie die schlechte Codierung, sie ist überall, lol)
public void tick() {

//System.out.println("DashCooldown: " + dashCooldown + " TimeDashing: " + timeDashing);
//dashing logic
if (timeDashing > 0) {
float dashDistance;

// First half of the dash: high speed
if (timeDashing < 10) {
dashDistance = 30; // Maximum speed
}
// Second half of the dash: gradually slow down
else {
dashDistance = 3 * (timeDashing / 7.0f); // Ease-out effect
}

// Apply the dash distance
if (forward) {
setX(getX() + dashDistance);
} else {
setX(getX() - dashDistance);
}

}

//sliding logic
if(crouched && jumped== 0 && touchingWallSide == "none" && steppingOnSlideableBlock) {
sliding = true;
} else {
sliding = false;

}
if(jumped ==0) {
bufferedJumpCollision = false;
}

if(jumped >0 || getVelY() > 1.5 || getVelY() < -1.5) {
steppingOnSlideableBlock = false;

steppingOnBlock = false;
slidingUnderBlock = false;

}

if (bufferedJumpIncoming && jumped == 0) {
setVelY(-13);
jumped+=1;

bufferedJumpIncoming = false;

}
if(isWallSliding || wallJumpCooldown 0) {
wallJumpCooldown --;

//input delay

if (wallJumpInputDelay > 0) {
wallJumpInputDelay--;
}

}

if(slidingCooldown 0) {
handler.getPlayer().setVelX(Math.max(velX - 0.8f, 0));
} else if (velX < 0) {
handler.getPlayer().setVelX(Math.min(velX + 0.8f, 0));
}
//if on the air after a wall jump
} else if(jumped > 0) {
if(wallJumpCooldown < 50) {

// reduce velocity gradually until it reaches 0
if (velX > 0) {
handler.getPlayer().setVelX(Math.max(velX - 0.2f, 0));
} else if (velX < 0) {
handler.getPlayer().setVelX(Math.min(velX + 0.2f, 0));
}
} else {
if (velX > 0) {
handler.getPlayer().setVelX(Math.max(velX - 0.8f, 0));
} else if (velX < 0) {
handler.getPlayer().setVelX(Math.min(velX + 0.8f, 0));
}
}
}

}

//set dashCooldown
if (dashCooldown < 15 && dashCooldown > 0) {
dashCooldown--;
} else if (dashCooldown 0 && timeDashing < 15) {
timeDashing += 2;
} else if (timeDashing >= 15) {
timeDashing = 0;
}

if (bulletCadence > 0 ) {
shooting = true;

} else if (bulletCadence == 0 ) {
shooting = false;

}
if (bulletCadence < 10 && bulletCadence > 0) {
bulletCadence++;

} else {
bulletCadence = 0;
}

// if the player is dead
if (!alive) {

// slowly decrease VelX
if (getVelX() > 0) {

setVelX(getVelX() - 0.1f);
}
if (getVelX() < 0) {
setVelX(getVelX() + 0.1f);

}

setX((getVelX()) + getX());
setY((getVelY()) + getY());

applyGravity();

return;
}
if (size == PlayerSize.Large) {

if (tex.getCharacter() == "mario") {
currSprite = spriteMarioL;
currAnimation = marioWalkL;

} else if (tex.getCharacter() == "bill") {
currSprite = spriteBillL;
currAnimation = billWalkL;

}
} else if (size == PlayerSize.Small) {

if (tex.getCharacter() == "mario") {
currSprite = spriteMarioS;
currAnimation = marioWalkS;

} else if (tex.getCharacter() == "bill") {
currSprite = spriteBillS;
currAnimation = billWalkS;

}
}

//update X
if(timeDashing > 0) {
//if dashing, ignore velocity
setX(getX());
}else {
//normal behaviour
setX(getVelX() + getX());

}

//update Y
if(timeDashing == 0) {
//if not dashing
setY(getVelY() + getY());
}
//limit x left side
if (getX() < 0) {
setX(0);

}
//limit x right side

if (getX() > game.getLevelWidth() -48) {
setX(game.getLevelWidth()-48);

}

if (isWallSliding) {

if(!crouched) {
if(wallJumpCooldown == 50) {

setVelY(1f);
}

} else {
setVelY(7f);

}

} else {
applyGravity();
}

if(sliding) {
if(forward) {
setVelX(12f);
} else {
setVelX(-12f);

}
}

collision();
currAnimation.runAnimation("endless");
if (getY() > 842) {
killPlayer();
}
//System.out.println(getX());
if(getVelX() >0) {
forward = true;
}
if(getVelX()

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post