Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualXeraNox

Posted 09 September 2012 - 05:32 AM

Hello Forum Posted Image
I started working on programming a small 2D platformer with the SDL and had a strange bug in a specific method.

What this method does is first checking for the arrow keys wether they are pressed or not, then for the WASD keys.

Three states are currently used:
The Left/Right keys move the Player two the specified direction.

The combination of the Up-key and the S-key let the Player Jump.

The problem I have now is that the player can't jump and move left at the same time, but he can actually move to the right while jumping.
I've done some testing and found that my program doesn't register the left key while the Up-Key and the S-key are pressed.

The relevant code:

void CPlayer::ProcessMovement ()
{
if (g_pFramework->KeyDown(SDLK_UP))
{
  if (g_pFramework->KeyDown(SDLK_w))
  {
   cout << "Direction: 1, Action: 1" << endl;
  }
  if (g_pFramework->KeyDown(SDLK_d))
  {
   cout << "Direction: 1, Action: 2" << endl;
  }
  if (g_pFramework->KeyDown(SDLK_s)) //The section for triggering the jump method
  {
   cout << "Direction: 1, Action: 3" << endl;
   if (m_bJumpAllow == 1)
   {
    cout << "Jump" << endl;
    Jump ();
   }
   m_bKeyPressed = true;
  }
  if (g_pFramework->KeyDown(SDLK_a))
  {
   cout << "Direction: 1, Action: 4" << endl;
  }
}
if (g_pFramework->KeyDown(SDLK_LEFT))
{
  if (g_pFramework->KeyDown(SDLK_w))
  {
  
  }
  if (g_pFramework->KeyDown(SDLK_d))
  {
   cout << "Direction: 4, Action: 2" << endl;
  }
  if (g_pFramework->KeyDown(SDLK_s))
  {
   cout << "Direction: 4, Action: 3" << endl;
  }
  if (g_pFramework->KeyDown(SDLK_a))
  {
   cout << "Direction: 4, Action: 4" << endl;
  }
}
if (g_pFramework->KeyDown(SDLK_RIGHT))
{
  if (g_pFramework->KeyDown(SDLK_w))
  {
   cout << "Direction: 2, Action: 1" << endl;
  }
  if (g_pFramework->KeyDown(SDLK_d))
  {
   cout << "Direction: 2, Action: 2" << endl;
  }
  if (g_pFramework->KeyDown(SDLK_s))
  {
   cout << "Direction: 2, Action: 3" << endl;
  }
  if (g_pFramework->KeyDown(SDLK_a))
  {
   cout << "Direction: 2, Action: 4" << endl;
  }
}
if (g_pFramework->KeyDown(SDLK_LEFT)) //Checking for movement to the left
  Run (0);
if (g_pFramework->KeyDown(SDLK_RIGHT)) //Same as above for the right
  Run (1);
if (!(g_pFramework->KeyDown(SDLK_LEFT)) && !(g_pFramework->KeyDown(SDLK_RIGHT)))
  CancelRun (); //This method Stops all horizontal movement if neither left or right is pressed
if (g_pFramework->KeyDown(SDLK_DOWN))
{
  if (g_pFramework->KeyDown(SDLK_w))
  {
   cout << "Direction: 3, Action: 1" << endl;
  }
  if (g_pFramework->KeyDown(SDLK_d))
  {
   cout << "Direction: 3, Action: 2" << endl;
  }
  if (g_pFramework->KeyDown(SDLK_s))
  {
   cout << "Direction: 3, Action: 3" << endl;
  }
  if (g_pFramework->KeyDown(SDLK_a))
  {
   cout << "Direction: 3, Action: 4" << endl;
  }
}
CheckJump ();
if (m_bKeyPressed == false)
{
  CancelJump();
}
else
{
  m_bKeyPressed = false;
}
}/
I hope you can help me with this problem, thanks in advance for that Posted Image

#5XeraNox

Posted 09 September 2012 - 05:30 AM

Hello Forum Posted Image
I started working on programming a small 2D platformer with the SDL and had a strange bug in a specific method.

What this method does is first checking for the arrow keys wether they are pressed or not, then for the WASD keys.

Three states are currently used:
The Left/Right keys move the Player two the specified direction.

The combination of the Up-key and the S-key let the Player Jump.

The problem I have now is that the player can't jump and move left at the same time, but he can actually move to the right while jumping.
I've done some testing and found that my program doesn't register the left key while the Up-Key and the S-key are pressed.

The relevant code:

