How to move 2 images w/the arrow keys, 1 working only while the alt key is held in combin. with an arrow key, the oth...

The Partridge Family were neither partridges nor a family. Discuss.
TheCollector
Posts: 41
Joined: August 1st, 2019, 9:57 pm

Re: How to move 2 images w/the arrow keys, 1 working only while the alt key is held in combin. with an arrow key, the ot

Post by TheCollector » August 2nd, 2019, 6:53 pm

Figured it out using step-over in the debugger.

TheCollector
Posts: 41
Joined: August 1st, 2019, 9:57 pm

Re: How to move 2 images w/the arrow keys, 1 working only while the alt key is held in combin. with an arrow key, the ot

Post by TheCollector » August 2nd, 2019, 6:54 pm

Figured it out using step-over in the debugger. Ended up adding an else statement to put the focus back on the reticle if the boat is not in use.

albinopapa
Posts: 3790
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: How to move 2 images w/the arrow keys, 1 working only while the alt key is held in combin. with an arrow key, the ot

Post by albinopapa » August 2nd, 2019, 8:09 pm

Try something like this:

Code: Select all

void Game::UpdateModel()
{
	// Keep all state changes in close vicinity to each other to make it
	// easier to find
	if( wnd.kbd.KeyIsPressed( VK_RETURN ) )
	{
		BoatIsInitiated = true;
		CrossHairIsInitiated = false;
	}
	else if( wnd.kbd.KeyIsPressed( VK_SHIFT ) )
	{
		BoatIsInitiated = false;
		CrossHairIsInitiated = true;

		// While cross hair is active, don't need to inhibit movement
		InhibitUp = false;
		InhibitDown = false;
		InhibitLeft = false;
		InhibitRight = false;
	}

	if( BoatIsInitiated )
	{
		// What this pattern does is if UP or DOWN is pressed and 
		// not inhibited then update boat velocity and if they are 
		// but the keys is not pressed then set the inhibit flags to false.
		// It also allows the cpu to skip the other cases once it finds a 
		// true case, so no need to check the rest.
		if( wnd.kbd.KeyIsPressed( VK_UP ) == true && InhibitUp == false )
		{
			bvy = bvy - 1;
			InhibitUp = true;
		}
		else if( wnd.kbd.KeyIsPressed( VK_DOWN ) == true && InhibitDown == false )
		{
			bvy = bvy + 1;
			InhibitDown = true;
		}
		else if( wnd.kbd.KeyIsPressed( VK_UP ) == false && InhibitUp == true )
		{
			InhibitUp = false;
		}
		else if( wnd.kbd.KeyIsPressed( VK_DOWN ) == false && InhibitDown == true )
		{
			InhibitDown = false;
		}

		// Since you can move in diagonal directions, this is a separate block
		// than the UP and DOWN, but still employs the same idea.
		if( wnd.kbd.KeyIsPressed( VK_LEFT ) == true && InhibitLeft == false )
		{
			bvx = bvx - 1;
			InhibitLeft = true;
		}
		else if( wnd.kbd.KeyIsPressed( VK_RIGHT ) == true && InhibitRight == false )
		{
			bvx = bvx + 1;
			InhibitRight = true;
		}
		else if( wnd.kbd.KeyIsPressed( VK_LEFT ) == false && InhibitLeft == true )
		{
			InhibitLeft = false;
		}
		else if( wnd.kbd.KeyIsPressed( VK_RIGHT ) == false && InhibitRight == true )
		{
			InhibitRight = false;
		}
	}
	else if( CrossHairIsInitiated )
	{
		//Color change for reticle
		if( wnd.kbd.KeyIsPressed( VK_CONTROL ) )
		{
			chgb = 0;
		}

		if(wnd.kbd.KeyIsPressed(VK_UP))
		{
			//Move reticle up
			chy = chy - 3;
		}
		else if( wnd.kbd.KeyIsPressed( VK_DOWN ) )
		{
			//Move reticle down
			chy = chy + 3;
		}

		if( wnd.kbd.KeyIsPressed( VK_LEFT ) )
		{
			//Move reticle left
			chx = chx - 3;
		}
		else if( wnd.kbd.KeyIsPressed( VK_RIGHT ) )
		{
			//Move reticle right
			chx = chx + 3;
		}
	}
	
	bx = bx + bvx;
	by = by + bvy;

}
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

albinopapa
Posts: 3790
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: How to move 2 images w/the arrow keys, 1 working only while the alt key is held in combin. with an arrow key, the ot

Post by albinopapa » August 2nd, 2019, 8:10 pm

Ha, yeah, had this all worked up for nothing lol. Good job working through it.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Post Reply