πŸŽ‰ Celebrating 25 Years of GameDev.net! πŸŽ‰

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Jump has a higher jump, had problems with editor.

Started by
15 comments, last by fleabay 4Β years, 2Β months ago

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 &amp; line,const int SCREENWIDTH, const int SCREENHEIGHT, Character &amp; character, std::vector<platform> &amp; vector, float&amp; positionX, float&amp; positionY, float velocityY, float velocityX,
		float gravity, int facingLeft, sf::RenderWindow &amp; window, sf::Sprite &amp; marioSpriteR, sf::Sprite &amp; marioSpriteL, int&amp; goingDown, int&amp; 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);





Advertisement

This editor needs fixing, however here's an image:

The entire code has gristle which I wanted to explain, but because of the problematic editor I'll just leave it at that.

Josheir

Josheir said:
I have a video that is submitted.

…

This editor needs fixing, however here's an image:

Post the URL for the video in code tags if nothing else works.

πŸ™‚πŸ™‚πŸ™‚πŸ™‚πŸ™‚<←The tone posse, ready for action.

Thanks, fleabay. I had multiple issues too. Also, I have a video, but no url. I updated the code on GitHub.

The jump code uses gravity, velocityx, velocityy, positiony, and positionx. Once in the do loop these variables should work the same way and therefore have the same jump reaction.

However, there seems to be two different jump heights.

Thanks, Josheir

I think isKeyPressed is not what you want to use. It checks the current state of the keypress so if a key is down, it's always true, hence the consecutive platform jumps. (this looks like what is happening) You probably want to use KeyPressed instead. It may be necessary to cache a 'true' value to a variable to determine if the key was recently pressed and to clear that variable once the jump is initiated.

I only have a passing knowledge of SFML so I can't give you specifics.

πŸ™‚πŸ™‚πŸ™‚πŸ™‚πŸ™‚<←The tone posse, ready for action.

Hopefully outstanding, thanks a ton, fleabay!

Josheir

I'm not sure if this is it. If there were consecutive calls to the function the jump variables would reset and should jump that same height.

Josheir

This topic is closed to new replies.

Advertisement