void CPlayer::ProcessMovement ()
{
	if (g_pFramework->KeyDown(SDLK_UP))
	{
		if (g_pFramework->KeyDown(SDLK_w))
		{
			cout << "Direction: 1, Action: 1" << endl;
		}
		if (g_pFramework->KeyDown(SDLK_d))
		{
			cout << "Direction: 1, Action: 2" << endl;
		}
    if (g_pFramework->KeyDown(SDLK_s)) //The code for triggering the jump-fuction
		{
			cout << "Direction: 1, Action: 3" << endl;
			if (m_bJumpAllow == 1)
			{
				cout << "Jump" << endl;
				Jump ();
			}
			m_bKeyPressed = true;
		}
		if (g_pFramework->KeyDown(SDLK_a))
		{
			cout << "Direction: 1, Action: 4" << endl;
		}
	}
	if (g_pFramework->KeyDown(SDLK_LEFT))
	{
		if (g_pFramework->KeyDown(SDLK_w))
		{
		  
		}
		if (g_pFramework->KeyDown(SDLK_d))
		{
			cout << "Direction: 4, Action: 2" << endl;
		}
		if (g_pFramework->KeyDown(SDLK_s))
		{
			cout << "Direction: 4, Action: 3" << endl;
		}
		if (g_pFramework->KeyDown(SDLK_a))
		{
			cout << "Direction: 4, Action: 4" << endl;
		}
	}
	if (g_pFramework->KeyDown(SDLK_RIGHT))
	{
		if (g_pFramework->KeyDown(SDLK_w))
		{
			cout << "Direction: 2, Action: 1" << endl;
		}
		if (g_pFramework->KeyDown(SDLK_d))
		{
			cout << "Direction: 2, Action: 2" << endl;
		}
		if (g_pFramework->KeyDown(SDLK_s))
		{
			cout << "Direction: 2, Action: 3" << endl;
		}
		if (g_pFramework->KeyDown(SDLK_a))
		{
			cout << "Direction: 2, Action: 4" << endl;
		}
	}
    if (g_pFramework->KeyDown(SDLK_LEFT)) //Checks if the player should move left
				Run (0);
	if (g_pFramework->KeyDown(SDLK_RIGHT)) //Does the same thing as above for the right side
				Run (1);
	if (!(g_pFramework->KeyDown(SDLK_LEFT)) && !(g_pFramework->KeyDown(SDLK_RIGHT)))
		CancelRun (); //This function cancels out the movement if neither left or right are pressed.
	if (g_pFramework->KeyDown(SDLK_DOWN))
	{
		if (g_pFramework->KeyDown(SDLK_w))
		{
			cout << "Direction: 3, Action: 1" << endl;
		}
		if (g_pFramework->KeyDown(SDLK_d))
		{
			cout << "Direction: 3, Action: 2" << endl;
		}
		if (g_pFramework->KeyDown(SDLK_s))
		{
			cout << "Direction: 3, Action: 3" << endl;
		}
		if (g_pFramework->KeyDown(SDLK_a))
		{
			cout << "Direction: 3, Action: 4" << endl;
		}
	}
	CheckJump ();
	if (m_bKeyPressed == false)
	{
		CancelJump();
	}
	else
	{
		m_bKeyPressed = false;
	}
}
I hope you can help me with this problem, thanks in advance for that Posted Image

#4XeraNox

Posted 09 September 2012 - 05:29 AM

Hello Forum Posted Image
I started working on programming a small 2D platformer with the SDL and had a strange bug in a specific method.

What this method does is first checking for the arrow keys wether they are pressed or not, then for the WASD keys.

Three states are currently used:
The Left/Right keys move the Player two the specified direction.

The combination of the Up-key and the S-key let the Player Jump.

The problem I have now is that the player can't jump and move left at the same time, but he can actually move to the right while jumping.
I've done some testing and found that my program doesn't register the left key while the Up-Key and the S-key are pressed.

The relevant code:

