Advertisement

jump code

Started by September 21, 2019 04:33 PM
10 comments, last by Tom Sloper 4 years, 12 months ago

I am polishing up my jumping code, I got my game to jump  up when I hit the space bar, but I want it to jump like in Mario brothers.


void spritejump()
{
		if (state == false)
		{
			if (positionY <= 20.0f)
			{
				positionY += 5.0f;
			}
			if (positionY == 20.0f)
			{
				state = true;
			}
		}
		else if (state == true)
		{
			if (positionY >= 0.0f)
			{
				positionY -= 5.0f;
			}
			if (positionY == 0.0f)
			{
				state = false;
			}
		}
}

void handleKeypress(unsigned char key, int x, int y)
{
	switch (key)
	{
	case 27:
		exit(0);
		break;
	case 32:
		for (int i = 0; i <= 10; i++)
		{
			spritejump();
		}
		break;

 

4 hours ago, phil67rpg said:

I am polishing up my jumping code, I got my game to jump  up when I hit the space bar, but I want it to jump like in Mario brothers.

No question asked. Thread closed.

-- Tom Sloper -- sloperama.com

This topic is closed to new replies.

Advertisement