I am making a Mario like game called, Platform Jump! The game is made with three zones. In the two end zones the character can run and jump left and right. In the midzone the movement is simulated with the platforms scrolled instead. I am almost done and plan to make it use variable jumping.
My problem is that from both the right and left when the character jumps sometimes it is about twice the normal height. This does not make sense to me because the variables that cause the jump are not changed when the character is in the process of jumping.
I have a video that is submitted. It shows a large jump and a regular jump. Although the jump is from the left the problem is also on the right (facing left.)
I have included half of the jump function that deals with from the left side.
The total code is at : https://github.com/josheirm/MarioBros/tree/platforms_next
Here is the code :
int Character::JumpInEndZone(int & line,const int SCREENWIDTH, const int SCREENHEIGHT, Character & character, std::vector<platform> & vector, float& positionX, float& positionY, float velocityY, float velocityX,
float gravity, int facingLeft, sf::RenderWindow & window, sf::Sprite & marioSpriteR, sf::Sprite & marioSpriteL, int& goingDown, int& characterOnBar)
{
//josh, for now
goingDown = 1;
do {
clock1.restart();
sf::Time elapsed1 = clock1.getElapsedTime();
while (elapsed1.asMilliseconds() <= TIME)
{
elapsed1 = clock1.getElapsedTime();
}
clock1.restart();
if (facingLeft == 1)
{
velocityX = -VELOCITYX;
currentCharacterPlacement = currentCharacterPlacement - VELOCITYX;
//currentLeftEdge = currentLeftEdge - VELOCITYX;
}
else
{
velocityX = VELOCITYX;
currentCharacterPlacement = currentCharacterPlacement + VELOCITYX;
//currentLeftEdge = currentLeftEdge + VELOCITYX;
}
int firstPositionX = positionX;
int firstPositionY = positionY;
positionY += velocityY;
positionX += velocityX;
velocityY += gravity;
int secondPositionY = positionY;
int secondPositionX = positionX;
//if positive going down
int horizontalChange = secondPositionX - firstPositionX;
////////////////
if (firstPositionY <= secondPositionY)
{
goingDown = 1;
}
//if landing with jump
if (positionY > (600 - 76))
{
positionY = (600 - 76);
//in rigth endzone
if (currentCharacterPlacement >= rightEndzoneLine)
{
marioSpriteL.setPosition(positionX, 600 - 76);
marioSpriteR.setPosition(positionX, 600 - 76);
window.clear();
platform::SearchVectorForPlatforms(vector, window, 0, 0, 0);
window.draw(marioSpriteR);
window.display();
//Sleep(40);
break;
//continue;
}//in mid zone
else if (positionX >= leftEndzoneLine )
{
marioSpriteL.setPosition((SCREENWIDTH / 2) - (76 / 2), 600 - 76);
marioSpriteR.setPosition((SCREENWIDTH / 2) - (76 / 2), 600 - 76);
//positionX = POSXCENTER;
//platform::SearchVectorForPlatforms(vector, window, -VELOCITYX, 0, 1);
window.clear();
platform::SearchVectorForPlatforms(vector, window, -VELOCITYX, 0, 1);
window.draw(marioSpriteR);
window.display();
break;
//continue;
}
else
{ //mid zone
marioSpriteL.setPosition(positionX, 600 - 76);
marioSpriteR.setPosition(positionX, 600 - 76);
window.clear();
platform::SearchVectorForPlatforms(vector, window, 0, 0, 0);
window.draw(marioSpriteR);