Hey, guys!
You guys helped me in the last topic I made for a help in collision for my
isometric race game (
this one), and I thank you very much
But now I'm getting stuck by this one problem, that is implementing a acceleration factor in my game. The main problem is that, as it is an Isometric game, the "speed+acceleration" and "speed+deacceleration" aren't enough to create a smooth functional moviment.
My code, for now, it's like this:
This is the code to acelerate:
void acelerar(){
frameCounter += frameSpeed*clock.restart().asSeconds();
if (frameCounter >= switchFrame){
frameCounter = 0;
if (actualSpeed.x >= topSpeed.x)
actualSpeed.x = topSpeed.x;
else if(actualSpeed.x < topSpeed.x)
actualSpeed.x += (actualSpeed.x + acceleration);
if (actualSpeed.y >= topSpeed.y)
actualSpeed.y = topSpeed.y;
else if (actualSpeed.y < topSpeed.y)
actualSpeed.y += (actualSpeed.y + acceleration);
}
if (spriteFrame <= 6)
carSprite.move(-actualSpeed.x, actualSpeed.y);
else
carSprite.move(-actualSpeed.x, -actualSpeed.y);
}
This is the code to swith the sprite's frame (The spritesheet is attached to the topic, for a better interpretation):
void aumentarAngulo(){
frameCounter += frameSpeed*clock.restart().asSeconds();
if (frameCounter >= switchFrame){
frameCounter = 0;
if (spriteFrame >= 0 && spriteFrame < 12)
spriteFrame++;
}
carSprite.setTextureRect(sf::IntRect(spriteFrame * width, 0, width, height));
}
diminuirAngulo(){
frameCounter += frameSpeed*clock.restart().asSeconds();
if (frameCounter >= switchFrame){
frameCounter = 0;
if (spriteFrame > 0 && spriteFrame <= 12)
spriteFrame--;
}
carSprite.setTextureRect(sf::IntRect(spriteFrame * width, 0, width, height));
}
And here's a simpler code that I was using to represent the moviment, but without an acceleration factor:
void re(){
if (spriteFrame <= 6)
carSprite.move(-topSpeed.x, topSpeed.y);
else
carSprite.move(-topSpeed.x, -topSpeed.y);
}
My game is based on an 90's race SNES game, Rock n' Roll Racing, so, the movement I'm trying to implement looks like
.
My problem resides in two problems:
1. The acceleration is different for the X axis and the Y axis at the same time, as for the velocity varies from a negative top-speed to a positive top-speed (since the moviment is in 360º).
2. When my car rotates, the velocity in both axis have to change, but not in the same way (and I can't use a simple rotate method, since my car it's a spritesheet, and rotate it can bug the graphic).
My car rotate from the keys "Up" and "Down", and it's movement is triggered by the "Ctrl" key.
I've tried doing the basic "when speed is lower than tospeed, accelerate", but when the car changes the frame, it changes the top-speed, leading the car to keep the velocity equals to the top-speed of the frame that it was when the acceleration began.
I would be very grateful if you guys could help me trough this
Thanks, seeya o/