void CPlayer::ProcessMovement ()
{
    if (g_pFramework->KeyDown(SDLK_UP))
    {
	    if (g_pFramework->KeyDown(SDLK_w))
	    {
		    cout << "Direction: 1, Action: 1" << endl;
	    }
	    if (g_pFramework->KeyDown(SDLK_d))
	    {
		    cout << "Direction: 1, Action: 2" << endl;
	    }
	   [b] if (g_pFramework->KeyDown(SDLK_s)) //The code for triggering the jump-fuction
	    {
		    cout << "Direction: 1, Action: 3" << endl;
		    if (m_bJumpAllow == 1)
		    {
			    cout << "Jump" << endl;
			    Jump ();
		    }
		    m_bKeyPressed = true;
	    }[/b]
	    if (g_pFramework->KeyDown(SDLK_a))
	    {
		    cout << "Direction: 1, Action: 4" << endl;
	    }
    }
    if (g_pFramework->KeyDown(SDLK_LEFT))
    {
	    if (g_pFramework->KeyDown(SDLK_w))
	    {
		   
	    }
	    if (g_pFramework->KeyDown(SDLK_d))
	    {
		    cout << "Direction: 4, Action: 2" << endl;
	    }
	    if (g_pFramework->KeyDown(SDLK_s))
	    {
		    cout << "Direction: 4, Action: 3" << endl;
	    }
	    if (g_pFramework->KeyDown(SDLK_a))
	    {
		    cout << "Direction: 4, Action: 4" << endl;
	    }
    }
    if (g_pFramework->KeyDown(SDLK_RIGHT))
    {
	    if (g_pFramework->KeyDown(SDLK_w))
	    {
		    cout << "Direction: 2, Action: 1" << endl;
	    }
	    if (g_pFramework->KeyDown(SDLK_d))
	    {
		    cout << "Direction: 2, Action: 2" << endl;
	    }
	    if (g_pFramework->KeyDown(SDLK_s))
	    {
		    cout << "Direction: 2, Action: 3" << endl;
	    }
	    if (g_pFramework->KeyDown(SDLK_a))
	    {
		    cout << "Direction: 2, Action: 4" << endl;
	    }
    }
	[b]if (g_pFramework->KeyDown(SDLK_LEFT)) //Checks if the player should move left
			    Run (0);
    if (g_pFramework->KeyDown(SDLK_RIGHT)) //Does the same thing as above for the right side
			    Run (1);
    if (!(g_pFramework->KeyDown(SDLK_LEFT)) && !(g_pFramework->KeyDown(SDLK_RIGHT)))
	    CancelRun (); //This function cancels out the movement if neither left or right are pressed.[/b]
    if (g_pFramework->KeyDown(SDLK_DOWN))
    {
	    if (g_pFramework->KeyDown(SDLK_w))
	    {
		    cout << "Direction: 3, Action: 1" << endl;
	    }
	    if (g_pFramework->KeyDown(SDLK_d))
	    {
		    cout << "Direction: 3, Action: 2" << endl;
	    }
	    if (g_pFramework->KeyDown(SDLK_s))
	    {
		    cout << "Direction: 3, Action: 3" << endl;
	    }
	    if (g_pFramework->KeyDown(SDLK_a))
	    {
		    cout << "Direction: 3, Action: 4" << endl;
	    }
    }
    CheckJump ();
    if (m_bKeyPressed == false)
    {
	    CancelJump();
    }
    else
    {
	    m_bKeyPressed = false;
    }
}
I hope you can help me with this problem, thanks in advance for that Posted Image

#3XeraNox

Posted 09 September 2012 - 05:28 AM

Hello Forum Posted Image
I started working on programming a small 2D platformer with the SDL and had a strange bug in a specific method.

What this method does is first checking for the arrow keys wether they are pressed or not, then for the WASD keys.

Three states are currently used:
The Left/Right keys move the Player two the specified direction.

The combination of the Up-key and the S-key let the Player Jump.

The problem I have now is that the player can't jump and move left at the same time, but he can actually move to the right while jumping.
I've done some testing and found that my program doesn't register the left key while the Up-Key and the S-key are pressed.

