3
For some time I’ve been developing a game of Volleyball in Java with Slick2d, but I’m having a very boring problem with the ball’s movement: I can’t get the ball to perform a parabola move (draw character, ball goes up, goes down on the other character) decent and keep the speed cool 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));
}
The way the code is above, sometimes the ball gets extremely fast (I suspect it is when the percentY
or the percentX
are very high) and so can not predict the movement of the ball. Can anyone help me? Thanks!