I've been developing a volleyball game in Java with Slick2D for some time now, but I'm having a pretty annoying problem with the movement of the ball: I can not get the ball to perform a parabola move draws, the ball goes up, descends into the other character) decent and keep the cool speed to play.
class update ball
float originalSpeed = (velocidade * InGameState.GetDeltaTime());
// Movimentação no eixo X
float speed;
if (distanceX < originalSpeed) {
speed = distanceX;
} else {
if (distanceX > originalSpeed) {
speed = originalSpeed;
} else {
speed = 0;
}
}
if (this.x < this.targetPositionX) {
this.speedX = speed;
} else {
if (this.x >= this.targetPositionX) {
this.speedX = -speed;
}
}
// Movimentação no eixo Y
if (distanceY < originalSpeed) {
speed = distanceY;
} else {
if (distanceY > originalSpeed) {
speed = originalSpeed;
} else {
speed = 0;
}
}
if (this.y < this.targetPositionY) {
this.speedY = speed;
} else {
if (this.y >= this.targetPositionY) {
this.speedY = -speed;
}
}
float percentX;
float percentY;
if (distanceX > distanceY) {
if (Math.abs(distanceY) < 1) {
percentX = 0;
} else {
percentX = (distanceX/distanceY);
}
percentY = 1;
} else {
if (distanceY > distanceX) {
percentX = 1;
if (Math.abs(distanceX) < 1) {
percentY = 0;
} else {
percentY = (distanceY/distanceX);
}
percentX = 1;
} else {
percentX = 1;
percentY = 1;
}
}
// Aplicação da "velocidade"
setX(this.x + (this.speedX * percentX));
setY(this.y + (this.speedY * percentY));
}
As the code above is, sometimes the ball gets extremely fast (I suspect it is when percentY
or percentX
gets too high) and thus can not predict the movement of the ball. Can someone help me? Thanks!