The relevant code:
[source lang="cpp"]void CPlayer::ProcessMovement (){ if (g_pFramework->KeyDown(SDLK_UP)) { if (g_pFramework->KeyDown(SDLK_w)) { cout << "Direction: 1, Action: 1" << endl; } if (g_pFramework->KeyDown(SDLK_d)) { cout << "Direction: 1, Action: 2" << endl; } [b]if (g_pFramework->KeyDown(SDLK_s)) //The code for triggering the jump-fuction { cout << "Direction: 1, Action: 3" << endl; if (m_bJumpAllow == 1) { cout << "Jump" << endl; Jump (); } m_bKeyPressed = true; }[/b] if (g_pFramework->KeyDown(SDLK_a)) { cout << "Direction: 1, Action: 4" << endl; } } if (g_pFramework->KeyDown(SDLK_LEFT)) { if (g_pFramework->KeyDown(SDLK_w)) { } if (g_pFramework->KeyDown(SDLK_d)) { cout << "Direction: 4, Action: 2" << endl; } if (g_pFramework->KeyDown(SDLK_s)) { cout << "Direction: 4, Action: 3" << endl; } if (g_pFramework->KeyDown(SDLK_a)) { cout << "Direction: 4, Action: 4" << endl; } } if (g_pFramework->KeyDown(SDLK_RIGHT)) { if (g_pFramework->KeyDown(SDLK_w)) { cout << "Direction: 2, Action: 1" << endl; } if (g_pFramework->KeyDown(SDLK_d)) { cout << "Direction: 2, Action: 2" << endl; } if (g_pFramework->KeyDown(SDLK_s)) { cout << "Direction: 2, Action: 3" << endl; } if (g_pFramework->KeyDown(SDLK_a)) { cout << "Direction: 2, Action: 4" << endl; } } [b]if (g_pFramework->KeyDown(SDLK_LEFT)) //Checks if the player should move left Run (0); if (g_pFramework->KeyDown(SDLK_RIGHT)) //Does the same thing as above for the right side Run (1);[/b] [b]if (!(g_pFramework->KeyDown(SDLK_LEFT)) && !(g_pFramework->KeyDown(SDLK_RIGHT))) CancelRun (); //This function cancels out the movement if neither left or right are pressed.[/b] if (g_pFramework->KeyDown(SDLK_DOWN)) { if (g_pFramework->KeyDown(SDLK_w)) { cout << "Direction: 3, Action: 1" << endl; } if (g_pFramework->KeyDown(SDLK_d)) { cout << "Direction: 3, Action: 2" << endl; } if (g_pFramework->KeyDown(SDLK_s)) { cout << "Direction: 3, Action: 3" << endl; } if (g_pFramework->KeyDown(SDLK_a)) { cout << "Direction: 3, Action: 4" << endl; } } CheckJump (); if (m_bKeyPressed == false) { CancelJump(); } else { m_bKeyPressed = false; }}[/source]
I hope you can help me with this problem, thanks in advance for that Posted Image

#2XeraNox

Posted 09 September 2012 - 05:28 AM

Hello Forum Posted Image
I started working on programming a small 2D platformer with the SDL and had a strange bug in a specific method.

What this method does is first checking for the arrow keys wether they are pressed or not, then for the WASD keys.

Three states are currently used:
The Left/Right keys move the Player two the specified direction.

The combination of the Up-key and the S-key let the Player Jump.

The problem I have now is that the player can't jump and move left at the same time, but he can actually move to the right while jumping.
I've done some testing and found that my program doesn't register the left key while the Up-Key and the S-key are pressed.

The relevant code:
[source lang="cpp"]void CPlayer::ProcessMovement (){ if (g_pFramework->KeyDown(SDLK_UP)) { if (g_pFramework->KeyDown(SDLK_w)) { cout << "Direction: 1, Action: 1" << endl; } if (g_pFramework->KeyDown(SDLK_d)) { cout << "Direction: 1, Action: 2" << endl; } [b]if (g_pFramework->KeyDown(SDLK_s)) //The code for triggering the jump-fuction { cout << "Direction: 1, Action: 3" << endl; if (m_bJumpAllow == 1) { cout << "Jump" << endl; Jump (); } m_bKeyPressed = true; }[/b] if (g_pFramework->KeyDown(SDLK_a)) { cout << "Direction: 1, Action: 4" << endl; } } if (g_pFramework->KeyDown(SDLK_LEFT)) { if (g_pFramework->KeyDown(SDLK_w)) { } if (g_pFramework->KeyDown(SDLK_d)) { cout << "Direction: 4, Action: 2" << endl; } if (g_pFramework->KeyDown(SDLK_s)) { cout << "Direction: 4, Action: 3" << endl; } if (g_pFramework->KeyDown(SDLK_a)) { cout << "Direction: 4, Action: 4" << endl; } } if (g_pFramework->KeyDown(SDLK_RIGHT)) { if (g_pFramework->KeyDown(SDLK_w)) { cout << "Direction: 2, Action: 1" << endl; } if (g_pFramework->KeyDown(SDLK_d)) { cout << "Direction: 2, Action: 2" << endl; } if (g_pFramework->KeyDown(SDLK_s)) { cout << "Direction: 2, Action: 3" << endl; } if (g_pFramework->KeyDown(SDLK_a)) { cout << "Direction: 2, Action: 4" << endl; } } [b]if (g_pFramework->KeyDown(SDLK_LEFT)) //Checks if the player should move left Run (0); if (g_pFramework->KeyDown(SDLK_RIGHT)) //Does the same thing as above for the right side Run (1);[/b] [b]if (!(g_pFramework->KeyDown(SDLK_LEFT)) && !(g_pFramework->KeyDown(SDLK_RIGHT))) CancelRun (); //This function cancels out the movement if neither left or right are pressed.[/b] if (g_pFramework->KeyDown(SDLK_DOWN)) { if (g_pFramework->KeyDown(SDLK_w)) { cout << "Direction: 3, Action: 1" << endl; } if (g_pFramework->KeyDown(SDLK_d)) { cout << "Direction: 3, Action: 2" << endl; } if (g_pFramework->KeyDown(SDLK_s)) { cout << "Direction: 3, Action: 3" << endl; } if (g_pFramework->KeyDown(SDLK_a)) { cout << "Direction: 3, Action: 4" << endl; } } CheckJump (); if (m_bKeyPressed == false) { CancelJump(); } else { m_bKeyPressed = false; }}[/source]
I hope you can help me with this problem, thanks in advance for that Posted Image

#1XeraNox

Posted 09 September 2012 - 05:27 AM

Hello Forum :)
I started working on programming a small 2D platformer with the SDL and had a strange bug in a specific method.

What this method does is first checking for the arrow keys wether they are pressed or not, then for the WASD keys.

Three states are currently used:
The Left/Right keys move the Player two the specified direction.

The combination of the Up-key and the S-key let the Player Jump.

The problem I have now is that the player can't jump and move left at the same time, but he can actually move to the right while jumping.
I've done some testing and found that my program doesn't register the left key while the Up-Key and the S-key are pressed.

The relevant code:
[source lang="cpp"]void CPlayer::ProcessMovement (){ if (g_pFramework->KeyDown(SDLK_UP)) { if (g_pFramework->KeyDown(SDLK_w)) { cout << "Direction: 1, Action: 1" << endl; } if (g_pFramework->KeyDown(SDLK_d)) { cout << "Direction: 1, Action: 2" << endl; } [b]if (g_pFramework->KeyDown(SDLK_s)) //The code for triggering the jump-fuction { cout << "Direction: 1, Action: 3" << endl; if (m_bJumpAllow == 1) { cout << "Jump" << endl; Jump (); } m_bKeyPressed = true; }[/b] if (g_pFramework->KeyDown(SDLK_a)) { cout << "Direction: 1, Action: 4" << endl; } } if (g_pFramework->KeyDown(SDLK_LEFT)) { if (g_pFramework->KeyDown(SDLK_w)) { } if (g_pFramework->KeyDown(SDLK_d)) { cout << "Direction: 4, Action: 2" << endl; } if (g_pFramework->KeyDown(SDLK_s)) { cout << "Direction: 4, Action: 3" << endl; } if (g_pFramework->KeyDown(SDLK_a)) { cout << "Direction: 4, Action: 4" << endl; } } if (g_pFramework->KeyDown(SDLK_RIGHT)) { if (g_pFramework->KeyDown(SDLK_w)) { cout << "Direction: 2, Action: 1" << endl; } if (g_pFramework->KeyDown(SDLK_d)) { cout << "Direction: 2, Action: 2" << endl; } if (g_pFramework->KeyDown(SDLK_s)) { cout << "Direction: 2, Action: 3" << endl; } if (g_pFramework->KeyDown(SDLK_a)) { cout << "Direction: 2, Action: 4" << endl; } } [b]if (g_pFramework->KeyDown(SDLK_LEFT)) //Checks if the player should move left Run (0); if (g_pFramework->KeyDown(SDLK_RIGHT)) //Does the same thing as above for the right side Run (1);[/b] [b]if (!(g_pFramework->KeyDown(SDLK_LEFT)) && !(g_pFramework->KeyDown(SDLK_RIGHT))) CancelRun (); //This function cancels out the movement if neither left or right are pressed.[/b] if (g_pFramework->KeyDown(SDLK_DOWN)) { if (g_pFramework->KeyDown(SDLK_w)) { cout << "Direction: 3, Action: 1" << endl; } if (g_pFramework->KeyDown(SDLK_d)) { cout << "Direction: 3, Action: 2" << endl; } if (g_pFramework->KeyDown(SDLK_s)) { cout << "Direction: 3, Action: 3" << endl; } if (g_pFramework->KeyDown(SDLK_a)) { cout << "Direction: 3, Action: 4" << endl; } } CheckJump (); if (m_bKeyPressed == false) { CancelJump(); } else { m_bKeyPressed = false; }}[/source]
I hope you can help me with this problem, thanks in advance for that :)

PARTNERS